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

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

All files » 6to5/transformation/transformers/ » es6-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 142   142   142 237 12 12 12   225       142   10   10         10 10   10   10 12 12                     10    
var util = require("../../util");
var t    = require("../../types");
 
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 = true;
 
  for (var i in computed) {
    var prop = computed[i];
    containerBody.unshift(
      t.expressionStatement(
        t.assignmentExpression(
          "=",
          t.memberExpression(objId, prop.key, true),
          prop.value
        )
      )
    );
  }
 
  return container;
};