forked from rollup/rollup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYieldExpression.ts
25 lines (22 loc) · 908 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
import type MagicString from 'magic-string';
import type { RenderOptions } from '../../utils/renderHelpers';
import type { HasEffectsContext } from '../ExecutionContext';
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;
hasEffects(context: HasEffectsContext): boolean {
if (!this.deoptimized) this.applyDeoptimizations();
return !(context.ignore.returnYield && !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, ' ');
}
}
}
}