Merge pull request #16544 from Microsoft/master-fixIncrementalParsingWithDynamicImport
[Master] wip - fix incremental parsing with dynamic import
This commit is contained in:
commit
47c1563649
|
@ -3733,7 +3733,7 @@ namespace ts {
|
|||
// 3)we have a MemberExpression which either completes the LeftHandSideExpression,
|
||||
// or starts the beginning of the first four CallExpression productions.
|
||||
let expression: MemberExpression;
|
||||
if (token() === SyntaxKind.ImportKeyword) {
|
||||
if (token() === SyntaxKind.ImportKeyword && lookAhead(nextTokenIsOpenParenOrLessThan)) {
|
||||
// We don't want to eagerly consume all import keyword as import call expression so we look a head to find "("
|
||||
// For example:
|
||||
// var foo3 = require("subfolder
|
||||
|
|
|
@ -803,6 +803,10 @@ namespace ts {
|
|||
// moduleAugmentations has changed
|
||||
oldProgram.structureIsReused = StructureIsReused.SafeModules;
|
||||
}
|
||||
if ((oldSourceFile.flags & NodeFlags.PossiblyContainsDynamicImport) !== (newSourceFile.flags & NodeFlags.PossiblyContainsDynamicImport)) {
|
||||
// dynamicImport has changed
|
||||
oldProgram.structureIsReused = StructureIsReused.SafeModules;
|
||||
}
|
||||
|
||||
if (!arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
|
||||
// 'types' references has changed
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
tests/cases/conformance/dynamicImport/1.ts(2,1): error TS1109: Expression expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ====
|
||||
export function foo() { return "foo"; }
|
||||
|
||||
==== tests/cases/conformance/dynamicImport/1.ts (1 errors) ====
|
||||
import
|
||||
import { foo } from './0';
|
||||
~~~~~~
|
||||
!!! error TS1109: Expression expected.
|
13
tests/baselines/reference/importCallExpressionIncorrect1.js
Normal file
13
tests/baselines/reference/importCallExpressionIncorrect1.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
//// [tests/cases/conformance/dynamicImport/importCallExpressionIncorrect1.ts] ////
|
||||
|
||||
//// [0.ts]
|
||||
export function foo() { return "foo"; }
|
||||
|
||||
//// [1.ts]
|
||||
import
|
||||
import { foo } from './0';
|
||||
|
||||
//// [0.js]
|
||||
export function foo() { return "foo"; }
|
||||
//// [1.js]
|
||||
import ;
|
|
@ -0,0 +1,10 @@
|
|||
tests/cases/conformance/dynamicImport/1.ts(1,9): error TS1109: Expression expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ====
|
||||
export function foo() { return "foo"; }
|
||||
|
||||
==== tests/cases/conformance/dynamicImport/1.ts (1 errors) ====
|
||||
var x = import { foo } from './0';
|
||||
~~~~~~
|
||||
!!! error TS1109: Expression expected.
|
12
tests/baselines/reference/importCallExpressionIncorrect2.js
Normal file
12
tests/baselines/reference/importCallExpressionIncorrect2.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
//// [tests/cases/conformance/dynamicImport/importCallExpressionIncorrect2.ts] ////
|
||||
|
||||
//// [0.ts]
|
||||
export function foo() { return "foo"; }
|
||||
|
||||
//// [1.ts]
|
||||
var x = import { foo } from './0';
|
||||
|
||||
//// [0.js]
|
||||
export function foo() { return "foo"; }
|
||||
//// [1.js]
|
||||
var x = ;
|
|
@ -0,0 +1,8 @@
|
|||
// @module: esnext
|
||||
// @target: esnext
|
||||
// @filename: 0.ts
|
||||
export function foo() { return "foo"; }
|
||||
|
||||
// @filename: 1.ts
|
||||
import
|
||||
import { foo } from './0';
|
|
@ -0,0 +1,7 @@
|
|||
// @module: esnext
|
||||
// @target: esnext
|
||||
// @filename: 0.ts
|
||||
export function foo() { return "foo"; }
|
||||
|
||||
// @filename: 1.ts
|
||||
var x = import { foo } from './0';
|
13
tests/cases/fourslash/incrementalParsingDynamicImport2.ts
Normal file
13
tests/cases/fourslash/incrementalParsingDynamicImport2.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
// @lib: es2015
|
||||
|
||||
// @Filename: ./foo.ts
|
||||
//// export function bar() { return 1; }
|
||||
|
||||
// @Filename: ./0.ts
|
||||
//// /*1*/ import { bar } from "./foo"
|
||||
verify.numberOfErrorsInCurrentFile(0);
|
||||
goTo.marker("1");
|
||||
edit.insert("var x = ");
|
||||
verify.numberOfErrorsInCurrentFile(1);
|
14
tests/cases/fourslash/incrementalParsingDynamicImport3.ts
Normal file
14
tests/cases/fourslash/incrementalParsingDynamicImport3.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
// @lib: es2015
|
||||
|
||||
// @Filename: ./foo.ts
|
||||
//// export function bar() { return 1; }
|
||||
|
||||
// @Filename: ./0.ts
|
||||
//// var x = import/*1*/
|
||||
|
||||
verify.numberOfErrorsInCurrentFile(0);
|
||||
goTo.marker("1");
|
||||
edit.insert("(");
|
||||
verify.numberOfErrorsInCurrentFile(2);
|
15
tests/cases/fourslash/incrementalParsingDynamicImport4.ts
Normal file
15
tests/cases/fourslash/incrementalParsingDynamicImport4.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
// @lib: es2015
|
||||
|
||||
// @Filename: ./foo.ts
|
||||
//// export function bar() { return 1; }
|
||||
|
||||
// @Filename: ./0.ts
|
||||
//// /*1*/
|
||||
//// import { bar } from "./foo"
|
||||
|
||||
verify.numberOfErrorsInCurrentFile(0);
|
||||
goTo.marker("1");
|
||||
edit.insert("import");
|
||||
verify.numberOfErrorsInCurrentFile(1);
|
Loading…
Reference in a new issue