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
Refactor, optimize and fix call args expansion #13341
Conversation
// https://github.com/prettier/prettier/issues/2456 | ||
// https://github.com/prettier/prettier/issues/5172 | ||
// A proper (printWidth-aware) fix for those would require a complex change in the doc printer. | ||
!secondArg?.left?.left && |
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.
Because this check didn't pass?
Prettier pr-13341
Playground link
--parser babel
Input:
call(function () {
return 1;
}, $var ||
($var ??
$var ??
$var ??
$var ??
$var ??
$var ??
$var ??
$var ??
"test"));
call(function () {
return 1;
}, $var ??
($var ??
$var ??
$var ??
$var ??
$var ??
$var ??
$var ??
$var ??
"test"));
Output:
call(function () {
return 1;
}, $var || ($var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? $var ?? "test"));
call(
function () {
return 1;
},
$var ??
$var ??
$var ??
$var ??
$var ??
$var ??
$var ??
$var ??
$var ??
"test",
);
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.
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.
Maybe just check if it's LogicalExpression chain for now? Unless you mean to match other types with left
.
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.
secondArg?.right?.right
will match a = b = c
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.
secondArg?.right?.right
will matcha = b = c
That would be perfectly okay.
Unless you mean to match other types with left.
Yes, I mean to match binary expression that are more complex than this:
setTimeout(() => {
// ...
}, 40 * rate);
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 have full list of those nodes with left
, right
, you can add more tests for them.
exports[`visitor keys estree 1`] = ` |
An Interesting case fixed by this PR. I guess the body of the function was printed in Prettier pr-13341 --parser babel Input: fs.readdirSync(suiteLoc).forEach(function (testName) {
(skip ? it.skip : it)(
testName,
buildTest(binName, testName, opts),
2_000_000,
);
});
{
(skip ? it.skip : it)(
testName,
buildTest(binName, testName, opts),
2_000_000,
);
} Output: fs.readdirSync(suiteLoc).forEach(function (testName) {
(skip ? it.skip : it)(
testName,
buildTest(binName, testName, opts),
2_000_000,
);
});
{
(skip ? it.skip : it)(
testName,
buildTest(binName, testName, opts),
2_000_000,
);
} Prettier 2.7.1 Output: fs.readdirSync(suiteLoc).forEach(function (testName) {
(skip
? it.skip
: it)(testName, buildTest(binName, testName, opts), 2_000_000);
});
{
(skip ? it.skip : it)(
testName,
buildTest(binName, testName, opts),
2_000_000
);
} |
…hortCallArgument heuristics)
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.
The output looks good 👍 .
Code in this file is a nightmare to understand (not because of this PR, it already is) 😢 .
In this PR, I tried to make it easier to follow what's going on. At least I untangled first arg expansion from last arg expansion. Now those are separate code paths. |
A quick search we have 130+ places of |
It's going to be very similar to adding support for |
Description
Checklist
docs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨