-
-
Notifications
You must be signed in to change notification settings - Fork 5.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
class-property transform leaks new.target in initializer to upper level #12737
Comments
Hey @JLHwung! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite." |
If it is the first time that you contribute to Babel, follow these steps: (you need to have
|
@nicolo-ribaudo I would love to work around this one... |
It's yours! If you need any help feel free to ask. |
Any progress on this? I can help on this! |
… `undefined` non-static prop is not affected fix babel#12737
… `undefined` (#13560) * fix(class-properties): replace `new.target` in static properties with `undefined` non-static prop is not affected fix #12737 * Update packages/babel-helper-create-class-features-plugin/src/fields.ts fix typo Co-authored-by: Brian Ng <bng412@gmail.com> * fix: add loose test case and fix replace condition * test: add new.target tests for static block * feat: move new-target replace into thisContextVisitor defaults to replace new.target, do not replace within function * feat: simplify thisContextVisitor remove function visitor since environmentVisitor is skipping arrow function * test: remove unused fixme comments Co-authored-by: Brian Ng <bng412@gmail.com>
… `undefined` (babel#13560) * fix(class-properties): replace `new.target` in static properties with `undefined` non-static prop is not affected fix babel#12737 * Update packages/babel-helper-create-class-features-plugin/src/fields.ts fix typo Co-authored-by: Brian Ng <bng412@gmail.com> * fix: add loose test case and fix replace condition * test: add new.target tests for static block * feat: move new-target replace into thisContextVisitor defaults to replace new.target, do not replace within function * feat: simplify thisContextVisitor remove function visitor since environmentVisitor is skipping arrow function * test: remove unused fixme comments Co-authored-by: Brian Ng <bng412@gmail.com>
Bug Report
Current behavior
(new C).Foo.p
evaluates toC
.Input Code
Expected behavior
(new C).Foo.p
should evaluate toundefined
.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 theclass
, we should replacenew.target
in class field initializers toundefined
if it is associated to the class scope, otherwisenew.target
is leaked to the uppernew.target
values.The replacing step can be inserted after
super()
is replaced in initializers:babel/packages/babel-helper-create-class-features-plugin/src/fields.js
Line 684 in bab5c62
More test examples:
The text was updated successfully, but these errors were encountered: