/
WhileStatement.ts
30 lines (27 loc) · 1018 Bytes
/
WhileStatement.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
import { HasEffectsContext, InclusionContext } from '../ExecutionContext';
import * as NodeType from './NodeType';
import { ExpressionNode, IncludeChildren, StatementBase, StatementNode } from './shared/Node';
export default class WhileStatement extends StatementBase {
body!: StatementNode;
test!: ExpressionNode;
type!: NodeType.tWhileStatement;
hasEffects(context: HasEffectsContext): boolean {
if (this.test.hasEffects(context)) return true;
const {
breakFlow,
ignore: { breakAndContinue }
} = context;
context.ignore.breakAndContinue = true;
if (this.body.hasEffects(context)) return true;
context.ignore.breakAndContinue = breakAndContinue;
context.breakFlow = breakFlow;
return false;
}
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren) {
this.included = true;
this.test.include(context, includeChildrenRecursively);
const { breakFlow } = context;
this.body.include(context, includeChildrenRecursively);
context.breakFlow = breakFlow;
}
}