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

incorrect handling of function calls with missing arguments #10047

Closed
brodybits opened this issue Jan 13, 2021 · 2 comments · Fixed by #10065
Closed

incorrect handling of function calls with missing arguments #10047

brodybits opened this issue Jan 13, 2021 · 2 comments · Fixed by #10065
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Comments

@brodybits
Copy link
Contributor

brodybits commented Jan 13, 2021

I am raising cases that I discovered from discussions on some recent PRs. I will understand if the Prettier team wants to split this into multiple issues.

Cases with comments in the wrong place

Case 1a

from discussion in PR #9857

results from recently merged PR #9787:

Prettier pr-9787
Playground link

--parser babel

Input:

call(foo,,/*a*/,/*b*/,bar)

Output:

call(foo /*a*/ /*b*/, , , , bar);

Expected output:

call(foo, , /*a*/, /*b*/, bar);

Case 1b

call(foo,/*a*/,/*b*/,bar)
results from recently merged PR #9787

Prettier pr-9787
Playground link

--parser babel

Input:

call(foo,/*a*/,/*b*/,bar)

Output:

call(foo /*a*/ /*b*/, , , bar);

Cases with internal TypeErrors

Case 2a

Fixed by PR #10023:

foo(, baz)

Currently results in an internal exception thrown by src/language-js/print/call-arguments.js, when using --parser=babel-ts:

$ ./bin/prettier.js --parser=babel-ts case2a.js
case2a.js[error] case2a.js: TypeError: Cannot read property 'type' of null
[error]     at printCallArguments (/home/brodybits/prettier/src/language-js/print/call-arguments.js:49:13)
[error]     at printCallExpression (/home/brodybits/prettier/src/language-js/print/call-expression.js:93:5)
[error]     at printPathNoParens (/home/brodybits/prettier/src/language-js/printer-estree.js:413:14)
[error]     at Object.genericPrint [as print] (/home/brodybits/prettier/src/language-js/printer-estree.js:100:30)
[error]     at callPluginPrintFunction (/home/brodybits/prettier/src/main/ast-to-doc.js:140:18)
[error]     at /home/brodybits/prettier/src/main/ast-to-doc.js:64:16
[error]     at printComments (/home/brodybits/prettier/src/main/comments.js:549:19)
[error]     at printGenerically (/home/brodybits/prettier/src/main/ast-to-doc.js:62:13)
[error]     at FastPath.call (/home/brodybits/prettier/src/common/fast-path.js:66:20)
[error]     at printPathNoParens (/home/brodybits/prettier/src/language-js/printer-estree.js:279:14)

Case 2b

not (yet) fixed by PR #10023:

foo(/*bar*/, baz)

Currently results in the same internal exception when using --parser=babel-ts.

Case 2c

also not (yet) fixed by PR #10023:

foo(/*bar*/, /*baz*/)

Currently results in the same internal exception when using --parser=babel-ts.

Case 2d

simplification of case 2c, raised by @fisker in discussion on PR #10023

foo(,)

Currently results in the same internal exception when using --parser=babel-ts.

@thorn0
Copy link
Member

thorn0 commented Jan 13, 2021

Supporting these cases of error recovery seems to be useless maintenance burden. Let's just rethrow Babel's errors in these cases and call it a day.

@brodybits
Copy link
Contributor Author

My apologies for the confusion, I reported multiple cases that I think we should take a look at. I have now updated the description to be hopefully more clear.

Case 1a and 1b are comments printed in the wrong place.

The cases with the exceptions are internal TypeErrors that come up when using --parser=babel-ts. These internal TypeErrors come from src/language-js/print/call-arguments.js.

These may be corner cases but I would love to see them resolved and tested someday. Unfortunately I cannot promise when I will get a chance to contribute any solutions. Thanks.

@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Apr 19, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants