Repository navigation
fix(tsrx): give analyzeCss :global placement errors file-relative positions - #72
Merged
Merged
Conversation
…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]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Merged
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 callinganalyzeCss(sheet)directly (Octane does) got a codedCompileErrorwhosepos/endwere body-relative and whoselocwasundefined. Only the JSX transform's re-anchoring on the<style>element gavecompileusers a position.Approach
parseStyletakes an optionalbodyorigin ({ start, line, column }of the body's first character) and records it on the sheet assourceStartplus a file-relativeloc. Nodestart/endstay body-relative, sorenderStylesheetskeeps indexingsourceunchanged and hashes are untouched.<style>body, so every sheetparseModuleproduces carries it.analyzeCssmaps the offending:globalpseudo-class through that origin at report time rather than attachinglocto every CSS node on every parse (the approach in fix(tsrx): give analyzeCss file-relative :global positions #65), defaultsfileNamefrom the sheet, accepts{ filename, errors, comments }to collect instead of throw, and reports a middle-placement selector once instead of once per trailing selector.: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 forcompile/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-relativepos/end/locfor directanalyzeCsscallers, multi-line bodies, theerrorsoption, filename precedence, one error per selector, a sheet parsed directly withparseStyleand abodyorigin, 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 typecheckand thetsrx-utils,tsrx-analyze, target compiler,language-server, andtypescript-pluginvitest 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
analyzeCssnow emits:globalplacement diagnostics with file-relativepos,end, andlocon the misplaced:globalpseudo-class (not the whole selector), defaultsfileNamefrom 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.parseStyleaccepts an optionalbodyorigin (offset and line/column of the style body’s first character). Sheets fromparseModulestoresourceStartand file-relativelocwhile CSS nodestart/endstay body-relative;css_node_source_positionmaps nodes at report time. The parser plugin passes that origin when parsing<style>bodies.Docs and types document the model. Tests cover direct
analyzeCss/parseStylepositioning, theerrorsoption, 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.