Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5032,13 +5032,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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions tests/baselines/reference/missingCloseBraceInObjectLiteral.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [missingCloseBraceInObjectLiteral.ts]
var foo = {
a: 'a',
b: 'b',
c: 'c'


//// [missingCloseBraceInObjectLiteral.js]
var foo = {
a: 'a',
b: 'b',
c: 'c'
};
13 changes: 13 additions & 0 deletions tests/baselines/reference/missingCloseBraceInObjectLiteral.symbols
Original file line number Diff line number Diff line change
@@ -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))

17 changes: 17 additions & 0 deletions tests/baselines/reference/missingCloseBraceInObjectLiteral.types
Original file line number Diff line number Diff line change
@@ -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"

Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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; }};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 4 additions & 0 deletions tests/cases/compiler/missingCloseBraceInObjectLiteral.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var foo = {
a: 'a',
b: 'b',
c: 'c'