-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Error on class fields accesses through super
in JS files
#55892
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
DanielRosenwasser
merged 5 commits into
microsoft:main
from
Andarist:fix/inferred-class-fields-in-js-not-through-super
Sep 29, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
292ab59
Error on class fields accesses through `super` in JS files
Andarist 49d3554
Fix all expando declaration types
Andarist 44010a3
Fixed bindable prototype accesses
Andarist 05b21a0
add a test for the accessor case
Andarist 23ec307
Fixed static name expressions
Andarist 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
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/classFieldSuperAccessibleJs1.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,18 @@ | ||
index.js(9,23): error TS2565: Property 'blah2' is used before being assigned. | ||
|
||
|
||
==== index.js (1 errors) ==== | ||
class C { | ||
static blah1 = 123; | ||
} | ||
C.blah2 = 456; | ||
|
||
class D extends C { | ||
static { | ||
console.log(super.blah1); | ||
console.log(super.blah2); | ||
~~~~~ | ||
!!! error TS2565: Property 'blah2' is used before being assigned. | ||
} | ||
} | ||
|
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/classFieldSuperAccessibleJs1.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,37 @@ | ||
//// [tests/cases/compiler/classFieldSuperAccessibleJs1.ts] //// | ||
|
||
=== index.js === | ||
class C { | ||
>C : Symbol(C, Decl(index.js, 0, 0), Decl(index.js, 2, 1)) | ||
|
||
static blah1 = 123; | ||
>blah1 : Symbol(C.blah1, Decl(index.js, 0, 9)) | ||
} | ||
C.blah2 = 456; | ||
>C.blah2 : Symbol(C.blah2, Decl(index.js, 2, 1)) | ||
>C : Symbol(C, Decl(index.js, 0, 0), Decl(index.js, 2, 1)) | ||
>blah2 : Symbol(C.blah2, Decl(index.js, 2, 1)) | ||
|
||
class D extends C { | ||
>D : Symbol(D, Decl(index.js, 3, 14)) | ||
>C : Symbol(C, Decl(index.js, 0, 0), Decl(index.js, 2, 1)) | ||
|
||
static { | ||
console.log(super.blah1); | ||
>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, --, --)) | ||
>super.blah1 : Symbol(C.blah1, Decl(index.js, 0, 9)) | ||
>super : Symbol(C, Decl(index.js, 0, 0), Decl(index.js, 2, 1)) | ||
>blah1 : Symbol(C.blah1, Decl(index.js, 0, 9)) | ||
|
||
console.log(super.blah2); | ||
>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, --, --)) | ||
>super.blah2 : Symbol(C.blah2, Decl(index.js, 2, 1)) | ||
>super : Symbol(C, Decl(index.js, 0, 0), Decl(index.js, 2, 1)) | ||
>blah2 : Symbol(C.blah2, Decl(index.js, 2, 1)) | ||
} | ||
} | ||
|
42 changes: 42 additions & 0 deletions
42
tests/baselines/reference/classFieldSuperAccessibleJs1.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,42 @@ | ||
//// [tests/cases/compiler/classFieldSuperAccessibleJs1.ts] //// | ||
|
||
=== index.js === | ||
class C { | ||
>C : C | ||
|
||
static blah1 = 123; | ||
>blah1 : number | ||
>123 : 123 | ||
} | ||
C.blah2 = 456; | ||
>C.blah2 = 456 : 456 | ||
>C.blah2 : number | ||
>C : typeof C | ||
>blah2 : number | ||
>456 : 456 | ||
|
||
class D extends C { | ||
>D : D | ||
>C : C | ||
|
||
static { | ||
console.log(super.blah1); | ||
>console.log(super.blah1) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>super.blah1 : number | ||
>super : typeof C | ||
>blah1 : number | ||
|
||
console.log(super.blah2); | ||
>console.log(super.blah2) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>super.blah2 : number | ||
>super : typeof C | ||
>blah2 : number | ||
} | ||
} | ||
|
77 changes: 77 additions & 0 deletions
77
tests/baselines/reference/classFieldSuperAccessibleJs2.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,77 @@ | ||
//// [tests/cases/compiler/classFieldSuperAccessibleJs2.ts] //// | ||
|
||
=== index.js === | ||
class C { | ||
>C : Symbol(C, Decl(index.js, 0, 0)) | ||
|
||
constructor() { | ||
this.foo = () => { | ||
>this.foo : Symbol(C.foo, Decl(index.js, 5, 3)) | ||
>this : Symbol(C, Decl(index.js, 0, 0)) | ||
>foo : Symbol(C.foo, Decl(index.js, 1, 17)) | ||
|
||
console.log("called arrow"); | ||
>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() { | ||
>foo : Symbol(C.foo, Decl(index.js, 5, 3)) | ||
|
||
console.log("called method"); | ||
>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 D extends C { | ||
>D : Symbol(D, Decl(index.js, 9, 1)) | ||
>C : Symbol(C, Decl(index.js, 0, 0)) | ||
|
||
foo() { | ||
>foo : Symbol(D.foo, Decl(index.js, 11, 19)) | ||
|
||
console.log("SUPER:"); | ||
>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, --, --)) | ||
|
||
super.foo(); | ||
>super.foo : Symbol(C.foo, Decl(index.js, 5, 3)) | ||
>super : Symbol(C, Decl(index.js, 0, 0)) | ||
>foo : Symbol(C.foo, Decl(index.js, 5, 3)) | ||
|
||
console.log("THIS:"); | ||
>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, --, --)) | ||
|
||
this.foo(); | ||
>this.foo : Symbol(D.foo, Decl(index.js, 11, 19)) | ||
>this : Symbol(D, Decl(index.js, 9, 1)) | ||
>foo : Symbol(D.foo, Decl(index.js, 11, 19)) | ||
} | ||
} | ||
|
||
const obj = new D(); | ||
>obj : Symbol(obj, Decl(index.js, 20, 5)) | ||
>D : Symbol(D, Decl(index.js, 9, 1)) | ||
|
||
obj.foo(); | ||
>obj.foo : Symbol(D.foo, Decl(index.js, 11, 19)) | ||
>obj : Symbol(obj, Decl(index.js, 20, 5)) | ||
>foo : Symbol(D.foo, Decl(index.js, 11, 19)) | ||
|
||
D.prototype.foo.call(obj); | ||
>D.prototype.foo.call : Symbol(CallableFunction.call, Decl(lib.es5.d.ts, --, --)) | ||
>D.prototype.foo : Symbol(D.foo, Decl(index.js, 11, 19)) | ||
>D.prototype : Symbol(D.prototype) | ||
>D : Symbol(D, Decl(index.js, 9, 1)) | ||
>prototype : Symbol(D.prototype) | ||
>foo : Symbol(D.foo, Decl(index.js, 11, 19)) | ||
>call : Symbol(CallableFunction.call, Decl(lib.es5.d.ts, --, --)) | ||
>obj : Symbol(obj, Decl(index.js, 20, 5)) | ||
|
92 changes: 92 additions & 0 deletions
92
tests/baselines/reference/classFieldSuperAccessibleJs2.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,92 @@ | ||
//// [tests/cases/compiler/classFieldSuperAccessibleJs2.ts] //// | ||
|
||
=== index.js === | ||
class C { | ||
>C : C | ||
|
||
constructor() { | ||
this.foo = () => { | ||
>this.foo = () => { console.log("called arrow"); } : () => void | ||
>this.foo : () => void | ||
>this : this | ||
>foo : () => void | ||
>() => { console.log("called arrow"); } : () => void | ||
|
||
console.log("called arrow"); | ||
>console.log("called arrow") : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>"called arrow" : "called arrow" | ||
|
||
}; | ||
} | ||
foo() { | ||
>foo : () => void | ||
|
||
console.log("called method"); | ||
>console.log("called method") : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>"called method" : "called method" | ||
} | ||
} | ||
|
||
class D extends C { | ||
>D : D | ||
>C : C | ||
|
||
foo() { | ||
>foo : () => void | ||
|
||
console.log("SUPER:"); | ||
>console.log("SUPER:") : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>"SUPER:" : "SUPER:" | ||
|
||
super.foo(); | ||
>super.foo() : void | ||
>super.foo : () => void | ||
>super : C | ||
>foo : () => void | ||
|
||
console.log("THIS:"); | ||
>console.log("THIS:") : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>"THIS:" : "THIS:" | ||
|
||
this.foo(); | ||
>this.foo() : void | ||
>this.foo : () => void | ||
>this : this | ||
>foo : () => void | ||
} | ||
} | ||
|
||
const obj = new D(); | ||
>obj : D | ||
>new D() : D | ||
>D : typeof D | ||
|
||
obj.foo(); | ||
>obj.foo() : void | ||
>obj.foo : () => void | ||
>obj : D | ||
>foo : () => void | ||
|
||
D.prototype.foo.call(obj); | ||
>D.prototype.foo.call(obj) : void | ||
>D.prototype.foo.call : <T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, ...args: A) => R | ||
>D.prototype.foo : () => void | ||
>D.prototype : D | ||
>D : typeof D | ||
>prototype : D | ||
>foo : () => void | ||
>call : <T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, ...args: A) => R | ||
>obj : D | ||
|
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.