forked from rollup/rollup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestElement.ts
55 lines (48 loc) · 1.82 KB
/
RestElement.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import type { HasEffectsContext } from '../ExecutionContext';
import type { NodeInteractionAssigned } from '../NodeInteractions';
import { EMPTY_PATH, type ObjectPath, UnknownKey } from '../utils/PathTracker';
import type LocalVariable from '../variables/LocalVariable';
import type Variable from '../variables/Variable';
import type * as NodeType from './NodeType';
import { type ExpressionEntity, UNKNOWN_EXPRESSION } from './shared/Expression';
import { NodeBase } from './shared/Node';
import type { PatternNode } from './shared/Pattern';
import type { VariableKind } from './shared/VariableKinds';
export default class RestElement extends NodeBase implements PatternNode {
declare argument: PatternNode;
declare type: NodeType.tRestElement;
private declarationInit: ExpressionEntity | null = null;
addExportedVariables(
variables: readonly Variable[],
exportNamesByVariable: ReadonlyMap<Variable, readonly string[]>
): void {
this.argument.addExportedVariables(variables, exportNamesByVariable);
}
declare(kind: VariableKind, init: ExpressionEntity): LocalVariable[] {
this.declarationInit = init;
return this.argument.declare(kind, UNKNOWN_EXPRESSION);
}
deoptimizePath(path: ObjectPath): void {
path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
}
hasEffectsOnInteractionAtPath(
path: ObjectPath,
interaction: NodeInteractionAssigned,
context: HasEffectsContext
): boolean {
return (
path.length > 0 ||
this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context)
);
}
markDeclarationReached(): void {
this.argument.markDeclarationReached();
}
protected applyDeoptimizations(): void {
this.deoptimized = true;
if (this.declarationInit !== null) {
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
this.scope.context.requestTreeshakingPass();
}
}
}