Code coverage report for 6to5/transformers/computed-property-names.js

Statements: 100% (22 / 22)      Branches: 100% (4 / 4)      Functions: 100% (3 / 3)      Lines: 100% (21 / 21)      Ignored: none     

All files » 6to5/transformers/ » computed-property-names.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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 481 1 1   1 34   34   34 41 10 10 10   31       34   8   8         8 8   8   8 10                     8    
var util = require("../util");
var b    = require("recast").types.builders;
var _    = require("lodash");
 
exports.ObjectExpression = function (node, parent, file) {
  var hasComputed = false;
 
  var computed = [];
 
  node.properties = node.properties.filter(function (prop) {
    if (prop.computed) {
      hasComputed = true;
      computed.unshift(prop);
      return false;
    } else {
      return true;
    }
  });
 
  if (!hasComputed) return;
 
  var objId = util.getUid(parent, file);
 
  var container = util.template("function-return-obj", {
    KEY: objId,
    OBJECT: node
  });
 
  var containerCallee = container.callee;
  var containerBody = containerCallee.body.body;
 
  containerCallee._aliasFunction = "arrows";
 
  _.each(computed, function (prop) {
    containerBody.unshift(
      b.expressionStatement(
        b.assignmentExpression(
          "=",
          b.memberExpression(objId, prop.key, true),
          prop.value
        )
      )
    );
  });
 
  return container;
};