| 22 | import { doNotDeoptimize, NodeBase, onlyIncludeSelfNoDeoptimize } from './shared/Node'; |
| 23 | |
| 24 | export default class ConditionalExpression extends NodeBase implements DeoptimizableEntity { |
| 25 | declare alternate: ExpressionNode; |
| 26 | declare consequent: ExpressionNode; |
| 27 | declare test: ExpressionNode; |
| 28 | declare type: NodeType.tConditionalExpression; |
| 29 | |
| 30 | get isBranchResolutionAnalysed(): boolean { |
| 31 | return isFlagSet(this.flags, Flag.isBranchResolutionAnalysed); |
| 32 | } |
| 33 | set isBranchResolutionAnalysed(value: boolean) { |
| 34 | this.flags = setFlag(this.flags, Flag.isBranchResolutionAnalysed, value); |
| 35 | } |
| 36 | |
| 37 | private get hasDeoptimizedCache(): boolean { |
| 38 | return isFlagSet(this.flags, Flag.hasDeoptimizedCache); |
| 39 | } |
| 40 | private set hasDeoptimizedCache(value: boolean) { |
| 41 | this.flags = setFlag(this.flags, Flag.hasDeoptimizedCache, value); |
| 42 | } |
| 43 | |
| 44 | private expressionsToBeDeoptimized: DeoptimizableEntity[] = []; |
| 45 | private usedBranch: ExpressionNode | null = null; |
| 46 | |
| 47 | deoptimizeArgumentsOnInteractionAtPath( |
| 48 | interaction: NodeInteraction, |
| 49 | path: ObjectPath, |
| 50 | recursionTracker: EntityPathTracker |
| 51 | ): void { |
| 52 | this.consequent.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker); |
| 53 | this.alternate.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker); |
| 54 | } |
| 55 | |
| 56 | deoptimizeCache(): void { |
| 57 | if (this.hasDeoptimizedCache) return; |
| 58 | this.hasDeoptimizedCache = true; |
| 59 | if (this.usedBranch !== null) { |
| 60 | const unusedBranch = this.usedBranch === this.consequent ? this.alternate : this.consequent; |
| 61 | this.usedBranch = null; |
| 62 | unusedBranch.deoptimizePath(UNKNOWN_PATH); |
| 63 | if (this.included) { |
| 64 | unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext()); |
| 65 | } |
| 66 | const { expressionsToBeDeoptimized } = this; |
| 67 | this.expressionsToBeDeoptimized = EMPTY_ARRAY as unknown as DeoptimizableEntity[]; |
| 68 | for (const expression of expressionsToBeDeoptimized) { |
| 69 | expression.deoptimizeCache(); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | deoptimizePath(path: ObjectPath): void { |
| 75 | const usedBranch = this.getUsedBranch(); |
| 76 | if (usedBranch) { |
| 77 | usedBranch.deoptimizePath(path); |
| 78 | } else { |
| 79 | this.consequent.deoptimizePath(path); |
| 80 | this.alternate.deoptimizePath(path); |
| 81 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…