Skip to content

Commit 93bdfd2

Browse files
authored
fix(47056): report errors for all properties with errors (microsoft#47057)
1 parent 270b0d1 commit 93bdfd2

File tree

6 files changed

+70
-2
lines changed

6 files changed

+70
-2
lines changed

Diff for: src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43089,7 +43089,7 @@ namespace ts {
4308943089
if (prop.kind === SyntaxKind.ShorthandPropertyAssignment && !inDestructuring && prop.objectAssignmentInitializer) {
4309043090
// having objectAssignmentInitializer is only valid in ObjectAssignmentPattern
4309143091
// outside of destructuring it is a syntax error
43092-
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);
43092+
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);
4309343093
}
4309443094

4309543095
if (name.kind === SyntaxKind.PrivateIdentifier) {

Diff for: tests/baselines/reference/objectLiteralErrors.errors.txt

+17-1
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,46)
7474
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
7575
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(43,22): error TS2322: Type 'number' is not assignable to type 'string'.
7676
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
77+
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.
78+
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.
79+
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(50,5): error TS18016: Private identifiers are not allowed outside class bodies.
7780

7881

79-
==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (76 errors) ====
82+
==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (79 errors) ====
8083
// Multiple properties with the same name
8184
var e1 = { a: 0, a: 0 };
8285
~
@@ -273,4 +276,17 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16)
273276
var g3 = { get a(): number { return undefined; }, set a(n: string) { } };
274277
~
275278
!!! error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
279+
280+
// did you mean colon errors
281+
var h1 = {
282+
x = 1,
283+
~
284+
!!! 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.
285+
y = 2,
286+
~
287+
!!! 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.
288+
#z: 3
289+
~~
290+
!!! error TS18016: Private identifiers are not allowed outside class bodies.
291+
}
276292

Diff for: tests/baselines/reference/objectLiteralErrors.js

+13
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } };
4343
var g1 = { get a(): number { return 4; }, set a(n: string) { } };
4444
var g2 = { get a() { return 4; }, set a(n: string) { } };
4545
var g3 = { get a(): number { return undefined; }, set a(n: string) { } };
46+
47+
// did you mean colon errors
48+
var h1 = {
49+
x = 1,
50+
y = 2,
51+
#z: 3
52+
}
4653

4754

4855
//// [objectLiteralErrors.js]
@@ -88,3 +95,9 @@ var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } };
8895
var g1 = { get a() { return 4; }, set a(n) { } };
8996
var g2 = { get a() { return 4; }, set a(n) { } };
9097
var g3 = { get a() { return undefined; }, set a(n) { } };
98+
// did you mean colon errors
99+
var h1 = {
100+
x: x,
101+
y: y,
102+
: 3
103+
};

Diff for: tests/baselines/reference/objectLiteralErrors.symbols

+14
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,17 @@ var g3 = { get a(): number { return undefined; }, set a(n: string) { } };
203203
>a : Symbol(a, Decl(objectLiteralErrors.ts, 43, 10), Decl(objectLiteralErrors.ts, 43, 49))
204204
>n : Symbol(n, Decl(objectLiteralErrors.ts, 43, 56))
205205

206+
// did you mean colon errors
207+
var h1 = {
208+
>h1 : Symbol(h1, Decl(objectLiteralErrors.ts, 46, 3))
209+
210+
x = 1,
211+
>x : Symbol(x, Decl(objectLiteralErrors.ts, 46, 10))
212+
213+
y = 2,
214+
>y : Symbol(y, Decl(objectLiteralErrors.ts, 47, 10))
215+
216+
#z: 3
217+
>#z : Symbol(#z, Decl(objectLiteralErrors.ts, 48, 10))
218+
}
219+

Diff for: tests/baselines/reference/objectLiteralErrors.types

+18
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,21 @@ var g3 = { get a(): number { return undefined; }, set a(n: string) { } };
318318
>a : number
319319
>n : string
320320

321+
// did you mean colon errors
322+
var h1 = {
323+
>h1 : { x: number; y: number; }
324+
>{ x = 1, y = 2, #z: 3} : { x: number; y: number; }
325+
326+
x = 1,
327+
>x : any
328+
>1 : 1
329+
330+
y = 2,
331+
>y : any
332+
>2 : 2
333+
334+
#z: 3
335+
>#z : number
336+
>3 : 3
337+
}
338+

Diff for: tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts

+7
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,10 @@ var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } };
4444
var g1 = { get a(): number { return 4; }, set a(n: string) { } };
4545
var g2 = { get a() { return 4; }, set a(n: string) { } };
4646
var g3 = { get a(): number { return undefined; }, set a(n: string) { } };
47+
48+
// did you mean colon errors
49+
var h1 = {
50+
x = 1,
51+
y = 2,
52+
#z: 3
53+
}

0 commit comments

Comments
 (0)