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 & test handling of foo(, baz) (first argument missing) #10023

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/language-js/print/call-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function printCallArguments(path, options, print) {
// useEffect(() => { ... }, [foo, bar, baz])
if (
args.length === 2 &&
args[0] &&
args[0].type === "ArrowFunctionExpression" &&
getFunctionParameters(args[0]).length === 0 &&
args[0].body.type === "BlockStatement" &&
Expand Down Expand Up @@ -284,6 +285,7 @@ function shouldGroupFirstArg(args) {
const [firstArg, secondArg] = args;
return (
!hasComment(firstArg) &&
firstArg &&
(firstArg.type === "FunctionExpression" ||
(firstArg.type === "ArrowFunctionExpression" &&
firstArg.body.type === "BlockStatement")) &&
Expand Down
15 changes: 15 additions & 0 deletions tests/js/call-missing-first-arg/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`call-missing-first-arg.js format 1`] = `
====================================options=====================================
parsers: ["babel-flow", "babel-ts"]
printWidth: 80
| printWidth
=====================================input======================================
foo(, baz);

=====================================output=====================================
foo(, baz);

================================================================================
`;
1 change: 1 addition & 0 deletions tests/js/call-missing-first-arg/call-missing-first-arg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo(, baz);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if we should test the cases with and without comments in each of the positions before and after the comma, for example:

Suggested change
foo(, baz);
foo(, baz);
foo(,);
foo(/*first*/, baz);
foo(,/*second*/ baz);
foo(, baz /* c */);
foo(/* first */, /* second */ baz /* c */);
foo(/* first */,);
foo(, /* second */);
foo(/* first */, /* second */);

1 change: 1 addition & 0 deletions tests/js/call-missing-first-arg/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(__dirname, ["babel-flow", "babel-ts"]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I tried with "babel" I did encounter what I think was a parse error. I think it would be ideal if we could test with ["babel", "babel-ts"] or event ["babel", "typescript"].