11export { default as isReference } from 'is-reference' ;
22
3+ function triStateAnd ( a , b ) {
4+ if ( a === false ) return false ;
5+ if ( b === false ) return false ;
6+ if ( a === true && b === true ) return true ;
7+ return null ;
8+ }
9+
10+ function triStateOr ( a , b ) {
11+ if ( a === true ) return true ;
12+ if ( b === true ) return true ;
13+ if ( a === false && b === false ) return false ;
14+ return null ;
15+ }
16+
317const operators = {
418 '==' : ( x ) => equals ( x . left , x . right , false ) ,
519
@@ -11,20 +25,9 @@ const operators = {
1125
1226 '!' : ( x ) => isFalsy ( x . argument ) ,
1327
14- '&&' : ( x ) => isTruthy ( x . left ) && isTruthy ( x . right ) ,
15-
16- '||' : ( x ) => {
17- const leftTruthy = isTruthy ( x . left ) ;
18- const rightTruthy = isTruthy ( x . right ) ;
19- // If left is definitely truthy, the whole expression is truthy
20- if ( leftTruthy === true ) return true ;
21- // If both are definitely falsy, the whole expression is falsy
22- if ( leftTruthy === false && rightTruthy === false ) return false ;
23- // If left is falsy but right is truthy, the whole expression is truthy
24- if ( leftTruthy === false && rightTruthy === true ) return true ;
25- // Otherwise it's conditional
26- return null ;
27- }
28+ '&&' : ( x ) => triStateAnd ( isTruthy ( x . left ) , isTruthy ( x . right ) ) ,
29+
30+ '||' : ( x ) => triStateOr ( isTruthy ( x . left ) , isTruthy ( x . right ) )
2831} ;
2932
3033function not ( value ) {
@@ -137,3 +140,4 @@ export function hasDefineEsmProperty(node) {
137140 return false ;
138141 } ) ;
139142}
143+
0 commit comments