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

Ensure expressions wrapped in parens #12082

Merged

Conversation

overlookmotel
Copy link
Contributor

@overlookmotel overlookmotel commented Sep 19, 2020

Fix for #12055.

The fix itself is very simple. I've added tests for the original bug and also some other weird cases which were previously producing incorrect output.

I am assuming that existing behavior for standalone expressions is correct.

i.e. generate( t.objectExpression([]) ).code should produce {} not ({}). Certainly that's what I want it to be!

One case produces excess parentheses:

t.arrowFunctionExpression(
  [],
  t.sequenceExpression([
    t.objectExpression([]),
    t.numericLiteral(1)]
  )
)

This generates () => (({}), 1). I couldn't see a way to avoid this without introducing excess complexity for a pretty uncommon case.

Please shout if you want any changes.

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

@overlookmotel overlookmotel force-pushed the arrow-function-object-expression-fix branch from c50ac51 to dd04ef5 Compare September 19, 2020 14:41
@babel-bot
Copy link
Collaborator

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

@codesandbox-ci
Copy link

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

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

@existentialism existentialism added pkg: generator PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Sep 21, 2020
Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

Thanks.

@existentialism existentialism merged commit 1a074ee into babel:main Sep 25, 2020
@existentialism
Copy link
Member

@overlookmotel thanks!

@overlookmotel
Copy link
Contributor Author

@existentialism No worries. Thanks for getting it merged swiftly.

@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 Dec 26, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 26, 2020
@overlookmotel overlookmotel deleted the arrow-function-object-expression-fix branch January 19, 2021 18:08
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 pkg: generator 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.

generate() produces incorrect output for arrow function expression
4 participants