Correctly bind import call expression

This commit is contained in:
Yui T
2017-03-17 16:58:51 -07:00
parent 804ab2c0df
commit 1af1005636
7 changed files with 21 additions and 7 deletions
+11
View File
@@ -2163,6 +2163,8 @@ namespace ts {
return bindJsxAttribute(<JsxAttribute>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
// Imports and exports
case SyntaxKind.ImportCallExpression:
return bindImportCallExpression(<ImportCallExpression>node);
case SyntaxKind.ImportEqualsDeclaration:
case SyntaxKind.NamespaceImport:
case SyntaxKind.ImportSpecifier:
@@ -2267,6 +2269,15 @@ namespace ts {
}
}
function bindImportCallExpression(node: ImportCallExpression) {
if (!file.dynamicImportIndicator) {
file.dynamicImportIndicator = node;
if (!file.externalModuleIndicator) {
bindSourceFileAsExternalModule();
}
}
}
function bindImportClause(node: ImportClause) {
if (node.name) {
declareSymbolAndAddToSymbolTable(node, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
+1 -1
View File
@@ -1644,7 +1644,7 @@ namespace ts {
if (node.resolvedTypeReferenceDirectiveNames !== undefined) updated.resolvedTypeReferenceDirectiveNames = node.resolvedTypeReferenceDirectiveNames;
if (node.imports !== undefined) updated.imports = node.imports;
if (node.moduleAugmentations !== undefined) updated.moduleAugmentations = node.moduleAugmentations;
if (node.containsDynamicImport !== undefined) updated.containsDynamicImport = node.containsDynamicImport;
if (node.dynamicImportIndicator !== undefined) updated.dynamicImportIndicator = node.dynamicImportIndicator;
return updateNode(updated, node);
}
+5 -1
View File
@@ -461,7 +461,11 @@ namespace ts {
}
export function isExternalModule(file: SourceFile): boolean {
return file.externalModuleIndicator !== undefined || file.containsDynamicImport;
return file.externalModuleIndicator !== undefined;
}
export function containedDynamicImport(file: SourceFile): boolean {
return file.dynamicImportIndicator !== undefined;
}
// Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter
+1 -1
View File
@@ -55,7 +55,7 @@ namespace ts {
* @param node The SourceFile node.
*/
function transformSourceFile(node: SourceFile) {
if (isDeclarationFile(node) || !(isExternalModule(node) || compilerOptions.isolatedModules)) {
if (isDeclarationFile(node) || !(isExternalModule(node) || compilerOptions.isolatedModules || containedDynamicImport(node))) {
return node;
}
+1 -3
View File
@@ -50,9 +50,7 @@ namespace ts {
* @param node The SourceFile node.
*/
function transformSourceFile(node: SourceFile) {
if (isDeclarationFile(node)
|| !(isExternalModule(node)
|| compilerOptions.isolatedModules)) {
if (isDeclarationFile(node) || !(isExternalModule(node) || compilerOptions.isolatedModules || containedDynamicImport(node))) {
return node;
}
+1 -1
View File
@@ -2253,6 +2253,7 @@ namespace ts {
/* @internal */ externalModuleIndicator: Node;
// The first node that causes this file to be a CommonJS module
/* @internal */ commonJsModuleIndicator: Node;
/* @internal */ dynamicImportIndicator: Node;
/* @internal */ identifiers: Map<string>;
/* @internal */ nodeCount: number;
@@ -2282,7 +2283,6 @@ namespace ts {
/* @internal */ moduleAugmentations: LiteralExpression[];
/* @internal */ patternAmbientModules?: PatternAmbientModule[];
/* @internal */ ambientModuleNames: string[];
/* @internal */ containsDynamicImport?: boolean;
}
export interface Bundle extends Node {
+1
View File
@@ -458,6 +458,7 @@ namespace ts {
public hasNoDefaultLib: boolean;
public externalModuleIndicator: Node; // The first node that causes this file to be an external module
public commonJsModuleIndicator: Node; // The first node that causes this file to be a CommonJS module
public dynamicImportIndicator: Node; // The first dynamic import in this file
public nodeCount: number;
public identifierCount: number;
public symbolCount: number;