-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ObjectPattern.ts
46 lines (41 loc) · 1.4 KB
/
ObjectPattern.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
import { ExecutionPathOptions } from '../ExecutionPathOptions';
import { EMPTY_PATH, ObjectPath } from '../values';
import Variable from '../variables/Variable';
import * as NodeType from './NodeType';
import Property from './Property';
import RestElement from './RestElement';
import { ExpressionEntity } from './shared/Expression';
import { NodeBase } from './shared/Node';
import { PatternNode } from './shared/Pattern';
export default class ObjectPattern extends NodeBase implements PatternNode {
type: NodeType.tObjectPattern;
properties: (Property | RestElement)[];
addExportedVariables(variables: Variable[]): void {
for (const property of this.properties) {
if (property.type === NodeType.Property) {
(<PatternNode>(<unknown>property.value)).addExportedVariables(variables);
} else {
property.argument.addExportedVariables(variables);
}
}
}
declare(kind: string, init: ExpressionEntity) {
for (const property of this.properties) {
property.declare(kind, init);
}
}
hasEffectsWhenAssignedAtPath(path: ObjectPath, options: ExecutionPathOptions) {
if (path.length > 0) return true;
for (const property of this.properties) {
if (property.hasEffectsWhenAssignedAtPath(EMPTY_PATH, options)) return true;
}
return false;
}
deoptimizePath(path: ObjectPath) {
if (path.length === 0) {
for (const property of this.properties) {
property.deoptimizePath(path);
}
}
}
}