Reuse Formatter::getModuleName(), fix opts
This commit is contained in:
parent
a37f2093bc
commit
df0e4f6431
@ -81,7 +81,7 @@ File.prototype.getModuleFormatter = function (type) {
|
||||
throw new ReferenceError("unknown module formatter type " + type);
|
||||
}
|
||||
|
||||
return new ModuleFormatter(this, opts);
|
||||
return new ModuleFormatter(this);
|
||||
};
|
||||
|
||||
File.prototype.parseShebang = function (code) {
|
||||
|
||||
@ -5,10 +5,9 @@ var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function AMDFormatter(file, opts) {
|
||||
function AMDFormatter(file) {
|
||||
this.file = file;
|
||||
this.ids = {};
|
||||
this.insertModuleId = opts.amdModuleId;
|
||||
}
|
||||
|
||||
util.inherits(AMDFormatter, CommonJSFormatter);
|
||||
@ -32,10 +31,8 @@ AMDFormatter.prototype.transform = function (ast) {
|
||||
|
||||
var container = t.functionExpression(null, params, t.blockStatement(body));
|
||||
var defineArgs = [names, container];
|
||||
if (this.insertModuleId) {
|
||||
var moduleName = this.getModuleName();
|
||||
defineArgs.unshift(t.literal(moduleName));
|
||||
}
|
||||
var moduleName = this.getModuleName();
|
||||
if (moduleName) defineArgs.unshift(t.literal(moduleName));
|
||||
var call = t.callExpression(t.identifier("define"), defineArgs);
|
||||
|
||||
program.body = [t.expressionStatement(call)];
|
||||
@ -46,6 +43,10 @@ AMDFormatter.prototype.getModuleName = function () {
|
||||
var filenameRelative = opts.filenameRelative;
|
||||
var moduleName = "";
|
||||
|
||||
if (!opts.amdModuleId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (opts.moduleRoot) {
|
||||
moduleName = opts.moduleRoot + "/";
|
||||
}
|
||||
|
||||
@ -32,10 +32,8 @@ UMDFormatter.prototype.transform = function (ast) {
|
||||
// runner
|
||||
|
||||
var defineArgs = [t.arrayExpression([t.literal("exports")].concat(names))];
|
||||
if (this.insertModuleId) {
|
||||
var moduleName = this.getModuleName();
|
||||
defineArgs.unshift(t.literal(moduleName));
|
||||
}
|
||||
var moduleName = this.getModuleName();
|
||||
if (moduleName) defineArgs.unshift(t.literal(moduleName));
|
||||
|
||||
var runner = util.template("umd-runner-body", {
|
||||
AMD_ARGUMENTS: defineArgs,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user