@@ -2,7 +2,6 @@ import { findVariable } from "./find-variable"
22import { getPropertyName } from "./get-property-name"
33import { getStringIfConstant } from "./get-string-if-constant"
44
5- const SENTINEL_TYPE = / ^ (?: .+ ?S t a t e m e n t | .+ ?D e c l a r a t i o n | (?: A r r a y | A r r o w F u n c t i o n | A s s i g n m e n t | C a l l | C l a s s | F u n c t i o n | M e m b e r | N e w | O b j e c t ) E x p r e s s i o n | A s s i g n m e n t P a t t e r n | P r o g r a m | V a r i a b l e D e c l a r a t o r ) $ / u
65const IMPORT_TYPE = / ^ (?: I m p o r t | E x p o r t (?: A l l | D e f a u l t | N a m e d ) ) D e c l a r a t i o n $ / u
76const has = Function . call . bind ( Object . hasOwnProperty )
87
@@ -26,6 +25,28 @@ function isModifiedGlobal(variable) {
2625 )
2726}
2827
28+ /**
29+ * Check if the value of a given node is passed through to the parent syntax as-is.
30+ * For example, `a` and `b` in (`a || b` and `c ? a : b`) are passed through.
31+ * @param {Node } node A node to check.
32+ * @returns {boolean } `true` if the node is passed through.
33+ */
34+ function isPassThrough ( node ) {
35+ const parent = node . parent
36+
37+ switch ( parent && parent . type ) {
38+ case "ConditionalExpression" :
39+ return parent . consequent === node || parent . alternate === node
40+ case "LogicalExpression" :
41+ return true
42+ case "SequenceExpression" :
43+ return parent . expressions [ parent . expressions . length - 1 ] === node
44+
45+ default :
46+ return false
47+ }
48+ }
49+
2950/**
3051 * The reference tracker.
3152 */
@@ -227,7 +248,7 @@ export class ReferenceTracker {
227248 //eslint-disable-next-line complexity
228249 * _iteratePropertyReferences ( rootNode , path , traceMap ) {
229250 let node = rootNode
230- while ( ! SENTINEL_TYPE . test ( node . parent . type ) ) {
251+ while ( isPassThrough ( node ) ) {
231252 node = node . parent
232253 }
233254
0 commit comments