mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Correctly bind import call expression
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user