Return a unique identifier node for each use.
This commit is contained in:
parent
20679979fc
commit
47a254025a
@ -220,7 +220,7 @@ export default class File extends Store {
|
||||
prependDeclaration(specifiers);
|
||||
}
|
||||
|
||||
return id;
|
||||
return t.identifier(id.name);
|
||||
}
|
||||
|
||||
addHelper(name: string): Object {
|
||||
|
||||
@ -1,11 +1,6 @@
|
||||
export default class Store {
|
||||
constructor() {
|
||||
this._map = new Map();
|
||||
this._map.dynamicData = {};
|
||||
}
|
||||
|
||||
setDynamic(key, fn) {
|
||||
this._map.dynamicData[key] = fn;
|
||||
}
|
||||
|
||||
set(key: string, val) {
|
||||
@ -15,12 +10,6 @@ export default class Store {
|
||||
get(key: string): any {
|
||||
if (this._map.has(key)) {
|
||||
return this._map.get(key);
|
||||
} else {
|
||||
if (Object.prototype.hasOwnProperty.call(this._map.dynamicData, key)) {
|
||||
const val = this._map.dynamicData[key]();
|
||||
this._map.set(key, val);
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user