-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Adjust offset to account for 'this' parameter when emitting parameter decorators #30495
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
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
26 changes: 26 additions & 0 deletions
26
tests/baselines/reference/decoratorOnClassMethodParameter2.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,26 @@ | ||
| //// [decoratorOnClassMethodParameter2.ts] | ||
| declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; | ||
|
|
||
| class C { | ||
| method(this: C, @dec p: number) {} | ||
| } | ||
|
|
||
| //// [decoratorOnClassMethodParameter2.js] | ||
| 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 __param = (this && this.__param) || function (paramIndex, decorator) { | ||
| return function (target, key) { decorator(target, key, paramIndex); } | ||
| }; | ||
| var C = /** @class */ (function () { | ||
| function C() { | ||
| } | ||
| C.prototype.method = function (p) { }; | ||
| __decorate([ | ||
| __param(0, dec) | ||
| ], C.prototype, "method", null); | ||
| return C; | ||
| }()); |
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/decoratorOnClassMethodParameter2.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,18 @@ | ||
| === tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter2.ts === | ||
| declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; | ||
| >dec : Symbol(dec, Decl(decoratorOnClassMethodParameter2.ts, 0, 0)) | ||
| >target : Symbol(target, Decl(decoratorOnClassMethodParameter2.ts, 0, 21)) | ||
| >Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
| >propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethodParameter2.ts, 0, 36)) | ||
| >parameterIndex : Symbol(parameterIndex, Decl(decoratorOnClassMethodParameter2.ts, 0, 66)) | ||
|
|
||
| class C { | ||
| >C : Symbol(C, Decl(decoratorOnClassMethodParameter2.ts, 0, 97)) | ||
|
|
||
| method(this: C, @dec p: number) {} | ||
| >method : Symbol(C.method, Decl(decoratorOnClassMethodParameter2.ts, 2, 9)) | ||
| >this : Symbol(this, Decl(decoratorOnClassMethodParameter2.ts, 3, 11)) | ||
| >C : Symbol(C, Decl(decoratorOnClassMethodParameter2.ts, 0, 97)) | ||
| >dec : Symbol(dec, Decl(decoratorOnClassMethodParameter2.ts, 0, 0)) | ||
| >p : Symbol(p, Decl(decoratorOnClassMethodParameter2.ts, 3, 19)) | ||
| } |
16 changes: 16 additions & 0 deletions
16
tests/baselines/reference/decoratorOnClassMethodParameter2.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,16 @@ | ||
| === tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter2.ts === | ||
| declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; | ||
| >dec : (target: Object, propertyKey: string | symbol, parameterIndex: number) => void | ||
| >target : Object | ||
| >propertyKey : string | symbol | ||
| >parameterIndex : number | ||
|
|
||
| class C { | ||
| >C : C | ||
|
|
||
| method(this: C, @dec p: number) {} | ||
| >method : (this: C, p: number) => void | ||
| >this : C | ||
| >dec : (target: Object, propertyKey: string | symbol, parameterIndex: number) => void | ||
| >p : number | ||
| } |
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/decoratorOnClassMethodThisParameter.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,14 @@ | ||
| tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodThisParameter.ts(4,17): error TS1003: Identifier expected. | ||
| tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodThisParameter.ts(4,17): error TS2680: A 'this' parameter must be the first parameter. | ||
|
|
||
|
|
||
| ==== tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodThisParameter.ts (2 errors) ==== | ||
| declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; | ||
|
|
||
| class C { | ||
| method(@dec this: C) {} | ||
| ~~~~ | ||
| !!! error TS1003: Identifier expected. | ||
| ~~~~~~~ | ||
| !!! error TS2680: A 'this' parameter must be the first parameter. | ||
| } |
26 changes: 26 additions & 0 deletions
26
tests/baselines/reference/decoratorOnClassMethodThisParameter.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,26 @@ | ||
| //// [decoratorOnClassMethodThisParameter.ts] | ||
| declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; | ||
|
|
||
| class C { | ||
| method(@dec this: C) {} | ||
| } | ||
|
|
||
| //// [decoratorOnClassMethodThisParameter.js] | ||
| 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 __param = (this && this.__param) || function (paramIndex, decorator) { | ||
| return function (target, key) { decorator(target, key, paramIndex); } | ||
| }; | ||
| var C = /** @class */ (function () { | ||
| function C() { | ||
| } | ||
| C.prototype.method = function () { }; | ||
| __decorate([ | ||
| __param(0, dec) | ||
| ], C.prototype, "method", null); | ||
| return C; | ||
| }()); |
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/decoratorOnClassMethodThisParameter.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,18 @@ | ||
| === tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodThisParameter.ts === | ||
| declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; | ||
| >dec : Symbol(dec, Decl(decoratorOnClassMethodThisParameter.ts, 0, 0)) | ||
| >target : Symbol(target, Decl(decoratorOnClassMethodThisParameter.ts, 0, 21)) | ||
| >Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
| >propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethodThisParameter.ts, 0, 36)) | ||
| >parameterIndex : Symbol(parameterIndex, Decl(decoratorOnClassMethodThisParameter.ts, 0, 66)) | ||
|
|
||
| class C { | ||
| >C : Symbol(C, Decl(decoratorOnClassMethodThisParameter.ts, 0, 97)) | ||
|
|
||
| method(@dec this: C) {} | ||
| >method : Symbol(C.method, Decl(decoratorOnClassMethodThisParameter.ts, 2, 9)) | ||
| >dec : Symbol(dec, Decl(decoratorOnClassMethodThisParameter.ts, 0, 0)) | ||
| > : Symbol((Missing), Decl(decoratorOnClassMethodThisParameter.ts, 3, 11)) | ||
| >this : Symbol(this, Decl(decoratorOnClassMethodThisParameter.ts, 3, 15)) | ||
| >C : Symbol(C, Decl(decoratorOnClassMethodThisParameter.ts, 0, 97)) | ||
| } |
16 changes: 16 additions & 0 deletions
16
tests/baselines/reference/decoratorOnClassMethodThisParameter.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,16 @@ | ||
| === tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodThisParameter.ts === | ||
| declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; | ||
| >dec : (target: Object, propertyKey: string | symbol, parameterIndex: number) => void | ||
| >target : Object | ||
| >propertyKey : string | symbol | ||
| >parameterIndex : number | ||
|
|
||
| class C { | ||
| >C : C | ||
|
|
||
| method(@dec this: C) {} | ||
| >method : (: any, this: C) => void | ||
| >dec : (target: Object, propertyKey: string | symbol, parameterIndex: number) => void | ||
| > : any | ||
| >this : C | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
...s/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter2.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,7 @@ | ||
| // @target:es5 | ||
| // @experimentaldecorators: true | ||
| declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; | ||
|
|
||
| class C { | ||
| method(this: C, @dec p: number) {} | ||
| } |
7 changes: 7 additions & 0 deletions
7
...ases/conformance/decorators/class/method/parameter/decoratorOnClassMethodThisParameter.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,7 @@ | ||
| // @target:es5 | ||
| // @experimentaldecorators: true | ||
| declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; | ||
|
|
||
| class C { | ||
| method(@dec this: C) {} | ||
| } |
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.
this type seems incorrectly printed?
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.
Are decorators on
thisparameters even a thing? O.oThere 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.
That's because this is a parse error (i.e.
@dec thisfails becausethisisn't an identifier), so you end up with a missing identifier.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.
No, decorators on
thisparameters were never valid, but we did not have a test that reflects this. I opted to add one while investigating this fixThere 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.
Huh. Neat.