feat: parse template expressions as TypeScript #48
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
repos/svelte-sublime!48
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/ts-template-expressions"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Svelte permits TypeScript in template expressions when the component uses TS. Sublime syntaxes cannot switch template parsing based on the script tag's
langattribute (context state does not persist across the file), so the expression embedding now extendsTypeScript.sublime-syntaxinstead of JavaScript. TS is a superset and the default TS package hard-codes.jsscopes for shared constructs, so plain-JS expressions scope identically and thesource.js.embedded.sveltecontract is unchanged — verified by the existing test suite passing untouched.TypeScript would consume an each block's
askeyword as a type assertion, so each-block source expressions go through a dedicated context that treats only the lastasbefore the closing brace as the block's own (matching the Svelte parser, which accepts{#each items as Item[] as item}and bindsitem). 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,
ascasts, generic calls, and both each-assertion forms, passing on ST builds 4143 and latest.