1 | var BlockStatement = require('./BlockStatement');
|
2 | var VariableDeclaration = require('./VariableDeclaration');
|
3 | var helpers = require('../helpers');
|
4 |
|
5 | var WhileStatement = module.exports = function(test, body) {
|
6 | this.type = 'WhileStatement';
|
7 | this.test = test;
|
8 | this.body = body;
|
9 | };
|
10 |
|
11 | WhileStatement.prototype.normalize = function (place) {
|
12 | if (this.body === null) {
|
13 | this.body = new BlockStatement([]);
|
14 | } else if (this.body.type !== 'BlockStatement') {
|
15 | this.body = new BlockStatement([this.body]);
|
16 | }
|
17 |
|
18 | this.body.normalize();
|
19 |
|
20 |
|
21 | var declarations = [];
|
22 | helpers.extractVariableDeclarations(this.body, declarations);
|
23 | declarations = helpers.reduceDeclarations(declarations);
|
24 | if (declarations.length > 0) {
|
25 | place.push(new VariableDeclaration(declarations, 'var'));
|
26 | }
|
27 | place.push(this);
|
28 | };
|