From 93bdfd25119f051f6f1358b166bc3b9d9f60257f Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 16 Dec 2021 22:58:15 +0200 Subject: [PATCH] fix(47056): report errors for all properties with errors (#47057) --- src/compiler/checker.ts | 2 +- .../reference/objectLiteralErrors.errors.txt | 18 +++++++++++++++++- .../baselines/reference/objectLiteralErrors.js | 13 +++++++++++++ .../reference/objectLiteralErrors.symbols | 14 ++++++++++++++ .../reference/objectLiteralErrors.types | 18 ++++++++++++++++++ .../objectLiterals/objectLiteralErrors.ts | 7 +++++++ 6 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cf15876bef4..1aff4bac02d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -43089,7 +43089,7 @@ namespace ts { if (prop.kind === SyntaxKind.ShorthandPropertyAssignment && !inDestructuring && prop.objectAssignmentInitializer) { // having objectAssignmentInitializer is only valid in ObjectAssignmentPattern // outside of destructuring it is a syntax error - return grammarErrorOnNode(prop.equalsToken!, Diagnostics.Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern); + grammarErrorOnNode(prop.equalsToken!, Diagnostics.Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern); } if (name.kind === SyntaxKind.PrivateIdentifier) { diff --git a/tests/baselines/reference/objectLiteralErrors.errors.txt b/tests/baselines/reference/objectLiteralErrors.errors.txt index 3c022929782..972e2a55241 100644 --- a/tests/baselines/reference/objectLiteralErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralErrors.errors.txt @@ -74,9 +74,12 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,46) tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,16): error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(43,22): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16): error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(48,7): 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. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(49,7): 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. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(50,5): error TS18016: Private identifiers are not allowed outside class bodies. -==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (76 errors) ==== +==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (79 errors) ==== // Multiple properties with the same name var e1 = { a: 0, a: 0 }; ~ @@ -273,4 +276,17 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16) var g3 = { get a(): number { return undefined; }, set a(n: string) { } }; ~ !!! error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type + + // did you mean colon errors + var h1 = { + x = 1, + ~ +!!! 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. + y = 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. + #z: 3 + ~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + } \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralErrors.js b/tests/baselines/reference/objectLiteralErrors.js index 1f721d3e71c..576e23b0b78 100644 --- a/tests/baselines/reference/objectLiteralErrors.js +++ b/tests/baselines/reference/objectLiteralErrors.js @@ -43,6 +43,13 @@ var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } }; var g1 = { get a(): number { return 4; }, set a(n: string) { } }; var g2 = { get a() { return 4; }, set a(n: string) { } }; var g3 = { get a(): number { return undefined; }, set a(n: string) { } }; + +// did you mean colon errors +var h1 = { + x = 1, + y = 2, + #z: 3 +} //// [objectLiteralErrors.js] @@ -88,3 +95,9 @@ var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } }; var g1 = { get a() { return 4; }, set a(n) { } }; var g2 = { get a() { return 4; }, set a(n) { } }; var g3 = { get a() { return undefined; }, set a(n) { } }; +// did you mean colon errors +var h1 = { + x: x, + y: y, + : 3 +}; diff --git a/tests/baselines/reference/objectLiteralErrors.symbols b/tests/baselines/reference/objectLiteralErrors.symbols index 94600906a2a..f2d19b661eb 100644 --- a/tests/baselines/reference/objectLiteralErrors.symbols +++ b/tests/baselines/reference/objectLiteralErrors.symbols @@ -203,3 +203,17 @@ var g3 = { get a(): number { return undefined; }, set a(n: string) { } }; >a : Symbol(a, Decl(objectLiteralErrors.ts, 43, 10), Decl(objectLiteralErrors.ts, 43, 49)) >n : Symbol(n, Decl(objectLiteralErrors.ts, 43, 56)) +// did you mean colon errors +var h1 = { +>h1 : Symbol(h1, Decl(objectLiteralErrors.ts, 46, 3)) + + x = 1, +>x : Symbol(x, Decl(objectLiteralErrors.ts, 46, 10)) + + y = 2, +>y : Symbol(y, Decl(objectLiteralErrors.ts, 47, 10)) + + #z: 3 +>#z : Symbol(#z, Decl(objectLiteralErrors.ts, 48, 10)) +} + diff --git a/tests/baselines/reference/objectLiteralErrors.types b/tests/baselines/reference/objectLiteralErrors.types index 271b657fd63..47631d9b1ae 100644 --- a/tests/baselines/reference/objectLiteralErrors.types +++ b/tests/baselines/reference/objectLiteralErrors.types @@ -318,3 +318,21 @@ var g3 = { get a(): number { return undefined; }, set a(n: string) { } }; >a : number >n : string +// did you mean colon errors +var h1 = { +>h1 : { x: number; y: number; } +>{ x = 1, y = 2, #z: 3} : { x: number; y: number; } + + x = 1, +>x : any +>1 : 1 + + y = 2, +>y : any +>2 : 2 + + #z: 3 +>#z : number +>3 : 3 +} + diff --git a/tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts b/tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts index 209b56eed6d..b95f12b6d14 100644 --- a/tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts +++ b/tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts @@ -44,3 +44,10 @@ var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } }; var g1 = { get a(): number { return 4; }, set a(n: string) { } }; var g2 = { get a() { return 4; }, set a(n: string) { } }; var g3 = { get a(): number { return undefined; }, set a(n: string) { } }; + +// did you mean colon errors +var h1 = { + x = 1, + y = 2, + #z: 3 +}