1 | var Literal = require('./Literal');
|
2 | var BlockStatement = require('./BlockStatement');
|
3 | var WhileStatement = require('./WhileStatement');
|
4 | var ExpressionStatement = require('./ExpressionStatement');
|
5 | var VariableDeclaration = require('./VariableDeclaration');
|
6 |
|
7 | var ForStatement = module.exports = function(init, test, update, body) {
|
8 | this.type = 'ForStatement';
|
9 | this.init = init;
|
10 | this.test = test;
|
11 | this.update = update;
|
12 | this.body = body;
|
13 | };
|
14 |
|
15 | ForStatement.prototype.normalize = function (place) {
|
16 | if (this.body === null) {
|
17 | this.body = new BlockStatement([]);
|
18 | } else if (this.body.type !== 'BlockStatement') {
|
19 | this.body = new BlockStatement([this.body]);
|
20 | }
|
21 |
|
22 | if (this.test === null) {
|
23 | this.test = new Literal(true);
|
24 | }
|
25 |
|
26 | if (this.update !== null) {
|
27 | this.body.body.push(new ExpressionStatement(this.update));
|
28 | }
|
29 |
|
30 | if (this.init !== null) {
|
31 | if (this.init.type === 'AssignmentExpression') {
|
32 | this.init = new ExpressionStatement(this.init);
|
33 | }
|
34 | place.push(this.init);
|
35 | }
|
36 |
|
37 | var whileStatement = new WhileStatement(this.test, this.body);
|
38 | whileStatement.normalize(place);
|
39 | this.transformedStatement = whileStatement;
|
40 | }
|