1
- /** @import { ArrowFunctionExpression, BlockStatement, CallExpression } from 'estree' */
1
+ /** @import { BlockStatement } from 'estree' */
2
2
/** @import { AST } from '#compiler' */
3
3
/** @import { ComponentContext } from '../types.js' */
4
4
import { dev } from '../../../../state.js' ;
@@ -9,27 +9,21 @@ import * as b from '#compiler/builders';
9
9
* @param {ComponentContext } context
10
10
*/
11
11
export function SnippetBlock ( node , context ) {
12
- const body = /** @type {BlockStatement } */ ( context . visit ( node . body ) ) ;
12
+ let fn = b . function_declaration (
13
+ node . expression ,
14
+ [ b . id ( '$$payload' ) , ...node . parameters ] ,
15
+ /** @type {BlockStatement } */ ( context . visit ( node . body ) )
16
+ ) ;
13
17
14
- if ( dev ) {
15
- body . body . unshift ( b . stmt ( b . call ( '$.validate_snippet_args' , b . id ( '$$payload' ) ) ) ) ;
16
- }
18
+ // @ts -expect-error - TODO remove this hack once $$render_inner for legacy bindings is gone
19
+ fn . ___snippet = true ;
17
20
18
- /** @type {ArrowFunctionExpression | CallExpression } */
19
- let fn = b . arrow ( [ b . id ( '$$payload' ) , ...node . parameters ] , body ) ;
21
+ const statements = node . metadata . can_hoist ? context . state . hoisted : context . state . init ;
20
22
21
23
if ( dev ) {
22
- fn = b . call ( '$.prevent_snippet_stringification' , fn ) ;
24
+ fn . body . body . unshift ( b . stmt ( b . call ( '$.validate_snippet_args' , b . id ( '$$payload' ) ) ) ) ;
25
+ statements . push ( b . stmt ( b . call ( '$.prevent_snippet_stringification' , fn . id ) ) ) ;
23
26
}
24
27
25
- const declaration = b . declaration ( 'const' , [ b . declarator ( node . expression , fn ) ] ) ;
26
-
27
- // @ts -expect-error - TODO remove this hack once $$render_inner for legacy bindings is gone
28
- fn . ___snippet = true ;
29
-
30
- if ( node . metadata . can_hoist ) {
31
- context . state . hoisted . push ( declaration ) ;
32
- } else {
33
- context . state . init . push ( declaration ) ;
34
- }
28
+ statements . push ( fn ) ;
35
29
}
0 commit comments