Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: register injected importDeclaration #10172

Merged
merged 2 commits into from Jul 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -35,6 +35,11 @@ export default declare(api => {

path.replaceWithMultiple(nodes);
},
ImportDefaultSpecifier(path) {
if (!path.scope.hasOwnBinding(path.node.local.name)) {
path.scope.registerDeclaration(path.parentPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to do this as soon as the import declaration is created, in the ExportNamedDeclaration visitor. This makes it clearer why we are doing it, and it prevents other plugin from running between the creating the declaration and registering it.

path.replaceWithMultiple(nodes); returns an array containing the new inserted paths: the first one should be the import declaration, and you can get it's default specifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.replaceWithMultiple(nodes) returns an array containing the new inserted paths.

Yes it is. It seems that @types/babel__traverse declares out-of-dated signature here.

}
},
},
};
});
@@ -0,0 +1 @@
export foo from "bar";
@@ -0,0 +1,3 @@
{
"plugins": ["proposal-export-default-from", "transform-typescript"]
}
@@ -0,0 +1,2 @@
import _foo from "bar";
export { _foo as foo };
Expand Up @@ -45,6 +45,11 @@ export default declare(api => {

path.replaceWithMultiple(nodes);
},
ImportNamespaceSpecifier(path) {
if (!path.scope.hasOwnBinding(path.node.local.name)) {
path.scope.registerDeclaration(path.parentPath);
}
},
},
};
});
@@ -0,0 +1 @@
export * as foo from "bar";
@@ -0,0 +1,3 @@
{
"plugins": ["proposal-export-namespace-from", "transform-typescript"]
}
@@ -0,0 +1,2 @@
import * as _foo from "bar";
export { _foo as foo };