Skip to content

Commit

Permalink
only mark dynamic import as replaced if it was completely overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored and lukastaegert committed Feb 14, 2019
1 parent 127f191 commit 0a1ceb0
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/ast/nodes/Import.ts
Expand Up @@ -47,7 +47,7 @@ export default class Import extends NodeBase {

private resolutionNamespace: string;
private resolutionInterop: boolean;
private rendered: boolean;
private replaced: boolean;

include() {
this.included = true;
Expand All @@ -56,14 +56,14 @@ export default class Import extends NodeBase {

initialise() {
this.included = false;
this.rendered = false;
this.replaced = false;
this.resolutionNamespace = undefined;
this.resolutionInterop = false;
this.context.addDynamicImport(this);
}

renderFinalResolution(code: MagicString, resolution: string) {
if (this.included && !this.rendered) {
if (this.included && !this.replaced) {
code.overwrite(this.parent.arguments[0].start, this.parent.arguments[0].end, resolution);
}
}
Expand All @@ -78,7 +78,7 @@ export default class Import extends NodeBase {
`Promise.resolve().then(function${_}()${_}{${_}return ${this.resolutionNamespace}${s}${_}})`
);

this.rendered = true;
this.replaced = true;
return;
}

Expand All @@ -91,8 +91,6 @@ export default class Import extends NodeBase {
const rightMechanism =
(this.resolutionInterop && importMechanism.interopRight) || importMechanism.right;
code.overwrite(this.parent.arguments[0].end, this.parent.end, rightMechanism);

this.rendered = true;
}
}

Expand Down

0 comments on commit 0a1ceb0

Please sign in to comment.