Skip to content
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

Merged

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Jan 31, 2021

Q                       A
Fixed Issues? Fixes #5074
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Since this fix is at the @babel/traverse level, it also fixes any other usage of insertAfter in class parameters.

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Class Fields labels Jan 31, 2021
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 31, 2021

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:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@babel-bot
Copy link
Collaborator

babel-bot commented Jan 31, 2021

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),
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member

@kaicataldo kaicataldo left a 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!

this.replaceWith(
t.callExpression(t.arrowFunctionExpression([], node), []),
);
(this.get("callee.body") as NodePath).insertAfter(nodes);
Copy link
Member Author

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.

@nicolo-ribaudo nicolo-ribaudo merged commit bab5c62 into babel:main Feb 2, 2021
@nicolo-ribaudo nicolo-ribaudo deleted the fix-insertafter-param-default branch February 2, 2021 14:38
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 5, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Class Fields
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Class property compilation broken when super is called in a parameter default
4 participants