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);
|
prependDeclaration(specifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
return id;
|
return t.identifier(id.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
addHelper(name: string): Object {
|
addHelper(name: string): Object {
|
||||||
|
|||||||
@ -1,11 +1,6 @@
|
|||||||
export default class Store {
|
export default class Store {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._map = new Map();
|
this._map = new Map();
|
||||||
this._map.dynamicData = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
setDynamic(key, fn) {
|
|
||||||
this._map.dynamicData[key] = fn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set(key: string, val) {
|
set(key: string, val) {
|
||||||
@ -15,12 +10,6 @@ export default class Store {
|
|||||||
get(key: string): any {
|
get(key: string): any {
|
||||||
if (this._map.has(key)) {
|
if (this._map.has(key)) {
|
||||||
return this._map.get(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() {
|
this.moduleName = moduleName;
|
||||||
return file.addImport(
|
|
||||||
`${moduleName}/regenerator`,
|
|
||||||
"default",
|
|
||||||
"regeneratorRuntime",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
visitor: {
|
visitor: {
|
||||||
ReferencedIdentifier(path, state) {
|
ReferencedIdentifier(path, state) {
|
||||||
const { node, parent, scope } = path;
|
const { node, parent, scope } = path;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
node.name === "regeneratorRuntime" &&
|
node.name === "regeneratorRuntime" &&
|
||||||
state.opts.regenerator !== false
|
state.opts.regenerator !== false
|
||||||
) {
|
) {
|
||||||
path.replaceWith(state.get("regeneratorIdentifier"));
|
path.replaceWith(
|
||||||
|
this.file.addImport(
|
||||||
|
`${this.moduleName}/regenerator`,
|
||||||
|
"default",
|
||||||
|
"regeneratorRuntime",
|
||||||
|
),
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user