feat: parse template expressions as TypeScript #48

Merged
corneliusio merged 1 commit from feat/ts-template-expressions into master 2026-08-21 16:14:12 +00:00
corneliusio commented 2026-08-15 07:22:17 +00:00 (Migrated from github.com)

Svelte permits TypeScript in template expressions when the component uses TS. Sublime syntaxes cannot switch template parsing based on the script tag's lang attribute (context state does not persist across the file), so the expression embedding now extends TypeScript.sublime-syntax instead of JavaScript. TS is a superset and the default TS package hard-codes .js scopes for shared constructs, so plain-JS expressions scope identically and the source.js.embedded.svelte contract is unchanged — verified by the existing test suite passing untouched.

TypeScript would consume an each block's as keyword as a type assertion, so each-block source expressions go through a dedicated context that treats only the last as before the closing brace as the block's own (matching the Svelte parser, which accepts {#each items as Item[] as item} and binds item). Parenthesized assertions also work: {#each (items as Item[]) as item}.

Addresses finding 1 of the syntax audit. Includes a review fix from gpt-5.6: unparenthesized top-level assertions in each sources keep their assertion meaning.

New tests cover typed arrow params, as casts, generic calls, and both each-assertion forms, passing on ST builds 4143 and latest.

Svelte permits TypeScript in template expressions when the component uses TS. Sublime syntaxes cannot switch template parsing based on the script tag's `lang` attribute (context state does not persist across the file), so the expression embedding now extends `TypeScript.sublime-syntax` instead of JavaScript. TS is a superset and the default TS package hard-codes `.js` scopes for shared constructs, so plain-JS expressions scope identically and the `source.js.embedded.svelte` contract is unchanged — verified by the existing test suite passing untouched. TypeScript would consume an each block's `as` keyword as a type assertion, so each-block source expressions go through a dedicated context that treats only the last `as` before the closing brace as the block's own (matching the Svelte parser, which accepts `{#each items as Item[] as item}` and binds `item`). Parenthesized assertions also work: `{#each (items as Item[]) as item}`. Addresses finding 1 of the syntax audit. Includes a review fix from gpt-5.6: unparenthesized top-level assertions in each sources keep their assertion meaning. New tests cover typed arrow params, `as` casts, generic calls, and both each-assertion forms, passing on ST builds 4143 and latest.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
repos/svelte-sublime!48
No description provided.