Skip to content

fix(core): report invalid @for heads and destructure awaited head defaults - #1133

Merged
jonkwheeler merged 5 commits into
tsrx-org:mainfrom
jonkwheeler:fix/for-loop-head
Nov 12, 2026
Merged

jonkwheeler merged 5 commits into
tsrx-org:mainfrom
jonkwheeler:fix/for-loop-head

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part of the @for semantics series (spec in #1132). This PR covers rules 2 and 3: loop bindings follow for...of rules, and invalid head forms get a diagnostic.

Every target lowers an @for item to a callback parameter, and the head's target became that parameter as written:

The check runs in each target's @for lowering (the shared one, which Vue's <VaporFor> path goes through, and Solid's own), so it reports a loop wherever it sits: top level, in an @if, @switch, or @try body, in another @for, or in a JSX value. An assignment head with a key gets a placeholder item parameter, so the type-only output stays valid on every target. When an awaited head is moved into the callback, the loop body runs in a block of its own after the destructuring, so the body's declarations can't shadow names the head reads (@for (const [item = await load('outer')] of rows) { const load = ...; } reads the outer load, as for...of does). TSRX2027 is a new code. It is listed in the specification appendix, has a content-mapper error example, and the features page and llms.txt document the head rule.

Migration (minor bump): a head without const or let that compiled before, such as @for (item of items) with no outer item, is now an error. Declare the loop variable: @for (const item of items).

var heads are left alone. They lower to a callback parameter and lose function scope, but no issue reports that, and rejecting them would be a separate decision.

Verification

  • Shared compile diagnostics tests (all five targets, plus Hono DOM) for assignment targets with an index (state.item, item, { item }, [state.item]), for using / await using, for both heads nested in @if, @for, @switch, @try, and a JSX value, and for keyed assignment heads with and without an index. They check the code, the reported position, and that the type-only output parses. The nested and keyed cases fail on Solid before the follow-up commit.
  • The reviewers' 720-case head matrix (9 valid and 9 invalid heads × 8 positions × 5 targets × strict, collect, loose, and type-only modes): every invalid head reports TSRX2027 in every mode, no output fails to parse, and nothing throws. The only remaining flags are the matrix's own setup and are the same on main: var item beside the fixture's outer let item reports TS2481, and await using in a non-async arrow reports TS2852 from the parser.
  • Shared source-mapping test: an @for head default that awaits emits parseable async output and maps its await keyword (React, Preact, Hono).
  • Hono SSR test with the [Bug]: Awaited @for destructuring defaults produce an unloadable Hono server module #224 repro shape: the module loads and renders <li>0:default</li><li>1:given</li>. On main it fails with the reported SyntaxError. A second loop whose body declares the load its head default calls renders outer:inner; without the body block it throws Cannot access 'load' before initialization.
  • content-mapper error-examples suite (native TypeScript 7 language server): both TSRX2027 examples show exactly once, with no TypeScript error on top.
  • First round: full npx vitest run --testTimeout=60000 with 10035 passed, 82 skipped, 0 failed. After the review fixes: the compiler, runtime, and vite-plugin projects for all five targets, plus tsrx-utils and content-mapper (--testTimeout=60000, 92 files): 6208 passed, 65 skipped, 0 failed.
  • pnpm typecheck: clean. prettier --check on the changed files: clean. pnpm changeset:check: passes.

Related

Fixes #267
Fixes #453
Fixes #224

🤖 Generated with Claude Code


Note

Medium Risk
Touches shared @for lowering on all targets and changes compile-time behavior for previously accepted head forms (breaking migration for undeclared loop variables); logic is well tested but compiler changes affect every framework output.

Overview
Introduces TSRX2027 so @for heads must declare the loop variable (@for (const item of items)). Assignment targets like @for (state.item of items) or bare @for (item of items), and using / await using heads, are diagnosed on every target and at any nesting depth instead of compiling to invalid or misleading callback parameters.

Lowering changes: shared validate_for_of_head runs during @for lowering (core and Solid). When the head needs an index or key but has no valid item binding, loop callbacks use a generated FOR_OF_ITEM_PARAM_NAME placeholder so type-only output still parses. Patterns with await in a destructuring default no longer become illegal async callback parameters: the callback receives the raw item, destructures it as the first statement, and wraps the loop body in its own block so body locals cannot shadow names the head’s default reads.

Documented in the changeset (minor bump), spec, features page, and llms.txt, with error examples and broad test coverage including Hono SSR for the awaited-default case.

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

jonkwheeler and others added 2 commits October 26, 2026 14:47
Every target lowers an `@for` item to a callback parameter, so the head's
target became that parameter as written. `@for (state.item of items)`
compiled without an error to `(state.item) => ...`, invalid output, and
`@for (item of items)` or `@for ({ item } of items)` silently shadowed
the outer binding instead of assigning it (tsrx-org#267). `@for (using item of
items)` dropped the `using`, so items were never disposed (tsrx-org#453).

Report both as TSRX2027 before the target lowers the loop, so React,
Preact, Solid, Vue, and Hono all reject them. The loop callback gets no
item parameter for an assignment target, so the type-only output stays
valid and the diagnostic is the only error; an index still comes second.

Fixes tsrx-org#267
Fixes tsrx-org#453

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A loop body that awaits becomes an async callback for
`map_iterable_async`, and the head's pattern was its parameter, so
`@for (const [item = await load()] of rows)` produced
`async ([item = await load()]) => ...`. An `await` is illegal in the
parameters of an async function, so the module failed to load (tsrx-org#224).

When the head's pattern awaits, the callback takes the item whole as a
generated parameter and destructures it with the head's declaration kind
as its first statement.

Fixes tsrx-org#224

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 82d1649. Configure here.

jonkwheeler and others added 2 commits October 27, 2026 07:53
Solid lowers a nested `@for` through its own `to_jsx_child`, which calls
its `for_of_statement_to_jsx_child` directly, so TSRX2027 was only
reported for a top-level loop: `@if (c) { @for (using item of items) {} }`
still dropped `using`, and `@for (state.item of items)` in an `@if`,
`@switch`, `@try`, nested `@for`, or JSX value lowered silently. The
check now runs in each target's `@for` lowering instead of the shared
dispatcher.

An assignment head with a `key` and no `index` also crashed Solid's
lowering (`clone_ast_node(undefined)`), which threw from
`compile_to_volar_mappings` and emitted `keyed={(,) => item}` when
collecting. The loop callback now gets its placeholder item parameter
whenever there is a key or an index.

The head check is a language removal for heads like
`@for (item of items)` that compiled before, so the changeset is minor
with a migration line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The callback for an awaited head default destructured the item as the
first statement of the block that also held the body's declarations.
The head reads names before the body's scope exists, so
`@for (const [item = await load('outer')] of rows) { const load = ...; }`
hit the body's `load` in its temporal dead zone and threw, where
`for...of` reads the outer `load`. The body now runs in a block of its
own after the destructuring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
jonkwheeler added a commit to jonkwheeler/tsrx that referenced this pull request Oct 27, 2026
…2028

Open PR tsrx-org#1133 already adds TSRX2027 for invalid `@for` heads, so the
Vue diagnostic for a component read above its declaration moves to
TSRX2028 in the error table, the message, the specification, the tests
and the changeset.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jonkwheeler
jonkwheeler marked this pull request as ready for review October 27, 2026 12:29
jonkwheeler added a commit that referenced this pull request Nov 12, 2026
…able (#1125)

* fix(vue): wrap every component form and keep wrapped components hoistable

Three gaps in how the Vue transform wraps components in
defineVaporComponent:

- The name lookup compared the walked function with its parent's child
  by identity. When the walk had replaced something inside the function
  (any nested function), it got a copy, the check failed, and arrow
  components stayed unwrapped (#240). A default-exported component with
  a nested function compiled to `export default const …` for the same
  reason. The lookup now uses the function as it appears in the path.
- A component that returns JSX through a local variable never gets the
  core `native_tsrx_function` flag, so it was never wrapped (#237). An
  uppercase function that returns a local binding initialized or
  assigned with JSX is now wrapped too.
- A wrapped declaration is a `const`, which is not hoisted, so a module
  that reads a component above its declaration threw "Cannot access
  before initialization" (#1073). Each wrapped component now moves above
  the first statement in its scope that reads it while the scope runs.
  Reads inside nested functions, types and export specifiers do not
  count, so other components keep the source order.

* fix(vue): move a component above an early read only when safe, else report TSRX2027

Review of the #1073 move found modules that load on main and broke:
reads in class instance fields, constant-false branches and shadowing
scopes counted as early reads, and moving a component past them made
vue-jsx-vapor's eager prop defaults (`{ label = PREFIX }` becomes
`props: { label: { default: PREFIX } }`) read a binding in its TDZ, or a
`var` before its assignment.

- The early-read finder now skips class instance fields and methods,
  branches a `const NAME = <literal>` or literal condition never takes,
  and blocks, loops, catch clauses and switches with their own binding
  of the name. Switch cases are no longer hoisting scopes.
- A component moves above the first early read only when no default in
  its props pattern reads a binding declared in the statements it would
  move past. Otherwise the compiler reports TSRX2027 at the read, naming
  the component and asking to move its declaration up.
- `export default function Card` now compiles to
  `const Card = defineVaporComponent(…); export default Card;`, so
  `typeof Card` and `export { Card }` keep working.

Reads through calls or IIFEs, from another case of the declaring switch,
and through circular imports cannot be detected and are documented.

* fix(vue): renumber the component read-before-declaration code to TSRX2028

Open PR #1133 already adds TSRX2027 for invalid `@for` heads, so the
Vue diagnostic for a component read above its declaration moves to
TSRX2028 in the error table, the message, the specification, the tests
and the changeset.

* fix(vue): treat assignments and shadowed constants as unsafe for the move

Two gaps in the "move if safe, else TSRX2028" rule:

- Only bindings declared in the skipped statements made a move unsafe.
  `let size = 1; const registry = { card: Card }; size = 2;` followed by
  `function Card({ s = size })` moved Card above the assignment, so its
  eagerly evaluated default captured 1 instead of 2. An assignment,
  update or property write to a binding a default reads, anywhere in the
  skipped statements, now makes the move unsafe and reports TSRX2028.
- Literal constants were not scoped: `const DEBUG = false;
  { const DEBUG = true; if (DEBUG) …Inner }` skipped a read that runs.
  A block, loop, catch clause or switch that declares its own binding of
  a constant now forgets that constant's value, so the read counts.

* fix(vue): report destructured prop defaults vue-jsx-vapor drops (TSRX2029)

vue-jsx-vapor's `defineVaporComponent` macro turns the defaults in a
component's destructured props into prop options, and its
`getTypeAndValue` keeps only a string, number, boolean or null literal,
an identifier, an object or array literal, or a function (seen through
`as` and `!`). Any other default, such as `cfg.size`, `-1`, `SIZE + 1`,
a call or a template literal, becomes `props: { s: null }`, so the prop
is undefined when the caller leaves it out. That already broke wrapped
components on main, and #1125 extends wrapping to shapes whose defaults
worked as plain functions.

Report TSRX2029 at each such default in every wrapped component, with a
suggestion to read the prop in the body (`const s = props.s ?? cfg.size`).
The code is in the error table and the specification.

Also document that a call in the skipped statements to a function that
assigns a binding a default reads is not followed by the move check.

* fix(vue): count enums, namespaces and wrapped mutations before moving a component

Bugbot review fixes for TSRX2028's move check:

- An enum, a namespace or an `import x = …` alias declared between the
  early read and the component compiles to a binding set when it runs,
  but wasn't counted, so a prop default reading it (`{ size = Size }`)
  moved above it and captured `undefined`. Ambient and type-only ones
  have no code and still don't count.
- Mutations were found only through plain member chains, so
  `(cfg as any).size = 2`, `cfg!.size = 2`, `[cfg.size] = [2]`,
  `delete cfg.size` and `(cfg?.nested).size = 2` let the component move
  above them. Assignment targets are now followed through patterns,
  parentheses, optional chains and TypeScript wrappers, and `delete`
  counts as a mutation.
- A namespace's own `var`s were read as module bindings, so a default
  reading an outer name the namespace shadows reported TSRX2028.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main added TSRX2028, TSRX2029 and TSRX2031 next to this branch's TSRX2027, so diagnostics.js and the spec's code list keep all four in numeric order. In features.tsrx the new @for head paragraph sits before main's reformatted loop paragraph, written with main's {' '} spacing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
@jonkwheeler
jonkwheeler merged commit 33022ba into tsrx-org:main Nov 12, 2026
8 checks passed
jonkwheeler added a commit to jonkwheeler/tsrx that referenced this pull request Nov 12, 2026
The Vue transform's import list keeps main's new ERROR_BOUNDARY_INTERNAL_NAME (tsrx-org#1175) and drops DIAGNOSTIC_CODES, which this PR leaves unused there. In for_of_statement_to_jsx_child, main's validate_for_of_head call (tsrx-org#1133) runs first, then this PR's check that skips an `@for await` the target already reported. The JSX transform imports find_first_top_level_await again beside this PR's find_top_level_awaits: this PR had dropped it, and main's tsrx-org#1133 calls it for an awaited `@for` head default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler added a commit to jonkwheeler/tsrx that referenced this pull request Nov 12, 2026
On main, tsrx-org#1133's @for head paragraph in features.tsrx was reformatted with {' '} spacing, and the spec's code list gained TSRX2028, TSRX2029 and TSRX2031 after TSRX2027. The paragraph takes this branch's const/let and var wording in main's spacing, and the TSRX2027 entry takes this branch's three lines ahead of main's new codes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler added a commit to jonkwheeler/tsrx that referenced this pull request Nov 12, 2026
…ent await walk

Two of main's shared tests failed on Solid, Vue and Hono DOM once this PR counted `await using` as an `await` in a component body.

- `reports an @for head that declares its item with using (tsrx-org#453)` (tsrx-org#1133) expects `@for (await using item of items)` to give TSRX2027 (FOR_HEAD_USING) alone. The walk also reported the head's declaration as TSRX2021, two errors on one token. It now skips a template `@for` head that declares its item with `using` or `await using`, which TSRX2027 already reports. A plain `for (await using x of xs)` still counts.
- `maps the keyword of a declaration and the brackets of a binding pattern (tsrx-org#1062)` (tsrx-org#1170) compiles a component with `await using h = null;` and expected no errors on every target. On a target whose components can't be async, this PR reports that `await using` as TSRX2021 on purpose, as its own tests show. The test now expects that one error there and none elsewhere, and its mapping checks are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler added a commit that referenced this pull request Nov 12, 2026
…mponents can't be async (#1220)

* fix(core): report every await in a component body on targets whose components can't be async

Solid, Vue and Hono DOM report each component `await` as TSRX2021, but
the finder that hands them to the target skipped four positions, so
these compiled to an async component with no error:

- an attribute of the root element: for a returned template it walked
  the element's children only;
- an `if` test, and a `switch` discriminant or case test: it walked the
  branches and case bodies only (a `catch` parameter default was missed
  the same way);
- `await using`: `is_await_node` matched only an `AwaitExpression` and
  `for await`, and an `await using` declaration holds neither.

With those parts walked, every branch of the per-statement dispatch
walked the whole statement, so `find_native_awaits` is now one walk of
the body. The walk visits an element's children before its attributes,
so the awaits are sorted by position to keep the errors in source order
and strict mode throwing at the first. `is_await_node` counts an
`await using` declaration, which also lets Hono DOM's async-component
check, in collect mode, leave such a component to the `await` error.

React, Preact and Hono server have no `validateComponentAwait` hook and
don't set `requireUseServerForAwait`, so their output and diagnostics
are unchanged.

Fixes #1201

* fix(core): make a generated callback holding an await using async

On React, Preact and Hono server, an `await using` in an `@for` body,
or in an `@if` or `@switch` body with setup statements, stayed in a
synchronous generated callback, so TypeScript reported TS2852 on the
output. `suspend_generated_closures` looked for an `AwaitExpression` or
`for await` only.

It now counts an `await using` declaration too, so the callback becomes
async and is awaited, as for an `await` there (#145). In an `@catch`
body, whose callback the target calls itself, it is reported as
TARGET_AWAIT_UNSUPPORTED, as an `await` is. On Solid, Vue and Hono DOM
the component error from the previous commit is still the only one.

Related: #1201

* fix(core): leave an @for head's await using to TSRX2027 in the component await walk

Two of main's shared tests failed on Solid, Vue and Hono DOM once this PR counted `await using` as an `await` in a component body.

- `reports an @for head that declares its item with using (#453)` (#1133) expects `@for (await using item of items)` to give TSRX2027 (FOR_HEAD_USING) alone. The walk also reported the head's declaration as TSRX2021, two errors on one token. It now skips a template `@for` head that declares its item with `using` or `await using`, which TSRX2027 already reports. A plain `for (await using x of xs)` still counts.
- `maps the keyword of a declaration and the brackets of a binding pattern (#1062)` (#1170) compiles a component with `await using h = null;` and expected no errors on every target. On a target whose components can't be async, this PR reports that `await using` as TSRX2021 on purpose, as its own tests show. The test now expects that one error there and none elsewhere, and its mapping checks are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler added a commit that referenced this pull request Nov 14, 2026
… the index (#1342)

* fix(core): give an @for body its own scope and let head defaults read the index

Every target lowers an `@for` to a callback whose parameters are the
head's item pattern and its index, with the body's statements directly in
the callback's body. Parameters and a body's top-level declarations share
one scope, so a body that declared the item's or the index's name again, as
a `for...of` body may, compiled to a duplicate declaration on React,
Preact, Hono, Solid and Vue (#1325). And the index parameter comes after the
pattern, so a default in the pattern that read the index threw "Cannot
access 'i' before initialization" when a row needed it (#1312).

The shared lowering now runs a body that declares a head name in a block of
its own. A key the head gives, `key id` or the index an index loop is keyed
by, is read into a generated `_$_key` before that block when it reads a
name the body declares, so React still keys each row by the head's name.
A pattern whose default or computed key reads the index is destructured as
the callback's first statement, as an awaited default already was (#1133).

Solid wraps the body the same way. A keyed Solid loop whose pattern reads
the index goes through `__for_keyed_rows`, whose key callback gets the index
number, and the child callback's memo reads the index accessor as `i()`, so
the default sees the number there too. Vue's `VaporFor` `getKey` callback
destructures such a pattern after the index, and a body that can skip a row
falls back to the shared lowering for it.

A shared runtime suite renders every case on React, Preact, Solid, Vue and
Hono (DOM), and the virtual code of every target is checked for TS2300,
TS2373, TS2448 and TS2451.

Fixes #1325
Fixes #1312

* fix(solid,vue): keep the head's declaration kind and an assignable index in key callbacks

Follow-up to Codex's review of the previous commit:

- The key callbacks that destructure the item after the index (Solid's
  `__for_keyed_rows` callback and Vue's `getKey`) declared the pattern
  with `const`, so `@for (let [a = 'r' + i, b] of rows; index i; key (a += b))`
  threw on assignment and the editor reported TS2588. They now use the
  head's own declaration kind, as the shared lowering does.
- A keyed Solid loop rewrote each read of the index in the item's pattern
  to the accessor call `i()`, so a default that writes the index
  (`[a = 'r' + i++]`) became `i()++`, which doesn't parse. The memo now
  reads the index into a `let` of its name, so the pattern reads, and can
  assign, the number as the callback parameter it is on the other
  targets. The type view, which has no memo, still reads it as `i()`.

* test(core,vue): pin the index a key callback reads when a head default reads it

Cursor Bugbot read Vue's `getKey` as destructuring a pattern that the keyed
slot had already rewritten to `i.value`. It doesn't: the slot rewrites a
copy, and `getKey` reads the index `VaporFor` passes it as a number. A Vue
compile test now pins both shapes (and fails if `getKey` reads `i.value`),
and the shared runtime suite renders a loop whose key reads a default that
reads the index, on every target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler added a commit to jonkwheeler/tsrx that referenced this pull request Nov 20, 2026
Selector lists that compiled before, often to CSS that styled the
component's own elements but also matched outside it, now fail with
TSRX3011, so this is a language removal: `minor`, with a migration line,
as tsrx-org#1223 and tsrx-org#1133 did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler added a commit that referenced this pull request Nov 20, 2026
…ck (#1424)

* fix(core): bare :global selector lists and modifiers in a :global block

A selector that starts with a bare `:global` makes its rule a global block:
the output scopes nothing in it. Two cases compiled to the wrong CSS.

A selector list with such a selector beside one that needs scoping lost
that scoping (`:global .w, .z` compiled to `.w, .z`), or, when the first
selector was a lone compound such as `.z`, the rule was read as a
`:global { ... }` block and its selector commented out, so its declarations
landed in the parent rule (`.p { .z,:global.w { color: red; } }` turned `.p`
red). A lone `:global` in a longer list did the same, or left an empty
selector (`:global.w,:global` gave `.w,`). Report these as TSRX3011
(CSS_GLOBAL_PLACEMENT), as Svelte does with css_global_block_invalid_list,
but only where scoping would be lost: outside another global block, when a
selector that doesn't start with a bare `:global`, or a rule nested in the
rule, would get a hash on its own. `:global.w, :global(.a)` and
`.p { :global .a, &.b { ... } }` still compile. The lone block check now
needs the rule's only selector to be the lone `:global`, so
`:global(.a), :global.w` compiles to `.a, .w` instead of losing its selector.

A `:global.x` modifier nested in a `:global { ... }` block got an `&`
although the block is dropped, so `:global { :global.w { ... } }` gave a
top-level `&.w`, which matches the root element. The `&` now goes in only
when a rule the output keeps is around it.

* fix(core): report a bare :global list only where its CSS was wrong

Review of the first commit found the new TSRX3011 errors also on lists that
compiled to the right CSS, and two outputs that turned invalid.

- A compound after a bare `:global` later in a selector is unscoped in a
  component (`:root :global .x` gives `:root .x`), so it no longer counts as
  needing a hash; the arguments of its `:is()`, `:where()` and `:has()`
  still do. `:global .note, :root :global .x` compiles to
  `.note, :root .x` again. (An assigned theme hashes such a compound; that is
  a separate bug.)
- A `:not()` argument without the hash only makes it match fewer elements,
  so `.p { :global.x, &:not(.z) }` compiles whatever the markup.
- A lone `:global` in a list inside a rule stands for that rule:
  `.card { :global.open, :global { ... } }` gives `&.open, &`, as the two
  rules do apart. It is reported only outside a rule, and only when the rule
  has declarations (`:global, .card {}` is empty either way). Outside a rule
  the output drops the selector, as for `:global { ... }`, instead of leaving
  an empty one.
- The `&` before a `:global` whose parent rules are all dropped `:global {}`
  blocks stays when the selector would otherwise start with a combinator:
  `:global { :global > .w {} }` gives `& > .w` again, not `> .w`.
- A global block that holds only at-rules a style rule can't hold drops its
  selector, so `:root, :global.w { @Keyframes -global-k {} }` gives a valid
  top-level `@keyframes k`, as on main, and the declarations in such an
  at-rule (`@font-face`) don't count as the rule's.

The lone-block, dropped-selector and parent-rule helpers move to
css-analyze.js, which the stylesheet transform now imports.

* fix(core): keep a dropped :global selector's CSS valid

Two outputs the first review fix left invalid, which main got valid by
accident when it dropped the whole selector:

- A bare `:global` followed by a combinator (`:global > .w`) with no rule
  around it for an `&` printed `> .w`, which is invalid. Keep the `&` there,
  as for a dropped `:global { ... }` parent: `& > .w`, the root's children.
  This also fixes a top-level `:global > .w { ... }`, invalid on main.
- A comment in a selector the output drops (`:global /* c */ { ... }`) ended
  the comment the output puts around the selector, so the rest of the
  selector and the stylesheet were read as CSS. Escape the comment's end
  there, as for an unused rule.

* fix(core): close the gaps Codex found in the :global list check

- A `:not()` within a `:not()` argument makes its hashes count again:
  leaving them out there widens the outer `:not()`, so
  `:global.w, :root:not(:root:not(.x))` is reported.
- The `&` of a compound in a rule whose element has the hash already makes a
  single compound in its `:where()` need no hash of its own, as `:where()`
  adds no specificity: `.p { :global.w, &:where(.p) }` compiles, as on main.
  `:is()` keeps the check, since its hash adds specificity.
- A global block that styles nothing drops its selector when it holds an
  at-rule a style rule can't hold anywhere through a `@media` or another
  group rule, or beside an empty rule, so
  `.card, :global.w { @media print { @font-face {} } }` stays valid.
- Whether a rule's selector is dropped is cached per rule: it asks the same
  of each rule around it, which took exponential time in lists of lone
  `:global`s nested many deep.
- Every `*/` in a rule or selector the output comments out is escaped, a
  string's included, so `:global[data-x="*/"] { ... }` and an unused rule
  with `content: "*/"` stay inside their comment.
- The `&` before a dropped lone `:global` looks past further lone bare
  `:global`s for a combinator: `:global { :global :global > .w {} }` gives
  `& > .w`.

* fix(core): settle the last :global list check mismatches Codex found

- A `:global(...)` compound keeps its arguments as written, so it counts as
  unscoped before the compounds after a bare `:global` are checked, and in a
  `:not()` argument too: `:root :global :global(.x):has(.a)` and
  `:root:not(:global(.x):not(.a))` compile, as on main.
- The `:where()` exemption for an `&` whose element has the hash doesn't
  apply in a `@scope`, where `&` stands for the scope's root.
- Whether a rule's element has the hash is cached per rule, like whether
  its selector is dropped: it asks the same of the rule around it, which was
  exponential in deep `&, &` nests.
- Only at-rules that hold descriptors (`@keyframes`, `@font-face`,
  `@property` and the like) count as ones a style rule can't hold, so a
  conditional rule the list doesn't name, such as `@when`, keeps its rule.
- An at-rule a style rule can't hold, in a rule inside the global block
  whose selector the output drops, makes the global block drop its selector
  too, so a `@font-face` two lists deep stays valid, as on main.

* fix(core): no cycle or @scope overreach in the :global list check

- A rule in a global block can ask whether the block drops its selector
  while the block asks the same of it (`:global.w { :global, :global.x {} }`
  overflowed the stack); the inner question now reads the block as kept.
- The `:where()` exemption is off only for a rule directly in a `@scope`,
  where `&` stands for the scope's root, not for one with a rule between:
  `@scope (.q) { .p { :global.w, &:where(.p) {} } }` compiles, as on main.
- `@function`, `@custom-media` and `@custom-selector` count as at-rules a
  style rule can't hold.

* fix(core): answer Bugbot's two findings on the :global list check

- The `:where()` exemption for an `&` whose element has the hash applies
  only to a compound with no combinator: `&:where(> .q)` points at a child,
  which would get the hash on its own, so `.p { :global.w, &:where(> .q) }`
  is reported.
- Whether a global block drops its selector because of the at-rules in it
  now asks only about the rules in it, never about the rules around it. The
  stopgap that read a block as kept while deciding it could cache a wrong
  answer for a lone `:global` list in it, which then lost its `&` when the
  block dropped its selector after all:
  `:global.w { :global, :global.x { .k {} } @font-face {} }` printed
  `, .x { ... }`.

* chore(changeset): release the :global list check as minor

Selector lists that compiled before, often to CSS that styled the
component's own elements but also matched outside it, now fail with
TSRX3011, so this is a language removal: `minor`, with a migration line,
as #1223 and #1133 did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant