Skip to content

fix(transpile): preserve newlines after multi-line block comments#34357

Merged
bartlomieju merged 1 commit into
mainfrom
fix/transpile-jsdoc-newline
May 25, 2026
Merged

fix(transpile): preserve newlines after multi-line block comments#34357
bartlomieju merged 1 commit into
mainfrom
fix/transpile-jsdoc-newline

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

SWC's code generator always writes a single space after a block
comment's closing */, regardless of what the original source had there.
For multi-line JSDoc this collapses the comment onto the same line as the
following statement, producing awkward output like */ export function greet(...). Restore the newline (plus the comment's leading indentation)
as a post-process pass on the emitted text.

The pass uses a small state machine that tracks string, template-literal,
and substitution contexts so */ appearing inside literals is left
untouched. It is skipped when --source-map is requested, since
inserting newlines would shift line numbers in the generated output
without a corresponding adjustment to the mappings.

Fixes #34317

SWC's code generator always emits a single space after `*/`, collapsing
JSDoc-style block comments onto the same line as the following statement.
Restore the newline as a post-process pass on the emitted output, with a
small state machine that tracks string and template-literal contexts so
`*/` inside literals is left untouched.

Skipped when source maps are requested, since adjusting the mappings to
account for inserted newlines is non-trivial.

Fixes #34317

@fibibot fibibot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No blocker found. restore_block_comment_newlines() only runs when source maps are disabled, so it fixes the default deno transpile output without shifting mappings; the string/template state tracking keeps comment-like text inside strings and template bodies from being rewritten. Holding approval until CI is green.

@fibibot fibibot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CI is green now, promoting prior review to APPROVE.

@bartlomieju
bartlomieju merged commit a865b21 into main May 25, 2026
136 checks passed
@bartlomieju
bartlomieju deleted the fix/transpile-jsdoc-newline branch May 25, 2026 14:37
littledivy pushed a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
…noland#34357)

SWC's code generator always writes a single space after a block
comment's closing `*/`, regardless of what the original source had
there. For multi-line JSDoc this collapses the comment onto the same line as
the following statement, producing awkward output like `*/ export function
greet(...)`. Restore the newline (plus the comment's leading
indentation) as a post-process pass on the emitted text.

The pass uses a small state machine that tracks string,
template-literal, and substitution contexts so `*/` appearing inside literals is left
untouched. It is skipped when `--source-map` is requested, since
inserting newlines would shift line numbers in the generated output
without a corresponding adjustment to the mappings.

Fixes denoland#34317
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

Successfully merging this pull request may close these issues.

Transpile: jsdoc lacks a newline character.

2 participants