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
Flatten function expression parameters in hugged last argument #9662
Conversation
@thorn0 sosukesuzuki/prettier-regression-testing#8 (comment) Less changes than I thought it would be. |
src/language-js/printer-estree.js
Outdated
options, | ||
args && | ||
args.expandLastArg && | ||
path.getParentNode().arguments.length > 1 |
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.
path.getParentNode().arguments.length > 1 | |
getCallArguments(path.getParentNode()).length > 1 |
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.
We don't have such a 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.
But I see what you mean...
Prettier pr-9662
Playground link
--parser typescript
Input:
a=import(function(){})
Output:
TypeError: Cannot read property 'length' of undefined
at https://deploy-preview-9662--prettier.netlify.app/lib/standalone.js:15:230593
at Object.print (https://deploy-preview-9662--prettier.netlify.app/lib/standalone.js:15:270143)
at Ri (https://deploy-preview-9662--prettier.netlify.app/lib/standalone.js:15:115017)
at https://deploy-preview-9662--prettier.netlify.app/lib/standalone.js:15:114478
at Object.printComments (https://deploy-preview-9662--prettier.netlify.app/lib/standalone.js:15:110760)
at e (https://deploy-preview-9662--prettier.netlify.app/lib/standalone.js:15:114458)
at https://deploy-preview-9662--prettier.netlify.app/lib/standalone.js:15:203119
at Ti.call (https://deploy-preview-9662--prettier.netlify.app/lib/standalone.js:15:112552)
at f (https://deploy-preview-9662--prettier.netlify.app/lib/standalone.js:15:203110)
at Ti.call (https://deploy-preview-9662--prettier.netlify.app/lib/standalone.js:15:112552)
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 we do... #9608
Fixes prettier#3376 This was done for arrow functions in prettier#1305 ("Avoid breaking arguments for last arg expansion"). This PR enables the same for function expressions unless the function expression is the only argument.
Fixes #3376
This was done for arrow functions in #1305 ("Avoid breaking arguments for last arg expansion").
This PR enables the same for function expressions unless the function expression is the only argument.
Before:
After:
Where did "unless the function expression is the only argument" come from? From code I found in the tests:
Apparently we want to keep it hugged.
docs/
directory)changelog_unreleased/*/pr-XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨