/
SpreadElement.ts
49 lines (45 loc) · 1.57 KB
/
SpreadElement.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
import { NormalizedTreeshakingOptions } from '../../rollup/types';
import { HasEffectsContext } from '../ExecutionContext';
import { NodeEvent } from '../NodeEvents';
import { ObjectPath, PathTracker, UNKNOWN_PATH, UnknownKey } from '../utils/PathTracker';
import * as NodeType from './NodeType';
import { ExpressionEntity } from './shared/Expression';
import { ExpressionNode, NodeBase } from './shared/Node';
export default class SpreadElement extends NodeBase {
argument!: ExpressionNode;
type!: NodeType.tSpreadElement;
protected deoptimized = false;
deoptimizeThisOnEventAtPath(
event: NodeEvent,
path: ObjectPath,
thisParameter: ExpressionEntity,
recursionTracker: PathTracker
): void {
if (path.length > 0) {
this.argument.deoptimizeThisOnEventAtPath(
event,
[UnknownKey, ...path],
thisParameter,
recursionTracker
);
}
}
hasEffects(context: HasEffectsContext): boolean {
if (!this.deoptimized) this.applyDeoptimizations();
const { propertyReadSideEffects } = this.context.options
.treeshake as NormalizedTreeshakingOptions;
return (
this.argument.hasEffects(context) ||
(propertyReadSideEffects &&
(propertyReadSideEffects === 'always' ||
this.argument.hasEffectsWhenAccessedAtPath(UNKNOWN_PATH, context)))
);
}
protected applyDeoptimizations(): void {
this.deoptimized = true;
// Only properties of properties of the argument could become subject to reassignment
// This will also reassign the return values of iterators
this.argument.deoptimizePath([UnknownKey, UnknownKey]);
this.context.requestTreeshakingPass();
}
}