@@ -238,53 +238,65 @@ export const javascript_visitors_runes = {
238
238
}
239
239
240
240
if ( rune === '$props' ) {
241
- assert . equal ( declarator . id . type , 'ObjectPattern' ) ;
242
-
243
241
/** @type {string[] } */
244
242
const seen = [ '$$slots' , '$$events' , '$$legacy' ] ;
245
243
246
244
if ( state . analysis . custom_element ) {
247
245
seen . push ( '$$host' ) ;
248
246
}
249
247
250
- for ( const property of declarator . id . properties ) {
251
- if ( property . type === 'Property' ) {
252
- const key = /** @type {import('estree').Identifier | import('estree').Literal } */ (
253
- property . key
254
- ) ;
255
- const name = key . type === 'Identifier' ? key . name : /** @type {string } */ ( key . value ) ;
256
-
257
- seen . push ( name ) ;
258
-
259
- let id =
260
- property . value . type === 'AssignmentPattern' ? property . value . left : property . value ;
261
- assert . equal ( id . type , 'Identifier' ) ;
262
- const binding = /** @type {import('#compiler').Binding } */ ( state . scope . get ( id . name ) ) ;
263
- let initial =
264
- binding . initial &&
265
- /** @type {import('estree').Expression } */ ( visit ( binding . initial ) ) ;
266
- // We're adding proxy here on demand and not within the prop runtime function so that
267
- // people not using proxied state anywhere in their code don't have to pay the additional bundle size cost
268
- if ( initial && binding . mutated && should_proxy_or_freeze ( initial , state . scope ) ) {
269
- initial = b . call ( '$.proxy' , initial ) ;
270
- }
248
+ if ( declarator . id . type === 'Identifier' ) {
249
+ /** @type {import('estree').Expression[] } */
250
+ const args = [ b . id ( '$$props' ) , b . array ( seen . map ( ( name ) => b . literal ( name ) ) ) ] ;
271
251
272
- if ( is_prop_source ( binding , state ) ) {
273
- declarations . push ( b . declarator ( id , get_prop_source ( binding , state , name , initial ) ) ) ;
274
- }
275
- } else {
276
- // RestElement
277
- /** @type {import('estree').Expression[] } */
278
- const args = [ b . id ( '$$props' ) , b . array ( seen . map ( ( name ) => b . literal ( name ) ) ) ] ;
279
-
280
- if ( state . options . dev ) {
281
- // include rest name, so we can provide informative error messages
282
- args . push (
283
- b . literal ( /** @type {import('estree').Identifier } */ ( property . argument ) . name )
252
+ if ( state . options . dev ) {
253
+ // include rest name, so we can provide informative error messages
254
+ args . push ( b . literal ( declarator . id . name ) ) ;
255
+ }
256
+
257
+ declarations . push ( b . declarator ( declarator . id , b . call ( '$.rest_props' , ...args ) ) ) ;
258
+ } else {
259
+ assert . equal ( declarator . id . type , 'ObjectPattern' ) ;
260
+
261
+ for ( const property of declarator . id . properties ) {
262
+ if ( property . type === 'Property' ) {
263
+ const key = /** @type {import('estree').Identifier | import('estree').Literal } */ (
264
+ property . key
284
265
) ;
266
+ const name = key . type === 'Identifier' ? key . name : /** @type {string } */ ( key . value ) ;
267
+
268
+ seen . push ( name ) ;
269
+
270
+ let id =
271
+ property . value . type === 'AssignmentPattern' ? property . value . left : property . value ;
272
+ assert . equal ( id . type , 'Identifier' ) ;
273
+ const binding = /** @type {import('#compiler').Binding } */ ( state . scope . get ( id . name ) ) ;
274
+ let initial =
275
+ binding . initial &&
276
+ /** @type {import('estree').Expression } */ ( visit ( binding . initial ) ) ;
277
+ // We're adding proxy here on demand and not within the prop runtime function so that
278
+ // people not using proxied state anywhere in their code don't have to pay the additional bundle size cost
279
+ if ( initial && binding . mutated && should_proxy_or_freeze ( initial , state . scope ) ) {
280
+ initial = b . call ( '$.proxy' , initial ) ;
281
+ }
282
+
283
+ if ( is_prop_source ( binding , state ) ) {
284
+ declarations . push ( b . declarator ( id , get_prop_source ( binding , state , name , initial ) ) ) ;
285
+ }
286
+ } else {
287
+ // RestElement
288
+ /** @type {import('estree').Expression[] } */
289
+ const args = [ b . id ( '$$props' ) , b . array ( seen . map ( ( name ) => b . literal ( name ) ) ) ] ;
290
+
291
+ if ( state . options . dev ) {
292
+ // include rest name, so we can provide informative error messages
293
+ args . push (
294
+ b . literal ( /** @type {import('estree').Identifier } */ ( property . argument ) . name )
295
+ ) ;
296
+ }
297
+
298
+ declarations . push ( b . declarator ( property . argument , b . call ( '$.rest_props' , ...args ) ) ) ;
285
299
}
286
-
287
- declarations . push ( b . declarator ( property . argument , b . call ( '$.rest_props' , ...args ) ) ) ;
288
300
}
289
301
}
290
302
0 commit comments