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

Support transforming params of arrow functions in class fields #13941

Merged
merged 2 commits into from Nov 9, 2021

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Nov 8, 2021

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

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories i: regression labels Nov 8, 2021
@@ -0,0 +1,7 @@
var _this = this;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another bug fixed by the new if (!path.isFunction()) return; check in the plugin.

@babel-bot
Copy link
Collaborator

babel-bot commented Nov 8, 2021

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/49716/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 8, 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 59c8ff9:

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


// In some cases arrowFunctionToExpression replaces the function with a wrapper.
// Return early; the wrapped function will be visited later in the AST traversal.
if (!path.isFunction()) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Can this check be strengthen to path.isFunctionExpression()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, currently path is guaranteed to be either a FunctionExpression or a CallExpression

// TODO(Babel 8): Consider defaulting to `false` for spec compliancy
noNewArrows = true,
allowInsertArrow = true,
) {
const thisEnvFn = fnPath.findParent(p => {
): { thisBinding: string; fnPath: NodePath<t.Function> } {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some comments about the return type? Especially we may have different fnPath output than the input.

);
});
const inConstructor = thisEnvFn?.node.kind === "constructor";
const inConstructor = thisEnvFn.isClassMethod({ kind: "constructor" });

if (thisEnvFn.isClassProperty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (thisEnvFn.isClassProperty()) {
if (thisEnvFn.isClassProperty() || thisEnvFn.isClassPrivateProperty()) {

@nicolo-ribaudo nicolo-ribaudo merged commit 43f9899 into babel:main Nov 9, 2021
@nicolo-ribaudo nicolo-ribaudo deleted the fix-13939 branch November 9, 2021 11:12
@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 Feb 9, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: regression 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Unable to transform arrow inside class property
4 participants