lexer_svelte.ts

Svelte lexer — the shared markup scanner (lexer_markup.ts) in svelte mode plus the {…} expression lexer.

Emits markup's tag/attr/comment/entity structure (no special_attr — svelte handles style=/on*= as ordinary attributes; js-style line and block comments between attributes emit comment leaves), script+lang_ts and style+lang_css regions (svelte scripts are always TypeScript), and svelte_expression containers whose forms nest a same-span block ({#if}/{:else if}/{/each}/…), each ({#each list as item}), at_directive ({@render}/{@const}/…), or declaration_tag ({const …}/{let …}) container with special_keyword/at_keyword/ keyword leaves and lang_ts interiors.

Notable behavior: an expression's closing brace is the one the ts lexer reaches as it tokenizes the interior, so braces nest to any depth and those in strings, templates, comments, and regexes don't count ({'}'} works). {#each} and {#await} split at the as/then ts stops at the same way. Two forms find the brace before lexing instead, by a scan that knows strings, templates, and comments but not regexes: a plain expression that starts with /, and an unknown sigil word; expression-valued attributes emit full structure (attr_name + attr_value with attr_equals, not the = swallowed into the name); quoted values interleave text and expressions (class="a {b} c"); the {#each} expression before as is lexed as ts; the closing } is always expression punctuation; as/then are keywords only in the each/await forms that define them, not anywhere they appear; directive modifiers (transition:fade|global) get punctuation pipes.

Resilience: an unterminated expression extends to the end of the window.

view source

Declarations
#

lexer_svelte
#

lexer_svelte.ts view source

SyntaxLang import {lexer_svelte} from '@fuzdev/fuz_code/lexer_svelte.js';

The Svelte language registration for the lexer engine.

Depends on
#

Imported by
#