| 12 | import type { VariableKind } from './shared/VariableKinds'; |
| 13 | |
| 14 | export default class ArrayPattern extends NodeBase implements DeclarationPatternNode { |
| 15 | declare elements: (PatternNode | null)[]; |
| 16 | declare type: NodeType.tArrayPattern; |
| 17 | |
| 18 | addExportedVariables( |
| 19 | variables: readonly Variable[], |
| 20 | exportNamesByVariable: ReadonlyMap<Variable, readonly string[]> |
| 21 | ): void { |
| 22 | for (const element of this.elements) { |
| 23 | element?.addExportedVariables(variables, exportNamesByVariable); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | declare( |
| 28 | kind: VariableKind, |
| 29 | destructuredInitPath: ObjectPath, |
| 30 | init: ExpressionEntity |
| 31 | ): LocalVariable[] { |
| 32 | const variables: LocalVariable[] = []; |
| 33 | const includedPatternPath = getIncludedPatternPath(destructuredInitPath); |
| 34 | for (const element of this.elements) { |
| 35 | if (element !== null) { |
| 36 | variables.push( |
| 37 | ...(element as DeclarationPatternNode).declare(kind, includedPatternPath, init) |
| 38 | ); |
| 39 | } |
| 40 | } |
| 41 | return variables; |
| 42 | } |
| 43 | |
| 44 | deoptimizeAssignment(destructuredInitPath: ObjectPath, init: ExpressionEntity): void { |
| 45 | const includedPatternPath = getIncludedPatternPath(destructuredInitPath); |
| 46 | for (const element of this.elements) { |
| 47 | element?.deoptimizeAssignment(includedPatternPath, init); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // Patterns can only be deoptimized at the empty path at the moment |
| 52 | deoptimizePath(): void { |
| 53 | for (const element of this.elements) { |
| 54 | element?.deoptimizePath(EMPTY_PATH); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | hasEffectsWhenDestructuring( |
| 59 | context: HasEffectsContext, |
| 60 | destructuredInitPath: ObjectPath, |
| 61 | init: ExpressionEntity |
| 62 | ): boolean { |
| 63 | const includedPatternPath = getIncludedPatternPath(destructuredInitPath); |
| 64 | for (const element of this.elements) { |
| 65 | if (element?.hasEffectsWhenDestructuring(context, includedPatternPath, init)) { |
| 66 | return true; |
| 67 | } |
| 68 | } |
| 69 | return false; |
| 70 | } |
| 71 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…