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

Comments are not preserved inside switch...case #3838

Closed
akellbl4 opened this issue Jul 18, 2024 · 2 comments
Closed

Comments are not preserved inside switch...case #3838

akellbl4 opened this issue Jul 18, 2024 · 2 comments

Comments

@akellbl4
Copy link

akellbl4 commented Jul 18, 2024

When a comment is placed inside switch block above case or default it is not preserved in the transpiled code.

@ghost
Copy link

ghost commented Aug 1, 2024

@evanw any update on this issue?

@evanw
Copy link
Owner

evanw commented Aug 16, 2024

The "legal comments" mechanism isn't designed for this use case. Legal comments are intended to be present but the specifics of where they are in the source code isn't supposed to matter. Legal comments are currently supported at the statement level but these things aren't statements (specifically a CaseBlock is a sequence of CaseClauses in JavaScript). I could "fix" what you're asking for by moving the comments into the case block so they are preserved (which is all the @preserve tag means), but that wouldn't achieve what you're trying to do.

What you're really asking for is for esbuild to support Istanbul's specific comment meta-language, which is not something that esbuild supports. You can read more about what supporting that would mean here: #578 (comment). It's very non-trivial.

I can try treating these as expression-level comments for now (which they aren't), which will attempt to preserve them as long as minification is disabled. It still won't treat them as legal comments, but perhaps that is enough for this use case.

@evanw evanw closed this as completed in f6e6481 Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants