Description
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'toDIRECTIVE_GENERATED_NAMES.JSXForExpression, and mention it in the comment above. - Add a
compileTypesInspectiontest (it's already used intests/compiler/volar.test.ts) with an async function whose@forbody contains anawait, and assert that the@forsegment 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
fix: update the TSRX toolchain to @tsrx/core 0.3.2 (#1294)