Skip to content
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
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 @@ -6,9 +6,17 @@ decoratorUsedBeforeDeclaration.ts(4,11): error TS2450: Enum 'Enum' used before i
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 (8 errors) ====
==== decoratorUsedBeforeDeclaration.ts (16 errors) ====
@lambda(Enum.No)
~~~~~~
!!! error TS2448: Block-scoped variable 'lambda' used before its declaration.
Expand Down Expand Up @@ -45,22 +53,46 @@ decoratorUsedBeforeDeclaration.ts(5,14): error TS2729: Property 'No' is used bef
}

@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

This file was deleted.