-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
YieldExpression.ts
35 lines (31 loc) · 1000 Bytes
/
YieldExpression.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
import MagicString from 'magic-string';
import { RenderOptions } from '../../utils/renderHelpers';
import { HasEffectsContext } from '../ExecutionContext';
import { UNKNOWN_PATH } from '../utils/PathTracker';
import * as NodeType from './NodeType';
import { ExpressionNode, NodeBase } from './shared/Node';
export default class YieldExpression extends NodeBase {
argument!: ExpressionNode | null;
delegate!: boolean;
type!: NodeType.tYieldExpression;
bind() {
super.bind();
if (this.argument !== null) {
this.argument.deoptimizePath(UNKNOWN_PATH);
}
}
hasEffects(context: HasEffectsContext) {
return (
!context.ignore.returnAwaitYield ||
(this.argument !== null && this.argument.hasEffects(context))
);
}
render(code: MagicString, options: RenderOptions) {
if (this.argument) {
this.argument.render(code, options, { preventASI: true });
if (this.argument.start === this.start + 5 /* 'yield'.length */) {
code.prependLeft(this.start + 5, ' ');
}
}
}
}