Skip to content

fix(codegen): remove leading whitespace from export statements after comments#17982

Merged
graphite-app[bot] merged 1 commit intomainfrom
fix/codegen-export-leading-space
Jan 14, 2026
Merged

fix(codegen): remove leading whitespace from export statements after comments#17982
graphite-app[bot] merged 1 commit intomainfrom
fix/codegen-export-leading-space

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Jan 14, 2026

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:

export { name8, /* comment */ name81 };
 export { variable1 as name9 };  // <-- unwanted leading space

After:

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

Copilot AI review requested due to automatic review settings January 14, 2026 07:23
@github-actions github-actions bot added A-codegen Area - Code Generation C-bug Category - Bug labels Jan 14, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_space flag after printing comments in ExportSpecifier to 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.

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Jan 14, 2026
Copy link
Member Author

Boshen commented Jan 14, 2026

Merge activity

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 14, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing fix/codegen-export-leading-space (affca7e) with main (4474ff1)1

Summary

✅ 42 untouched benchmarks
⏩ 3 skipped benchmarks2

Footnotes

  1. No successful run was found on main (8687b09) during the generation of this report, so 4474ff1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

…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)
@graphite-app graphite-app bot force-pushed the fix/codegen-export-leading-space branch from affca7e to 2619c66 Compare January 14, 2026 07:32
@graphite-app graphite-app bot merged commit 2619c66 into main Jan 14, 2026
20 checks passed
@graphite-app graphite-app bot deleted the fix/codegen-export-leading-space branch January 14, 2026 07:38
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-codegen Area - Code Generation C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants