Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ func (c *Checker) isBlockScopedNameDeclaredBeforeUse(declaration *ast.Node, usag
func (c *Checker) isUsedInFunctionOrInstanceProperty(usage *ast.Node, declaration *ast.Node, declContainer *ast.Node) bool {
for current := usage; current != nil && current != declContainer; current = current.Parent {
if ast.IsFunctionLike(current) {
return true
return ast.GetImmediatelyInvokedFunctionExpression(current) == nil
}
if ast.IsClassStaticBlockDeclaration(current) {
return declaration.Pos() < usage.Pos()
Expand All @@ -1933,6 +1933,15 @@ func (c *Checker) isUsedInFunctionOrInstanceProperty(usage *ast.Node, declaratio
}
}
}
if current.Parent != nil && ast.IsDecorator(current.Parent) && current.Parent.AsDecorator().Expression == current {
decorator := current.Parent.AsDecorator()
if ast.IsParameter(decorator.Parent) {
return c.isUsedInFunctionOrInstanceProperty(decorator.Parent.Parent.Parent, declaration, declContainer)
}
if ast.IsMethodDeclaration(decorator.Parent) {
return c.isUsedInFunctionOrInstanceProperty(decorator.Parent.Parent, declaration, declContainer)
}
}
}
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ blockScopedVariablesUseBeforeDef.ts(100,12): error TS2448: Block-scoped variable
blockScopedVariablesUseBeforeDef.ts(111,28): error TS2448: Block-scoped variable 'a' used before its declaration.
blockScopedVariablesUseBeforeDef.ts(112,21): error TS2448: Block-scoped variable 'a' used before its declaration.
blockScopedVariablesUseBeforeDef.ts(122,22): error TS2448: Block-scoped variable 'a' used before its declaration.
blockScopedVariablesUseBeforeDef.ts(128,9): error TS2448: Block-scoped variable 'foo' used before its declaration.
blockScopedVariablesUseBeforeDef.ts(131,9): error TS2448: Block-scoped variable 'foo' used before its declaration.
blockScopedVariablesUseBeforeDef.ts(153,20): error TS2450: Enum 'Enum' used before its declaration.


==== blockScopedVariablesUseBeforeDef.ts (7 errors) ====
==== blockScopedVariablesUseBeforeDef.ts (10 errors) ====
function foo0() {
let a = x;
~
Expand Down Expand Up @@ -157,9 +160,15 @@ blockScopedVariablesUseBeforeDef.ts(122,22): error TS2448: Block-scoped variable
const promise = (async () => {
promise
foo
~~~
!!! error TS2448: Block-scoped variable 'foo' used before its declaration.
!!! related TS2728 blockScopedVariablesUseBeforeDef.ts:134:11: 'foo' is declared here.
await null
promise
foo
~~~
!!! error TS2448: Block-scoped variable 'foo' used before its declaration.
!!! related TS2728 blockScopedVariablesUseBeforeDef.ts:134:11: 'foo' is declared here.
})()

const foo = 1;
Expand All @@ -182,6 +191,9 @@ blockScopedVariablesUseBeforeDef.ts(122,22): error TS2448: Block-scoped variable

function foo18() {
let a = (() => Enum.Yes)();
~~~~
!!! error TS2450: Enum 'Enum' used before its declaration.
!!! related TS2728 blockScopedVariablesUseBeforeDef.ts:154:10: 'Enum' is declared here.
enum Enum {
No = 0,
Yes = 1,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ decoratorUsedBeforeDeclaration.ts(2,7): error TS2450: Enum 'Enum' used before it
decoratorUsedBeforeDeclaration.ts(4,4): error TS2448: Block-scoped variable 'lambda' used before its declaration.
decoratorUsedBeforeDeclaration.ts(4,11): error TS2450: Enum 'Enum' used before its declaration.
decoratorUsedBeforeDeclaration.ts(5,9): error TS2450: Enum 'Enum' used before its declaration.
decoratorUsedBeforeDeclaration.ts(12,4): error TS2448: Block-scoped variable 'lambda' used before its declaration.
decoratorUsedBeforeDeclaration.ts(12,11): error TS2450: Enum 'Enum' used before its declaration.
decoratorUsedBeforeDeclaration.ts(13,9): error TS2450: Enum 'Enum' used before its declaration.
decoratorUsedBeforeDeclaration.ts(18,4): error TS2448: Block-scoped variable 'lambda' used before its declaration.
decoratorUsedBeforeDeclaration.ts(24,11): error TS2448: Block-scoped variable 'lambda' used before its declaration.
decoratorUsedBeforeDeclaration.ts(24,18): error TS2450: Enum 'Enum' used before its declaration.
decoratorUsedBeforeDeclaration.ts(24,33): error TS2450: Enum 'Enum' used before its declaration.
decoratorUsedBeforeDeclaration.ts(28,11): error TS2448: Block-scoped variable 'lambda' used before its declaration.


==== decoratorUsedBeforeDeclaration.ts (6 errors) ====
==== decoratorUsedBeforeDeclaration.ts (14 errors) ====
@lambda(Enum.No)
~~~~~~
!!! error TS2448: Block-scoped variable 'lambda' used before its declaration.
Expand Down Expand Up @@ -37,22 +45,46 @@ decoratorUsedBeforeDeclaration.ts(5,9): error TS2450: Enum 'Enum' used before it
}

@lambda(Enum.No)
~~~~~~
!!! error TS2448: Block-scoped variable 'lambda' used before its declaration.
!!! related TS2728 decoratorUsedBeforeDeclaration.ts:40:7: 'lambda' is declared here.
~~~~
!!! error TS2450: Enum 'Enum' used before its declaration.
!!! related TS2728 decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here.
@deco(Enum.No)
~~~~
!!! error TS2450: Enum 'Enum' used before its declaration.
!!! related TS2728 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 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 decoratorUsedBeforeDeclaration.ts:40:7: 'lambda' is declared here.
~~~~
!!! error TS2450: Enum 'Enum' used before its declaration.
!!! related TS2728 decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here.
~~~~
!!! error TS2450: Enum 'Enum' used before its declaration.
!!! related TS2728 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 decoratorUsedBeforeDeclaration.ts:40:7: 'lambda' is declared here.
return "Hello, " + this.greeting;
}
}
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rest of this diff should go away with #1828

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll wait to look at the PR until that one gets through the merge queue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

synced with main now and it's gone :)

Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@
-decoratorUsedBeforeDeclaration.ts(4,16): error TS2729: Property 'No' is used before its initialization.
decoratorUsedBeforeDeclaration.ts(5,9): error TS2450: Enum 'Enum' used before its declaration.
-decoratorUsedBeforeDeclaration.ts(5,14): error TS2729: Property 'No' is used before its initialization.
-decoratorUsedBeforeDeclaration.ts(12,4): error TS2448: Block-scoped variable 'lambda' used before its declaration.
-decoratorUsedBeforeDeclaration.ts(12,11): error TS2450: Enum 'Enum' used before its declaration.
-decoratorUsedBeforeDeclaration.ts(13,9): error TS2450: Enum 'Enum' used before its declaration.
-decoratorUsedBeforeDeclaration.ts(18,4): error TS2448: Block-scoped variable 'lambda' used before its declaration.
-decoratorUsedBeforeDeclaration.ts(24,11): error TS2448: Block-scoped variable 'lambda' used before its declaration.
-decoratorUsedBeforeDeclaration.ts(24,18): error TS2450: Enum 'Enum' used before its declaration.
-decoratorUsedBeforeDeclaration.ts(24,33): error TS2450: Enum 'Enum' used before its declaration.
-decoratorUsedBeforeDeclaration.ts(28,11): error TS2448: Block-scoped variable 'lambda' used before its declaration.
-
-
decoratorUsedBeforeDeclaration.ts(12,4): error TS2448: Block-scoped variable 'lambda' used before its declaration.
decoratorUsedBeforeDeclaration.ts(12,11): error TS2450: Enum 'Enum' used before its declaration.
decoratorUsedBeforeDeclaration.ts(13,9): error TS2450: Enum 'Enum' used before its declaration.
@@= skipped -13, +11 lines =@@
decoratorUsedBeforeDeclaration.ts(28,11): error TS2448: Block-scoped variable 'lambda' used before its declaration.


-==== decoratorUsedBeforeDeclaration.ts (16 errors) ====
+
+
+==== decoratorUsedBeforeDeclaration.ts (6 errors) ====
+==== decoratorUsedBeforeDeclaration.ts (14 errors) ====
@lambda(Enum.No)
~~~~~~
!!! error TS2448: Block-scoped variable 'lambda' used before its declaration.
@@= skipped -33, +23 lines =@@
@@= skipped -20, +20 lines =@@
~~~~
!!! error TS2450: Enum 'Enum' used before its declaration.
!!! related TS2728 decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here.
Expand All @@ -40,51 +35,4 @@
-!!! related TS2728 decoratorUsedBeforeDeclaration.ts:36:3: 'No' is declared here.
greeting: string;

constructor(message: string) {
@@= skipped -17, +11 lines =@@
}

@lambda(Enum.No)
- ~~~~~~
-!!! error TS2448: Block-scoped variable 'lambda' used before its declaration.
-!!! related TS2728 decoratorUsedBeforeDeclaration.ts:40:7: 'lambda' is declared here.
- ~~~~
-!!! error TS2450: Enum 'Enum' used before its declaration.
-!!! related TS2728 decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here.
@deco(Enum.No)
- ~~~~
-!!! error TS2450: Enum 'Enum' used before its declaration.
-!!! related TS2728 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 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 decoratorUsedBeforeDeclaration.ts:40:7: 'lambda' is declared here.
- ~~~~
-!!! error TS2450: Enum 'Enum' used before its declaration.
-!!! related TS2728 decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here.
- ~~~~
-!!! error TS2450: Enum 'Enum' used before its declaration.
-!!! related TS2728 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 decoratorUsedBeforeDeclaration.ts:40:7: 'lambda' is declared here.
return "Hello, " + this.greeting;
}
}
constructor(message: string) {