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

Statements: 100% (25 / 25)      Branches: 100% (2 / 2)      Functions: 100% (3 / 3)      Lines: 100% (24 / 24)      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 48 49 50 511   1 1 1 1   1 13     1   1 13 13       13 13 12         13 13   13       13 13 13   13       12           13 13    
module.exports = UMDFormatter;
 
var AMDFormatter = require("./amd");
var util         = require("../../util");
var t            = require("../../types");
var _            = require("lodash");
 
function UMDFormatter() {
  AMDFormatter.apply(this, arguments);
}
 
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 = [];
  for (var name in this.ids) {
    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 defineArgs = [t.arrayExpression([t.literal("exports")].concat(names))];
  var moduleName = this.getModuleName();
  if (moduleName) defineArgs.unshift(t.literal(moduleName));
 
  var runner = util.template("umd-runner-body", {
    AMD_ARGUMENTS: defineArgs,
 
    COMMON_ARGUMENTS: names.map(function (name) {
      return t.callExpression(t.identifier("require"), [name]);
    })
  });
 
  //
 
  var call = t.callExpression(runner, [factory]);
  program.body = [t.expressionStatement(call)];
};