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
fix(class-properties): replace new.target
in static properties with undefined
#13560
Conversation
… `undefined` non-static prop is not affected fix babel#12737
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/47387/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit f5cbf58:
|
packages/babel-helper-create-class-features-plugin/src/fields.ts
Outdated
Show resolved
Hide resolved
packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties/options.json
Show resolved
Hide resolved
fix typo Co-authored-by: Brian Ng <bng412@gmail.com>
packages/babel-helper-create-class-features-plugin/src/fields.ts
Outdated
Show resolved
Hide resolved
We can now enable tests |
defaults to replace new.target, do not replace within function
packages/babel-helper-create-class-features-plugin/src/fields.ts
Outdated
Show resolved
Hide resolved
remove function visitor since environmentVisitor is skipping arrow function
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.
Thanks!
var _class, _temp; | ||
|
||
this.Foo = (_temp = _class = class {}, (() => { | ||
// fixme: new.target should be undefined after transformed |
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.
Nit: you can delete this comment from input.js
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.
Thanks!
… `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>
When we meet a static class property, we traverse to visit all
new.target
with aMetaProperty
visitor.Then we find out if or not this
new.target
is associated with a class by:Now, if
func
is a child ofprop
, we do nothing. If not, that meansnew.target
now is leaked to uppernew.target
, we just replace it byundefined
/void 0
.