-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
ESNext+[[Define]]: reference to param props illegal #36425
Conversation
When target: "esnext" and useDefineForClassFields: true, property declaration initialisers should not be able to reference parameter properties; class fields are initialised before the constructor runs, but parameter properties are not: ```ts class C { foo = this.bar constructor(public bar: string) { } } ``` emits code that looks like this: ```js class C { bar foo = this.bar constructor(bar) { this.bar = bar } } new C('x').foo.length // crashes; foo is undefined ``` This PR adds an error on foo's declaration with ESNext+[[Define]].
class C { | ||
qux = this.bar // should error | ||
bar = this.foo // should error | ||
quiz = this.bar // ok |
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.
Given the code change, I don't understand why the lines with // ok
don't error. It is nice that they don't though.
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.
Something in this PR broke checking of deferred access to (regular) properties. Will open an issue after investigating.
class C {
bar = () => this.foo; // was no error in -dev.20200124, is an error in -dev.20200125
foo = 1;
}
When target: "esnext" and useDefineForClassFields: true, property
declaration initialisers should not be able to reference parameter
properties; class fields are initialised before the constructor runs,
but parameter properties are not:
emits code that looks like this:
This PR adds an error on foo's declaration with ESNext+[[Define]].
Fixes #36410