Skip to content

Claim @for inspection origins for __map_iterable_async (@tsrx/core 0.3) #1292

Closed

Description

@leonidaz

Summary

compileTypesInspection claims each @for keyword by matching the generated text __map_iterable. With @tsrx/core 0.3.0 (tsrx-org/tsrx#212), a @for body that contains an await lowers to __map_iterable_async instead. The keyword claim no longer matches, and the @for keyword's segment falls back to the whole loop block.

This affects only the inspection segments from compileTypesInspection. compileToVolarMappings doesn't pass inspect, and the runtime compiler never uses these names.

Details

compileTypesInspection compiles with inspect: true (volar.js#L825). With that flag, core anchors the @for keyword's source span on the helper identifier the loop lowers to. collectDirectiveOrigins then claims the keyword only when the generated text is one of DIRECTIVE_GENERATED_NAMES.JSXForExpression, which is ['__map_iterable'] (volar.js#L657). buildFatSegments compares that text exactly (claim.texts.has(code.slice(from, to).trim())).

With core 0.3.0 and Octane's platform descriptor, the source map anchors @for on these generated tokens:

@for body Generated token at the @for anchor
<li>{item}</li> __map_iterable
<li>{await Promise.resolve(item)}</li> in an async function __map_iterable_async

So for the second loop, the keyword resolves to the smallest node starting at @for, which is the whole @for … { … } block, instead of its four characters.

Only code in async functions reaches this, and Octane already rejects that at build time. The fix is still one entry.

Change

  • Add '__map_iterable_async' to DIRECTIVE_GENERATED_NAMES.JSXForExpression, and mention it in the comment above.
  • Add a compileTypesInspection test (it's already used in tests/compiler/volar.test.ts) with an async function whose @for body contains an await, and assert that the @for segment covers only the keyword.

This belongs with the upcoming upgrade to tsrx 0.3, together with the octane/tsrx-iterable re-export.

Checked by compiling both loops with core's createJsxTransform from tsrx main and decoding the source map at the @for offset. Octane's buildFatSegments wasn't run against core 0.3.0.

Activity

  1. added
    agent-authored
    on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-authoredtooling

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions