Repository navigation
Fix crash in decorator metadata emit for decorated object literal members #64633
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
Jake Bailey (jakebailey)
merged 1 commit into
microsoft:main
from
Andarist:fix-decorator-metadata-object-literal-crash
Oct 6, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...tdata/baselines/reference/compiler/decoratorMetadataObjectLiteralMethodNoCrash.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| decoratorMetadataObjectLiteralMethodNoCrash.ts(4,7): error TS1206: Decorators are not valid here. | ||
| decoratorMetadataObjectLiteralMethodNoCrash.ts(13,15): error TS1206: Decorators are not valid here. | ||
| decoratorMetadataObjectLiteralMethodNoCrash.ts(14,19): error TS1206: Decorators are not valid here. | ||
|
|
||
|
|
||
| ==== decoratorMetadataObjectLiteralMethodNoCrash.ts (3 errors) ==== | ||
| declare function dec(...args: any[]): any; | ||
|
|
||
| const o = { | ||
| m(@dec x: string) {} | ||
| ~ | ||
| !!! error TS1206: Decorators are not valid here. | ||
| }; | ||
|
|
||
| class C { | ||
| @dec | ||
| prop!: number; | ||
|
|
||
| method() { | ||
| return { | ||
| m(@dec x: string) {}, | ||
| ~ | ||
| !!! error TS1206: Decorators are not valid here. | ||
| set s(@dec v: number) {} | ||
| ~ | ||
| !!! error TS1206: Decorators are not valid here. | ||
| }; | ||
| } | ||
| } | ||
|
|
49 changes: 49 additions & 0 deletions
49
tsc/testdata/baselines/reference/compiler/decoratorMetadataObjectLiteralMethodNoCrash.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //// [tests/cases/compiler/decoratorMetadataObjectLiteralMethodNoCrash.ts] //// | ||
|
|
||
| //// [decoratorMetadataObjectLiteralMethodNoCrash.ts] | ||
| declare function dec(...args: any[]): any; | ||
|
|
||
| const o = { | ||
| m(@dec x: string) {} | ||
| }; | ||
|
|
||
| class C { | ||
| @dec | ||
| prop!: number; | ||
|
|
||
| method() { | ||
| return { | ||
| m(@dec x: string) {}, | ||
| set s(@dec v: number) {} | ||
| }; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| //// [decoratorMetadataObjectLiteralMethodNoCrash.js] | ||
| "use strict"; | ||
| var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
| var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
| if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
| else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
| return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
| }; | ||
| var __metadata = (this && this.__metadata) || function (k, v) { | ||
| if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
| }; | ||
| const o = { | ||
| m(x) { } | ||
| }; | ||
| class C { | ||
| prop; | ||
| method() { | ||
| return { | ||
| m(x) { }, | ||
| set s(v) { } | ||
| }; | ||
| } | ||
| } | ||
| __decorate([ | ||
| dec, | ||
| __metadata("design:type", Number) | ||
| ], C.prototype, "prop", void 0); |
44 changes: 44 additions & 0 deletions
44
...testdata/baselines/reference/compiler/decoratorMetadataObjectLiteralMethodNoCrash.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| //// [tests/cases/compiler/decoratorMetadataObjectLiteralMethodNoCrash.ts] //// | ||
|
|
||
| === decoratorMetadataObjectLiteralMethodNoCrash.ts === | ||
| declare function dec(...args: any[]): any; | ||
| >dec : Symbol(dec, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 0, 0)) | ||
| >args : Symbol(args, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 0, 21)) | ||
|
|
||
| const o = { | ||
| >o : Symbol(o, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 2, 5)) | ||
|
|
||
| m(@dec x: string) {} | ||
| >m : Symbol(m, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 2, 11)) | ||
| >dec : Symbol(dec, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 0, 0)) | ||
| >x : Symbol(x, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 3, 6)) | ||
|
|
||
| }; | ||
|
|
||
| class C { | ||
| >C : Symbol(C, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 4, 2)) | ||
|
|
||
| @dec | ||
| >dec : Symbol(dec, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 0, 0)) | ||
|
|
||
| prop!: number; | ||
| >prop : Symbol(C.prop, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 6, 9)) | ||
|
|
||
| method() { | ||
| >method : Symbol(C.method, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 8, 18)) | ||
|
|
||
| return { | ||
| m(@dec x: string) {}, | ||
| >m : Symbol(m, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 11, 16)) | ||
| >dec : Symbol(dec, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 0, 0)) | ||
| >x : Symbol(x, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 12, 14)) | ||
|
|
||
| set s(@dec v: number) {} | ||
| >s : Symbol(s, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 12, 33)) | ||
| >dec : Symbol(dec, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 0, 0)) | ||
| >v : Symbol(v, Decl(decoratorMetadataObjectLiteralMethodNoCrash.ts, 13, 18)) | ||
|
|
||
| }; | ||
| } | ||
| } | ||
|
|
47 changes: 47 additions & 0 deletions
47
tsc/testdata/baselines/reference/compiler/decoratorMetadataObjectLiteralMethodNoCrash.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| //// [tests/cases/compiler/decoratorMetadataObjectLiteralMethodNoCrash.ts] //// | ||
|
|
||
| === decoratorMetadataObjectLiteralMethodNoCrash.ts === | ||
| declare function dec(...args: any[]): any; | ||
| >dec : (...args: any[]) => any | ||
| >args : any[] | ||
|
|
||
| const o = { | ||
| >o : { m(x: string): void; } | ||
| >{ m(@dec x: string) {}} : { m(x: string): void; } | ||
|
|
||
| m(@dec x: string) {} | ||
| >m : (x: string) => void | ||
| >dec : (...args: any[]) => any | ||
| >x : string | ||
|
|
||
| }; | ||
|
|
||
| class C { | ||
| >C : C | ||
|
|
||
| @dec | ||
| >dec : (...args: any[]) => any | ||
|
|
||
| prop!: number; | ||
| >prop : number | ||
|
|
||
| method() { | ||
| >method : () => { m(x: string): void; s: number; } | ||
|
|
||
| return { | ||
| >{ m(@dec x: string) {}, set s(@dec v: number) {} } : { m(x: string): void; s: number; } | ||
|
|
||
| m(@dec x: string) {}, | ||
| >m : (x: string) => void | ||
| >dec : (...args: any[]) => any | ||
| >x : string | ||
|
|
||
| set s(@dec v: number) {} | ||
| >s : number | ||
| >dec : (...args: any[]) => any | ||
| >v : number | ||
|
|
||
| }; | ||
| } | ||
| } | ||
|
|
20 changes: 20 additions & 0 deletions
20
tsc/testdata/tests/cases/compiler/decoratorMetadataObjectLiteralMethodNoCrash.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // @experimentalDecorators: true | ||
| // @emitDecoratorMetadata: true | ||
|
Andarist marked this conversation as resolved.
|
||
|
|
||
| declare function dec(...args: any[]): any; | ||
|
|
||
| const o = { | ||
| m(@dec x: string) {} | ||
| }; | ||
|
|
||
| class C { | ||
| @dec | ||
| prop!: number; | ||
|
|
||
| method() { | ||
| return { | ||
| m(@dec x: string) {}, | ||
| set s(@dec v: number) {} | ||
| }; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix here matches Strada conceptually. Strada passed down
parent(also in the case of object literal expressions). This patch just reuses the neighboring pattern (the same thing as invisitClassExpression) for doing the equivalent here in Corsa