Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 36dfd77

Browse filesBrowse files
author
Andy
authored
Parse an object literal property as shorthand unless followed by '(' or ':' (microsoft#28121)
1 parent abce9ae commit 36dfd77
Copy full SHA for 36dfd77

40 files changed

+163-93Lines changed: 163 additions & 93 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/parser.ts‎

Copy file name to clipboardExpand all lines: src/compiler/parser.ts
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4738,8 +4738,7 @@ namespace ts {
47384738
// CoverInitializedName[Yield] :
47394739
// IdentifierReference[?Yield] Initializer[In, ?Yield]
47404740
// this is necessary because ObjectLiteral productions are also used to cover grammar for ObjectAssignmentPattern
4741-
const isShorthandPropertyAssignment =
4742-
tokenIsIdentifier && (token() === SyntaxKind.CommaToken || token() === SyntaxKind.CloseBraceToken || token() === SyntaxKind.EqualsToken);
4741+
const isShorthandPropertyAssignment = tokenIsIdentifier && (token() !== SyntaxKind.ColonToken);
47434742
if (isShorthandPropertyAssignment) {
47444743
node.kind = SyntaxKind.ShorthandPropertyAssignment;
47454744
const equalsToken = parseOptionalToken(SyntaxKind.EqualsToken);
Collapse file

‎src/testRunner/unittests/convertCompilerOptionsFromJson.ts‎

Copy file name to clipboardExpand all lines: src/testRunner/unittests/convertCompilerOptionsFromJson.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,8 @@ namespace ts {
596596
{
597597
compilerOptions: {
598598
target: undefined,
599-
module: ModuleKind.ESNext
599+
module: ModuleKind.ESNext,
600+
experimentalDecorators: true,
600601
},
601602
hasParseErrors: true
602603
}
Collapse file

‎src/testRunner/unittests/tsconfigParsing.ts‎

Copy file name to clipboardExpand all lines: src/testRunner/unittests/tsconfigParsing.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ namespace ts {
141141

142142
it("returns object with error when json is invalid", () => {
143143
const parsed = parseConfigFileTextToJson("/apath/tsconfig.json", "invalid");
144-
assert.deepEqual(parsed.config, { invalid: undefined });
144+
assert.deepEqual(parsed.config, {});
145145
const expected = createCompilerDiagnostic(Diagnostics._0_expected, "{");
146146
const error = parsed.error!;
147147
assert.equal(error.messageText, expected.messageText);
Collapse file
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
tests/cases/compiler/incompleteObjectLiteral1.ts(1,14): error TS1005: ':' expected.
1+
tests/cases/compiler/incompleteObjectLiteral1.ts(1,12): error TS2304: Cannot find name 'aa'.
2+
tests/cases/compiler/incompleteObjectLiteral1.ts(1,14): error TS1005: ',' expected.
23

34

4-
==== tests/cases/compiler/incompleteObjectLiteral1.ts (1 errors) ====
5+
==== tests/cases/compiler/incompleteObjectLiteral1.ts (2 errors) ====
56
var tt = { aa; }
7+
~~
8+
!!! error TS2304: Cannot find name 'aa'.
69
~
7-
!!! error TS1005: ':' expected.
10+
!!! error TS1005: ',' expected.
811
var x = tt;
Collapse file

‎tests/baselines/reference/incompleteObjectLiteral1.js‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/incompleteObjectLiteral1.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ var tt = { aa; }
33
var x = tt;
44

55
//// [incompleteObjectLiteral1.js]
6-
var tt = { aa: };
6+
var tt = { aa: aa };
77
var x = tt;
Collapse file

‎tests/baselines/reference/incompleteObjectLiteral1.types‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/incompleteObjectLiteral1.types
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ var tt = { aa; }
33
>tt : { aa: any; }
44
>{ aa; } : { aa: any; }
55
>aa : any
6-
> : any
76

87
var x = tt;
98
>x : { aa: any; }
Collapse file

‎tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.errors.txt
+20-5Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr
77
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(9,8): error TS1005: ':' expected.
88
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(10,10): error TS1005: ':' expected.
99
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(12,1): error TS1005: ':' expected.
10-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(15,6): error TS1005: ':' expected.
11-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,6): error TS1005: ':' expected.
12-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,6): error TS1005: ':' expected.
10+
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(15,5): error TS2304: Cannot find name 'a'.
11+
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(15,6): error TS1005: ',' expected.
12+
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,5): error TS2304: Cannot find name 'a'.
13+
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,6): error TS1005: ',' expected.
14+
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,12): error TS1005: ':' expected.
15+
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,5): error TS2304: Cannot find name 'a'.
16+
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,6): error TS1005: ',' expected.
17+
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,9): error TS1005: ':' expected.
1318
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(20,17): error TS1005: ':' expected.
1419

1520

16-
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts (13 errors) ====
21+
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts (18 errors) ====
1722
// errors
1823
var y = {
1924
"stringLiteral",
@@ -47,13 +52,23 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr
4752

4853
var x = {
4954
a.b,
55+
~
56+
!!! error TS2304: Cannot find name 'a'.
5057
~
51-
!!! error TS1005: ':' expected.
58+
!!! error TS1005: ',' expected.
5259
a["ss"],
60+
~
61+
!!! error TS2304: Cannot find name 'a'.
5362
~
63+
!!! error TS1005: ',' expected.
64+
~
5465
!!! error TS1005: ':' expected.
5566
a[1],
67+
~
68+
!!! error TS2304: Cannot find name 'a'.
5669
~
70+
!!! error TS1005: ',' expected.
71+
~
5772
!!! error TS1005: ':' expected.
5873
};
5974

Collapse file

‎tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.js‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.js
+9-5Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var x = {
2121
var v = { class }; // error
2222

2323
//// [objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.js]
24+
var _a;
2425
// errors
2526
var y = {
2627
"stringLiteral": ,
@@ -33,9 +34,12 @@ var y = {
3334
"class": ,
3435
"typeof":
3536
};
36-
var x = {
37-
a: .b,
38-
a: ["ss"],
39-
a: [1]
40-
};
37+
var x = (_a = {
38+
a: a, : .b,
39+
a: a
40+
},
41+
_a["ss"] = ,
42+
_a.a = a,
43+
_a[1] = ,
44+
_a);
4145
var v = { "class": }; // error
Collapse file

‎tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.symbols‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.symbols
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,17 @@ var x = {
3737

3838
a.b,
3939
>a : Symbol(a, Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 13, 9), Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 14, 8), Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 15, 12))
40+
> : Symbol((Missing), Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 14, 5))
4041

4142
a["ss"],
4243
>a : Symbol(a, Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 13, 9), Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 14, 8), Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 15, 12))
44+
>["ss"] : Symbol(["ss"], Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 15, 5))
45+
>"ss" : Symbol(["ss"], Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 15, 5))
4346

4447
a[1],
4548
>a : Symbol(a, Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 13, 9), Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 14, 8), Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 15, 12))
49+
>[1] : Symbol([1], Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 16, 5))
50+
>1 : Symbol([1], Decl(objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts, 16, 5))
4651

4752
};
4853

Collapse file

‎tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.types‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.types
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,27 @@ var y = {
4141
> : any
4242

4343
var x = {
44-
>x : { a: number[]; }
45-
>{ a.b, a["ss"], a[1],} : { a: number[]; }
44+
>x : { a: any; (Missing): any; ["ss"]: any; [1]: any; }
45+
>{ a.b, a["ss"], a[1],} : { a: any; (Missing): any; ["ss"]: any; [1]: any; }
4646

4747
a.b,
4848
>a : any
49+
> : any
4950
>.b : any
5051
> : any
5152
>b : any
5253

5354
a["ss"],
5455
>a : any
55-
>["ss"] : string[]
56+
>["ss"] : any
5657
>"ss" : "ss"
58+
> : any
5759

5860
a[1],
5961
>a : any
60-
>[1] : number[]
62+
>[1] : any
6163
>1 : 1
64+
> : any
6265

6366
};
6467

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.