mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 02:18:37 -05:00
Parse an object literal property as shorthand unless followed by '(' or ':' (#28121)
This commit is contained in:
@@ -4738,8 +4738,7 @@ namespace ts {
|
||||
// CoverInitializedName[Yield] :
|
||||
// IdentifierReference[?Yield] Initializer[In, ?Yield]
|
||||
// this is necessary because ObjectLiteral productions are also used to cover grammar for ObjectAssignmentPattern
|
||||
const isShorthandPropertyAssignment =
|
||||
tokenIsIdentifier && (token() === SyntaxKind.CommaToken || token() === SyntaxKind.CloseBraceToken || token() === SyntaxKind.EqualsToken);
|
||||
const isShorthandPropertyAssignment = tokenIsIdentifier && (token() !== SyntaxKind.ColonToken);
|
||||
if (isShorthandPropertyAssignment) {
|
||||
node.kind = SyntaxKind.ShorthandPropertyAssignment;
|
||||
const equalsToken = parseOptionalToken(SyntaxKind.EqualsToken);
|
||||
|
||||
@@ -596,7 +596,8 @@ namespace ts {
|
||||
{
|
||||
compilerOptions: {
|
||||
target: undefined,
|
||||
module: ModuleKind.ESNext
|
||||
module: ModuleKind.ESNext,
|
||||
experimentalDecorators: true,
|
||||
},
|
||||
hasParseErrors: true
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace ts {
|
||||
|
||||
it("returns object with error when json is invalid", () => {
|
||||
const parsed = parseConfigFileTextToJson("/apath/tsconfig.json", "invalid");
|
||||
assert.deepEqual(parsed.config, { invalid: undefined });
|
||||
assert.deepEqual(parsed.config, {});
|
||||
const expected = createCompilerDiagnostic(Diagnostics._0_expected, "{");
|
||||
const error = parsed.error!;
|
||||
assert.equal(error.messageText, expected.messageText);
|
||||
|
||||
Reference in New Issue
Block a user