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

Do not create invalid code when simplifying object pattern assignments #4204

Merged
merged 2 commits into from Aug 10, 2021

Conversation

@lukastaegert
Copy link
Member

@lukastaegert lukastaegert commented Aug 9, 2021

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

When simplifying statements that include object pattern assignments, we need to add parentheses when the assignment would end up as an expression statement or arrow function return value. https://rollupjs.org/repl/?version=2.56.1&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmxldCUyMGZvbyUyQyUyMHVudXNlZCUzQiU1Q24lMkYlMkYlMjBUaGUlMjBsZWFkaW5nJTIwJTVDJTIyJTdCJTVDJTIyJTIwd2lsbCUyMGJlJTIwbWlzaW50ZXJwcmV0ZWQlMjBhcyUyMGElMjBibG9jayUyMHN0YXRlbWVudCU1Q25udWxsJTJDJTIwJTdCJTIwZm9vJTIwJTdEJTIwJTNEJTIwJTdCJTIwZm9vJTNBJTIwJ2JhciclMjAlN0QlM0IlNUNuYXNzZXJ0LnN0cmljdEVxdWFsKGZvbyUyQyUyMCdiYXInKSUzQiU1Q24lNUNuJTJGJTJGJTIwQWdhaW4lMkMlMjB0aGUlMjBsZWFkaW5nJTIwJTVDJTIyJTdCJTVDJTIyJTIwd2lsbCUyMGJlJTIwbWlzaW50ZXJwcmV0ZWQlMjBhcyUyMGElMjBibG9jayUyMHN0YXRlbWVudCU1Q25jb25zdCUyMGFzc2lnbiUyMCUzRCUyMCgpJTIwJTNEJTNFJTIwdW51c2VkJTIwJTNEJTIwJTdC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lMkMlMjJuYW1lJTIyJTNBJTIybXlCdW5kbGUlMjIlMkMlMjJhbWQlMjIlM0ElN0IlMjJpZCUyMiUzQSUyMiUyMiU3RCUyQyUyMmdsb2JhbHMlMjIlM0ElN0IlN0QlN0QlMkMlMjJleGFtcGxlJTIyJTNBbnVsbCU3RA==

@github-actions
Copy link

@github-actions github-actions bot commented Aug 9, 2021

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#simplify-object-pattern-assignment

or load it into the REPL:
https://rollupjs.org/repl/?pr=4204

@codecov
Copy link

@codecov codecov bot commented Aug 9, 2021

Codecov Report

Merging #4204 (51f5fa2) into master (2a097a8) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4204      +/-   ##
==========================================
- Coverage   98.37%   98.37%   -0.01%     
==========================================
  Files         202      202              
  Lines        7253     7248       -5     
  Branches     2126     2118       -8     
==========================================
- Hits         7135     7130       -5     
  Misses         58       58              
  Partials       60       60              
Impacted Files Coverage Δ
src/ast/nodes/ExportDefaultDeclaration.ts 100.00% <ø> (ø)
src/utils/renderHelpers.ts 100.00% <ø> (ø)
src/ast/nodes/AssignmentExpression.ts 100.00% <100.00%> (ø)
src/ast/nodes/BinaryExpression.ts 97.43% <100.00%> (-0.07%) ⬇️
src/ast/nodes/CallExpression.ts 100.00% <100.00%> (ø)
src/ast/nodes/ClassExpression.ts 100.00% <100.00%> (ø)
src/ast/nodes/ConditionalExpression.ts 100.00% <100.00%> (ø)
src/ast/nodes/FunctionExpression.ts 100.00% <100.00%> (ø)
src/ast/nodes/LogicalExpression.ts 100.00% <100.00%> (ø)
src/ast/nodes/MemberExpression.ts 100.00% <100.00%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2a097a8...51f5fa2. Read the comment docs.

@lukastaegert lukastaegert merged commit 4224666 into master Aug 10, 2021
8 of 9 checks passed
@lukastaegert lukastaegert deleted the simplify-object-pattern-assignment branch Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant