Do not collect imports in parser as it makes it very hard for incremental parsing

This commit is contained in:
Kanchalai Tanglertsampan
2017-03-16 17:47:10 -07:00
parent 6db02e7438
commit a77f0d2b1a
3 changed files with 9 additions and 12 deletions
-4
View File
@@ -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();
+8 -7
View File
@@ -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);
}
}
}
+1 -1
View File
@@ -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,