forked from rollup/rollup
/
ArrowFunctionExpression.ts
57 lines (52 loc) · 1.83 KB
/
ArrowFunctionExpression.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
56
57
import { type CallOptions } from '../CallOptions';
import { type HasEffectsContext } from '../ExecutionContext';
import ReturnValueScope from '../scopes/ReturnValueScope';
import type Scope from '../scopes/Scope';
import { type ObjectPath } from '../utils/PathTracker';
import BlockStatement from './BlockStatement';
import * as NodeType from './NodeType';
import FunctionBase from './shared/FunctionBase';
import { type ExpressionNode } from './shared/Node';
import { ObjectEntity } from './shared/ObjectEntity';
import { OBJECT_PROTOTYPE } from './shared/ObjectPrototype';
import type { PatternNode } from './shared/Pattern';
export default class ArrowFunctionExpression extends FunctionBase {
declare async: boolean;
declare body: BlockStatement | ExpressionNode;
declare params: readonly PatternNode[];
declare preventChildBlockScope: true;
declare scope: ReturnValueScope;
declare type: NodeType.tArrowFunctionExpression;
protected objectEntity: ObjectEntity | null = null;
createScope(parentScope: Scope): void {
this.scope = new ReturnValueScope(parentScope, this.context);
}
hasEffects(): boolean {
if (!this.deoptimized) this.applyDeoptimizations();
return false;
}
hasEffectsWhenCalledAtPath(
path: ObjectPath,
callOptions: CallOptions,
context: HasEffectsContext
): boolean {
if (super.hasEffectsWhenCalledAtPath(path, callOptions, context)) return true;
const { ignore, brokenFlow } = context;
context.ignore = {
breaks: false,
continues: false,
labels: new Set(),
returnYield: true
};
if (this.body.hasEffects(context)) return true;
context.ignore = ignore;
context.brokenFlow = brokenFlow;
return false;
}
protected getObjectEntity(): ObjectEntity {
if (this.objectEntity !== null) {
return this.objectEntity;
}
return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
}
}