fix(codegen): remove leading whitespace from export statements after comments#17982
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where leading whitespace was incorrectly added to export statements following block comments within export specifiers. The issue occurred because the print_next_indent_as_space flag, set by print_comments(), was not being consumed when print_soft_space() was called instead of print_indent().
Changes:
- Reset the
print_next_indent_as_spaceflag after printing comments inExportSpecifierto prevent flag leakage - Update test snapshot to reflect corrected output format
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/oxc_codegen/src/gen.rs | Added flag reset after comment printing in two locations within ExportSpecifier::r#gen() |
| crates/oxc_codegen/tests/integration/snapshots/ts.snap | Updated snapshot to show corrected export statement formatting without unwanted leading spaces |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
…comments (#17982) ## Summary - Clear the `print_next_indent_as_space` flag after printing comments in `ExportSpecifier` to prevent it from leaking to subsequent statements When a block comment like `/* comment */` is printed inside an export specifier, the flag is set expecting `print_indent()` to consume it. However, `ExportSpecifier` calls `print_soft_space()` instead, leaving the flag set. This caused the next export statement to incorrectly print a leading space. Before: ```js export { name8, /* comment */ name81 }; export { variable1 as name9 }; // <-- unwanted leading space ``` After: ```js export { name8, /* comment */ name81 }; export { variable1 as name9 }; ``` ## Test plan - Existing tests pass - Snapshot updated to reflect the fix Closes #17884 🤖 Generated with [Claude Code](https://claude.com/claude-code)
affca7e to
2619c66
Compare
Summary
print_next_indent_as_spaceflag after printing comments inExportSpecifierto prevent it from leaking to subsequent statementsWhen a block comment like
/* comment */is printed inside an export specifier, the flag is set expectingprint_indent()to consume it. However,ExportSpecifiercallsprint_soft_space()instead, leaving the flag set. This caused the next export statement to incorrectly print a leading space.Before:
After:
Test plan
Closes #17884
🤖 Generated with Claude Code