@@ -16,7 +16,7 @@ import { tryCastLiteralValueToBoolean } from '../utils/tryCastLiteralValueToBool
1616import type * as NodeType from './NodeType' ;
1717import { Flag , isFlagSet , setFlag } from './shared/BitFlags' ;
1818import type { ExpressionEntity , LiteralValueOrUnknown } from './shared/Expression' ;
19- import { UnknownValue } from './shared/Expression' ;
19+ import { UnknownFalsyValue , UnknownTruthyValue , UnknownValue } from './shared/Expression' ;
2020import { MultiExpression } from './shared/MultiExpression' ;
2121import type { ExpressionNode , IncludeChildren } from './shared/Node' ;
2222import { doNotDeoptimize , NodeBase , onlyIncludeSelfNoDeoptimize } from './shared/Node' ;
@@ -78,7 +78,18 @@ export default class ConditionalExpression extends NodeBase implements Deoptimiz
7878origin : DeoptimizableEntity
7979) : LiteralValueOrUnknown {
8080const usedBranch = this . getUsedBranch ( ) ;
81- if ( ! usedBranch ) return UnknownValue ;
81+ if ( ! usedBranch ) {
82+ const consequentValue = this . consequent . getLiteralValueAtPath ( path , recursionTracker , origin ) ;
83+ const castedConsequentValue = tryCastLiteralValueToBoolean ( consequentValue ) ;
84+ if ( castedConsequentValue === UnknownValue ) return UnknownValue ;
85+ const alternateValue = this . alternate . getLiteralValueAtPath ( path , recursionTracker , origin ) ;
86+ const castedAlternateValue = tryCastLiteralValueToBoolean ( alternateValue ) ;
87+ if ( castedConsequentValue !== castedAlternateValue ) return UnknownValue ;
88+ this . expressionsToBeDeoptimized . push ( origin ) ;
89+ if ( consequentValue !== alternateValue )
90+ return castedConsequentValue ? UnknownTruthyValue : UnknownFalsyValue ;
91+ return consequentValue ;
92+ }
8293this . expressionsToBeDeoptimized . push ( origin ) ;
8394return usedBranch . getLiteralValueAtPath ( path , recursionTracker , origin ) ;
8495}
0 commit comments