@@ -20,19 +20,23 @@ const { ReferenceTracker } = eslintUtils
20
20
* @property {MemberExpression | CallExpression } node
21
21
* @property {string } method
22
22
* @property {CallExpression } define
23
+ * @property {(CallExpression | Identifier | MemberExpression)[] } defineChain Holds the initialization path for assignment of ref objects.
23
24
*
24
25
* @typedef {object } RefObjectReferenceForPattern
25
26
* @property {'pattern' } type
26
27
* @property {ObjectPattern } node
27
28
* @property {string } method
28
29
* @property {CallExpression } define
30
+ * @property {(CallExpression | Identifier | MemberExpression)[] } defineChain Holds the initialization path for assignment of ref objects.
29
31
*
30
32
* @typedef {object } RefObjectReferenceForIdentifier
31
33
* @property {'expression' | 'pattern' } type
32
34
* @property {Identifier } node
35
+ * @property {VariableDeclarator | null } variableDeclarator
33
36
* @property {VariableDeclaration | null } variableDeclaration
34
37
* @property {string } method
35
38
* @property {CallExpression } define
39
+ * @property {(CallExpression | Identifier | MemberExpression)[] } defineChain Holds the initialization path for assignment of ref objects.
36
40
*
37
41
* @typedef {RefObjectReferenceForIdentifier | RefObjectReferenceForExpression | RefObjectReferenceForPattern } RefObjectReference
38
42
*/
@@ -258,6 +262,13 @@ module.exports = {
258
262
extractReactiveVariableReferences
259
263
}
260
264
265
+ /**
266
+ * @typedef {object } RefObjectReferenceContext
267
+ * @property {string } method
268
+ * @property {CallExpression } define
269
+ * @property {(CallExpression | Identifier | MemberExpression)[] } defineChain Holds the initialization path for assignment of ref objects.
270
+ */
271
+
261
272
/**
262
273
* @implements {RefObjectReferences}
263
274
*/
@@ -312,12 +323,19 @@ class RefObjectReferenceExtractor {
312
323
type : 'expression' ,
313
324
node,
314
325
method,
315
- define : node
326
+ define : node ,
327
+ defineChain : [ node ]
316
328
} )
317
329
}
318
330
return
319
331
}
320
332
333
+ const ctx = {
334
+ method,
335
+ define : node ,
336
+ defineChain : [ node ]
337
+ }
338
+
321
339
if ( method === 'toRefs' ) {
322
340
const propertyReferenceExtractor = definePropertyReferenceExtractor (
323
341
this . context
@@ -327,63 +345,65 @@ class RefObjectReferenceExtractor {
327
345
for ( const name of propertyReferences . allProperties ( ) . keys ( ) ) {
328
346
for ( const nest of propertyReferences . getNestNodes ( name ) ) {
329
347
if ( nest . type === 'expression' ) {
330
- this . processMemberExpression ( nest . node , method , node )
348
+ this . processMemberExpression ( nest . node , ctx )
331
349
} else if ( nest . type === 'pattern' ) {
332
- this . processPattern ( nest . node , method , node )
350
+ this . processPattern ( nest . node , ctx )
333
351
}
334
352
}
335
353
}
336
354
} else {
337
- this . processPattern ( pattern , method , node )
355
+ this . processPattern ( pattern , ctx )
338
356
}
339
357
}
340
358
341
359
/**
342
- * @param {Expression } node
343
- * @param {string } method
344
- * @param {CallExpression } define
360
+ * @param {MemberExpression | Identifier } node
361
+ * @param {RefObjectReferenceContext } ctx
345
362
*/
346
- processExpression ( node , method , define ) {
363
+ processExpression ( node , ctx ) {
347
364
const parent = node . parent
348
365
if ( parent . type === 'AssignmentExpression' ) {
349
366
if ( parent . operator === '=' && parent . right === node ) {
350
367
// `(foo = obj.mem)`
351
- this . processPattern ( parent . left , method , define )
368
+ this . processPattern ( parent . left , {
369
+ ...ctx ,
370
+ defineChain : [ node , ...ctx . defineChain ]
371
+ } )
352
372
return true
353
373
}
354
374
} else if ( parent . type === 'VariableDeclarator' && parent . init === node ) {
355
375
// `const foo = obj.mem`
356
- this . processPattern ( parent . id , method , define )
376
+ this . processPattern ( parent . id , {
377
+ ...ctx ,
378
+ defineChain : [ node , ...ctx . defineChain ]
379
+ } )
357
380
return true
358
381
}
359
382
return false
360
383
}
361
384
/**
362
385
* @param {MemberExpression } node
363
- * @param {string } method
364
- * @param {CallExpression } define
386
+ * @param {RefObjectReferenceContext } ctx
365
387
*/
366
- processMemberExpression ( node , method , define ) {
367
- if ( this . processExpression ( node , method , define ) ) {
388
+ processMemberExpression ( node , ctx ) {
389
+ if ( this . processExpression ( node , ctx ) ) {
368
390
return
369
391
}
370
392
this . references . set ( node , {
371
393
type : 'expression' ,
372
394
node,
373
- method,
374
- define
395
+ ...ctx
375
396
} )
376
397
}
377
398
378
399
/**
379
400
* @param {Pattern } node
380
- * @param {string } method
381
- * @param {CallExpression } define
401
+ * @param {RefObjectReferenceContext } ctx
382
402
*/
383
- processPattern ( node , method , define ) {
403
+ processPattern ( node , ctx ) {
384
404
switch ( node . type ) {
385
405
case 'Identifier' : {
386
- this . processIdentifierPattern ( node , method , define )
406
+ this . processIdentifierPattern ( node , ctx )
387
407
break
388
408
}
389
409
case 'ArrayPattern' :
@@ -395,13 +415,12 @@ class RefObjectReferenceExtractor {
395
415
this . references . set ( node , {
396
416
type : 'pattern' ,
397
417
node,
398
- method,
399
- define
418
+ ...ctx
400
419
} )
401
420
return
402
421
}
403
422
case 'AssignmentPattern' : {
404
- this . processPattern ( node . left , method , define )
423
+ this . processPattern ( node . left , ctx )
405
424
return
406
425
}
407
426
// No default
@@ -410,10 +429,9 @@ class RefObjectReferenceExtractor {
410
429
411
430
/**
412
431
* @param {Identifier } node
413
- * @param {string } method
414
- * @param {CallExpression } define
432
+ * @param {RefObjectReferenceContext } ctx
415
433
*/
416
- processIdentifierPattern ( node , method , define ) {
434
+ processIdentifierPattern ( node , ctx ) {
417
435
if ( this . _processedIds . has ( node ) ) {
418
436
return
419
437
}
@@ -434,16 +452,16 @@ class RefObjectReferenceExtractor {
434
452
}
435
453
if (
436
454
reference . isRead ( ) &&
437
- this . processExpression ( reference . identifier , method , define )
455
+ this . processExpression ( reference . identifier , ctx )
438
456
) {
439
457
continue
440
458
}
441
459
this . references . set ( reference . identifier , {
442
460
type : reference . isWrite ( ) ? 'pattern' : 'expression' ,
443
461
node : reference . identifier ,
444
- method ,
445
- define ,
446
- variableDeclaration : def ? def . parent : null
462
+ variableDeclarator : def ? def . node : null ,
463
+ variableDeclaration : def ? def . parent : null ,
464
+ ... ctx
447
465
} )
448
466
}
449
467
}
0 commit comments