-
Notifications
You must be signed in to change notification settings - Fork 12.8k
align ClassStaticBlockDeclaration with IIFE in CFA #44969
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fa66faf
align ClassStaticBlockDeclaration with IIFE in CFA
Zzzen 2af5e8e
isIIFELike => isImmediatelyInvoked
Zzzen 038d7c4
fix unexpected used-before-assignment errors
Zzzen 7b074c5
Merge branch 'microsoft:main' into cfa-in-class-static-block
Zzzen 311ed52
fix unexpected used-before-assignment errors in class static block
Zzzen ecb3adb
update baseline
Zzzen 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//// [classStaticBlock28.ts] | ||
let foo: number; | ||
|
||
class C { | ||
static { | ||
foo = 1 | ||
} | ||
} | ||
|
||
console.log(foo) | ||
|
||
//// [classStaticBlock28.js] | ||
"use strict"; | ||
var foo; | ||
var C = /** @class */ (function () { | ||
function C() { | ||
} | ||
return C; | ||
}()); | ||
(function () { | ||
foo = 1; | ||
})(); | ||
console.log(foo); |
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,19 @@ | ||
=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock28.ts === | ||
let foo: number; | ||
>foo : Symbol(foo, Decl(classStaticBlock28.ts, 0, 3)) | ||
|
||
class C { | ||
>C : Symbol(C, Decl(classStaticBlock28.ts, 0, 16)) | ||
|
||
static { | ||
foo = 1 | ||
>foo : Symbol(foo, Decl(classStaticBlock28.ts, 0, 3)) | ||
} | ||
} | ||
|
||
console.log(foo) | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>foo : Symbol(foo, Decl(classStaticBlock28.ts, 0, 3)) | ||
|
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,22 @@ | ||
=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock28.ts === | ||
let foo: number; | ||
>foo : number | ||
|
||
class C { | ||
>C : C | ||
|
||
static { | ||
foo = 1 | ||
>foo = 1 : 1 | ||
>foo : number | ||
>1 : 1 | ||
} | ||
} | ||
|
||
console.log(foo) | ||
>console.log(foo) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>foo : number | ||
|
53 changes: 53 additions & 0 deletions
53
tests/baselines/reference/classStaticBlockUseBeforeDef3.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,53 @@ | ||
tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef3.ts(14,21): error TS2448: Block-scoped variable 'FOO' used before its declaration. | ||
tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef3.ts(14,21): error TS2454: Variable 'FOO' is used before being assigned. | ||
|
||
|
||
==== tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef3.ts (2 errors) ==== | ||
class A { | ||
static { | ||
A.doSomething(); // should not error | ||
} | ||
|
||
static doSomething() { | ||
console.log("gotcha!"); | ||
} | ||
} | ||
|
||
|
||
class Baz { | ||
static { | ||
console.log(FOO); // should error | ||
~~~ | ||
!!! error TS2448: Block-scoped variable 'FOO' used before its declaration. | ||
!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef3.ts:18:7: 'FOO' is declared here. | ||
~~~ | ||
!!! error TS2454: Variable 'FOO' is used before being assigned. | ||
} | ||
} | ||
|
||
const FOO = "FOO"; | ||
class Bar { | ||
static { | ||
console.log(FOO); // should not error | ||
} | ||
} | ||
|
||
let u = "FOO" as "FOO" | "BAR"; | ||
|
||
class CFA { | ||
static { | ||
u = "BAR"; | ||
u; // should be "BAR" | ||
} | ||
|
||
static t = 1; | ||
|
||
static doSomething() {} | ||
|
||
static { | ||
u; // should be "BAR" | ||
} | ||
} | ||
|
||
u; // should be "BAR" | ||
|
78 changes: 78 additions & 0 deletions
78
tests/baselines/reference/classStaticBlockUseBeforeDef3.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,78 @@ | ||
=== tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef3.ts === | ||
class A { | ||
>A : Symbol(A, Decl(classStaticBlockUseBeforeDef3.ts, 0, 0)) | ||
|
||
static { | ||
A.doSomething(); // should not error | ||
>A.doSomething : Symbol(A.doSomething, Decl(classStaticBlockUseBeforeDef3.ts, 3, 5)) | ||
>A : Symbol(A, Decl(classStaticBlockUseBeforeDef3.ts, 0, 0)) | ||
>doSomething : Symbol(A.doSomething, Decl(classStaticBlockUseBeforeDef3.ts, 3, 5)) | ||
} | ||
|
||
static doSomething() { | ||
>doSomething : Symbol(A.doSomething, Decl(classStaticBlockUseBeforeDef3.ts, 3, 5)) | ||
|
||
console.log("gotcha!"); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
} | ||
} | ||
|
||
|
||
class Baz { | ||
>Baz : Symbol(Baz, Decl(classStaticBlockUseBeforeDef3.ts, 8, 1)) | ||
|
||
static { | ||
console.log(FOO); // should error | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>FOO : Symbol(FOO, Decl(classStaticBlockUseBeforeDef3.ts, 17, 5)) | ||
} | ||
} | ||
|
||
const FOO = "FOO"; | ||
>FOO : Symbol(FOO, Decl(classStaticBlockUseBeforeDef3.ts, 17, 5)) | ||
|
||
class Bar { | ||
>Bar : Symbol(Bar, Decl(classStaticBlockUseBeforeDef3.ts, 17, 18)) | ||
|
||
static { | ||
console.log(FOO); // should not error | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>FOO : Symbol(FOO, Decl(classStaticBlockUseBeforeDef3.ts, 17, 5)) | ||
} | ||
} | ||
|
||
let u = "FOO" as "FOO" | "BAR"; | ||
>u : Symbol(u, Decl(classStaticBlockUseBeforeDef3.ts, 24, 3)) | ||
|
||
class CFA { | ||
>CFA : Symbol(CFA, Decl(classStaticBlockUseBeforeDef3.ts, 24, 31)) | ||
|
||
static { | ||
u = "BAR"; | ||
>u : Symbol(u, Decl(classStaticBlockUseBeforeDef3.ts, 24, 3)) | ||
|
||
u; // should be "BAR" | ||
>u : Symbol(u, Decl(classStaticBlockUseBeforeDef3.ts, 24, 3)) | ||
} | ||
|
||
static t = 1; | ||
>t : Symbol(CFA.t, Decl(classStaticBlockUseBeforeDef3.ts, 30, 5)) | ||
|
||
static doSomething() {} | ||
>doSomething : Symbol(CFA.doSomething, Decl(classStaticBlockUseBeforeDef3.ts, 32, 17)) | ||
|
||
static { | ||
u; // should be "BAR" | ||
>u : Symbol(u, Decl(classStaticBlockUseBeforeDef3.ts, 24, 3)) | ||
} | ||
} | ||
|
||
u; // should be "BAR" | ||
>u : Symbol(u, Decl(classStaticBlockUseBeforeDef3.ts, 24, 3)) | ||
|
89 changes: 89 additions & 0 deletions
89
tests/baselines/reference/classStaticBlockUseBeforeDef3.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,89 @@ | ||
=== tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef3.ts === | ||
class A { | ||
>A : A | ||
|
||
static { | ||
A.doSomething(); // should not error | ||
>A.doSomething() : void | ||
>A.doSomething : () => void | ||
>A : typeof A | ||
>doSomething : () => void | ||
} | ||
|
||
static doSomething() { | ||
>doSomething : () => void | ||
|
||
console.log("gotcha!"); | ||
>console.log("gotcha!") : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>"gotcha!" : "gotcha!" | ||
} | ||
} | ||
|
||
|
||
class Baz { | ||
>Baz : Baz | ||
|
||
static { | ||
console.log(FOO); // should error | ||
>console.log(FOO) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>FOO : "FOO" | ||
} | ||
} | ||
|
||
const FOO = "FOO"; | ||
>FOO : "FOO" | ||
>"FOO" : "FOO" | ||
|
||
class Bar { | ||
>Bar : Bar | ||
|
||
static { | ||
console.log(FOO); // should not error | ||
>console.log(FOO) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>FOO : "FOO" | ||
} | ||
} | ||
|
||
let u = "FOO" as "FOO" | "BAR"; | ||
>u : "FOO" | "BAR" | ||
>"FOO" as "FOO" | "BAR" : "FOO" | "BAR" | ||
>"FOO" : "FOO" | ||
|
||
class CFA { | ||
>CFA : CFA | ||
|
||
static { | ||
u = "BAR"; | ||
>u = "BAR" : "BAR" | ||
>u : "FOO" | "BAR" | ||
>"BAR" : "BAR" | ||
|
||
u; // should be "BAR" | ||
>u : "BAR" | ||
} | ||
|
||
static t = 1; | ||
>t : number | ||
>1 : 1 | ||
|
||
static doSomething() {} | ||
>doSomething : () => void | ||
|
||
static { | ||
u; // should be "BAR" | ||
>u : "BAR" | ||
} | ||
} | ||
|
||
u; // should be "BAR" | ||
>u : "BAR" | ||
|
11 changes: 11 additions & 0 deletions
11
tests/cases/conformance/classes/classStaticBlock/classStaticBlock28.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,11 @@ | ||
// @strict: true | ||
|
||
let foo: number; | ||
|
||
class C { | ||
static { | ||
foo = 1 | ||
} | ||
} | ||
|
||
console.log(foo) |
45 changes: 45 additions & 0 deletions
45
tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef3.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,45 @@ | ||
// @noEmit: true | ||
// @strict: true | ||
|
||
class A { | ||
static { | ||
A.doSomething(); // should not error | ||
} | ||
|
||
static doSomething() { | ||
console.log("gotcha!"); | ||
} | ||
} | ||
|
||
|
||
class Baz { | ||
static { | ||
console.log(FOO); // should error | ||
} | ||
} | ||
|
||
const FOO = "FOO"; | ||
class Bar { | ||
static { | ||
console.log(FOO); // should not error | ||
} | ||
} | ||
|
||
let u = "FOO" as "FOO" | "BAR"; | ||
|
||
class CFA { | ||
static { | ||
u = "BAR"; | ||
u; // should be "BAR" | ||
} | ||
|
||
static t = 1; | ||
|
||
static doSomething() {} | ||
|
||
static { | ||
u; // should be "BAR" | ||
} | ||
} | ||
|
||
u; // should be "BAR" |
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.
I am not sure how to format these lines, so here is how prettier handles it.
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.
I would have done it slightly differently, but prettier's format is fine.