Return a unique identifier node for each use.

This commit is contained in:
Logan Smyth
2017-09-08 02:11:04 -07:00
parent 20679979fc
commit 47a254025a
3 changed files with 9 additions and 21 deletions

View File

@@ -39,24 +39,23 @@ export default function({ types: t }) {
);
}
this.setDynamic("regeneratorIdentifier", function() {
return file.addImport(
`${moduleName}/regenerator`,
"default",
"regeneratorRuntime",
);
});
this.moduleName = moduleName;
},
visitor: {
ReferencedIdentifier(path, state) {
const { node, parent, scope } = path;
if (
node.name === "regeneratorRuntime" &&
state.opts.regenerator !== false
) {
path.replaceWith(state.get("regeneratorIdentifier"));
path.replaceWith(
this.file.addImport(
`${this.moduleName}/regenerator`,
"default",
"regeneratorRuntime",
),
);
return;
}