Skip to content

Fix off-by-one mappings for recovered unclosed tags - #61

Merged
leonidaz merged 1 commit into
feat/scoped-styles-applyfrom
cursor/unclosed-tag-mappings-74c4
Sep 4, 2026
Merged

leonidaz merged 1 commit into
feat/scoped-styles-applyfrom
cursor/unclosed-tag-mappings-74c4

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #48.

When loose-mode recovery synthesizes a closing element for an unclosed tag (for example <span> typed without </span>), to_jsx_element was attaching the whole element's location to that close. The generated name span then mapped to source <spa, and the opening < lost its mapping. Editor features keyed on the tag name (auto-close, rename, hover) landed one character early.

This PR leaves the synthesized closing element unlocated and clones its name from the opening tag name token, so:

  • the synthesized </span> name maps to span, not <spa
  • the opening < keeps a mapping like a balanced element

A shared compile_to_volar_mappings regression test covers the recovered-unclosed-tag offsets. Scope is #48 only; style-specific fatal CSS (#47) is left alone.

Verification

The issue repro now maps as follows:

  • source < of <span> (offset 31) → generated < of <span>
  • source span (offset 32) → both the opening name and the synthesized </span> name
  • no mapping of length 4 starting at < (<spa)

The new test passed on React, Preact, Solid, and Vue. Related shared source-mapping tests also passed (368).

Open in Web Open in Cursor 

Loose-mode recovery synthesized a closing element with the whole
element's location, so the generated </span> name mapped to <spa and
the opening < lost its mapping. Leave the synthesized close unlocated
and clone the name from the opening tag token.

Co-authored-by: Jon Wheeler <[email protected]>
@vercel

vercel Bot commented Sep 4, 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 4, 2026 3:10pm UTC
tsrx-website-mcp Ready Ready Preview Sep 4, 2026 3:10pm UTC

Request Review

@cursor

cursor Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@leonidaz — ready for your review when you have a minute. Implements #48 (unclosed-tag mapping off-by-one in loose mode).

@leonidaz
leonidaz merged commit a5cabbd into feat/scoped-styles-apply Sep 4, 2026
4 checks passed
@leonidaz
leonidaz deleted the cursor/unclosed-tag-mappings-74c4 branch September 4, 2026 15:49
leonidaz added a commit that referenced this pull request Sep 5, 2026
* feat(tsrx): lexically scoped style blocks, $class, and apply

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]>

* fix(tsrx): scope @else if bodies and dedupe static theme diamonds

- 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]>

* feat(tooling): editor and lint support for scoped style blocks and apply

- 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]>

* feat(language-server): scoped style blocks, apply, and coded diagnostics

- 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]>

* fix(tsrx): map the type-only apply $class read for verification only

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]>

* docs(tsrx): specify lexically scoped style blocks, $class, and apply

- 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]>

* chore: changesets for the scoped-style tooling and MCP changes

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

* feat(tsrx): expose the scoped-style conformance fixtures and parser spec 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]>

* fix(tsrx): print type-only style stand-ins as void expressions

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]>

* chore: changeset for the IntelliJ plugin grammar update

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

* test(vscode-plugin): type the runtime-registered grammar id for shiki

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

* chore(tsrx): ship the MIT license file with @tsrx/core

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]>

* refactor(tsrx): inline is_reference so the analyzer bundles without an 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]>

* feat(tsrx): a block whose $class is read is a theme

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]>

* test(tsrx): conformance fixture for opting elements into a theme with $class

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

* docs(tsrx): opting elements into a theme with $class

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]>

* fix(tsrx-mcp): escape the docs-index sentence template

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

* chore: regenerate agent rules

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

* feat(tsrx): amendment A1 for scoped style blocks

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]>

* test(tooling): hold scoped style blocks in fragments

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]>

* docs: amendment A1 wording for scoped style blocks

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]>

* docs: call the style scope a sibling scope

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]>

* docs: rewrite the style docs in plain language

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]>

* docs: explain :global() and when to pass $class instead

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]>

* docs: document the :global block form and nesting

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]>

* docs: give the opt-in example's article its own local class

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]>

* fix: map recovered unclosed tags to the opening name token (#61)

Loose-mode recovery synthesized a closing element with the whole
element's location, so the generated </span> name mapped to <spa and
the opening < lost its mapping. Leave the synthesized close unlocated
and clone the name from the opening tag token.

Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: Jon Wheeler <[email protected]>

* fix(tests): type source mapping helper

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Co-authored-by: Jon Wheeler <[email protected]>
Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: Jon Wheeler <[email protected]>

This branch was successfully deployed

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

3 participants