mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Do not collect imports in parser as it makes it very hard for incremental parsing
This commit is contained in:
@@ -3696,10 +3696,6 @@ namespace ts {
|
||||
// var foo3 = require("subfolder
|
||||
// import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression
|
||||
const importCall = parseImportCallExpression();
|
||||
if (importCall.specifier.kind === SyntaxKind.StringLiteral) {
|
||||
(sourceFile.imports || (sourceFile.imports = [])).push(importCall.specifier as StringLiteral);
|
||||
}
|
||||
sourceFile.containsDynamicImport = true;
|
||||
return importCall;
|
||||
}
|
||||
const expression = token() === SyntaxKind.SuperKeyword ? parseSuperExpression() : parseMemberExpressionOrHigher();
|
||||
|
||||
@@ -1183,7 +1183,7 @@ namespace ts {
|
||||
const isDtsFile = isDeclarationFile(file);
|
||||
|
||||
// file.imports may not be undefined if there exists dynamic import
|
||||
let imports = file.imports;
|
||||
let imports: LiteralExpression[];
|
||||
let moduleAugmentations: LiteralExpression[];
|
||||
let ambientModules: string[];
|
||||
|
||||
@@ -1202,9 +1202,7 @@ namespace ts {
|
||||
|
||||
for (const node of file.statements) {
|
||||
collectModuleReferences(node, /*inAmbientModule*/ false);
|
||||
if (isJavaScriptFile) {
|
||||
collectRequireCalls(node);
|
||||
}
|
||||
collectImportOrRequireCalls(node);
|
||||
}
|
||||
|
||||
file.imports = imports || emptyArray;
|
||||
@@ -1266,12 +1264,15 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function collectRequireCalls(node: Node): void {
|
||||
if (isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) {
|
||||
function collectImportOrRequireCalls(node: Node): void {
|
||||
if (isJavaScriptFile && isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) {
|
||||
(imports || (imports = [])).push(<StringLiteral>(<CallExpression>node).arguments[0]);
|
||||
}
|
||||
else if (node.kind === SyntaxKind.ImportCallExpression && (<ImportCallExpression>node).specifier.kind === SyntaxKind.StringLiteral) {
|
||||
(imports || (imports = [])).push(<StringLiteral>(<ImportCallExpression>node).specifier);
|
||||
}
|
||||
else {
|
||||
forEachChild(node, collectRequireCalls);
|
||||
forEachChild(node, collectImportOrRequireCalls);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace ts {
|
||||
start: undefined,
|
||||
length: undefined,
|
||||
}, {
|
||||
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'.",
|
||||
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2018'.",
|
||||
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
|
||||
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user