Fix missing import call expression in function and class declaration

This commit is contained in:
Kanchalai Tanglertsampan
2017-03-14 12:26:20 -07:00
parent ffbb445148
commit be375cb786
4 changed files with 68 additions and 11 deletions
+11 -11
View File
@@ -482,11 +482,11 @@ namespace ts {
return visitEndOfDeclarationMarker(<EndOfDeclarationMarker>node);
default:
return visitEachChild(node, visitor, context);
return visitEachChild(node, importCallExpressionVisitor, context);
}
}
function visitor(node: Node): VisitResult<Node> {
function importCallExpressionVisitor(node: Node): VisitResult<Node> {
// This visitor does not need to descend into the tree if there is no dynamic import,
// as export/import statements are only transformed at the top level of a file.
if (!currentSourceFile.containsDynamicImport) {
@@ -497,7 +497,7 @@ namespace ts {
case SyntaxKind.ImportCallExpression:
return visitImportCallExpression(<ImportCallExpression>node);
default:
return visitEachChild(node, visitor, context);
return visitEachChild(node, importCallExpressionVisitor, context);
}
}
@@ -803,9 +803,9 @@ namespace ts {
node.asteriskToken,
getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true),
/*typeParameters*/ undefined,
visitNodes(node.parameters, visitor),
visitNodes(node.parameters, importCallExpressionVisitor),
/*type*/ undefined,
node.body
visitEachChild(node.body, importCallExpressionVisitor, context)
),
/*location*/ node
),
@@ -814,7 +814,7 @@ namespace ts {
);
}
else {
statements = append(statements, node);
statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context));
}
if (hasAssociatedEndOfDeclarationMarker(node)) {
@@ -845,7 +845,7 @@ namespace ts {
visitNodes(node.modifiers, modifierVisitor, isModifier),
getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true),
/*typeParameters*/ undefined,
visitNodes(node.heritageClauses, visitor),
visitNodes(node.heritageClauses, importCallExpressionVisitor),
node.members
),
node
@@ -855,7 +855,7 @@ namespace ts {
);
}
else {
statements = append(statements, node);
statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context));
}
if (hasAssociatedEndOfDeclarationMarker(node)) {
@@ -907,7 +907,7 @@ namespace ts {
}
}
else {
statements = append(statements, visitEachChild(node, visitor, context));
statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context));
}
if (hasAssociatedEndOfDeclarationMarker(node)) {
@@ -930,7 +930,7 @@ namespace ts {
function transformInitializedVariable(node: VariableDeclaration): Expression {
if (isBindingPattern(node.name)) {
return flattenDestructuringAssignment(
visitNode(node, visitor),
visitNode(node, importCallExpressionVisitor),
/*visitor*/ undefined,
context,
FlattenLevel.All,
@@ -947,7 +947,7 @@ namespace ts {
),
/*location*/ node.name
),
visitNode(node.initializer, visitor)
visitNode(node.initializer, importCallExpressionVisitor)
);
}
}
@@ -0,0 +1,17 @@
// @module: commonjs
// @target: esnext
// @filename: 0.ts
export class B {
print() { return "I am B"}
}
// @filename: 2.ts
// We use Promise<any> for now as there is no way to specify shape of module object
function foo(x: Promise<any>) {
x.then(value => {
let b = new value.B();
b.print();
})
}
foo(import("./0"));
@@ -0,0 +1,14 @@
// @module: commonjs
// @target: esnext
// @filename: 0.ts
export class B {
print() { return "I am B"}
}
// @filename: 2.ts
async function foo() {
class C extends (await import("./0")).B {}
var c = new C();
c.print();
}
foo();
@@ -0,0 +1,26 @@
// @module: commonjs
// @target: esnext
// @filename: 0.ts
export class B {
print() { return "I am B"}
}
export function foo() { return "foo" }
// @filename: 1.ts
export function backup() { return "backup"; }
// @filename: 2.ts
declare var console: any;
class C {
private myModule = import("./0");
method() {
this.myModule.then(Zero => {
console.log(Zero.foo());
}, async err => {
console.log(err);
let one = await import("./1");
console.log(one.backup());
});
}
}