| 15 | import Variable from './Variable'; |
| 16 | |
| 17 | export default class NamespaceVariable extends Variable { |
| 18 | readonly context: AstContext; |
| 19 | declare isNamespace: true; |
| 20 | readonly module: Module; |
| 21 | |
| 22 | private areAllMembersDeoptimized = false; |
| 23 | private mergedNamespaces: readonly Variable[] = []; |
| 24 | private nonExplicitNamespacesIncluded = false; |
| 25 | private referencedEarly = false; |
| 26 | private readonly references: IdentifierBase[] = []; |
| 27 | |
| 28 | constructor(context: AstContext) { |
| 29 | super(context.getModuleName()); |
| 30 | this.context = context; |
| 31 | this.module = context.module; |
| 32 | } |
| 33 | |
| 34 | addReference(identifier: IdentifierBase): void { |
| 35 | this.references.push(identifier); |
| 36 | this.name = identifier.name; |
| 37 | } |
| 38 | |
| 39 | deoptimizeArgumentsOnInteractionAtPath( |
| 40 | interaction: NodeInteraction, |
| 41 | path: ObjectPath, |
| 42 | recursionTracker: EntityPathTracker |
| 43 | ) { |
| 44 | if (path.length > 1 || (path.length === 1 && interaction.type === INTERACTION_CALLED)) { |
| 45 | const key = path[0]; |
| 46 | if (typeof key === 'string') { |
| 47 | this.module |
| 48 | .getExportedVariablesByName() |
| 49 | .get(key) |
| 50 | ?.deoptimizeArgumentsOnInteractionAtPath(interaction, path.slice(1), recursionTracker); |
| 51 | } else { |
| 52 | deoptimizeInteraction(interaction); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | deoptimizePath(path: ObjectPath) { |
| 58 | if (path.length > 1) { |
| 59 | const key = path[0]; |
| 60 | if (typeof key === 'string') { |
| 61 | this.module.getExportedVariablesByName().get(key)?.deoptimizePath(path.slice(1)); |
| 62 | } else if (!this.areAllMembersDeoptimized) { |
| 63 | this.areAllMembersDeoptimized = true; |
| 64 | for (const variable of this.module.getExportedVariablesByName().values()) { |
| 65 | variable.deoptimizePath(UNKNOWN_PATH); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | getLiteralValueAtPath(path: ObjectPath): LiteralValueOrUnknown { |
| 72 | if (path[0] === SymbolToStringTag) { |
| 73 | return 'Module'; |
| 74 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…