Skip to content

Commit

Permalink
Revert "Adding Diagnostic message for missing ']' and ')' in Array li…
Browse files Browse the repository at this point in the history
…teral and conditional statements (microsoft#40884)"

This reverts commit 555ef73.
  • Loading branch information
jessetrinity committed May 19, 2021
1 parent bcef31c commit fbb2f79
Show file tree
Hide file tree
Showing 20 changed files with 17 additions and 251 deletions.
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Expand Up @@ -15,7 +15,7 @@
"category": "Error",
"code": 1006
},
"The parser expected to find a '{1}' to match the '{0}' token here.": {
"The parser expected to find a '}' to match the '{' token here.": {
"category": "Error",
"code": 1007
},
Expand Down
47 changes: 15 additions & 32 deletions src/compiler/parser.ts
Expand Up @@ -1543,20 +1543,6 @@ namespace ts {
return false;
}

function parseExpectedMatchingBrackets(openKind: SyntaxKind, closeKind: SyntaxKind, openPosition: number) {
if (!parseExpected(closeKind)) {
const lastError = lastOrUndefined(parseDiagnostics);
if (lastError && lastError.code === Diagnostics._0_expected.code) {
addRelatedInfo(
lastError,
createDetachedDiagnostic(fileName, openPosition, 1, Diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, tokenToString(openKind), tokenToString(closeKind))
);
}
return false;
}
return true;
}

function parseOptional(t: SyntaxKind): boolean {
if (token() === t) {
nextToken();
Expand Down Expand Up @@ -5447,11 +5433,10 @@ namespace ts {

function parseArrayLiteralExpression(): ArrayLiteralExpression {
const pos = getNodePos();
const openBracketPosition = scanner.getTokenPos();
parseExpected(SyntaxKind.OpenBracketToken);
const multiLine = scanner.hasPrecedingLineBreak();
const elements = parseDelimitedList(ParsingContext.ArrayLiteralMembers, parseArgumentOrArrayLiteralElement);
parseExpectedMatchingBrackets(SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken, openBracketPosition);
parseExpected(SyntaxKind.CloseBracketToken);
return finishNode(factory.createArrayLiteralExpression(elements, multiLine), pos);
}

Expand Down Expand Up @@ -5525,7 +5510,7 @@ namespace ts {
if (lastError && lastError.code === Diagnostics._0_expected.code) {
addRelatedInfo(
lastError,
createDetachedDiagnostic(fileName, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, tokenToString(SyntaxKind.OpenBraceToken), tokenToString(SyntaxKind.CloseBraceToken))
createDetachedDiagnostic(fileName, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_to_match_the_token_here)
);
}
}
Expand Down Expand Up @@ -5614,14 +5599,16 @@ namespace ts {
if (parseExpected(SyntaxKind.OpenBraceToken, diagnosticMessage) || ignoreMissingOpenBrace) {
const multiLine = scanner.hasPrecedingLineBreak();
const statements = parseList(ParsingContext.BlockStatements, parseStatement);
parseExpectedMatchingBrackets(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, openBracePosition);
const result = withJSDoc(finishNode(factory.createBlock(statements, multiLine), pos), hasJSDoc);
if (token() === SyntaxKind.EqualsToken) {
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);
nextToken();
if (!parseExpected(SyntaxKind.CloseBraceToken)) {
const lastError = lastOrUndefined(parseDiagnostics);
if (lastError && lastError.code === Diagnostics._0_expected.code) {
addRelatedInfo(
lastError,
createDetachedDiagnostic(fileName, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_to_match_the_token_here)
);
}
}

return result;
return finishNode(factory.createBlock(statements, multiLine), pos);
}
else {
const statements = createMissingList<Statement>();
Expand Down Expand Up @@ -5670,10 +5657,9 @@ namespace ts {
const pos = getNodePos();
const hasJSDoc = hasPrecedingJSDocComment();
parseExpected(SyntaxKind.IfKeyword);
const openParenPosition = scanner.getTokenPos();
parseExpected(SyntaxKind.OpenParenToken);
const expression = allowInAnd(parseExpression);
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
parseExpected(SyntaxKind.CloseParenToken);
const thenStatement = parseStatement();
const elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement() : undefined;
return withJSDoc(finishNode(factory.createIfStatement(expression, thenStatement, elseStatement), pos), hasJSDoc);
Expand All @@ -5685,10 +5671,9 @@ namespace ts {
parseExpected(SyntaxKind.DoKeyword);
const statement = parseStatement();
parseExpected(SyntaxKind.WhileKeyword);
const openParenPosition = scanner.getTokenPos();
parseExpected(SyntaxKind.OpenParenToken);
const expression = allowInAnd(parseExpression);
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
parseExpected(SyntaxKind.CloseParenToken);

// From: https://mail.mozilla.org/pipermail/es-discuss/2011-August/016188.html
// 157 min --- All allen at wirfs-brock.com CONF --- "do{;}while(false)false" prohibited in
Expand All @@ -5702,10 +5687,9 @@ namespace ts {
const pos = getNodePos();
const hasJSDoc = hasPrecedingJSDocComment();
parseExpected(SyntaxKind.WhileKeyword);
const openParenPosition = scanner.getTokenPos();
parseExpected(SyntaxKind.OpenParenToken);
const expression = allowInAnd(parseExpression);
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
parseExpected(SyntaxKind.CloseParenToken);
const statement = parseStatement();
return withJSDoc(finishNode(factory.createWhileStatement(expression, statement), pos), hasJSDoc);
}
Expand Down Expand Up @@ -5781,10 +5765,9 @@ namespace ts {
const pos = getNodePos();
const hasJSDoc = hasPrecedingJSDocComment();
parseExpected(SyntaxKind.WithKeyword);
const openParenPosition = scanner.getTokenPos();
parseExpected(SyntaxKind.OpenParenToken);
const expression = allowInAnd(parseExpression);
parseExpectedMatchingBrackets(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, openParenPosition);
parseExpected(SyntaxKind.CloseParenToken);
const statement = doInsideOfContext(NodeFlags.InWithStatement, parseStatement);
return withJSDoc(finishNode(factory.createWithStatement(expression, statement), pos), hasJSDoc);
}
Expand Down
Expand Up @@ -121,7 +121,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
if (retValue != 0 ^= {
~~
!!! error TS1005: ')' expected.
!!! related TS1007 tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts:22:20: The parser expected to find a ')' to match the '(' token here.
~


Expand Down Expand Up @@ -505,7 +504,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
!!! error TS1135: Argument expression expected.
~
!!! error TS1005: '(' expected.
!!! related TS1007 tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts:257:33: The parser expected to find a ')' to match the '(' token here.
~~~~~~
!!! error TS2693: 'string' only refers to a type, but is being used as a value here.
~~~
Expand Down
Expand Up @@ -39,7 +39,6 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
!!! error TS2322: Type 'string' is not assignable to type 'number'.
~
!!! error TS1005: ',' expected.
!!! related TS1007 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts:7:4: The parser expected to find a ']' to match the '[' token here.
a0([1, 2, [["world"]], "string"]); // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'.
Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions tests/baselines/reference/missingCloseBracketInArray.js

This file was deleted.

5 changes: 0 additions & 5 deletions tests/baselines/reference/missingCloseBracketInArray.symbols

This file was deleted.

11 changes: 0 additions & 11 deletions tests/baselines/reference/missingCloseBracketInArray.types

This file was deleted.

32 changes: 0 additions & 32 deletions tests/baselines/reference/missingCloseParenStatements.errors.txt

This file was deleted.

28 changes: 0 additions & 28 deletions tests/baselines/reference/missingCloseParenStatements.js

This file was deleted.

37 changes: 0 additions & 37 deletions tests/baselines/reference/missingCloseParenStatements.symbols

This file was deleted.

67 changes: 0 additions & 67 deletions tests/baselines/reference/missingCloseParenStatements.types

This file was deleted.

Expand Up @@ -8,7 +8,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrayLiteralExpressions
var texCoords = [2, 2, 0.5000001192092895, 0.8749999 ; 403953552, 0.5000001192092895, 0.8749999403953552];
~
!!! error TS1005: ',' expected.
!!! related TS1007 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrayLiteralExpressions/parserErrorRecoveryArrayLiteralExpression3.ts:1:17: The parser expected to find a ']' to match the '[' token here.
~~~~~~~~~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
Expand Up @@ -11,7 +11,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IfStatements/parserErro
}
~
!!! error TS1005: ')' expected.
!!! related TS1007 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IfStatements/parserErrorRecoveryIfStatement2.ts:3:8: The parser expected to find a ')' to match the '(' token here.
f2() {
}
f3() {
Expand Down
Expand Up @@ -11,7 +11,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IfStatements/parserErro
}
~
!!! error TS1005: ')' expected.
!!! related TS1007 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IfStatements/parserErrorRecoveryIfStatement3.ts:3:8: The parser expected to find a ')' to match the '(' token here.
f2() {
}
f3() {
Expand Down
3 changes: 0 additions & 3 deletions tests/baselines/reference/reservedWords2.errors.txt
Expand Up @@ -45,7 +45,6 @@ tests/cases/compiler/reservedWords2.ts(12,17): error TS1138: Parameter declarati
!!! error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
~
!!! error TS1005: ')' expected.
!!! related TS1007 tests/cases/compiler/reservedWords2.ts:1:14: The parser expected to find a ')' to match the '(' token here.
import * as while from "foo"

!!! error TS2300: Duplicate identifier '(Missing)'.
Expand All @@ -59,7 +58,6 @@ tests/cases/compiler/reservedWords2.ts(12,17): error TS1138: Parameter declarati
!!! error TS2304: Cannot find name 'from'.
~~~~~
!!! error TS1005: ')' expected.
!!! related TS1007 tests/cases/compiler/reservedWords2.ts:2:20: The parser expected to find a ')' to match the '(' token here.

var typeof = 10;
~~~~~~
Expand Down Expand Up @@ -105,7 +103,6 @@ tests/cases/compiler/reservedWords2.ts(12,17): error TS1138: Parameter declarati
!!! error TS1005: ';' expected.
~
!!! error TS1005: '(' expected.
!!! related TS1007 tests/cases/compiler/reservedWords2.ts:9:18: The parser expected to find a ')' to match the '(' token here.
~
!!! error TS1128: Declaration or statement expected.
enum void {}
Expand Down

0 comments on commit fbb2f79

Please sign in to comment.