@@ -21,6 +21,10 @@ export function SnippetBlock(node, context) {
21
21
/** @type {Statement[] } */
22
22
const declarations = [ ] ;
23
23
24
+ if ( dev ) {
25
+ declarations . push ( b . stmt ( b . call ( '$.validate_snippet_args' , b . spread ( b . id ( 'arguments' ) ) ) ) ) ;
26
+ }
27
+
24
28
const transform = { ...context . state . transform } ;
25
29
const child_state = { ...context . state , transform } ;
26
30
@@ -71,33 +75,15 @@ export function SnippetBlock(node, context) {
71
75
}
72
76
}
73
77
}
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
- }
90
78
body = b . block ( [
91
79
...declarations ,
92
80
.../** @type {BlockStatement } */ ( context . visit ( node . body , child_state ) ) . body
93
81
] ) ;
94
82
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 ) ;
101
87
102
88
const declaration = b . const ( node . expression , snippet ) ;
103
89
0 commit comments