Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit be375cb

Browse filesBrowse files
author
Kanchalai Tanglertsampan
committed
Fix missing import call expression in function and class declaration
1 parent ffbb445 commit be375cb
Copy full SHA for be375cb

4 files changed

+68-11Lines changed: 68 additions & 11 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/transformers/module/module.ts‎

Copy file name to clipboardExpand all lines: src/compiler/transformers/module/module.ts
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,11 @@ namespace ts {
482482
return visitEndOfDeclarationMarker(<EndOfDeclarationMarker>node);
483483

484484
default:
485-
return visitEachChild(node, visitor, context);
485+
return visitEachChild(node, importCallExpressionVisitor, context);
486486
}
487487
}
488488

489-
function visitor(node: Node): VisitResult<Node> {
489+
function importCallExpressionVisitor(node: Node): VisitResult<Node> {
490490
// This visitor does not need to descend into the tree if there is no dynamic import,
491491
// as export/import statements are only transformed at the top level of a file.
492492
if (!currentSourceFile.containsDynamicImport) {
@@ -497,7 +497,7 @@ namespace ts {
497497
case SyntaxKind.ImportCallExpression:
498498
return visitImportCallExpression(<ImportCallExpression>node);
499499
default:
500-
return visitEachChild(node, visitor, context);
500+
return visitEachChild(node, importCallExpressionVisitor, context);
501501
}
502502
}
503503

@@ -803,9 +803,9 @@ namespace ts {
803803
node.asteriskToken,
804804
getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true),
805805
/*typeParameters*/ undefined,
806-
visitNodes(node.parameters, visitor),
806+
visitNodes(node.parameters, importCallExpressionVisitor),
807807
/*type*/ undefined,
808-
node.body
808+
visitEachChild(node.body, importCallExpressionVisitor, context)
809809
),
810810
/*location*/ node
811811
),
@@ -814,7 +814,7 @@ namespace ts {
814814
);
815815
}
816816
else {
817-
statements = append(statements, node);
817+
statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context));
818818
}
819819

820820
if (hasAssociatedEndOfDeclarationMarker(node)) {
@@ -845,7 +845,7 @@ namespace ts {
845845
visitNodes(node.modifiers, modifierVisitor, isModifier),
846846
getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true),
847847
/*typeParameters*/ undefined,
848-
visitNodes(node.heritageClauses, visitor),
848+
visitNodes(node.heritageClauses, importCallExpressionVisitor),
849849
node.members
850850
),
851851
node
@@ -855,7 +855,7 @@ namespace ts {
855855
);
856856
}
857857
else {
858-
statements = append(statements, node);
858+
statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context));
859859
}
860860

861861
if (hasAssociatedEndOfDeclarationMarker(node)) {
@@ -907,7 +907,7 @@ namespace ts {
907907
}
908908
}
909909
else {
910-
statements = append(statements, visitEachChild(node, visitor, context));
910+
statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context));
911911
}
912912

913913
if (hasAssociatedEndOfDeclarationMarker(node)) {
@@ -930,7 +930,7 @@ namespace ts {
930930
function transformInitializedVariable(node: VariableDeclaration): Expression {
931931
if (isBindingPattern(node.name)) {
932932
return flattenDestructuringAssignment(
933-
visitNode(node, visitor),
933+
visitNode(node, importCallExpressionVisitor),
934934
/*visitor*/ undefined,
935935
context,
936936
FlattenLevel.All,
@@ -947,7 +947,7 @@ namespace ts {
947947
),
948948
/*location*/ node.name
949949
),
950-
visitNode(node.initializer, visitor)
950+
visitNode(node.initializer, importCallExpressionVisitor)
951951
);
952952
}
953953
}
Collapse file
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// @module: commonjs
2+
// @target: esnext
3+
// @filename: 0.ts
4+
export class B {
5+
print() { return "I am B"}
6+
}
7+
8+
// @filename: 2.ts
9+
// We use Promise<any> for now as there is no way to specify shape of module object
10+
function foo(x: Promise<any>) {
11+
x.then(value => {
12+
let b = new value.B();
13+
b.print();
14+
})
15+
}
16+
17+
foo(import("./0"));
Collapse file
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @module: commonjs
2+
// @target: esnext
3+
// @filename: 0.ts
4+
export class B {
5+
print() { return "I am B"}
6+
}
7+
8+
// @filename: 2.ts
9+
async function foo() {
10+
class C extends (await import("./0")).B {}
11+
var c = new C();
12+
c.print();
13+
}
14+
foo();
Collapse file
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// @module: commonjs
2+
// @target: esnext
3+
// @filename: 0.ts
4+
export class B {
5+
print() { return "I am B"}
6+
}
7+
8+
export function foo() { return "foo" }
9+
10+
// @filename: 1.ts
11+
export function backup() { return "backup"; }
12+
13+
// @filename: 2.ts
14+
declare var console: any;
15+
class C {
16+
private myModule = import("./0");
17+
method() {
18+
this.myModule.then(Zero => {
19+
console.log(Zero.foo());
20+
}, async err => {
21+
console.log(err);
22+
let one = await import("./1");
23+
console.log(one.backup());
24+
});
25+
}
26+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.