feat: support modern Svelte 5 syntax #51
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!51
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/modern-svelte-syntax"
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?
Closes the remaining Svelte 5 gaps in the grammar. Each item mirrors the compiler's parser rather than the docs prose where the two differ.
//and/* */in attribute position (elements and components) are scopedcomment.line.double-slash.svelte/comment.block.svelte, exactly where Svelte'sread_attributereads them. Unquoted values (href=//host) and/>are untouched; a stray//>deliberately does not start a comment so it can't swallow the tag end.<Foo.Bar.Baz>,<foo.bar.baz>,<Foo.$bar.Baz>are components; each./:ispunctuation.accessor.svelte. Name classes followregex_valid_component_name($allowed, member segments may start with digits).onand whose value is a single expression (={…},="{…}",='{…}') isentity.other.attribute-name.event.svelte, styled like theon:clickdirective and wrapped inmeta.attribute-with-value.event.htmlso selectors for HTML events still match. This is the compiler'sis_event_attributecontract: names are case sensitive,on={x}/on-click={x}/once={x}count, and string values (onclick="alert(1)",onlabel="{a} b") stay ordinary attributes.$state,$state.raw|snapshot|eager,$derived(.by),$effect(.pre|tracking|root|pending),$props(.id),$bindable,$inspect(.trace),$hostaresupport.function.rune.sveltein template expressions and in<script>/<script lang="ts">. Script contents now embed two package-owned hidden syntaxes (source.js.script.svelte,source.ts.script.svelte) that extend the stock JS/TS syntaxes; the embed scope stayssource.js|ts.embedded.html, so third-party scope selectors, comment toggling and symbol indexing are unaffected. The TS side also gains the CDATA branch the JS side already had.{#each expr}and{#each expr, index}; the source expression stops at a top-level comma.{#each rows as row: Row},as { id }: Row,{:then value: Value},{:catch { message }: Err}reuse the TSts-type-annotationcontext.{:then}/{:catch}now go through the binding context like the inlinethen/catchforms.asdetection is rewritten: the block's ownasis the last top-levelas(one not followed by anotherasoutside brackets). That is what the compiler does — acorn-typescript parses greedily and Svelte hands the trailingTSAsExpressionback — and it fixes{#each items as item (item.id as string)}while keeping{#each items as Item[] as item}andas { a: { b: string } } as item. Limits (two bracket levels, single line) are documented in the variable's comment.Tests add ~450 assertions: the above plus
classarrays/objects,<svelte:boundary>withfailed/pendingsnippets andonerror, markupawait,bind:on elements and components,<script module>, CDATA in JS and TS scripts, and negative cases for the comment and event rules. Suite passes locally on builds 4143 and latest via the syntax-test binary; reviewed by Codex (two rounds) and an independent Claude pass, with every finding either fixed or documented as an engine limit.