| 34 | import Variable from './Variable'; |
| 35 | |
| 36 | export default class LocalVariable extends Variable { |
| 37 | calledFromTryStatement = false; |
| 38 | |
| 39 | readonly declarations: (Identifier | ExportDefaultDeclaration)[]; |
| 40 | readonly module: Module; |
| 41 | |
| 42 | protected additionalInitializers: ExpressionEntity[] | null = null; |
| 43 | // Caching and deoptimization: |
| 44 | // We track deoptimization when we do not return something unknown |
| 45 | protected deoptimizationTracker: EntityPathTracker; |
| 46 | protected includedPathTracker: IncludedPathTracker = new IncludedFullPathTracker(); |
| 47 | private expressionsToBeDeoptimized: DeoptimizableEntity[] = []; |
| 48 | |
| 49 | constructor( |
| 50 | name: string, |
| 51 | declarator: Identifier | ExportDefaultDeclaration | null, |
| 52 | public init: ExpressionEntity, |
| 53 | /** if this is non-empty, the actual init is this path of this.init */ |
| 54 | protected initPath: ObjectPath, |
| 55 | context: AstContext, |
| 56 | readonly kind: VariableKind |
| 57 | ) { |
| 58 | super(name); |
| 59 | this.declarations = declarator ? [declarator] : []; |
| 60 | this.deoptimizationTracker = context.deoptimizationTracker; |
| 61 | this.module = context.module; |
| 62 | } |
| 63 | |
| 64 | addDeclaration(identifier: Identifier, init: ExpressionEntity): void { |
| 65 | this.declarations.push(identifier); |
| 66 | this.markInitializersForDeoptimization().push(init); |
| 67 | } |
| 68 | |
| 69 | consolidateInitializers(): void { |
| 70 | if (this.additionalInitializers) { |
| 71 | for (const initializer of this.additionalInitializers) { |
| 72 | initializer.deoptimizePath(UNKNOWN_PATH); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | deoptimizeArgumentsOnInteractionAtPath( |
| 78 | interaction: NodeInteraction, |
| 79 | path: ObjectPath, |
| 80 | recursionTracker: EntityPathTracker |
| 81 | ): void { |
| 82 | if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) { |
| 83 | deoptimizeInteraction(interaction); |
| 84 | return; |
| 85 | } |
| 86 | recursionTracker.withTrackedEntityAtPath( |
| 87 | path, |
| 88 | this.init, |
| 89 | () => { |
| 90 | this.init.deoptimizeArgumentsOnInteractionAtPath( |
| 91 | interaction, |
| 92 | [...this.initPath, ...path], |
| 93 | recursionTracker |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…