Skip to content

Commit

Permalink
fix import alias
Browse files Browse the repository at this point in the history
  • Loading branch information
FogelAI committed Sep 9, 2023
1 parent fb2d37e commit b96217a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-barrels",
"version": "1.0.5",
"version": "1.0.6",
"description": "This Babel plugin transforms indirect imports through a barrel file (index.js) into direct imports.",
"homepage": "https://github.com/FogelAI/babel-plugin-transform-barrels",
"main": "src/barrel.js",
Expand Down
10 changes: 5 additions & 5 deletions src/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class AST {
} else return "named";
}

static createASTImportDeclaration = ({exportedName: specifierLocalName, localName: specifierImportedName, path: modulePath, type: specifierType}) => {
static createASTImportDeclaration = ({localName, importedName, path, type}) => {
return t.importDeclaration(
[
specifierType === "named"
? t.importSpecifier(t.identifier(specifierLocalName),t.identifier(specifierImportedName))
: t.importDefaultSpecifier(t.identifier(specifierLocalName))
type === "named"
? t.importSpecifier(t.identifier(localName),t.identifier(importedName))
: t.importDefaultSpecifier(t.identifier(localName))
,
],
t.stringLiteral(modulePath)
t.stringLiteral(path)
)
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/barrel.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,13 @@ const importDeclarationVisitor = (path, state) => {
importModuleAbsolutePath,
specifier.imported.name
);
return AST.createASTImportDeclaration(directSpecifierObject);
const newImportProperties = {
localName: specifier.local.name,
importedName: directSpecifierObject["localName"],
path: directSpecifierObject["path"],
type: directSpecifierObject["type"],
}
return AST.createASTImportDeclaration(newImportProperties);
}
);
path.replaceWithMultiple(directSpecifierASTArray);
Expand Down

0 comments on commit b96217a

Please sign in to comment.