-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Labels
Spec: Class Fieldsgood first issueoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue
Description
Bug Report
- I would like to work on a fix!
Current behavior
(new C).Foo.p evaluates to C.
Input Code
class C {
constructor() {
this.Foo = class {
static p = new.target
}
}
}Expected behavior
(new C).Foo.p should evaluate to undefined.
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
See REPL configs
Environment
REPL
Possible Solution
When we are converting class properties into defineProperty calls that are appended to the class, we should replace new.target in class field initializers to undefined if it is associated to the class scope, otherwise new.target is leaked to the upper new.target values.
The replacing step can be inserted after super() is replaced in initializers:
| const replaced = replaceThisContext(prop, ref, superRef, state, loose); |
More test examples:
class C {
constructor() {
this.Foo = class {
static p1 = class { constructor() { new.target } } // should not replace
static p2 = new function () { new.target } // should not replace
static p3 = () => { new.target } // should replace
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Spec: Class Fieldsgood first issueoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue