lib/optimiser.js
function combineContiguousOutputStatements (ast) {
  traverse.traverse(ast, {
    enter: function (node, parent) {
      if (node.type !== 'BlockStatement') {
        return;
      }
      var prev = false;

      node.body = fast.reduce(node.body, function (body, statement) {
        if (
          !body.length ||
          statement.type !== 'ExpressionStatement' ||
          statement.expression.type !== 'AssignmentExpression' ||
          statement.expression.operator !== '+=' ||
          statement.expression.left.type !== 'Identifier' ||
          statement.expression.left.name !== 'html'
        ) {
          prev = false;
          body.push(statement);
          return body;
        }
        else if (!prev) {
          prev = statement;
          body.push(statement);
          return body;
        }
        prev.expression.right = {
          type: 'BinaryExpression',
          operator: '+',
          left: prev.expression.right,
          right: statement.expression.right
        };
        return body;
      }, []);
    }
  });
  return ast;
}
function combineContiguousOutputStatements (ast) {
  traverse.traverse(ast, {
    enter: function (node, parent) {
      if (node.type !== 'BlockStatement') {
        return;
      }
      var prev = false;

      node.body = fast.reduce(node.body, function (body, statement) {
        if (
          !body.length ||
          statement.type !== 'ExpressionStatement' ||
          statement.expression.type !== 'AssignmentExpression' ||
          statement.expression.operator !== '+=' ||
          statement.expression.left.type !== 'Identifier' ||
          statement.expression.left.name !== 'html'
        ) {
          prev = false;
          body.push(statement);
          return body;
        }
        else if (!prev) {
          prev = statement;
          body.push(statement);
          return body;
        }
        prev.expression.right = {
          type: 'BinaryExpression',
          operator: '+',
          left: prev.expression.right,
          right: statement.expression.right
        };
        return body;
      }, []);
    }
  });
  return ast;
}
function combineContiguousOutputStatements ( ast ) { traverse . traverse ( ast , { enter : function ( node , parent ) { if ( node . type !== 'BlockStatement' ) { return ; } var prev = false ; node . body = fast . reduce ( node . body , function ( body , statement ) { if ( ! body . length || statement . type !== 'ExpressionStatement' || statement . expression . type !== 'AssignmentExpression' || statement . expression . operator !== '+=' || statement . expression . left . type !== 'Identifier' || statement . expression . left . name !== 'html' ) { prev = false ; body . push ( statement ) ; return body ; } else if ( ! prev ) { prev = statement ; body . push ( statement ) ; return body ; } prev . expression . right = { type : 'BinaryExpression' , operator : '+' , left : prev . expression . right , right : statement . expression . right } ; return body ; } , [ ] ) ; } } ) ; return ast ; }
Turn sequential OutputStatements into one big one.
Turn sequential OutputStatements into one big one .