-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ThrowStatement.ts
27 lines (23 loc) · 928 Bytes
/
ThrowStatement.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
import MagicString from 'magic-string';
import { RenderOptions } from '../../utils/renderHelpers';
import { BROKEN_FLOW_ERROR_RETURN_LABEL, InclusionContext } from '../ExecutionContext';
import * as NodeType from './NodeType';
import { ExpressionNode, IncludeChildren, StatementBase } from './shared/Node';
export default class ThrowStatement extends StatementBase {
argument!: ExpressionNode;
type!: NodeType.tThrowStatement;
hasEffects() {
return true;
}
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren) {
this.included = true;
this.argument.include(context, includeChildrenRecursively);
context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
}
render(code: MagicString, options: RenderOptions) {
this.argument.render(code, options, { preventASI: true });
if (this.argument.start === this.start + 5 /* 'throw'.length */) {
code.prependLeft(this.start + 5, ' ');
}
}
}