Skip to content

Commit 44f2336

Browse files
authored
Merge pull request #16633 from Microsoft/release-2.4_fixIncrementalParsing
[Release 2.4] Port fix incremental parsing PR
2 parents 2721fd4 + 4875a27 commit 44f2336

11 files changed

+108
-1
lines changed

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3700,7 +3700,7 @@ namespace ts {
37003700
// 3)we have a MemberExpression which either completes the LeftHandSideExpression,
37013701
// or starts the beginning of the first four CallExpression productions.
37023702
let expression: MemberExpression;
3703-
if (token() === SyntaxKind.ImportKeyword) {
3703+
if (token() === SyntaxKind.ImportKeyword && lookAhead(nextTokenIsOpenParenOrLessThan)) {
37043704
// We don't want to eagerly consume all import keyword as import call expression so we look a head to find "("
37053705
// For example:
37063706
// var foo3 = require("subfolder

src/compiler/program.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,10 @@ namespace ts {
802802
// moduleAugmentations has changed
803803
oldProgram.structureIsReused = StructureIsReused.SafeModules;
804804
}
805+
if ((oldSourceFile.flags & NodeFlags.PossiblyContainsDynamicImport) !== (newSourceFile.flags & NodeFlags.PossiblyContainsDynamicImport)) {
806+
// dynamicImport has changed
807+
oldProgram.structureIsReused = StructureIsReused.SafeModules;
808+
}
805809

806810
if (!arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
807811
// 'types' references has changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/conformance/dynamicImport/1.ts(2,1): error TS1109: Expression expected.
2+
3+
4+
==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ====
5+
export function foo() { return "foo"; }
6+
7+
==== tests/cases/conformance/dynamicImport/1.ts (1 errors) ====
8+
import
9+
import { foo } from './0';
10+
~~~~~~
11+
!!! error TS1109: Expression expected.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [tests/cases/conformance/dynamicImport/importCallExpressionIncorrect1.ts] ////
2+
3+
//// [0.ts]
4+
export function foo() { return "foo"; }
5+
6+
//// [1.ts]
7+
import
8+
import { foo } from './0';
9+
10+
//// [0.js]
11+
export function foo() { return "foo"; }
12+
//// [1.js]
13+
import ;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tests/cases/conformance/dynamicImport/1.ts(1,9): error TS1109: Expression expected.
2+
3+
4+
==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ====
5+
export function foo() { return "foo"; }
6+
7+
==== tests/cases/conformance/dynamicImport/1.ts (1 errors) ====
8+
var x = import { foo } from './0';
9+
~~~~~~
10+
!!! error TS1109: Expression expected.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [tests/cases/conformance/dynamicImport/importCallExpressionIncorrect2.ts] ////
2+
3+
//// [0.ts]
4+
export function foo() { return "foo"; }
5+
6+
//// [1.ts]
7+
var x = import { foo } from './0';
8+
9+
//// [0.js]
10+
export function foo() { return "foo"; }
11+
//// [1.js]
12+
var x = ;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @module: esnext
2+
// @target: esnext
3+
// @filename: 0.ts
4+
export function foo() { return "foo"; }
5+
6+
// @filename: 1.ts
7+
import
8+
import { foo } from './0';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @module: esnext
2+
// @target: esnext
3+
// @filename: 0.ts
4+
export function foo() { return "foo"; }
5+
6+
// @filename: 1.ts
7+
var x = import { foo } from './0';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// @lib: es2015
4+
5+
// @Filename: ./foo.ts
6+
//// export function bar() { return 1; }
7+
8+
// @Filename: ./0.ts
9+
//// /*1*/ import { bar } from "./foo"
10+
verify.numberOfErrorsInCurrentFile(0);
11+
goTo.marker("1");
12+
edit.insert("var x = ");
13+
verify.numberOfErrorsInCurrentFile(1);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// @lib: es2015
4+
5+
// @Filename: ./foo.ts
6+
//// export function bar() { return 1; }
7+
8+
// @Filename: ./0.ts
9+
//// var x = import/*1*/
10+
11+
verify.numberOfErrorsInCurrentFile(0);
12+
goTo.marker("1");
13+
edit.insert("(");
14+
verify.numberOfErrorsInCurrentFile(2);

0 commit comments

Comments
 (0)