@@ -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
@@ -30,12 +34,7 @@ export function SnippetBlock(node, context) {
30
34
if ( ! argument ) continue ;
31
35
32
36
if ( argument . type === 'Identifier' ) {
33
- args . push ( {
34
- type : 'AssignmentPattern' ,
35
- left : argument ,
36
- right : b . id ( '$.noop' )
37
- } ) ;
38
-
37
+ args . push ( b . assignment_pattern ( argument , b . id ( '$.noop' ) ) ) ;
39
38
transform [ argument . name ] = { read : b . call } ;
40
39
41
40
continue ;
@@ -66,29 +65,16 @@ export function SnippetBlock(node, context) {
66
65
}
67
66
}
68
67
}
69
- if ( dev ) {
70
- declarations . unshift (
71
- b . stmt (
72
- b . call (
73
- '$.validate_snippet_args' ,
74
- .../** @type {Identifier[] } */ (
75
- args . map ( ( arg ) => ( arg ?. type === 'Identifier' ? arg : arg ?. left ) )
76
- )
77
- )
78
- )
79
- ) ;
80
- }
68
+
81
69
body = b . block ( [
82
70
...declarations ,
83
71
.../** @type {BlockStatement } */ ( context . visit ( node . body , child_state ) ) . body
84
72
] ) ;
85
73
86
- /** @type {Expression } */
87
- let snippet = b . arrow ( args , body ) ;
88
-
89
- if ( dev ) {
90
- snippet = b . call ( '$.wrap_snippet' , b . id ( context . state . analysis . name ) , snippet ) ;
91
- }
74
+ // in dev we use a FunctionExpression (not arrow function) so we can use `arguments`
75
+ let snippet = dev
76
+ ? b . call ( '$.wrap_snippet' , b . id ( context . state . analysis . name ) , b . function ( null , args , body ) )
77
+ : b . arrow ( args , body ) ;
92
78
93
79
const declaration = b . const ( node . expression , snippet ) ;
94
80
0 commit comments