Skip to content

Commit 3cb457a

Browse files
committed
This reverts commit 5770434.
1 parent 8721dd0 commit 3cb457a

File tree

53 files changed

+255
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+255
-336
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"category": "Error",
1616
"code": 1006
1717
},
18-
"The parser expected to find a '}' to match the '{' token here.": {
18+
"The parser expected to find a '{1}' to match the '{0}' token here.": {
1919
"category": "Error",
2020
"code": 1007
2121
},

src/compiler/parser.ts

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,24 +1341,27 @@ namespace ts {
13411341
return inContext(NodeFlags.AwaitContext);
13421342
}
13431343

1344-
function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void {
1345-
parseErrorAt(scanner.getTokenPos(), scanner.getTextPos(), message, arg0);
1344+
function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | undefined {
1345+
return parseErrorAt(scanner.getTokenPos(), scanner.getTextPos(), message, arg0);
13461346
}
13471347

1348-
function parseErrorAtPosition(start: number, length: number, message: DiagnosticMessage, arg0?: any): void {
1348+
function parseErrorAtPosition(start: number, length: number, message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | undefined {
13491349
// Don't report another error if it would just be at the same position as the last error.
13501350
const lastError = lastOrUndefined(parseDiagnostics);
1351+
let result: DiagnosticWithDetachedLocation | undefined;
13511352
if (!lastError || start !== lastError.start) {
1352-
parseDiagnostics.push(createDetachedDiagnostic(fileName, start, length, message, arg0));
1353+
result = createDetachedDiagnostic(fileName, start, length, message, arg0);
1354+
parseDiagnostics.push(result);
13531355
}
13541356

13551357
// Mark that we've encountered an error. We'll set an appropriate bit on the next
13561358
// node we finish so that it can't be reused incrementally.
13571359
parseErrorBeforeNextFinishedNode = true;
1360+
return result;
13581361
}
13591362

1360-
function parseErrorAt(start: number, end: number, message: DiagnosticMessage, arg0?: any): void {
1361-
parseErrorAtPosition(start, end - start, message, arg0);
1363+
function parseErrorAt(start: number, end: number, message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | undefined {
1364+
return parseErrorAtPosition(start, end - start, message, arg0);
13621365
}
13631366

13641367
function parseErrorAtRange(range: TextRange, message: DiagnosticMessage, arg0?: any): void {
@@ -1552,6 +1555,20 @@ namespace ts {
15521555
return false;
15531556
}
15541557

1558+
function parseExpectedMatchingBrackets(openKind: SyntaxKind, closeKind: SyntaxKind, openPosition: number) {
1559+
if (token() === closeKind) {
1560+
nextToken();
1561+
return;
1562+
}
1563+
const lastError = parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(closeKind));
1564+
if (lastError) {
1565+
addRelatedInfo(
1566+
lastError,
1567+
createDetachedDiagnostic(fileName, openPosition, 1, Diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, tokenToString(openKind), tokenToString(closeKind))
1568+
);
1569+
}
1570+
}
1571+
15551572
function parseOptional(t: SyntaxKind): boolean {
15561573
if (token() === t) {
15571574
nextToken();
@@ -5481,10 +5498,11 @@ namespace ts {
54815498

54825499
function parseArrayLiteralExpression(): ArrayLiteralExpression {
54835500
const pos = getNodePos();
5501+
const openBracketPosition = scanner.getTokenPos();
54845502
parseExpected(SyntaxKind.OpenBracketToken);
54855503
const multiLine = scanner.hasPrecedingLineBreak();
54865504
const elements = parseDelimitedList(ParsingContext.ArrayLiteralMembers, parseArgumentOrArrayLiteralElement);
5487-
parseExpected(SyntaxKind.CloseBracketToken);
5505+
parseExpectedMatchingBrackets(SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken, openBracketPosition);
54885506
return finishNode(factory.createArrayLiteralExpression(elements, multiLine), pos);
54895507
}
54905508

@@ -5553,15 +5571,7 @@ namespace ts {
55535571
parseExpected(SyntaxKind.OpenBraceToken);
55545572
const multiLine = scanner.hasPrecedingLineBreak();
55555573
const properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement, /*considerSemicolonAsDelimiter*/ true);
5556-
if (!parseExpected(SyntaxKind.CloseBraceToken)) {
5557-
const lastError = lastOrUndefined(parseDiagnostics);
5558-
if (lastError && lastError.code === Diagnostics._0_expected.code) {
5559-
addRelatedInfo(
5560-
lastError,
5561-
createDetachedDiagnostic(fileName, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_to_match_the_token_here)
5562-
);
5563-
}
5564-
}
5574+
parseExpectedMatchingBrackets(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, openBracePosition);
55655575
return finishNode(factory.createObjectLiteralExpression(properties, multiLine), pos);
55665576
}
55675577

@@ -5647,15 +5657,7 @@ namespace ts {
56475657
if (parseExpected(SyntaxKind.OpenBraceToken, diagnosticMessage) || ignoreMissingOpenBrace) {
56485658
const multiLine = scanner.hasPrecedingLineBreak();
56495659
const statements = parseList(ParsingContext.BlockStatements, parseStatement);
5650-
if (!parseExpected(SyntaxKind.CloseBraceToken)) {
5651-
const lastError = lastOrUndefined(parseDiagnostics);
5652-
if (lastError && lastError.code === Diagnostics._0_expected.code) {
5653-
addRelatedInfo(
5654-
lastError,
5655-
createDetachedDiagnostic(fileName, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_to_match_the_token_here)
5656-
);
5657-
}
5658-
}
5660+
parseExpectedMatchingBrackets(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, openBracePosition);
56595661
const result = withJSDoc(finishNode(factory.createBlock(statements, multiLine), pos), hasJSDoc);
56605662
if (token() === SyntaxKind.EqualsToken) {
56615663
parseErrorAtCurrentToken(Diagnostics.Declaration_or_statement_expected_This_follows_a_block_of_statements_so_if_you_intended_to_write_a_destructuring_assignment_you_might_need_to_wrap_the_the_whole_assignment_in_parentheses);
@@ -5711,9 +5713,10 @@ namespace ts {
57115713
const pos = getNodePos();
57125714
const hasJSDoc = hasPrecedingJSDocComment();
57135715
parseExpected(SyntaxKind.IfKeyword);
5716+
const openParenPosition = scanner.getTokenPos();
57145717
parseExpected(SyntaxKind.OpenParenToken);
57155718
const expression = allowInAnd(parseExpression);
5716-
parseExpected(SyntaxKind.CloseParenToken);
5719+
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
57175720
const thenStatement = parseStatement();
57185721
const elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement() : undefined;
57195722
return withJSDoc(finishNode(factory.createIfStatement(expression, thenStatement, elseStatement), pos), hasJSDoc);
@@ -5725,9 +5728,10 @@ namespace ts {
57255728
parseExpected(SyntaxKind.DoKeyword);
57265729
const statement = parseStatement();
57275730
parseExpected(SyntaxKind.WhileKeyword);
5731+
const openParenPosition = scanner.getTokenPos();
57285732
parseExpected(SyntaxKind.OpenParenToken);
57295733
const expression = allowInAnd(parseExpression);
5730-
parseExpected(SyntaxKind.CloseParenToken);
5734+
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
57315735

57325736
// From: https://mail.mozilla.org/pipermail/es-discuss/2011-August/016188.html
57335737
// 157 min --- All allen at wirfs-brock.com CONF --- "do{;}while(false)false" prohibited in
@@ -5741,9 +5745,10 @@ namespace ts {
57415745
const pos = getNodePos();
57425746
const hasJSDoc = hasPrecedingJSDocComment();
57435747
parseExpected(SyntaxKind.WhileKeyword);
5748+
const openParenPosition = scanner.getTokenPos();
57445749
parseExpected(SyntaxKind.OpenParenToken);
57455750
const expression = allowInAnd(parseExpression);
5746-
parseExpected(SyntaxKind.CloseParenToken);
5751+
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
57475752
const statement = parseStatement();
57485753
return withJSDoc(finishNode(factory.createWhileStatement(expression, statement), pos), hasJSDoc);
57495754
}
@@ -5819,9 +5824,10 @@ namespace ts {
58195824
const pos = getNodePos();
58205825
const hasJSDoc = hasPrecedingJSDocComment();
58215826
parseExpected(SyntaxKind.WithKeyword);
5827+
const openParenPosition = scanner.getTokenPos();
58225828
parseExpected(SyntaxKind.OpenParenToken);
58235829
const expression = allowInAnd(parseExpression);
5824-
parseExpected(SyntaxKind.CloseParenToken);
5830+
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
58255831
const statement = doInsideOfContext(NodeFlags.InWithStatement, parseStatement);
58265832
return withJSDoc(finishNode(factory.createWithStatement(expression, statement), pos), hasJSDoc);
58275833
}
@@ -8074,13 +8080,9 @@ namespace ts {
80748080
hasChildren = true;
80758081
if (child.kind === SyntaxKind.JSDocTypeTag) {
80768082
if (childTypeTag) {
8077-
parseErrorAtCurrentToken(Diagnostics.A_JSDoc_typedef_comment_may_not_contain_multiple_type_tags);
8078-
const lastError = lastOrUndefined(parseDiagnostics);
8083+
const lastError = parseErrorAtCurrentToken(Diagnostics.A_JSDoc_typedef_comment_may_not_contain_multiple_type_tags);
80798084
if (lastError) {
8080-
addRelatedInfo(
8081-
lastError,
8082-
createDetachedDiagnostic(fileName, 0, 0, Diagnostics.The_tag_was_first_specified_here)
8083-
);
8085+
addRelatedInfo(lastError, createDetachedDiagnostic(fileName, 0, 0, Diagnostics.The_tag_was_first_specified_here));
80848086
}
80858087
break;
80868088
}

tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
121121
if (retValue != 0 ^= {
122122
~~
123123
!!! error TS1005: ')' expected.
124+
!!! related TS1007 tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts:22:20: The parser expected to find a ')' to match the '(' token here.
124125
~
125126

126127

tests/baselines/reference/errorRecoveryWithDotFollowedByNamespaceKeyword.errors.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@ tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts(9,2): err
1616
}
1717

1818
!!! error TS1005: '}' expected.
19-
!!! related TS1007 tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts:3:19: The parser expected to find a '}' to match the '{' token here.
20-
!!! related TS1007 tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts:2:20: The parser expected to find a '}' to match the '{' token here.
19+
!!! related TS1007 tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts:3:19: The parser expected to find a '}' to match the '{' token here.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests/cases/compiler/missingCloseBracketInArray.ts(1,48): error TS1005: ']' expected.
2+
3+
4+
==== tests/cases/compiler/missingCloseBracketInArray.ts (1 errors) ====
5+
var alphas:string[] = alphas = ["1","2","3","4"
6+
7+
!!! error TS1005: ']' expected.
8+
!!! related TS1007 tests/cases/compiler/missingCloseBracketInArray.ts:1:32: The parser expected to find a ']' to match the '[' token here.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//// [missingCloseBracketInArray.ts]
2+
var alphas:string[] = alphas = ["1","2","3","4"
3+
4+
//// [missingCloseBracketInArray.js]
5+
var alphas = alphas = ["1", "2", "3", "4"];
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/compiler/missingCloseBracketInArray.ts ===
2+
var alphas:string[] = alphas = ["1","2","3","4"
3+
>alphas : Symbol(alphas, Decl(missingCloseBracketInArray.ts, 0, 3))
4+
>alphas : Symbol(alphas, Decl(missingCloseBracketInArray.ts, 0, 3))
5+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/missingCloseBracketInArray.ts ===
2+
var alphas:string[] = alphas = ["1","2","3","4"
3+
>alphas : string[]
4+
>alphas = ["1","2","3","4" : string[]
5+
>alphas : string[]
6+
>["1","2","3","4" : string[]
7+
>"1" : "1"
8+
>"2" : "2"
9+
>"3" : "3"
10+
>"4" : "4"
11+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
tests/cases/compiler/missingCloseParenStatements.ts(2,26): error TS1005: ')' expected.
2+
tests/cases/compiler/missingCloseParenStatements.ts(4,5): error TS1005: ')' expected.
3+
tests/cases/compiler/missingCloseParenStatements.ts(8,39): error TS1005: ')' expected.
4+
tests/cases/compiler/missingCloseParenStatements.ts(11,35): error TS1005: ')' expected.
5+
6+
7+
==== tests/cases/compiler/missingCloseParenStatements.ts (4 errors) ====
8+
var a1, a2, a3 = 0;
9+
if ( a1 && (a2 + a3 > 0) {
10+
~
11+
!!! error TS1005: ')' expected.
12+
!!! related TS1007 tests/cases/compiler/missingCloseParenStatements.ts:2:4: The parser expected to find a ')' to match the '(' token here.
13+
while( (a2 > 0) && a1
14+
{
15+
~
16+
!!! error TS1005: ')' expected.
17+
!!! related TS1007 tests/cases/compiler/missingCloseParenStatements.ts:3:10: The parser expected to find a ')' to match the '(' token here.
18+
do {
19+
var i = i + 1;
20+
a1 = a1 + i;
21+
with ((a2 + a3 > 0) && a1 {
22+
~
23+
!!! error TS1005: ')' expected.
24+
!!! related TS1007 tests/cases/compiler/missingCloseParenStatements.ts:8:18: The parser expected to find a ')' to match the '(' token here.
25+
console.log(x);
26+
}
27+
} while (i < 5 && (a1 > 5);
28+
~
29+
!!! error TS1005: ')' expected.
30+
!!! related TS1007 tests/cases/compiler/missingCloseParenStatements.ts:11:17: The parser expected to find a ')' to match the '(' token here.
31+
}
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [missingCloseParenStatements.ts]
2+
var a1, a2, a3 = 0;
3+
if ( a1 && (a2 + a3 > 0) {
4+
while( (a2 > 0) && a1
5+
{
6+
do {
7+
var i = i + 1;
8+
a1 = a1 + i;
9+
with ((a2 + a3 > 0) && a1 {
10+
console.log(x);
11+
}
12+
} while (i < 5 && (a1 > 5);
13+
}
14+
}
15+
16+
//// [missingCloseParenStatements.js]
17+
var a1, a2, a3 = 0;
18+
if (a1 && (a2 + a3 > 0)) {
19+
while ((a2 > 0) && a1) {
20+
do {
21+
var i = i + 1;
22+
a1 = a1 + i;
23+
with ((a2 + a3 > 0) && a1) {
24+
console.log(x);
25+
}
26+
} while (i < 5 && (a1 > 5));
27+
}
28+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/compiler/missingCloseParenStatements.ts ===
2+
var a1, a2, a3 = 0;
3+
>a1 : Symbol(a1, Decl(missingCloseParenStatements.ts, 0, 3))
4+
>a2 : Symbol(a2, Decl(missingCloseParenStatements.ts, 0, 7))
5+
>a3 : Symbol(a3, Decl(missingCloseParenStatements.ts, 0, 11))
6+
7+
if ( a1 && (a2 + a3 > 0) {
8+
>a1 : Symbol(a1, Decl(missingCloseParenStatements.ts, 0, 3))
9+
>a2 : Symbol(a2, Decl(missingCloseParenStatements.ts, 0, 7))
10+
>a3 : Symbol(a3, Decl(missingCloseParenStatements.ts, 0, 11))
11+
12+
while( (a2 > 0) && a1
13+
>a2 : Symbol(a2, Decl(missingCloseParenStatements.ts, 0, 7))
14+
>a1 : Symbol(a1, Decl(missingCloseParenStatements.ts, 0, 3))
15+
{
16+
do {
17+
var i = i + 1;
18+
>i : Symbol(i, Decl(missingCloseParenStatements.ts, 5, 15))
19+
>i : Symbol(i, Decl(missingCloseParenStatements.ts, 5, 15))
20+
21+
a1 = a1 + i;
22+
>a1 : Symbol(a1, Decl(missingCloseParenStatements.ts, 0, 3))
23+
>a1 : Symbol(a1, Decl(missingCloseParenStatements.ts, 0, 3))
24+
>i : Symbol(i, Decl(missingCloseParenStatements.ts, 5, 15))
25+
26+
with ((a2 + a3 > 0) && a1 {
27+
>a2 : Symbol(a2, Decl(missingCloseParenStatements.ts, 0, 7))
28+
>a3 : Symbol(a3, Decl(missingCloseParenStatements.ts, 0, 11))
29+
>a1 : Symbol(a1, Decl(missingCloseParenStatements.ts, 0, 3))
30+
31+
console.log(x);
32+
}
33+
} while (i < 5 && (a1 > 5);
34+
>i : Symbol(i, Decl(missingCloseParenStatements.ts, 5, 15))
35+
>a1 : Symbol(a1, Decl(missingCloseParenStatements.ts, 0, 3))
36+
}
37+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
=== tests/cases/compiler/missingCloseParenStatements.ts ===
2+
var a1, a2, a3 = 0;
3+
>a1 : any
4+
>a2 : any
5+
>a3 : number
6+
>0 : 0
7+
8+
if ( a1 && (a2 + a3 > 0) {
9+
>a1 && (a2 + a3 > 0) : boolean
10+
>a1 : any
11+
>(a2 + a3 > 0) : boolean
12+
>a2 + a3 > 0 : boolean
13+
>a2 + a3 : any
14+
>a2 : any
15+
>a3 : number
16+
>0 : 0
17+
18+
while( (a2 > 0) && a1
19+
>(a2 > 0) && a1 : any
20+
>(a2 > 0) : boolean
21+
>a2 > 0 : boolean
22+
>a2 : any
23+
>0 : 0
24+
>a1 : any
25+
{
26+
do {
27+
var i = i + 1;
28+
>i : any
29+
>i + 1 : any
30+
>i : any
31+
>1 : 1
32+
33+
a1 = a1 + i;
34+
>a1 = a1 + i : any
35+
>a1 : any
36+
>a1 + i : any
37+
>a1 : any
38+
>i : any
39+
40+
with ((a2 + a3 > 0) && a1 {
41+
>(a2 + a3 > 0) && a1 : any
42+
>(a2 + a3 > 0) : boolean
43+
>a2 + a3 > 0 : boolean
44+
>a2 + a3 : any
45+
>a2 : any
46+
>a3 : number
47+
>0 : 0
48+
>a1 : any
49+
50+
console.log(x);
51+
>console.log(x) : any
52+
>console.log : any
53+
>console : any
54+
>log : any
55+
>x : any
56+
}
57+
} while (i < 5 && (a1 > 5);
58+
>i < 5 && (a1 > 5) : boolean
59+
>i < 5 : boolean
60+
>i : any
61+
>5 : 5
62+
>(a1 > 5) : boolean
63+
>a1 > 5 : boolean
64+
>a1 : any
65+
>5 : 5
66+
}
67+
}

0 commit comments

Comments
 (0)