Repository navigation
fix(tsrx): give analyzeCss file-relative :global positions - #65
Closed
jonkwheeler wants to merge 28 commits into
Closed
jonkwheeler wants to merge 28 commits into
jonkwheeler wants to merge 28 commits into
Conversation
Implement RFC tsrx-org/RFCs#1 in @tsrx/core: - parser: self-closing <style … /> (no body, no scope hash) and <style> siblings around the single output node in @{ } and directive bodies; raw-text elements restore the tokenizer context before reading the token after their closing tag, so a <style> in a @case body no longer breaks the following } or @case - analyzer: style-analyze pass (run with createScopes inside analyzeTsrx) classifies assigned blocks as theme or class-map, resolves apply targets through real bindings with declared-before-use, and reports the new STYLE_* and CSS_GLOBAL_PLACEMENT diagnostic codes - transform: a style-scopes pre-pass owns scope discovery, lexical CSS emission order, and class stamping (hashes outer→inner, then applied themes); replaces the per-fragment collection and the 'one style tag' error; element-rooted assigned templates keep their CSS; assigned blocks expose $class; prepareStylesheetForRender gains scope/class-map/theme modes; cssHash is deduped per scope - tests: parser spec table (oxc-tsrx porting spec), analyzer matrix, shared scope/theme/diagnostic cases for every JSX target, an ordering property test, and type-level $class tests Co-Authored-By: Claude Fable 5.1 <[email protected]>
- the style pre-pass and analyzer treat the plain IfStatement alternates of an @if directive (@else if chains) as branch scopes - statically resolvable hashes appear once in $class and in stamped classes when a theme is applied directly and through another theme (D12) - conformance fixtures under tests/fixtures/scoped-styles with a fixture-driven describe for every JSX target (Octane vendors them) Co-Authored-By: Claude Fable 5.1 <[email protected]>
- typescript-plugin: attribute-aware <style> fallback regex (self-closing,
'>' inside apply={…}), real cssMappings in workspace fixtures
- language tooling tests for prettier (idempotent formatting of every
new form), eslint rules (style siblings are not output nodes), eslint
parser scope references through apply={…}
- tsrx-mcp review_tsrx_styles recognizes self-closed blocks and themes
- TextMate and tree-sitter grammars: self-closing <style … />, style
siblings in code-block and directive bodies; regenerated bundle, queries
copied to zed/nvim; vscode grammar scope tests
- changesets for the vscode and zed extensions
Co-Authored-By: Claude Fable 5.1 <[email protected]>
- completion snippets for <style> and <style apply={…} />
- style diagnostics keep their core codes (tsrx-style-apply-target, …)
- auto-insert matches opening tags with a brace/quote-aware scanner, so
'>' inside apply={…} and self-closed <style … /> behave, and closes an
unclosed <style> even while the file only has fallback mappings
- tests: embedded CSS codes per block, snippets, auto-insert, diagnostics
on the apply target, hover/definition on $class through TypeScript
Co-Authored-By: Claude Fable 5.1 <[email protected]>
The synthesized `theme.$class` read in editor output borrows the target's span so type errors land on the authored identifier, but it no longer serves hover or navigation there, and the renamed data-tsrx-apply attribute is unmapped. Co-Authored-By: Claude Fable 5.1 <[email protected]>
- specification.tsrx: grammar (self-closing <style>, apply targets, style siblings in code-block and directive bodies), scope model, $class and theme vs class-map, apply resolution and declared-before-use, normative emission order, and one static-constraint entry per STYLE_* code - features.tsrx, llms.txt, demo snippets: lexical scopes, precedence, themes and apply; the playground shows Octane's injected CSS - README and bundler READMEs say lexically scoped; rulesync rules gain the scope/theme authoring assumptions (generated files regenerated) - tsrx-mcp docs index regenerated with the new spec sections - core exports buildStyleClassMap for consumer compilers Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…pec table Consumer compilers run them from @tsrx/core/test-harness/scoped-styles-fixtures and @tsrx/core/test-harness/style-syntax instead of vendoring copies; the fixture files ship in the package. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Consecutive <style> siblings in a code-block or directive body printed as adjacent JSX expression statements in editor output, which TypeScript rejects (TS2657); each stand-in is now its own void expression. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Consumers that bundle the package (Octane's Volar compiler bundle) look for a license notice inside the package directory, which a git checkout lacked. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…n extra notice analyzeTsrx now runs createScopes, which pulls scope.js into consumer bundles (Octane's Volar compiler bundle); [email protected] ships no license file, so the 40-line helper is inlined with attribution. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Reading `theme.$class` opts one element (or a child component's element, through a prop) into the block's whole stylesheet, so such a block keeps every selector like an exported or applied one instead of pruning its element selectors as a class map. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… $class Co-Authored-By: Claude Fable 5.1 <[email protected]>
Spec 4.6.3 (theme = exported, applied, or `$class` read; `styleClassRead` metadata), a features-page subsection with a Card/App example, llms.txt bullets and a cheat-sheet row, a demo snippet, the rulesync clause, and the regenerated MCP docs index. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Rule A: a standalone `<style>` block is a child of an element or fragment
and that children list is its scope. It styles the items beside it and
everything below them, never the element that contains it; a selector that
only matches the container is pruned. Statement lists hold no standalone
blocks: the D3 parser relaxation is reverted, so a block beside the output
node of a `@{ … }` or control-flow body is the ordinary multiple-outputs
error again, and a lone block there (or a block in statement position) is
the new `STYLE_STANDALONE_NEEDS_FRAGMENT` diagnostic. The pre-pass drops
its statement-list scope machinery and threads `<style ref>` maps of
children-list scopes to the nearest statement slot.
Rule B: raw CSS in `<style>` is TSRX template syntax. A bodied standalone
block outside every `@{ … }` and control-flow body is the new
`STYLE_STANDALONE_OUTSIDE_TEMPLATE` diagnostic; head styles, resource
styles, and self-closing blocks are exempt.
Rule C: `<style>` whose first non-whitespace child character is `{` parses
as an ordinary `JSXElement` named `style` with expression-container
children — no stylesheet, no hash, never stamped or extracted.
Fixtures, the shared suite (including the seeded ordering property test,
which now models element children lists as scopes), the analyzer placement
tables, and the `STYLE_SYNTAX_CASES` parser table follow the new rules; the
`sibling-scope` fixture pins the amendment's Status class table.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
A `<style>` block is an output node again, so the eslint
`require-statement-container-body` rule returns to counting it as template
output (its D3 relaxation is removed) and the eslint, prettier, and
language-server cases move their blocks into fragments beside the output.
Plain-TSX plugin fixtures become `@{ … }` bodies. Completion snippet text
and the MCP `review_tsrx_styles` wording describe the amended rules, and
`<style>{css}</style>` is reported as an ordinary element rather than an
error.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
The specification (4.6.1, 4.6.2, 5.1, A.3, the grammar table, and the
static-constraints listing), the features page, llms.txt, the shared agent
rules, the core README, and the MCP documentation index describe the
children-list scope rule, the two new diagnostics, and plain-TSX
`<style>{css}</style>`. Examples that relied on a nested block styling its
container, or on a block beside the output node, wrap the block and its
output in a fragment. Changesets are extended accordingly (patch bumps).
Co-Authored-By: Claude Fable 5.1 <[email protected]>
A standalone `<style>` block is scoped to the children list it sits in:
it styles its siblings and everything below them, and sibling blocks
share one hash. Readers took "lexically scoped" to mean the block reaches
everything in its `@{ ... }` body, so the docs, llms.txt, specification
(4.6, 4.6.2 is now "Sibling scopes"), features page, package READMEs,
changesets, the MCP docs index, and the language-server `<style>`
completion now say "sibling scope" and define it where it first appears.
"Lexical" keeps its JavaScript meaning (binding scope, emission order,
and the TSX placement rule).
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Each style section now makes one point, its title states that point, and it opens with the rule, then an example, then what to do. "Hash class" is defined once up front on every surface (the class the compiler adds to an element so the block's selectors match only there) and used afterwards. Jargon is replaced with plain words: branch for arm, "adds the hash class" for stamp, "the block that applies it" for applier, "a block with CSS in it" for bodied, and "output", "removed as unused", "moved to the top of the module", and "source order, outer first" for emit, prune, hoist, and pre-order. Covers features.tsrx (new subsections and a before/after fragment example), llms.txt, README.md, packages/tsrx/README.md, specification 4.6 prose and the 5.1 closing paragraph, and the MCP docs index with its test. No fact, example output, code, grammar, or diagnostic changes. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Expand the features page's ":global()" section into a full treatment: the four forms with their compiled output, the specificity rule (hash on the first compound only, :where on the rest), and a decision table for choosing between :global and passing theme.$class to a child. Add a compact version with the same table to llms.txt and the MCP docs index, one rule line to the agent rules, and one normative sentence to specification 4.6. Pin the :global output shapes for every target in the shared scoped-styles tests. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Add the block form, :global { ... }, beside the selector form in the
features page, llms.txt, the MCP docs index, the agent rules, and the one
normative sentence in specification 4.6. Show a :global block nested under
a scoped selector as the way to style several classes of a child you cannot
change, and contrast it with plain nesting, which scopes both parts.
Pin the block, nested, and plain-nesting output shapes for every target in
the shared global-forms test.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
The $class opt-in example declared a .local rule the article never used. The article now carries local alongside the passed theme class, written as a template literal because array class values are a target-specific feature; the shared test, the class-opt-in conformance fixture, and the generated MCP docs index follow. Co-Authored-By: Claude Fable 5.1 <[email protected]>
parseStyle now records the style body's file origin so CSS nodes carry loc and sourceStart, while start/end stay body-relative for stylesheet rendering. analyzeCss remaps CompileError pos/end/loc for direct callers. Co-authored-by: Jon Wheeler <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
jonkwheeler
marked this pull request as ready for review
September 4, 2026 15:15
Contributor
Contributor
|
READY FOR REVIEW |
Contributor
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.
analyzeCssnow reports:globalplacement errors with file-relativepos/end/loc, so direct callers (Octane) can place editor squiggles.Approach
Keep CSS
start/endbody-relative sorenderStylesheetscan still indexstylesheet.source. GiveparseStylean optional file origin (start/sourceLine/sourceColumn) and attachlocplussourceStart/filenameon the sheet.analyzeCssremaps the diagnostic node through that origin and accepts optional{ filename, errors, comments, start }.The JSX transform still re-anchors
CSS_GLOBAL_PLACEMENTon the<style>element forcompile/compile_to_volar_mappings, so those consumers keep their existing positions.Tests
packages/tsrx/tests/analyze/styles.test.js(:global placement) now asserts:fileNamepos/endthat cover:globalinside the<style>bodylocmatching those offsetsincluding a multiline
parseModulepath and a directparseStyleorigin.