forked from rollup/rollup
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathYieldExpression.ts
More file actions
37 lines (32 loc) · 1.23 KB
/
YieldExpression.ts
File metadata and controls
37 lines (32 loc) · 1.23 KB
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
import type MagicString from 'magic-string';
import type { RenderOptions } from '../../utils/renderHelpers';
import type { HasEffectsContext, InclusionContext } from '../ExecutionContext';
import { UNKNOWN_PATH } from '../utils/PathTracker';
import type * as NodeType from './NodeType';
import { type ExpressionNode, NodeBase } from './shared/Node';
export default class YieldExpression extends NodeBase {
declare argument: ExpressionNode | null;
declare delegate: boolean;
declare type: NodeType.tYieldExpression;
applyDeoptimizations() {
this.deoptimized = true;
this.argument?.deoptimizePath(UNKNOWN_PATH);
}
hasEffects(context: HasEffectsContext): boolean {
if (!this.deoptimized) this.applyDeoptimizations();
return !(context.ignore.returnYield && !this.argument?.hasEffects(context));
}
includeNode(context: InclusionContext) {
this.included = true;
if (!this.deoptimized) this.applyDeoptimizations();
this.argument?.includePath(UNKNOWN_PATH, 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, ' ');
}
}
}
}