diff --git a/tsc/internal/checker/grammarchecks.go b/tsc/internal/checker/grammarchecks.go index 7583ca819550f..7282241c8bcee 100644 --- a/tsc/internal/checker/grammarchecks.go +++ b/tsc/internal/checker/grammarchecks.go @@ -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 diff --git a/tsc/testdata/baselines/reference/compiler/objectShorthandGrammar.errors.txt b/tsc/testdata/baselines/reference/compiler/objectShorthandGrammar.errors.txt new file mode 100644 index 0000000000000..2b22db62a0fdd --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/objectShorthandGrammar.errors.txt @@ -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. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/objectShorthandGrammar.js b/tsc/testdata/baselines/reference/compiler/objectShorthandGrammar.js new file mode 100644 index 0000000000000..32cd488a0179f --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/objectShorthandGrammar.js @@ -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 }; diff --git a/tsc/testdata/baselines/reference/compiler/objectShorthandGrammar.symbols b/tsc/testdata/baselines/reference/compiler/objectShorthandGrammar.symbols new file mode 100644 index 0000000000000..846c36e723eef --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/objectShorthandGrammar.symbols @@ -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)) + diff --git a/tsc/testdata/baselines/reference/compiler/objectShorthandGrammar.types b/tsc/testdata/baselines/reference/compiler/objectShorthandGrammar.types new file mode 100644 index 0000000000000..16346baab46be --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/objectShorthandGrammar.types @@ -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 + diff --git a/tsc/testdata/tests/cases/compiler/objectShorthandGrammar.ts b/tsc/testdata/tests/cases/compiler/objectShorthandGrammar.ts new file mode 100644 index 0000000000000..9f4ed3b910fb6 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/objectShorthandGrammar.ts @@ -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 };