-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
ForStatement.ts
36 lines (32 loc) · 1.29 KB
/
ForStatement.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
import MagicString from 'magic-string';
import { NO_SEMICOLON, RenderOptions } from '../../utils/renderHelpers';
import { ExecutionPathOptions } from '../ExecutionPathOptions';
import BlockScope from '../scopes/BlockScope';
import Scope from '../scopes/Scope';
import * as NodeType from './NodeType';
import { ExpressionNode, StatementBase, StatementNode } from './shared/Node';
import VariableDeclaration from './VariableDeclaration';
export default class ForStatement extends StatementBase {
body: StatementNode;
init: VariableDeclaration | ExpressionNode | null;
test: ExpressionNode | null;
type: NodeType.tForStatement;
update: ExpressionNode | null;
createScope(parentScope: Scope) {
this.scope = new BlockScope(parentScope);
}
hasEffects(options: ExecutionPathOptions): boolean {
return (
(this.init && this.init.hasEffects(options)) ||
(this.test && this.test.hasEffects(options)) ||
(this.update && this.update.hasEffects(options)) ||
this.body.hasEffects(options.setIgnoreBreakStatements())
);
}
render(code: MagicString, options: RenderOptions) {
if (this.init) this.init.render(code, options, NO_SEMICOLON);
if (this.test) this.test.render(code, options, NO_SEMICOLON);
if (this.update) this.update.render(code, options, NO_SEMICOLON);
this.body.render(code, options);
}
}