MCPcopy
hub / github.com/rollup/rollup / ParameterVariable

Class ParameterVariable

src/ast/variables/ParameterVariable.ts:39–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37const UNKNOWN_DEOPTIMIZED_ENTITY = new Set<ExpressionEntity>([UNKNOWN_EXPRESSION]);
38
39export default class ParameterVariable extends LocalVariable {
40 protected includedPathTracker = new IncludedTopLevelPathTracker();
41 private argumentsToBeDeoptimized = new Set<ExpressionEntity>();
42 private deoptimizationInteractions: TrackedInteraction[] = [];
43 private deoptimizations = new EntityPathTracker();
44 private deoptimizedFields = new Set<ObjectPathKey>();
45 private expressionsDependingOnKnownValue: DeoptimizableEntity[] = [];
46 private knownValue: ExpressionEntity | null = null;
47 private knownValueLiteral: LiteralValueOrUnknown = UnknownValue;
48
49 constructor(
50 name: string,
51 declarator: Identifier | ExportDefaultDeclaration | null,
52 argumentPath: ObjectPath,
53 context: AstContext
54 ) {
55 super(name, declarator, UNKNOWN_EXPRESSION, argumentPath, context, 'parameter');
56 }
57
58 addArgumentForDeoptimization(entity: ExpressionEntity): void {
59 this.updateKnownValue(entity);
60 if (entity === UNKNOWN_EXPRESSION) {
61 // As unknown expressions fully deoptimize all interactions, we can clear
62 // the interaction cache at this point provided we keep this optimization
63 // in mind when adding new interactions
64 if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
65 this.argumentsToBeDeoptimized.add(UNKNOWN_EXPRESSION);
66 for (const { interaction } of this.deoptimizationInteractions) {
67 deoptimizeInteraction(interaction);
68 }
69 this.deoptimizationInteractions = NO_INTERACTIONS;
70 }
71 } else if (this.deoptimizedFields.has(UnknownKey)) {
72 // This means that we already deoptimized all interactions and no longer
73 // track them
74 entity.deoptimizePath([...this.initPath, UnknownKey]);
75 } else if (!this.argumentsToBeDeoptimized.has(entity)) {
76 this.argumentsToBeDeoptimized.add(entity);
77 for (const field of this.deoptimizedFields) {
78 entity.deoptimizePath([...this.initPath, field]);
79 }
80 for (const { interaction, path } of this.deoptimizationInteractions) {
81 entity.deoptimizeArgumentsOnInteractionAtPath(
82 interaction,
83 [...this.initPath, ...path],
84 SHARED_RECURSION_TRACKER
85 );
86 }
87 }
88 }
89
90 /** This says we should not make assumptions about the value of the parameter.
91 * This is different from deoptimization that will also cause argument values
92 * to be deoptimized. */
93 markReassigned(): void {
94 if (this.isReassigned) {
95 return;
96 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…