-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
nicolo-ribaudo
commented
Nov 8, 2021
•
edited by gitpod-io
bot
Loading
edited by gitpod-io
bot
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 |
@@ -0,0 +1,7 @@ | |||
var _this = this; |
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.
This is another bug fixed by the new if (!path.isFunction()) return;
check in the plugin.
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/49716/ |
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:
|
|
||
// 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; |
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.
Q: Can this check be strengthen to path.isFunctionExpression()
?
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.
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> } { |
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.
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()) { |
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.
if (thisEnvFn.isClassProperty()) { | |
if (thisEnvFn.isClassProperty() || thisEnvFn.isClassPrivateProperty()) { |