| 22 | const unset = Symbol('unset'); |
| 23 | |
| 24 | export default class IfStatement extends StatementBase implements DeoptimizableEntity { |
| 25 | declare alternate: StatementNode | null; |
| 26 | declare consequent: StatementNode; |
| 27 | declare test: ExpressionNode; |
| 28 | declare type: NodeType.tIfStatement; |
| 29 | |
| 30 | declare alternateScope?: TrackingScope; |
| 31 | declare consequentScope: TrackingScope; |
| 32 | private testValue: LiteralValueOrUnknown | typeof unset = unset; |
| 33 | |
| 34 | deoptimizeCache(): void { |
| 35 | this.testValue = UnknownValue; |
| 36 | } |
| 37 | |
| 38 | hasEffects(context: HasEffectsContext): boolean { |
| 39 | if (this.test.hasEffects(context)) { |
| 40 | return true; |
| 41 | } |
| 42 | const testValue = this.getTestValue(); |
| 43 | if (typeof testValue === 'symbol') { |
| 44 | const { brokenFlow } = context; |
| 45 | if (this.consequent.hasEffects(context)) return true; |
| 46 | const consequentBrokenFlow = context.brokenFlow; |
| 47 | context.brokenFlow = brokenFlow; |
| 48 | if (this.alternate === null) return false; |
| 49 | if (this.alternate.hasEffects(context)) return true; |
| 50 | context.brokenFlow = context.brokenFlow && consequentBrokenFlow; |
| 51 | return false; |
| 52 | } |
| 53 | return testValue ? this.consequent.hasEffects(context) : !!this.alternate?.hasEffects(context); |
| 54 | } |
| 55 | |
| 56 | include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void { |
| 57 | this.included = true; |
| 58 | if (includeChildrenRecursively) { |
| 59 | this.includeRecursively(includeChildrenRecursively, context); |
| 60 | } else { |
| 61 | const testValue = this.getTestValue(); |
| 62 | if (typeof testValue === 'symbol') { |
| 63 | this.includeUnknownTest(context); |
| 64 | } else { |
| 65 | this.includeKnownTest(context, testValue); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | parseNode(esTreeNode: GenericEsTreeNode): this { |
| 71 | this.consequent = new (this.scope.context.getNodeConstructor(esTreeNode.consequent.type))( |
| 72 | this, |
| 73 | (this.consequentScope = new TrackingScope(this.scope)) |
| 74 | ).parseNode(esTreeNode.consequent); |
| 75 | if (esTreeNode.alternate) { |
| 76 | this.alternate = new (this.scope.context.getNodeConstructor(esTreeNode.alternate.type))( |
| 77 | this, |
| 78 | (this.alternateScope = new TrackingScope(this.scope)) |
| 79 | ).parseNode(esTreeNode.alternate); |
| 80 | } |
| 81 | return super.parseNode(esTreeNode); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…