forked from rollup/rollup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReturnStatement.ts
37 lines (32 loc) · 1.29 KB
/
ReturnStatement.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
import type MagicString from 'magic-string';
import type { RenderOptions } from '../../utils/renderHelpers';
import { type HasEffectsContext, type InclusionContext } from '../ExecutionContext';
import type * as NodeType from './NodeType';
import { UNKNOWN_EXPRESSION } from './shared/Expression';
import { type ExpressionNode, type IncludeChildren, StatementBase } from './shared/Node';
export default class ReturnStatement extends StatementBase {
declare argument: ExpressionNode | null;
declare type: NodeType.tReturnStatement;
hasEffects(context: HasEffectsContext): boolean {
if (!context.ignore.returnYield || this.argument?.hasEffects(context)) return true;
context.brokenFlow = true;
return false;
}
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
this.included = true;
this.argument?.include(context, includeChildrenRecursively);
context.brokenFlow = true;
}
initialise(): void {
super.initialise();
this.scope.addReturnExpression(this.argument || UNKNOWN_EXPRESSION);
}
render(code: MagicString, options: RenderOptions): void {
if (this.argument) {
this.argument.render(code, options, { preventASI: true });
if (this.argument.start === this.start + 6 /* 'return'.length */) {
code.prependLeft(this.start + 6, ' ');
}
}
}
}