Skip to content

Commit 96be4f4

Browse files
crisbetoleonsenft
authored andcommitted
fix(compiler): abstract emitter producing incorrect code for dynamic imports
Fixes that the abstract emitter wasn't adding quotes around the URL of a dynamic import.
1 parent 5e99ae9 commit 96be4f4

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

packages/compiler/src/output/abstract_emitter.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,15 @@ export abstract class AbstractEmitterVisitor
396396

397397
visitDynamicImportExpr(ast: o.DynamicImportExpr, ctx: EmitterVisitorContext): void {
398398
this.printLeadingComments(ast, ctx);
399-
ctx.print(ast, `import(${ast.url})`);
399+
ctx.print(ast, `import(`);
400+
401+
if (typeof ast.url === 'string') {
402+
ctx.print(ast, escapeIdentifier(ast.url, true)!);
403+
} else {
404+
ast.url.visitExpression(this, ctx);
405+
}
406+
407+
ctx.print(ast, `)`);
400408
}
401409

402410
visitNotExpr(ast: o.NotExpr, ctx: EmitterVisitorContext): void {
@@ -409,13 +417,14 @@ export abstract class AbstractEmitterVisitor
409417
this.printLeadingComments(ast, ctx);
410418
ctx.print(ast, `function${ast.name ? ' ' + ast.name : ''}(`);
411419
this.visitParams(ast.params, ctx);
412-
ctx.println(ast, `)`);
420+
ctx.print(ast, `)`);
413421
ast.type?.visitType(this, ctx);
414-
ctx.println(ast, ` {`);
422+
ctx.print(ast, ` {`);
423+
ctx.println(ast);
415424
ctx.incIndent();
416425
this.visitAllStatements(ast.statements, ctx);
417426
ctx.decIndent();
418-
ctx.print(ast, `}`);
427+
ctx.println(ast, `}`);
419428
}
420429

421430
visitArrowFunctionExpr(ast: o.ArrowFunctionExpr, ctx: EmitterVisitorContext): void {
@@ -424,14 +433,15 @@ export abstract class AbstractEmitterVisitor
424433
this.visitParams(ast.params, ctx);
425434
ctx.print(ast, ')');
426435
ast.type?.visitType(this, ctx);
427-
ctx.print(ast, ' =>');
436+
ctx.print(ast, ' => ');
428437

429438
if (Array.isArray(ast.body)) {
430-
ctx.println(ast, `{`);
439+
ctx.print(ast, `{`);
440+
ctx.println(ast);
431441
ctx.incIndent();
432442
this.visitAllStatements(ast.body, ctx);
433443
ctx.decIndent();
434-
ctx.print(ast, `}`);
444+
ctx.println(ast, `}`);
435445
} else {
436446
const shouldParenthesize = this.shouldParenthesize(ast.body, ast);
437447

@@ -451,9 +461,10 @@ export abstract class AbstractEmitterVisitor
451461
this.printLeadingComments(stmt, ctx);
452462
ctx.print(stmt, `function ${stmt.name}(`);
453463
this.visitParams(stmt.params, ctx);
454-
ctx.println(stmt, `)`);
464+
ctx.print(stmt, `)`);
455465
stmt.type?.visitType(this, ctx);
456-
ctx.println(stmt, ` {`);
466+
ctx.print(stmt, ` {`);
467+
ctx.println(stmt);
457468
ctx.incIndent();
458469
this.visitAllStatements(stmt.statements, ctx);
459470
ctx.decIndent();

0 commit comments

Comments
 (0)