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

yield with array literals Prettifies incorrectly #1673

Open
nicholaides opened this issue Jan 4, 2025 · 3 comments
Open

yield with array literals Prettifies incorrectly #1673

nicholaides opened this issue Jan 4, 2025 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@nicholaides
Copy link

nicholaides commented Jan 4, 2025

Input:

yield [2,3]
yield await [foo, bar]

Actual output:

yield[(2, 3)];
yield[(await foo, await bar)];

Expected output:

yield[2, 3];
yield[await foo, await bar];
@edemaine
Copy link
Collaborator

edemaine commented Jan 5, 2025

Civet generates the expected output. The output you're seeing is a bug in Prettier. Possibly fixed in a newer version; I'll check whether updating fixes it.

@edemaine edemaine added the documentation Improvements or additions to documentation label Jan 5, 2025
@nicholaides
Copy link
Author

So it is. I'll try to remember to turn off Prettier in the playground next time I have a bug report.

@edemaine
Copy link
Collaborator

edemaine commented Jan 5, 2025

Here's a relevant Prettier issue: prettier/prettier#16167
(also links to a discussion about the cause)

It turns out that wrapping the example in a function* (so that yield is valid) works:

function* f
  yield [2,3]
  yield await [foo, bar]

Playground link

It's plausible to me that we could fix this in some way, when there's a top-level yield like this.

  • Perhaps we shouldn't run Prettier? (easiest)
  • Perhaps we should try to wrap in function*, run Prettier, then unwrap? (the unwrapping seems tricky)

Or we could wait for Prettier to fix the bug (but it's been several months, so I wouldn't hold my breath).

@edemaine edemaine changed the title yield with array literals compiles incorrectly yield with array literals compiles incorrectly (Prettier bug) Jan 5, 2025
@edemaine edemaine changed the title yield with array literals compiles incorrectly (Prettier bug) yield with array literals Prettifies incorrectly Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants