1 | var util = require('util');
|
2 |
|
3 | var BlockStatement = module.exports = function(body) {
|
4 | this.type = 'BlockStatement';
|
5 | this.body = body;
|
6 | this.async = false;
|
7 |
|
8 | if (!this.body) {
|
9 | this.body = [];
|
10 | }
|
11 | if (!util.isArray(this.body)) {
|
12 | this.body = [this.body];
|
13 | }
|
14 | for (var i = 0; i < this.body.length; i++) {
|
15 | if (this.body[i].async) {
|
16 | this.async = true;
|
17 | }
|
18 | }
|
19 | };
|
20 |
|
21 | BlockStatement.prototype.normalize = function () {
|
22 | var body = [];
|
23 | for (var i = 0; i < this.body.length; i++) {
|
24 | var statement = this.body[i];
|
25 | if (statement.type === 'ForStatement') {
|
26 | statement.normalize(body);
|
27 | statement = statement.transformedStatement;
|
28 | } else {
|
29 | statement.normalize(body);
|
30 | }
|
31 | this.body[i] = statement;
|
32 | }
|
33 | this.body = body;
|
34 | };
|
35 |
|
36 | BlockStatement.prototype.transform = function () {
|
37 | var newBody = [];
|
38 | var place = newBody;
|
39 | for (var i = 0; i < this.body.length; i++) {
|
40 | var statement = this.body[i];
|
41 | var newPlace = place;
|
42 | newPlace = statement.transform(place);
|
43 | if (newPlace !== place) {
|
44 | place = newPlace;
|
45 | this.async = true;
|
46 | }
|
47 | }
|
48 | this.body = newBody;
|
49 | return place;
|
50 | };
|