Skip to content

Commit

Permalink
skip final resolution if dynamic import has already been rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Feb 3, 2019
1 parent 364e3fe commit e90c19a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ast/nodes/Import.ts
Expand Up @@ -47,6 +47,7 @@ export default class Import extends NodeBase {

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

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

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

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

this.rendered = true;
return;
}

Expand All @@ -87,6 +91,8 @@ 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 e90c19a

Please sign in to comment.