Skip to content

feat: add Svelte language support#210

Open
yilanboy wants to merge 3 commits into
tempestphp:mainfrom
yilanboy:add-svelte-language-support
Open

feat: add Svelte language support#210
yilanboy wants to merge 3 commits into
tempestphp:mainfrom
yilanboy:add-svelte-language-support

Conversation

@yilanboy
Copy link
Copy Markdown
Contributor

This PR adds a Svelte language support that extends HTML and injects TypeScript.

It also includes two small JS/TS pattern changes that are technically out of scope, but were required for Svelte (and TypeScript in general) to highlight correctly. They are scoped narrowly and covered by tests.

What's in the PR

Svelte 5 language (in scope)

  • Support Runes like $state(), $derived, $effect, etc.
  • Support expression like {expression}.
  • Support block keyword like {#if}, {:else}, {/each}, {@const}, etc.
  • Support directives like bind:value.

Out-of-scope but necessary

  • JsMethodPattern allows $: Required for Svelte 5 runes ($state(), $derived(), $effect(), …). Also correct for plain JS ($()).
// before
return '(?<match>[\w]+)\(';
// after
return '(?<match>[\w\$]+)\(';
  • New TsMethodPattern: matches name<Generics>( so createList<Todo[]>(initial) highlights the method name. The existing TsGenericPattern was consuming <…> first and leaving the method name unstyled.
// make 'createList' can be render as a function, even it is in front of the generic syntax
createList<Todo[]>(initial)

- update JS method pattern, including '$'
- update TS method pattern, make it can catch method with generics
- add Svelte language patterns and tests
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 16, 2026

Benchmark Results

Comparison of add-svelte-language-support against main (fe0107137025b90260aee80128cc4e46071541ff).

Open to see the benchmark results
benchmark subject set revs its mem_peak mode rstdev
HighlighterBench benchParse apache 100 5 2.045mb +0.26% 72.694305μs +0.03% ±0.41% -56.45%
HighlighterBench benchParse bash 100 5 2.077mb +0.26% 206.412192μs +0.10% ±0.75% +169.43%
HighlighterBench benchParse bbcode 100 5 2.041mb 0.00% 74.277965μs +0.13% ±0.33% -55.56%
HighlighterBench benchParse blade 100 5 2.649mb +2.70% 1,090.161996μs +0.25% ±1.08% +31.51%
HighlighterBench benchParse css 100 5 2.063mb +0.26% 139.495010μs +0.25% ±0.55% -62.58%
HighlighterBench benchParse diff 100 5 2.043mb 0.00% 26.936732μs +0.66% ±0.74% +6.96%
HighlighterBench benchParse dockerfile 100 5 2.045mb +0.26% 88.669178μs +0.54% ±0.87% -1.68%
HighlighterBench benchParse dotenv 100 5 2.049mb +0.26% 77.057397μs -0.69% ±0.64% -5.93%
HighlighterBench benchParse gdscript 100 5 2.143mb +0.25% 330.076458μs +0.03% ±0.47% +17.80%
HighlighterBench benchParse graphql 100 5 2.064mb +0.26% 150.800685μs -0.35% ±0.43% -41.60%
HighlighterBench benchParse html 100 5 2.067mb +0.26% 116.195890μs +0.04% ±0.53% -2.97%
HighlighterBench benchParse ini 100 5 2.052mb +0.26% 86.178376μs +1.12% ±0.44% -33.94%
HighlighterBench benchParse javascript 100 5 2.131mb +0.28% 270.614110μs -0.36% ±0.38% -50.81%
HighlighterBench benchParse json 100 5 2.106mb +0.25% 236.552642μs +0.20% ±0.34% -44.16%
HighlighterBench benchParse markdown 100 5 2.054mb +0.26% 75.138141μs +0.02% ±1.06% -2.85%
HighlighterBench benchParse nginx 100 5 2.118mb +0.25% 266.195479μs +0.69% ±0.60% +19.14%
HighlighterBench benchParse php 100 5 2.410mb +0.22% 754.486791μs +0.52% ±0.54% -18.32%
HighlighterBench benchParse python 100 5 2.307mb +0.23% 419.350313μs -0.06% ±0.80% +112.12%
HighlighterBench benchParse scss 100 5 2.079mb +0.26% 184.538200μs +1.11% ±0.54% +36.36%
HighlighterBench benchParse sql 100 5 2.079mb +0.26% 157.600685μs +0.28% ±0.61% -39.12%
HighlighterBench benchParse svelte 100 5 ERR 1,060.223679μs +0.00% ±0.85% +0.00%
HighlighterBench benchParse terminal 100 5 2.074mb +0.26% 195.069041μs +0.46% ±0.34% -38.91%
HighlighterBench benchParse terraform 100 5 2.078mb +0.26% 172.979609μs -0.38% ±0.47% +49.10%
HighlighterBench benchParse typescript 100 5 2.500mb +0.35% 248.381996μs +1.47% ±0.45% -60.78%
HighlighterBench benchParse twig 100 5 19.185mb +0.03% 1,458.715695μs +0.51% ±1.54% +12.48%
HighlighterBench benchParse xml 100 5 2.082mb +0.26% 177.034971μs +0.34% ±0.59% +14.15%
HighlighterBench benchParse yaml 100 5 2.139mb +0.25% 316.960235μs -1.42% ±0.61% -31.41%

Generated by phpbench against commit 6bbca79

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant