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 fields when super()
is in a default param
#12729
Fix class fields when super()
is in a default param
#12729
Conversation
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 bea6378:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/39188/ |
if (scope.path.isPattern()) { | ||
this.replaceWith( | ||
t.callExpression( | ||
t.arrowFunctionExpression([], this.node as t.Expression), |
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: use invariant instead if node will never be t.VariableDeclaration
when scope.path
is pattern.
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.
Oh I just realize that it is TypeScript! so we can use microsoft/TypeScript#32695 instead.
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.
Like @JLHwung, def prefer type safety and avoiding casting. Otherwise, LGTM!
4001fed
to
bea6378
Compare
this.replaceWith( | ||
t.callExpression(t.arrowFunctionExpression([], node), []), | ||
); | ||
(this.get("callee.body") as NodePath).insertAfter(nodes); |
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.
I replaced the first typecast with an assertion. I have left this one as a type cast since TS doesn't know that .get
doesn't return an array here, but we know that it's a single node because it's the body of the arrow expression built at line 138.
Since this fix is at the
@babel/traverse
level, it also fixes any other usage ofinsertAfter
in class parameters.