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