Skip to content

Commit 1989b70

Browse files
author
Armando Aguirre
authored
Merge pull request #18192 from armanio123/FixExpressionExpectedAtEOF
Added logic to check for EOF when creating a missing node.
2 parents cc678a5 + c2168cb commit 1989b70

6 files changed

+30
-15
lines changed

src/compiler/parser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,10 @@ namespace ts {
12071207
return finishNode(node);
12081208
}
12091209

1210-
return createMissingNode<Identifier>(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false, diagnosticMessage || Diagnostics.Identifier_expected);
1210+
// Only for end of file because the error gets reported incorrectly on embedded script tags.
1211+
const reportAtCurrentPosition = token() === SyntaxKind.EndOfFileToken;
1212+
1213+
return createMissingNode<Identifier>(SyntaxKind.Identifier, reportAtCurrentPosition, diagnosticMessage || Diagnostics.Identifier_expected);
12111214
}
12121215

12131216
function parseIdentifier(diagnosticMessage?: DiagnosticMessage): Identifier {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
tests/cases/compiler/conflictMarkerTrivia4.ts(1,12): error TS2304: Cannot find name 'div'.
2+
tests/cases/compiler/conflictMarkerTrivia4.ts(1,16): error TS1109: Expression expected.
23
tests/cases/compiler/conflictMarkerTrivia4.ts(2,1): error TS1185: Merge conflict marker encountered.
3-
tests/cases/compiler/conflictMarkerTrivia4.ts(2,13): error TS1109: Expression expected.
44

55

66
==== tests/cases/compiler/conflictMarkerTrivia4.ts (3 errors) ====
77
const x = <div>
88
~~~
99
!!! error TS2304: Cannot find name 'div'.
10+
11+
!!! error TS1109: Expression expected.
1012
<<<<<<< HEAD
1113
~~~~~~~
12-
!!! error TS1185: Merge conflict marker encountered.
13-
14-
!!! error TS1109: Expression expected.
14+
!!! error TS1185: Merge conflict marker encountered.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
tests/cases/compiler/incompleteDottedExpressionAtEOF.ts(2,10): error TS2304: Cannot find name 'window'.
2-
tests/cases/compiler/incompleteDottedExpressionAtEOF.ts(2,18): error TS1003: Identifier expected.
2+
tests/cases/compiler/incompleteDottedExpressionAtEOF.ts(2,17): error TS1003: Identifier expected.
33

44

55
==== tests/cases/compiler/incompleteDottedExpressionAtEOF.ts (2 errors) ====
66
// used to leak __missing into error message
77
var p2 = window.
88
~~~~~~
99
!!! error TS2304: Cannot find name 'window'.
10-
10+
1111
!!! error TS1003: Identifier expected.

tests/baselines/reference/jsxAndTypeAssertion.errors.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(14,45): error TS1005: '}' ex
1010
tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(18,2): error TS17008: JSX element 'foo' has no corresponding closing tag.
1111
tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(18,8): error TS17008: JSX element 'foo' has no corresponding closing tag.
1212
tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(18,13): error TS17008: JSX element 'foo' has no corresponding closing tag.
13+
tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(18,83): error TS1109: Expression expected.
1314
tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: ':' expected.
1415
tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: '</' expected.
16+
tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: '}' expected.
1517

1618

17-
==== tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx (14 errors) ====
19+
==== tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx (16 errors) ====
1820
declare var createElement: any;
1921

2022
class foo {}
@@ -57,10 +59,14 @@ tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: '</' ex
5759
!!! error TS17008: JSX element 'foo' has no corresponding closing tag.
5860
~~~
5961
!!! error TS17008: JSX element 'foo' has no corresponding closing tag.
62+
63+
!!! error TS1109: Expression expected.
6064

6165

6266

6367

6468
!!! error TS1005: ':' expected.
6569

66-
!!! error TS1005: '</' expected.
70+
!!! error TS1005: '</' expected.
71+
72+
!!! error TS1005: '}' expected.
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions4.ts(5,1): error TS2554: Expected 3 arguments, but got 4.
22
tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions4.ts(5,24): error TS1109: Expression expected.
3-
tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions4.ts(5,28): error TS1109: Expression expected.
3+
tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions4.ts(5,27): error TS1109: Expression expected.
4+
tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions4.ts(5,28): error TS1005: '}' expected.
45

56

6-
==== tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions4.ts (3 errors) ====
7+
==== tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions4.ts (4 errors) ====
78
function f(x: TemplateStringsArray, y: string, z: string) {
89
}
910

@@ -13,5 +14,7 @@ tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions4.ts(5,28):
1314
!!! error TS2554: Expected 3 arguments, but got 4.
1415
~
1516
!!! error TS1109: Expression expected.
17+
18+
!!! error TS1109: Expression expected.
1619

17-
!!! error TS1109: Expression expected.
20+
!!! error TS1005: '}' expected.
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions5.ts(5,1): error TS2554: Expected 3 arguments, but got 4.
2-
tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions5.ts(5,30): error TS1109: Expression expected.
2+
tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions5.ts(5,29): error TS1109: Expression expected.
3+
tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions5.ts(5,30): error TS1005: '}' expected.
34

45

5-
==== tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions5.ts (2 errors) ====
6+
==== tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions5.ts (3 errors) ====
67
function f(x: TemplateStringsArray, y: string, z: string) {
78
}
89

910
// Incomplete call, but too many parameters.
1011
f `123qdawdrqw${ 1 }${ 2 }${
1112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1213
!!! error TS2554: Expected 3 arguments, but got 4.
14+
15+
!!! error TS1109: Expression expected.
1316

14-
!!! error TS1109: Expression expected.
17+
!!! error TS1005: '}' expected.

0 commit comments

Comments
 (0)