Fix class fields when super() is in a default param#12729
Fix class fields when super() is in a default param#12729nicolo-ribaudo merged 2 commits intobabel:mainfrom
super() is in a default param#12729Conversation
|
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.
nit: use invariant instead if node will never be t.VariableDeclaration when scope.path is pattern.
There was a problem hiding this comment.
Oh I just realize that it is TypeScript! so we can use microsoft/TypeScript#32695 instead.
kaicataldo
left a comment
There was a problem hiding this comment.
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.
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/traverselevel, it also fixes any other usage ofinsertAfterin class parameters.