Skip to content

Commit

Permalink
feat(babel/compat): Support type-only import/export specifiers (#2342)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane authored Oct 5, 2021
1 parent b64afb5 commit ef4c80b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions ecmascript/babel/ast/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ pub enum ExportKind {
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
#[serde(tag = "type")]
pub struct ExportSpecifier {
#[serde(flatten)]
pub base: BaseNode,
pub local: Identifier,
pub exported: IdOrString,
pub export_kind: ExportKind,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down
5 changes: 5 additions & 0 deletions ecmascript/babel/compat/src/babelify/module_decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ impl Babelify for ExportNamedSpecifier {
base: ctx.base(self.span),
local: self.orig.clone().babelify(ctx),
exported: IdOrString::Id(self.exported.unwrap_or(self.orig).babelify(ctx)),
export_kind: if self.is_type_only {
ExportKind::Type
} else {
ExportKind::Value
},
}
}
}
14 changes: 7 additions & 7 deletions ecmascript/babel/compat/src/swcify/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use swc_babel_ast::{
DeclareClass, DeclareExportAllDeclaration, DeclareExportDeclaration, DeclareFunction,
DeclareInterface, DeclareModule, DeclareModuleExports, DeclareTypeAlias, DeclareVariable,
DoWhileStatement, EmptyStatement, ExportAllDeclaration, ExportDefaultDeclType,
ExportDefaultDeclaration, ExportNamedDeclaration, ExpressionStatement, ForInStatement,
ForOfStatement, ForStatement, ForStmtInit, ForStmtLeft, FunctionDeclaration, IdOrString,
IfStatement, ImportAttribute, ImportDeclaration, ImportKind, ImportNamespaceSpecifier,
ImportSpecifierType, LabeledStatement, ReturnStatement, Statement, SwitchStatement,
ThrowStatement, TryStatement, VariableDeclaration, VariableDeclarationKind, VariableDeclarator,
WhileStatement, WithStatement,
ExportDefaultDeclaration, ExportKind, ExportNamedDeclaration, ExpressionStatement,
ForInStatement, ForOfStatement, ForStatement, ForStmtInit, ForStmtLeft, FunctionDeclaration,
IdOrString, IfStatement, ImportAttribute, ImportDeclaration, ImportKind,
ImportNamespaceSpecifier, ImportSpecifierType, LabeledStatement, ReturnStatement, Statement,
SwitchStatement, ThrowStatement, TryStatement, VariableDeclaration, VariableDeclarationKind,
VariableDeclarator, WhileStatement, WithStatement,
};
use swc_common::DUMMY_SP;
use swc_ecma_ast::{
Expand Down Expand Up @@ -568,7 +568,7 @@ impl Swcify for swc_babel_ast::ExportSpecifier {
span: ctx.span(&self.base),
orig: self.local.swcify(ctx).id,
exported: Some(self.exported.swcify(ctx).expect_ident()),
is_type_only: false, // TODO: update this once Babel supports
is_type_only: matches!(self.export_kind, ExportKind::Type),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@
"identifierName": "a"
},
"name": "a"
}
},
"exportKind": "value"
}
],
"source": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@
"identifierName": "y"
},
"name": "y"
}
},
"exportKind": "value"
}
],
"source": null,
Expand Down
1 change: 1 addition & 0 deletions ecmascript/babel/visit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,7 @@ define!({
pub base: BaseNode,
pub local: Identifier,
pub exported: IdOrString,
pub export_kind: ExportKind,
}
pub struct ExportDefaultSpecifier {
pub base: BaseNode,
Expand Down

0 comments on commit ef4c80b

Please sign in to comment.