mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Show token hints for missing closing braces (#36317)
* Add error for missing brace in object literal * Add new baseline test * Update all affected tests
This commit is contained in:
parent
c6cfd66fa8
commit
b014e2b568
@ -5110,13 +5110,22 @@ namespace ts {
|
||||
|
||||
function parseObjectLiteralExpression(): ObjectLiteralExpression {
|
||||
const node = <ObjectLiteralExpression>createNode(SyntaxKind.ObjectLiteralExpression);
|
||||
const openBracePosition = scanner.getTokenPos();
|
||||
parseExpected(SyntaxKind.OpenBraceToken);
|
||||
if (scanner.hasPrecedingLineBreak()) {
|
||||
node.multiLine = true;
|
||||
}
|
||||
|
||||
node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement, /*considerSemicolonAsDelimiter*/ true);
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
if (!parseExpected(SyntaxKind.CloseBraceToken)) {
|
||||
const lastError = lastOrUndefined(parseDiagnostics);
|
||||
if (lastError && lastError.code === Diagnostics._0_expected.code) {
|
||||
addRelatedInfo(
|
||||
lastError,
|
||||
createFileDiagnostic(sourceFile, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_to_match_the_token_here)
|
||||
);
|
||||
}
|
||||
}
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
tests/cases/compiler/missingCloseBraceInObjectLiteral.ts(5,1): error TS1005: '}' expected.
|
||||
|
||||
|
||||
==== tests/cases/compiler/missingCloseBraceInObjectLiteral.ts (1 errors) ====
|
||||
var foo = {
|
||||
a: 'a',
|
||||
b: 'b',
|
||||
c: 'c'
|
||||
|
||||
|
||||
!!! error TS1005: '}' expected.
|
||||
!!! related TS1007 tests/cases/compiler/missingCloseBraceInObjectLiteral.ts:1:11: The parser expected to find a '}' to match the '{' token here.
|
||||
@ -0,0 +1,13 @@
|
||||
//// [missingCloseBraceInObjectLiteral.ts]
|
||||
var foo = {
|
||||
a: 'a',
|
||||
b: 'b',
|
||||
c: 'c'
|
||||
|
||||
|
||||
//// [missingCloseBraceInObjectLiteral.js]
|
||||
var foo = {
|
||||
a: 'a',
|
||||
b: 'b',
|
||||
c: 'c'
|
||||
};
|
||||
@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/missingCloseBraceInObjectLiteral.ts ===
|
||||
var foo = {
|
||||
>foo : Symbol(foo, Decl(missingCloseBraceInObjectLiteral.ts, 0, 3))
|
||||
|
||||
a: 'a',
|
||||
>a : Symbol(a, Decl(missingCloseBraceInObjectLiteral.ts, 0, 11))
|
||||
|
||||
b: 'b',
|
||||
>b : Symbol(b, Decl(missingCloseBraceInObjectLiteral.ts, 1, 11))
|
||||
|
||||
c: 'c'
|
||||
>c : Symbol(c, Decl(missingCloseBraceInObjectLiteral.ts, 2, 11))
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
=== tests/cases/compiler/missingCloseBraceInObjectLiteral.ts ===
|
||||
var foo = {
|
||||
>foo : { a: string; b: string; c: string; }
|
||||
>{ a: 'a', b: 'b', c: 'c' : { a: string; b: string; c: string; }
|
||||
|
||||
a: 'a',
|
||||
>a : string
|
||||
>'a' : "a"
|
||||
|
||||
b: 'b',
|
||||
>b : string
|
||||
>'b' : "b"
|
||||
|
||||
c: 'c'
|
||||
>c : string
|
||||
>'c' : "c"
|
||||
|
||||
@ -32,6 +32,7 @@ tests/cases/conformance/classes/nestedClassDeclaration.ts(17,1): error TS1128: D
|
||||
!!! error TS2304: Cannot find name 'C4'.
|
||||
~
|
||||
!!! error TS1005: ',' expected.
|
||||
!!! related TS1007 tests/cases/conformance/classes/nestedClassDeclaration.ts:14:9: The parser expected to find a '}' to match the '{' token here.
|
||||
}
|
||||
}
|
||||
~
|
||||
|
||||
@ -9,4 +9,5 @@ tests/cases/compiler/objectLiteralWithSemicolons4.ts(3,1): error TS1005: ',' exp
|
||||
!!! error TS18004: No value exists in scope for the shorthand property 'a'. Either declare one or provide an initializer.
|
||||
;
|
||||
~
|
||||
!!! error TS1005: ',' expected.
|
||||
!!! error TS1005: ',' expected.
|
||||
!!! related TS1007 tests/cases/compiler/objectLiteralWithSemicolons4.ts:1:9: The parser expected to find a '}' to match the '{' token here.
|
||||
@ -28,6 +28,7 @@ tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts(4,20): error T
|
||||
!!! error TS2304: Cannot find name 'matchMedia'.
|
||||
~
|
||||
!!! error TS1005: ',' expected.
|
||||
!!! related TS1007 tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts:3:10: The parser expected to find a '}' to match the '{' token here.
|
||||
~
|
||||
!!! error TS1128: Declaration or statement expected.
|
||||
let o10 = { ...get x() { return 12; }};
|
||||
|
||||
@ -25,6 +25,7 @@ tests/cases/compiler/parseErrorIncorrectReturnToken.ts(12,1): error TS1128: Decl
|
||||
m(n: number) => string {
|
||||
~~
|
||||
!!! error TS1005: '{' expected.
|
||||
!!! related TS1007 tests/cases/compiler/parseErrorIncorrectReturnToken.ts:8:9: 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.
|
||||
~
|
||||
|
||||
@ -14,4 +14,5 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserEr
|
||||
~
|
||||
!!! error TS1005: ':' expected.
|
||||
|
||||
!!! error TS1005: '}' expected.
|
||||
!!! error TS1005: '}' expected.
|
||||
!!! related TS1007 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts:1:9: The parser expected to find a '}' to match the '{' token here.
|
||||
@ -11,4 +11,5 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserEr
|
||||
~
|
||||
!!! error TS1005: ':' expected.
|
||||
|
||||
!!! error TS1005: '}' expected.
|
||||
!!! error TS1005: '}' expected.
|
||||
!!! related TS1007 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral3.ts:1:9: The parser expected to find a '}' to match the '{' token here.
|
||||
@ -11,4 +11,5 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserEr
|
||||
~
|
||||
!!! error TS1005: ':' expected.
|
||||
|
||||
!!! error TS1005: '}' expected.
|
||||
!!! error TS1005: '}' expected.
|
||||
!!! related TS1007 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral4.ts:1:9: The parser expected to find a '}' to match the '{' token here.
|
||||
@ -8,4 +8,5 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserEr
|
||||
~
|
||||
!!! error TS1005: ':' expected.
|
||||
|
||||
!!! error TS1005: '}' expected.
|
||||
!!! error TS1005: '}' expected.
|
||||
!!! related TS1007 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral5.ts:1:9: The parser expected to find a '}' to match the '{' token here.
|
||||
4
tests/cases/compiler/missingCloseBraceInObjectLiteral.ts
Normal file
4
tests/cases/compiler/missingCloseBraceInObjectLiteral.ts
Normal file
@ -0,0 +1,4 @@
|
||||
var foo = {
|
||||
a: 'a',
|
||||
b: 'b',
|
||||
c: 'c'
|
||||
Loading…
x
Reference in New Issue
Block a user