forked from rollup/rollup
/
BreakStatement.ts
35 lines (32 loc) · 1.02 KB
/
BreakStatement.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
import {
BROKEN_FLOW_BREAK_CONTINUE,
BROKEN_FLOW_ERROR_RETURN_LABEL,
HasEffectsContext,
InclusionContext
} from '../ExecutionContext';
import Identifier from './Identifier';
import * as NodeType from './NodeType';
import { StatementBase } from './shared/Node';
export default class BreakStatement extends StatementBase {
declare label: Identifier | null;
declare type: NodeType.tBreakStatement;
hasEffects(context: HasEffectsContext): boolean {
if (this.label) {
if (!context.ignore.labels.has(this.label.name)) return true;
context.includedLabels.add(this.label.name);
context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
} else {
if (!context.ignore.breaks) return true;
context.brokenFlow = BROKEN_FLOW_BREAK_CONTINUE;
}
return false;
}
include(context: InclusionContext): void {
this.included = true;
if (this.label) {
this.label.include();
context.includedLabels.add(this.label.name);
}
context.brokenFlow = this.label ? BROKEN_FLOW_ERROR_RETURN_LABEL : BROKEN_FLOW_BREAK_CONTINUE;
}
}