use :node;

var Node = module.require('../Node').Node;

fn BlockStatement(body)

extends Node {

this.type = 'BlockStatement';
this.body = body;

for statement, i in body {
  if statement {
    statement.parent = this;
  } else {
    body[i] = { type: 'EmptyStatement' };
  }
}

}

BlockStatement.prototype.codegen = () -> {

if !super.codegen() {
  return;
}

var i = 0;
while (i < this.body.length) {
  var statement = this.body[i];

  if !statement || statement.codeGenerated {
    i++;
    continue;
  }

  if statement.codegen?() {
    this.body[this.body.indexOf(statement)] = statement;
    i++;
  } else {
    this.body.splice(i, 1);
  }
}

return this;

};

exports.BlockStatement = BlockStatement;