Skip to content

fix(47056): Only the first did-you-mean-colon error in an object literal is reported #47057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2021
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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43067,7 +43067,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) {
Expand Down
18 changes: 17 additions & 1 deletion tests/baselines/reference/objectLiteralErrors.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
~
Expand Down Expand Up @@ -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.
}

13 changes: 13 additions & 0 deletions tests/baselines/reference/objectLiteralErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
};
14 changes: 14 additions & 0 deletions tests/baselines/reference/objectLiteralErrors.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

18 changes: 18 additions & 0 deletions tests/baselines/reference/objectLiteralErrors.types
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
}