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: ensure (a?.b)() has proper this #11623

Merged
merged 12 commits into from Jun 1, 2020
Merged

fix: ensure (a?.b)() has proper this #11623

merged 12 commits into from Jun 1, 2020

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented May 27, 2020

Q                       A
Fixed Issues? Fixes #10802, closes #11327
Patch: Bug Fix? Yes
Tests Added + Pass? Yes
License MIT

It has been out there for quite a while and the fix seems more tricky than previously proposed in #11327 and #10802.

This PR supersedes #11552 .

Todo

  • (a?.#m)()
  • parserOpts.createParenthesizedExpression

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 27, 2020

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 a2d5657:

Sandbox Source
romantic-star-3rm5q Configuration
boring-violet-ybrr6 Configuration

@babel-bot
Copy link
Collaborator

babel-bot commented May 27, 2020

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

@JLHwung JLHwung marked this pull request as ready for review May 28, 2020 01:20
@@ -167,13 +167,19 @@ const handle = {
const parentIsOptionalCall = parentPath.isOptionalCallExpression({
callee: node,
});
const isParenthesizedMemberCall =
parentPath.isCallExpression({ callee: node }) &&
node.extra?.parenthesized;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current approach does not support parserOpts.createParenthesizedExpressions. When developing I realize that the whole transform does not take ParenthesizedExpressions into account, I suggest we address it in a separate PR before this one gets too big to review.

optionalPath.isOptionalCallExpression()
optionalPath.isOptionalCallExpression() ||
optionalPath.isParenthesizedExpression() ||
optionalPath.isTSNonNullExpression()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By doing so we also fix cases like a!!?.b are not transformed currently.

Copy link
Member

Choose a reason for hiding this comment

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

@oliverdunk Should we also check for this in your PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, I'll add that now 👍

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Class Fields Spec: Optional Chaining labels May 30, 2020
@JLHwung JLHwung added PR: Spec Compliance 👓 A type of pull request used for our changelog categories and removed PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels May 30, 2020
optionalPath.isOptionalCallExpression()
optionalPath.isOptionalCallExpression() ||
optionalPath.isParenthesizedExpression() ||
optionalPath.isTSNonNullExpression()
Copy link
Member

Choose a reason for hiding this comment

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

@oliverdunk Should we also check for this in your PR?

@JLHwung JLHwung merged commit 1e115ae into babel:master Jun 1, 2020
@JLHwung JLHwung deleted the fix-10802 branch June 1, 2020 14:25
@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 Sep 1, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2020
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: Spec Compliance 👓 A type of pull request used for our changelog categories Spec: Class Fields Spec: Optional Chaining
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional Chaining does not propagate receiver when parenthesized
6 participants