Code coverage report for 6to5/transformation/modules/umd.js

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

All files » 6to5/transformation/modules/ » umd.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 1   1 11 11     1   1 11 11       11 11 12         11 11   11       11       12           11 11    
module.exports = UMDFormatter;
 
var AMDFormatter = require("./amd");
var util         = require("../../util");
var t            = require("../../types");
var _            = require("lodash");
 
function UMDFormatter(file) {
  this.file = file;
  this.ids  = {};
}
 
util.inherits(UMDFormatter, AMDFormatter);
 
UMDFormatter.prototype.transform = function (ast) {
  var program = ast.program;
  var body    = program.body;
 
  // build an array of module names
 
  var names = [];
  _.each(this.ids, function (id, name) {
    names.push(t.literal(name));
  });
 
  // factory
 
  var ids  = _.values(this.ids);
  var args = [t.identifier("exports")].concat(ids);
 
  var factory = t.functionExpression(null, args, t.blockStatement(body));
 
  // runner
 
  var runner = util.template("umd-runner-body", {
    AMD_ARGUMENTS: t.arrayExpression([t.literal("exports")].concat(names)),
 
    COMMON_ARGUMENTS: names.map(function (name) {
      return t.callExpression(t.identifier("require"), [name]);
    })
  });
 
  //
 
  var call = t.callExpression(runner, [factory]);
  program.body = [t.expressionStatement(call)];
};