Merge pull request #190 from webpro/amd-module-id
Make AMD module id's optional
This commit is contained in:
@@ -11,7 +11,7 @@ var _ = require("lodash");
|
||||
|
||||
function File(opts) {
|
||||
this.opts = File.normaliseOptions(opts);
|
||||
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
this.moduleFormatter = this.getModuleFormatter(this.opts.modules, this.opts);
|
||||
|
||||
this.declarations = {};
|
||||
this.uids = {};
|
||||
|
||||
@@ -29,10 +29,11 @@ AMDFormatter.prototype.transform = function (ast) {
|
||||
var params = _.values(this.ids);
|
||||
params.unshift(t.identifier("exports"));
|
||||
|
||||
var moduleName = this.getModuleName();
|
||||
|
||||
var container = t.functionExpression(null, params, t.blockStatement(body));
|
||||
var call = t.callExpression(t.identifier("define"), [t.literal(moduleName), names, container]);
|
||||
var defineArgs = [names, container];
|
||||
var moduleName = this.getModuleName();
|
||||
if (moduleName) defineArgs.unshift(t.literal(moduleName));
|
||||
var call = t.callExpression(t.identifier("define"), defineArgs);
|
||||
|
||||
program.body = [t.expressionStatement(call)];
|
||||
};
|
||||
@@ -42,6 +43,10 @@ AMDFormatter.prototype.getModuleName = function () {
|
||||
var filenameRelative = opts.filenameRelative;
|
||||
var moduleName = "";
|
||||
|
||||
if (!opts.amdModuleIds) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (opts.moduleRoot) {
|
||||
moduleName = opts.moduleRoot + "/";
|
||||
}
|
||||
|
||||
@@ -31,10 +31,12 @@ UMDFormatter.prototype.transform = function (ast) {
|
||||
|
||||
// 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: [t.literal(moduleName), t.arrayExpression([t.literal("exports")].concat(names))],
|
||||
AMD_ARGUMENTS: defineArgs,
|
||||
|
||||
COMMON_ARGUMENTS: names.map(function (name) {
|
||||
return t.callExpression(t.identifier("require"), [name]);
|
||||
|
||||
Reference in New Issue
Block a user