@@ -21,6 +21,10 @@ export function SnippetBlock(node, context) {
2121 /** @type {Statement[] } */
2222 const declarations = [ ] ;
2323
24+ if ( dev ) {
25+ declarations . push ( b . stmt ( b . call ( '$.validate_snippet_args' , b . spread ( b . id ( 'arguments' ) ) ) ) ) ;
26+ }
27+
2428 const transform = { ...context . state . transform } ;
2529 const child_state = { ...context . state , transform } ;
2630
@@ -71,33 +75,15 @@ export function SnippetBlock(node, context) {
7175 }
7276 }
7377 }
74- if ( dev ) {
75- const [ anchor , ...validations_args ] = args ;
76- declarations . unshift (
77- b . stmt (
78- b . call (
79- '$.validate_snippet_args' ,
80- .../** @type {Identifier[] } */ (
81- [ anchor , b . array ( fallback_arr . map ( ( i ) => b . literal ( i ) ) ) , ...validations_args ] . map (
82- ( arg ) =>
83- arg ?. type === 'Identifier' || arg . type === 'ArrayExpression' ? arg : arg ?. left
84- )
85- )
86- )
87- )
88- ) ;
89- }
9078 body = b . block ( [
9179 ...declarations ,
9280 .../** @type {BlockStatement } */ ( context . visit ( node . body , child_state ) ) . body
9381 ] ) ;
9482
95- /** @type {Expression } */
96- let snippet = b . arrow ( args , body ) ;
97-
98- if ( dev ) {
99- snippet = b . call ( '$.wrap_snippet' , b . id ( context . state . analysis . name ) , snippet ) ;
100- }
83+ // in dev we use a FunctionExpression (not arrow function) so we can use `arguments`
84+ let snippet = dev
85+ ? b . call ( '$.wrap_snippet' , b . id ( context . state . analysis . name ) , b . function ( null , args , body ) )
86+ : b . arrow ( args , body ) ;
10187
10288 const declaration = b . const ( node . expression , snippet ) ;
10389
0 commit comments