Code coverage report for 6to5/lib/6to5/transformation/transformers/_block-hoist.js

Statements: 100% (19 / 19)      Branches: 100% (10 / 10)      Functions: 100% (3 / 3)      Lines: 100% (15 / 15)      Ignored: none     

All files » 6to5/lib/6to5/transformation/transformers/ » _block-hoist.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 331 1                 1     65723 65723 141209 141209   65723   34 34 228 228 228 228     34        
var useStrict = require("./use-strict");
var _         = require("lodash");
 
// Priority:
//
//  - 0 We want this to be at the **very** bottom
//  - 1 Default node position
//  - 2 Priority over normal nodes
//  - 3 We want this to be at the **very** top
 
exports.BlockStatement =
exports.Program = {
  exit: function (node) {
    var hasChange = false;
    for (var i in node.body) {
      var bodyNode = node.body[i];
      if (bodyNode && bodyNode._blockHoist != null) hasChange = true;
    }
    if (!hasChange) return;
 
    useStrict._wrap(node, function () {
      var nodePriorities = _.groupBy(node.body, function (bodyNode) {
        var priority = bodyNode._blockHoist;
        if (priority == null) priority = 1;
        if (priority === true) priority = 2;
        return priority;
      });
 
      node.body = _.flatten(_.values(nodePriorities).reverse());
    });
  }
};