forked from rollup/rollup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpreadElement.ts
50 lines (46 loc) · 1.67 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
50
import type { NormalizedTreeshakingOptions } from '../../rollup/types';
import type { HasEffectsContext } from '../ExecutionContext';
import type { NodeInteraction } from '../NodeInteractions';
import { NODE_INTERACTION_UNKNOWN_ACCESS } from '../NodeInteractions';
import { type ObjectPath, type PathTracker, UNKNOWN_PATH, UnknownKey } from '../utils/PathTracker';
import type * as NodeType from './NodeType';
import { type ExpressionNode, NodeBase } from './shared/Node';
export default class SpreadElement extends NodeBase {
declare argument: ExpressionNode;
declare type: NodeType.tSpreadElement;
deoptimizeArgumentsOnInteractionAtPath(
interaction: NodeInteraction,
path: ObjectPath,
recursionTracker: PathTracker
): void {
if (path.length > 0) {
this.argument.deoptimizeArgumentsOnInteractionAtPath(
interaction,
[UnknownKey, ...path],
recursionTracker
);
}
}
hasEffects(context: HasEffectsContext): boolean {
if (!this.deoptimized) this.applyDeoptimizations();
const { propertyReadSideEffects } = this.scope.context.options
.treeshake as NormalizedTreeshakingOptions;
return (
this.argument.hasEffects(context) ||
(propertyReadSideEffects &&
(propertyReadSideEffects === 'always' ||
this.argument.hasEffectsOnInteractionAtPath(
UNKNOWN_PATH,
NODE_INTERACTION_UNKNOWN_ACCESS,
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.scope.context.requestTreeshakingPass();
}
}