| 41 | export type LogicalOperator = '||' | '&&' | '??'; |
| 42 | |
| 43 | export default class LogicalExpression extends NodeBase implements DeoptimizableEntity { |
| 44 | declare left: ExpressionNode; |
| 45 | declare operator: LogicalOperator; |
| 46 | declare right: ExpressionNode; |
| 47 | declare type: NodeType.tLogicalExpression; |
| 48 | |
| 49 | //private isBranchResolutionAnalysed = false; |
| 50 | private get isBranchResolutionAnalysed(): boolean { |
| 51 | return isFlagSet(this.flags, Flag.isBranchResolutionAnalysed); |
| 52 | } |
| 53 | private set isBranchResolutionAnalysed(value: boolean) { |
| 54 | this.flags = setFlag(this.flags, Flag.isBranchResolutionAnalysed, value); |
| 55 | } |
| 56 | |
| 57 | // We collect deoptimization information if usedBranch !== null |
| 58 | private expressionsToBeDeoptimized: DeoptimizableEntity[] = []; |
| 59 | private usedBranch: ExpressionNode | null = null; |
| 60 | |
| 61 | private get hasDeoptimizedCache(): boolean { |
| 62 | return isFlagSet(this.flags, Flag.hasDeoptimizedCache); |
| 63 | } |
| 64 | private set hasDeoptimizedCache(value: boolean) { |
| 65 | this.flags = setFlag(this.flags, Flag.hasDeoptimizedCache, value); |
| 66 | } |
| 67 | |
| 68 | deoptimizeArgumentsOnInteractionAtPath( |
| 69 | interaction: NodeInteraction, |
| 70 | path: ObjectPath, |
| 71 | recursionTracker: EntityPathTracker |
| 72 | ): void { |
| 73 | this.left.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker); |
| 74 | this.right.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker); |
| 75 | } |
| 76 | |
| 77 | deoptimizeCache(): void { |
| 78 | if (this.hasDeoptimizedCache) return; |
| 79 | this.hasDeoptimizedCache = true; |
| 80 | if (this.usedBranch) { |
| 81 | const unusedBranch = this.usedBranch === this.left ? this.right : this.left; |
| 82 | this.usedBranch = null; |
| 83 | unusedBranch.deoptimizePath(UNKNOWN_PATH); |
| 84 | if (this.included) { |
| 85 | // As we are not tracking inclusions, we just include everything |
| 86 | unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext()); |
| 87 | } |
| 88 | } |
| 89 | const { |
| 90 | scope: { context }, |
| 91 | expressionsToBeDeoptimized |
| 92 | } = this; |
| 93 | this.expressionsToBeDeoptimized = EMPTY_ARRAY as unknown as DeoptimizableEntity[]; |
| 94 | for (const expression of expressionsToBeDeoptimized) { |
| 95 | expression.deoptimizeCache(); |
| 96 | } |
| 97 | // Request another pass because we need to ensure "include" runs again if |
| 98 | // it is rendered |
| 99 | context.requestTreeshakingPass(); |
| 100 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…