Skip to content

Commit

Permalink
fix: support case of import module with aliased name (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia committed Aug 16, 2023
1 parent 41b5c9c commit 1ae3423
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/node-transform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/swc-plugin-node-transform",
"version": "0.1.1",
"version": "0.1.2",
"license": "MIT",
"keywords": ["swc-plugin"],
"main": "swc_plugin_node_transform.wasm",
Expand Down
8 changes: 6 additions & 2 deletions packages/node-transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,17 @@ impl Fold for NodeTransform {
match specifier {
ImportSpecifier::Named(named) => {
let ImportNamedSpecifier {
local, ..
local, imported, ..
} = named;
let mut property = &local.sym;
if let Some(ModuleExportName::Ident(import_ident)) = imported {
property = &import_ident.sym;
}
new_module_items.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Const,
declare: false,
decls: vec![create_member_decl(local.clone(), &import_val, &local.sym)],
decls: vec![create_member_decl(local.clone(), &import_val, property)],
})))))
}
ImportSpecifier::Namespace(namespace) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/node-transform/tests/fixture/import-local/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { a as b } from 'test';

console.log(b);
3 changes: 3 additions & 0 deletions packages/node-transform/tests/fixture/import-local/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const __ice_import_0__ = await __ice_import__("test");
const b = __ice_import_0__.a;
console.log(b);

0 comments on commit 1ae3423

Please sign in to comment.