/
YieldExpression.ts
39 lines (35 loc) · 1.17 KB
/
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
36
37
38
39
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;
protected deoptimized = false;
hasEffects(context: HasEffectsContext): boolean {
if (!this.deoptimized) this.applyDeoptimizations();
return (
!context.ignore.returnAwaitYield ||
(this.argument !== null && this.argument.hasEffects(context))
);
}
render(code: MagicString, options: RenderOptions): void {
if (this.argument) {
this.argument.render(code, options, { preventASI: true });
if (this.argument.start === this.start + 5 /* 'yield'.length */) {
code.prependLeft(this.start + 5, ' ');
}
}
}
protected applyDeoptimizations(): void {
this.deoptimized = true;
const { argument } = this;
if (argument) {
argument.deoptimizePath(UNKNOWN_PATH);
this.context.requestTreeshakingPass();
}
}
}