@@ -2,7 +2,6 @@ import { findVariable } from "./find-variable"
2
2
import { getPropertyName } from "./get-property-name"
3
3
import { getStringIfConstant } from "./get-string-if-constant"
4
4
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
6
5
const 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
7
6
const has = Function . call . bind ( Object . hasOwnProperty )
8
7
@@ -26,6 +25,28 @@ function isModifiedGlobal(variable) {
26
25
)
27
26
}
28
27
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
+
29
50
/**
30
51
* The reference tracker.
31
52
*/
@@ -227,7 +248,7 @@ export class ReferenceTracker {
227
248
//eslint-disable-next-line complexity
228
249
* _iteratePropertyReferences ( rootNode , path , traceMap ) {
229
250
let node = rootNode
230
- while ( ! SENTINEL_TYPE . test ( node . parent . type ) ) {
251
+ while ( isPassThrough ( node ) ) {
231
252
node = node . parent
232
253
}
233
254
0 commit comments