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
1 change: 0 additions & 1 deletion tsc/internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,6 @@ func (c *Checker) checkGrammarObjectLiteralExpression(node *ast.ObjectLiteralExp
ast.KindPropertyAssignment:
var commonProp *ast.NamedMemberBase
if prop.Kind == ast.KindShorthandPropertyAssignment {
prop.ClassLikeData()
commonProp = &prop.AsShorthandPropertyAssignment().NamedMemberBase
} else {
commonProp = &prop.AsPropertyAssignment().NamedMemberBase
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
objectShorthandGrammar.ts(3,25): error TS1162: An object member cannot be declared optional.
objectShorthandGrammar.ts(4,25): error TS1255: A definite assignment assertion '!' is not permitted in this context.
objectShorthandGrammar.ts(5,29): error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern.
objectShorthandGrammar.ts(6,28): error TS1117: An object literal cannot have multiple properties with the same name.


==== objectShorthandGrammar.ts (4 errors) ====
const value = 1;
const valid = { value, other: value };
const optional = { value? };
~
!!! error TS1162: An object member cannot be declared optional.
const definite = { value! };
~
!!! error TS1255: A definite assignment assertion '!' is not permitted in this context.
const initializer = { value = 2 };
~
!!! error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern.
const duplicate = { value, value };
~~~~~
!!! error TS1117: An object literal cannot have multiple properties with the same name.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/objectShorthandGrammar.ts] ////

//// [objectShorthandGrammar.ts]
const value = 1;
const valid = { value, other: value };
const optional = { value? };
const definite = { value! };
const initializer = { value = 2 };
const duplicate = { value, value };


//// [objectShorthandGrammar.js]
"use strict";
const value = 1;
const valid = { value, other: value };
const optional = { value };
const definite = { value };
const initializer = { value = 2 };
const duplicate = { value, value };
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [tests/cases/compiler/objectShorthandGrammar.ts] ////

=== objectShorthandGrammar.ts ===
const value = 1;
>value : Symbol(value, Decl(objectShorthandGrammar.ts, 0, 5))

const valid = { value, other: value };
>valid : Symbol(valid, Decl(objectShorthandGrammar.ts, 1, 5))
>value : Symbol(value, Decl(objectShorthandGrammar.ts, 1, 15))
>other : Symbol(other, Decl(objectShorthandGrammar.ts, 1, 22))
>value : Symbol(value, Decl(objectShorthandGrammar.ts, 0, 5))

const optional = { value? };
>optional : Symbol(optional, Decl(objectShorthandGrammar.ts, 2, 5))
>value : Symbol(value, Decl(objectShorthandGrammar.ts, 2, 18))

const definite = { value! };
>definite : Symbol(definite, Decl(objectShorthandGrammar.ts, 3, 5))
>value : Symbol(value, Decl(objectShorthandGrammar.ts, 3, 18))

const initializer = { value = 2 };
>initializer : Symbol(initializer, Decl(objectShorthandGrammar.ts, 4, 5))
>value : Symbol(value, Decl(objectShorthandGrammar.ts, 4, 21))

const duplicate = { value, value };
>duplicate : Symbol(duplicate, Decl(objectShorthandGrammar.ts, 5, 5))
>value : Symbol(value, Decl(objectShorthandGrammar.ts, 5, 19), Decl(objectShorthandGrammar.ts, 5, 26))
>value : Symbol(value, Decl(objectShorthandGrammar.ts, 5, 19), Decl(objectShorthandGrammar.ts, 5, 26))

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//// [tests/cases/compiler/objectShorthandGrammar.ts] ////

=== objectShorthandGrammar.ts ===
const value = 1;
>value : 1
>1 : 1

const valid = { value, other: value };
>valid : { value: number; other: number; }
>{ value, other: value } : { value: number; other: number; }
>value : number
>other : number
>value : 1

const optional = { value? };
>optional : { value: number; }
>{ value? } : { value: number; }
>value : number

const definite = { value! };
>definite : { value: number; }
>{ value! } : { value: number; }
>value : number

const initializer = { value = 2 };
>initializer : { value: number; }
>{ value = 2 } : { value: number; }
>value : number
>2 : 2

const duplicate = { value, value };
>duplicate : { value: number; }
>{ value, value } : { value: number; }
>value : number
>value : number

8 changes: 8 additions & 0 deletions tsc/testdata/tests/cases/compiler/objectShorthandGrammar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @strict: true

const value = 1;
const valid = { value, other: value };
const optional = { value? };
const definite = { value! };
const initializer = { value = 2 };
const duplicate = { value, value };
Loading