Skip to content

fix(tsrx): give analyzeCss :global placement errors file-relative positions - #72

Merged
leonidaz merged 1 commit into
mainfrom
fix/analyze-css-global-positions
Sep 5, 2026
Merged

leonidaz merged 1 commit into
mainfrom
fix/analyze-css-global-positions

Conversation

@leonidaz

@leonidaz leonidaz commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #45. Supersedes #65, which carries the same intent on top of a stale merge of main.

Problem

CSS nodes only carry offsets relative to the <style> body, so a consumer calling analyzeCss(sheet) directly (Octane does) got a coded CompileError whose pos/end were body-relative and whose loc was undefined. Only the JSX transform's re-anchoring on the <style> element gave compile users a position.

Approach

  • parseStyle takes an optional body origin ({ start, line, column } of the body's first character) and records it on the sheet as sourceStart plus a file-relative loc. Node start/end stay body-relative, so renderStylesheets keeps indexing source unchanged and hashes are untouched.
  • The parser plugin passes the origin for every <style> body, so every sheet parseModule produces carries it.
  • analyzeCss maps the offending :global pseudo-class through that origin at report time rather than attaching loc to every CSS node on every parse (the approach in fix(tsrx): give analyzeCss file-relative :global positions #65), defaults fileName from the sheet, accepts { filename, errors, comments } to collect instead of throw, and reports a middle-placement selector once instead of once per trailing selector.
  • The error is anchored on the :global(...) pseudo-class itself rather than the enclosing relative selector, which would include the leading combinator whitespace.

The transform still re-anchors the diagnostic on the <style> element for compile / compile_to_volar_mappings: the type-only output has no tokens inside a CSS body, so that block is the only range the language server can map back to the document. A new language-server test pins that behaviour down.

Tests

  • packages/tsrx/tests/analyze/styles.test.js (:global placement): file-relative pos/end/loc for direct analyzeCss callers, multi-line bodies, the errors option, filename precedence, one error per selector, a sheet parsed directly with parseStyle and a body origin, and body-relative positions when parsed without one.
  • packages/language-server/tests/compileErrorDiagnosticPlugin.test.js: the editor diagnostic lands on the <style> block.

Ran pnpm typecheck and the tsrx-utils, tsrx-analyze, target compiler, language-server, and typescript-plugin vitest projects locally.

🤖 Generated with Claude Code


Note

Low Risk
Targeted diagnostic and parse-metadata changes for CSS analysis; behavior is well covered by new tests and does not alter rendering or selector semantics.

Overview
analyzeCss now emits :global placement diagnostics with file-relative pos, end, and loc on the misplaced :global pseudo-class (not the whole selector), defaults fileName from the parsed sheet, and accepts { filename, errors, comments } so callers can collect issues instead of throwing. Middle-placement violations report once per selector instead of once per trailing segment.

parseStyle accepts an optional body origin (offset and line/column of the style body’s first character). Sheets from parseModule store sourceStart and file-relative loc while CSS node start/end stay body-relative; css_node_source_position maps nodes at report time. The parser plugin passes that origin when parsing <style> bodies.

Docs and types document the model. Tests cover direct analyzeCss/parseStyle positioning, the errors option, and a language-server case where compile still highlights the whole <style> block because type-only output has no in-body CSS tokens.

Reviewed by Cursor Bugbot for commit 7308c9d. Bugbot is set up for automated code reviews on this repo. Configure here.

…itions

CSS nodes only carry offsets relative to the style body, so a consumer
calling analyzeCss(sheet) directly got a coded CompileError whose pos/end
were body-relative and whose loc was undefined; only the JSX transform's
re-anchoring on the <style> element gave compile users a position.

parseStyle now takes an optional `body` origin (the body's file offset,
line, and column) and records it on the sheet as `sourceStart` plus a
file-relative `loc`, with node start/end left body-relative so stylesheet
rendering keeps indexing `source`. The parser plugin passes the origin for
every <style> body. analyzeCss maps the offending `:global` pseudo-class
through that origin at report time (no per-node work on parse), defaults
`fileName` from the sheet, accepts `{ filename, errors, comments }` to
collect instead of throw, and reports a middle-placement selector once.

The transform still anchors the diagnostic on the <style> element: the
type-only output has no tokens inside a CSS body, so that block is the
only range the language server can map back to the document.

Fixes #45

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@vercel

vercel Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
tsrx-website Ready Ready Preview Sep 5, 2026 9:20pm UTC
tsrx-website-mcp Ready Ready Preview Sep 5, 2026 9:20pm UTC

Request Review

@leonidaz
leonidaz merged commit b11381d into main Sep 5, 2026
11 checks passed
@leonidaz
leonidaz deleted the fix/analyze-css-global-positions branch September 5, 2026 21:24
@github-actions github-actions Bot mentioned this pull request Sep 5, 2026

This branch was successfully deployed

2 active deployments
Preview – tsrx-website — 7308c9dd Deployed Sep 5, 2026 by vercel[bot]
Preview – tsrx-website-mcp — 7308c9dd Deployed Sep 5, 2026 by vercel[bot]
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.

analyzeCss :global placement diagnostics carry CSS-relative positions

1 participant