Skip to content

Commit 7a4c331

Browse files
authored
Visit default export expressions (#18977)
1 parent 28658de commit 7a4c331

6 files changed

+56
-2
lines changed

src/compiler/transformers/module/module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,10 +861,10 @@ namespace ts {
861861
if (original && hasAssociatedEndOfDeclarationMarker(original)) {
862862
// Defer exports until we encounter an EndOfDeclarationMarker node
863863
const id = getOriginalNodeId(node);
864-
deferredExports[id] = appendExportStatement(deferredExports[id], createIdentifier("default"), node.expression, /*location*/ node, /*allowComments*/ true);
864+
deferredExports[id] = appendExportStatement(deferredExports[id], createIdentifier("default"), visitNode(node.expression, importCallExpressionVisitor), /*location*/ node, /*allowComments*/ true);
865865
}
866866
else {
867-
statements = appendExportStatement(statements, createIdentifier("default"), node.expression, /*location*/ node, /*allowComments*/ true);
867+
statements = appendExportStatement(statements, createIdentifier("default"), visitNode(node.expression, importCallExpressionVisitor), /*location*/ node, /*allowComments*/ true);
868868
}
869869

870870
return singleOrMany(statements);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/compiler/dynamicImportInDefaultExportExpression.ts(3,23): error TS2307: Cannot find module './foo2'.
2+
3+
4+
==== tests/cases/compiler/dynamicImportInDefaultExportExpression.ts (1 errors) ====
5+
export default {
6+
getInstance: function () {
7+
return import('./foo2');
8+
~~~~~~~~
9+
!!! error TS2307: Cannot find module './foo2'.
10+
}
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [dynamicImportInDefaultExportExpression.ts]
2+
export default {
3+
getInstance: function () {
4+
return import('./foo2');
5+
}
6+
}
7+
8+
//// [dynamicImportInDefaultExportExpression.js]
9+
"use strict";
10+
exports.__esModule = true;
11+
exports["default"] = {
12+
getInstance: function () {
13+
return Promise.resolve().then(function () { return require('./foo2'); });
14+
}
15+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/dynamicImportInDefaultExportExpression.ts ===
2+
export default {
3+
getInstance: function () {
4+
>getInstance : Symbol(getInstance, Decl(dynamicImportInDefaultExportExpression.ts, 0, 16))
5+
6+
return import('./foo2');
7+
}
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/dynamicImportInDefaultExportExpression.ts ===
2+
export default {
3+
>{ getInstance: function () { return import('./foo2'); }} : { getInstance: () => Promise<any>; }
4+
5+
getInstance: function () {
6+
>getInstance : () => Promise<any>
7+
>function () { return import('./foo2'); } : () => Promise<any>
8+
9+
return import('./foo2');
10+
>import('./foo2') : Promise<any>
11+
>'./foo2' : "./foo2"
12+
}
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @skipLibCheck: true
2+
// @lib: es6
3+
export default {
4+
getInstance: function () {
5+
return import('./foo2');
6+
}
7+
}

0 commit comments

Comments
 (0)