/
AwaitExpression.ts
29 lines (26 loc) · 1.06 KB
/
AwaitExpression.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
import { HasEffectsContext, InclusionContext } from '../ExecutionContext';
import ArrowFunctionExpression from './ArrowFunctionExpression';
import * as NodeType from './NodeType';
import FunctionNode from './shared/FunctionNode';
import { ExpressionNode, IncludeChildren, Node, NodeBase } from './shared/Node';
export default class AwaitExpression extends NodeBase {
argument!: ExpressionNode;
type!: NodeType.tAwaitExpression;
hasEffects(context: HasEffectsContext) {
return !context.ignore.returnAwaitYield || this.argument.hasEffects(context);
}
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren) {
if (!this.included) {
this.included = true;
checkTopLevelAwait: if (!this.context.usesTopLevelAwait) {
let parent = this.parent;
do {
if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
break checkTopLevelAwait;
} while ((parent = (parent as Node).parent as Node));
this.context.usesTopLevelAwait = true;
}
}
this.argument.include(context, includeChildrenRecursively);
}
}