-
Notifications
You must be signed in to change notification settings - Fork 13.4k
check usage before declaration for decorators #50372
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
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
132 changes: 132 additions & 0 deletions
132
tests/baselines/reference/decoratorUsedBeforeDeclaration.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,132 @@ | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(1,2): error TS2448: Block-scoped variable 'lambda' used before its declaration. | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(1,9): error TS2450: Enum 'Enum' used before its declaration. | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(2,7): error TS2450: Enum 'Enum' used before its declaration. | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(4,4): error TS2448: Block-scoped variable 'lambda' used before its declaration. | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(4,11): error TS2450: Enum 'Enum' used before its declaration. | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(5,9): error TS2450: Enum 'Enum' used before its declaration. | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(12,4): error TS2448: Block-scoped variable 'lambda' used before its declaration. | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(12,11): error TS2450: Enum 'Enum' used before its declaration. | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(13,9): error TS2450: Enum 'Enum' used before its declaration. | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(18,4): error TS2448: Block-scoped variable 'lambda' used before its declaration. | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(24,11): error TS2448: Block-scoped variable 'lambda' used before its declaration. | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(24,18): error TS2450: Enum 'Enum' used before its declaration. | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(24,33): error TS2450: Enum 'Enum' used before its declaration. | ||
| tests/cases/compiler/decoratorUsedBeforeDeclaration.ts(28,11): error TS2448: Block-scoped variable 'lambda' used before its declaration. | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/decoratorUsedBeforeDeclaration.ts (14 errors) ==== | ||
| @lambda(Enum.No) | ||
| ~~~~~~ | ||
| !!! error TS2448: Block-scoped variable 'lambda' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:40:7: 'lambda' is declared here. | ||
| ~~~~ | ||
| !!! error TS2450: Enum 'Enum' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here. | ||
| @deco(Enum.No) | ||
| ~~~~ | ||
| !!! error TS2450: Enum 'Enum' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here. | ||
| class Greeter { | ||
| @lambda(Enum.No) | ||
| ~~~~~~ | ||
| !!! error TS2448: Block-scoped variable 'lambda' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:40:7: 'lambda' is declared here. | ||
| ~~~~ | ||
| !!! error TS2450: Enum 'Enum' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here. | ||
| @deco(Enum.No) | ||
| ~~~~ | ||
| !!! error TS2450: Enum 'Enum' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here. | ||
| greeting: string; | ||
|
|
||
| constructor(message: string) { | ||
| this.greeting = message; | ||
| } | ||
|
|
||
| @lambda(Enum.No) | ||
| ~~~~~~ | ||
| !!! error TS2448: Block-scoped variable 'lambda' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:40:7: 'lambda' is declared here. | ||
| ~~~~ | ||
| !!! error TS2450: Enum 'Enum' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here. | ||
| @deco(Enum.No) | ||
| ~~~~ | ||
| !!! error TS2450: Enum 'Enum' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here. | ||
| greet() { | ||
| return "Hello, " + this.greeting; | ||
| } | ||
|
|
||
| @lambda | ||
| ~~~~~~ | ||
| !!! error TS2448: Block-scoped variable 'lambda' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:40:7: 'lambda' is declared here. | ||
| @deco | ||
| greet1() { | ||
| return "Hello, " + this.greeting; | ||
| } | ||
|
|
||
| greet2(@lambda(Enum.No) @deco(Enum.No) param) { | ||
| ~~~~~~ | ||
| !!! error TS2448: Block-scoped variable 'lambda' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:40:7: 'lambda' is declared here. | ||
| ~~~~ | ||
| !!! error TS2450: Enum 'Enum' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here. | ||
| ~~~~ | ||
| !!! error TS2450: Enum 'Enum' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here. | ||
| return "Hello, " + this.greeting; | ||
| } | ||
|
|
||
| greet3(@lambda @deco param) { | ||
| ~~~~~~ | ||
| !!! error TS2448: Block-scoped variable 'lambda' used before its declaration. | ||
| !!! related TS2728 tests/cases/compiler/decoratorUsedBeforeDeclaration.ts:40:7: 'lambda' is declared here. | ||
| return "Hello, " + this.greeting; | ||
| } | ||
| } | ||
|
|
||
| function deco(...args: any[]): any {} | ||
|
|
||
| enum Enum { | ||
| No = 0, | ||
| Yes = 1, | ||
| } | ||
|
|
||
| const lambda = (...args: any[]): any => {}; | ||
|
|
||
| @lambda(Enum.No) | ||
| @deco(Enum.No) | ||
| class Greeter1 { | ||
| @lambda(Enum.No) | ||
| @deco(Enum.No) | ||
| greeting: string; | ||
|
|
||
| constructor(message: string) { | ||
| this.greeting = message; | ||
| } | ||
|
|
||
| @lambda(Enum.No) | ||
| @deco(Enum.No) | ||
| greet() { | ||
| return "Hello, " + this.greeting; | ||
| } | ||
|
|
||
| @lambda | ||
| @deco | ||
| greet1() { | ||
| return "Hello, " + this.greeting; | ||
| } | ||
|
|
||
| greet2(@lambda(Enum.No) @deco(Enum.No) param) { | ||
| return "Hello, " + this.greeting; | ||
| } | ||
|
|
||
| greet3(@lambda @deco param) { | ||
| return "Hello, " + this.greeting; | ||
| } | ||
| } | ||
|
|
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.
Enum is not checked properly. playground