Skip to content

fix(formatter): map embedded template ranges through source map ??????#9636

Closed
raashish1601 wants to merge 2 commits intobiomejs:mainfrom
raashish1601:contributor-06/biome-9484
Closed

fix(formatter): map embedded template ranges through source map ??????#9636
raashish1601 wants to merge 2 commits intobiomejs:mainfrom
raashish1601:contributor-06/biome-9484

Conversation

@raashish1601
Copy link
Copy Markdown

Fixes #9484

The formatter now maps embedded template chunk ranges back through the JavaScript source map before looking up parsed embedded snippets. This keeps TSX files with earlier parenthesized-JSX rewrites from shifting later embedded GraphQL ranges and tripping the printer's embedded-tag invariants.

Test Plan

  • Added issue_9484 to crates/biome_service/src/workspace/server.tests.rs
  • cargo test -p biome_service issue_9484 -- --nocapture
  • cargo test -p biome_service format_js_with_embedded_graphql -- --nocapture
  • cargo test -p biome_service issue_9131 -- --nocapture
  • cargo fmt --all
  • git diff --check

Docs

  • Not needed; this is a formatter bug fix.

This PR was created with AI assistance (Codex).

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 28, 2026

🦋 Changeset detected

Latest commit: 8332bf6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added A-Project Area: project A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages labels Mar 28, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b9a51bfb-0a03-4e18-80c4-982f3ae5e06a

📥 Commits

Reviewing files that changed from the base of the PR and between f21ae12 and 8332bf6.

📒 Files selected for processing (1)
  • crates/biome_service/src/workspace/server.tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_service/src/workspace/server.tests.rs

Walkthrough

Refactors embedded template-chunk range selection into a new helper embedded_template_chunk_range(...) that centralises delegation checks, plausibility detection and range computation, and conditionally remaps ranges via the formatter's source map. The JS and TS formatter implementations are updated to use this helper. Adds a regression test that formats an in-memory .tsx file containing an embedded gql template literal and updates snapshot expectations for embedded CSS formatting. Also adds a changeset for a patch release.

Possibly related PRs

Suggested reviewers

  • siketyan
  • dyc3
  • ematipico
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: mapping embedded template ranges through the source map to resolve TSX formatter crashes.
Description check ✅ Passed The description is well-related to the changeset, explaining the fix for issue #9484 and providing a concrete test plan with specific cargo commands.
Linked Issues check ✅ Passed The PR fully addresses issue #9484 by implementing source map range mapping for embedded template chunks, eliminating the formatter crashes caused by shifted ranges in TSX files.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the embedded template range mapping issue: formatter logic refactoring, test additions, and snapshot updates for related tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 28, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 168 skipped benchmarks1


Comparing raashish1601:contributor-06/biome-9484 (8332bf6) with main (c17e08e)2

Open in CodSpeed

Footnotes

  1. 168 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.

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

@ematipico ematipico added the M-Likely Agent Meta: this was likely an automated PR without a human in the loop label Mar 28, 2026
@ematipico
Copy link
Copy Markdown
Member

Can you explain why source maps were used?

@ematipico ematipico closed this Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Formatter Area: formatter A-Project Area: project L-JavaScript Language: JavaScript and super languages M-Likely Agent Meta: this was likely an automated PR without a human in the loop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript File with GraphQL and gql`` crashes

2 participants