-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ArgumentsVariable.ts
38 lines (33 loc) · 1.2 KB
/
ArgumentsVariable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type { AstContext } from '../../Module';
import type { NodeInteraction } from '../NodeInteractions';
import { INTERACTION_ACCESSED } from '../NodeInteractions';
import type { ExpressionEntity } from '../nodes/shared/Expression';
import { UNKNOWN_EXPRESSION } from '../nodes/shared/Expression';
import type { ObjectPath } from '../utils/PathTracker';
import { UNKNOWN_PATH } from '../utils/PathTracker';
import LocalVariable from './LocalVariable';
export default class ArgumentsVariable extends LocalVariable {
private deoptimizedArguments: ExpressionEntity[] = [];
constructor(context: AstContext) {
super('arguments', null, UNKNOWN_EXPRESSION, context);
}
addArgumentToBeDeoptimized(argument: ExpressionEntity): void {
if (this.included) {
argument.deoptimizePath(UNKNOWN_PATH);
} else {
this.deoptimizedArguments.push(argument);
}
}
hasEffectsOnInteractionAtPath(path: ObjectPath, { type }: NodeInteraction): boolean {
return type !== INTERACTION_ACCESSED || path.length > 1;
}
include() {
if (!this.included) {
super.include();
for (const argument of this.deoptimizedArguments) {
argument.deoptimizePath(UNKNOWN_PATH);
}
this.deoptimizedArguments.length = 0;
}
}
}