File tree Expand file tree Collapse file tree 6 files changed +62
-2
lines changed Expand file tree Collapse file tree 6 files changed +62
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ feat: add Snippet type
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import * as acorn from 'acorn';
2
2
import { walk } from 'zimmerframe' ;
3
3
import { tsPlugin } from 'acorn-typescript' ;
4
4
5
- // @ts -expect-error
6
5
const ParserWithTS = acorn . Parser . extend ( tsPlugin ( ) ) ;
7
6
8
7
/**
Original file line number Diff line number Diff line change
1
+ // Silence the acorn typescript errors through this ambient type definition + tsconfig.json path alias
2
+ // That way we can omit `"skipLibCheck": true` and catch other errors in our d.ts files
3
+ declare module 'acorn-typescript' ;
Original file line number Diff line number Diff line change @@ -185,6 +185,19 @@ export type ComponentType<Comp extends SvelteComponent> = (new (
185
185
element ?: typeof HTMLElement ;
186
186
} ;
187
187
188
+ declare const SnippetReturn : unique symbol ;
189
+
190
+ /**
191
+ * The type of a `#snippet` block. You can use it to (for example) express that your component expects a snippet of a certain type:
192
+ * ```ts
193
+ * let { banner } = $props<{ banner: Snippet<{ text: string }> }>();
194
+ * ```
195
+ * You can only call a snippet through the `{@render ...}` tag.
196
+ */
197
+ export interface Snippet < T = void > {
198
+ ( arg : T ) : typeof SnippetReturn ;
199
+ }
200
+
188
201
interface DispatchOptions {
189
202
cancelable ?: boolean ;
190
203
}
Original file line number Diff line number Diff line change
1
+ import type { Snippet } from 'svelte' ;
2
+
3
+ const return_type : ReturnType < Snippet > = null as any ;
4
+
5
+ // @ts -expect-error
6
+ const a : Snippet < { text : string } > = ( ) => { } ;
7
+ // @ts -expect-error
8
+ const b : Snippet < boolean > = ( a , b ) => {
9
+ return return_type ;
10
+ } ;
11
+ // @ts -expect-error
12
+ const c : Snippet < boolean > = ( a : string ) => {
13
+ return return_type ;
14
+ } ;
15
+ // @ts -expect-error
16
+ const d : Snippet < boolean > = ( a : string , b : number ) => {
17
+ return return_type ;
18
+ } ;
19
+ // @ts -expect-error
20
+ const e : Snippet = ( a : string ) => {
21
+ return return_type ;
22
+ } ;
23
+ const f : Snippet = ( a ) => {
24
+ // @ts -expect-error
25
+ a ?. x ;
26
+ return return_type ;
27
+ } ;
28
+ const g : Snippet < boolean > = ( a ) => {
29
+ // @ts -expect-error
30
+ a === '' ;
31
+ a === true ;
32
+ return return_type ;
33
+ } ;
34
+ const h : Snippet < { a : true } > = ( a ) => {
35
+ a . a === true ;
36
+ return return_type ;
37
+ } ;
38
+ const i : Snippet = ( ) => {
39
+ return return_type ;
40
+ } ;
Original file line number Diff line number Diff line change 10
10
"noErrorTruncation" : true ,
11
11
"allowSyntheticDefaultImports" : true ,
12
12
"verbatimModuleSyntax" : true ,
13
- "skipLibCheck" : true ,
14
13
"types" : [" node" ],
15
14
"strict" : true ,
16
15
"allowJs" : true ,
17
16
"checkJs" : true ,
18
17
"paths" : {
18
+ "acorn-typescript" : [" ./src/compiler/phases/1-parse/ambient.d.ts" ],
19
19
"svelte" : [" ./src/main/public.d.ts" ],
20
20
"svelte/action" : [" ./src/action/public.d.ts" ],
21
21
"svelte/compiler" : [" ./src/compiler/public.d.ts" ],
You can’t perform that action at this time.
0 commit comments