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

Re-enable error recovery for contextual keywords used as identifiers #10603

Open
thorn0 opened this issue Mar 26, 2021 · 8 comments
Open

Re-enable error recovery for contextual keywords used as identifiers #10603

thorn0 opened this issue Mar 26, 2021 · 8 comments
Labels
difficulty:easy Issues that should be easy to fix. Resolve me on the train to work! lang:javascript Issues affecting JS type:tests Issues about tests that are not correct, should be added, or similar

Comments

@thorn0
Copy link
Member

thorn0 commented Mar 26, 2021

yield = 3

causes an error: Unexpected reserved word 'yield' (playground), which should only happen in modules. In non-module code, yield is an acceptable identifier (spec). Prettier 2.2.1 handles this better thanks to the error recovery (playground).

Originally posted by @thorn0 in #10446 (comment)

@thorn0 thorn0 added lang:javascript Issues affecting JS type:bug Issues identifying ugly output, or a defect in the program labels Mar 26, 2021
@fisker
Copy link
Sponsor Member

fisker commented Mar 26, 2021

var let = 3

Should not be error too.

@thorn0 thorn0 changed the title Re-enable error recovery for some reserved words used as identifiers Re-enable error recovery for contextual keywords used as identifiers Apr 13, 2021
@thorn0
Copy link
Member Author

thorn0 commented Apr 13, 2021

Turns out Prettier simply shouldn't rethrow Unexpected reserved word errors. See babel/babel#13033 (comment)
For the keywords like for, var, etc., the error message is different (Unexpected keyword).

@thorn0 thorn0 added the difficulty:easy Issues that should be easy to fix. Resolve me on the train to work! label Apr 13, 2021
@satya-nutella
Copy link

@thorn0 I would like to contribute to this if possible, I am a first time contributor here. Any directions on this would be awesome

@thorn0
Copy link
Member Author

thorn0 commented May 20, 2021

@meehawk Sorry, but I'm afraid this has been fixed by #10802.

Prettier 2.3.0
Playground link

--parser babel

Input:

yield = 3
var let = 3

Output:

yield = 3;
var let = 3;

@thorn0 thorn0 closed this as completed May 20, 2021
@thorn0
Copy link
Member Author

thorn0 commented May 20, 2021

On the other hand, tests for this weren't added, so let's reopen the issue.

@meehawk Would you like to contribute tests?

@thorn0 thorn0 reopened this May 20, 2021
@thorn0 thorn0 added type:tests Issues about tests that are not correct, should be added, or similar and removed type:bug Issues identifying ugly output, or a defect in the program labels May 20, 2021
@satya-nutella
Copy link

@thorn0 sure that sounds like an amazing place to start though I am not that experienced when it comes to testing. Do you have any pointers on how could I get started?

@thorn0
Copy link
Member Author

thorn0 commented May 21, 2021

@MohananT
Copy link

MohananT commented Aug 6, 2022

Can I start the tests for this fix? @thorn0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty:easy Issues that should be easy to fix. Resolve me on the train to work! lang:javascript Issues affecting JS type:tests Issues about tests that are not correct, should be added, or similar
Projects
None yet
Development

No branches or pull requests

4 participants