expose moduleName option - closes #158

This commit is contained in:
Sebastian McKenzie
2014-11-14 17:19:39 +11:00
parent 43e2f121a6
commit fdd1451d53
4 changed files with 22 additions and 5 deletions

View File

@@ -15,12 +15,13 @@ util.inherits(AMDFormatter, CommonJSFormatter);
AMDFormatter.prototype.transform = function (ast) {
var program = ast.program;
var body = program.body;
var self = this;
// build an array of module names
var names = [t.literal("exports")];
_.each(this.ids, function (id, name) {
names.push(t.literal(name));
names.push(t.literal(self._moduleName(name)));
});
names = t.arrayExpression(names);

View File

@@ -7,12 +7,21 @@ function CommonJSFormatter(file) {
this.file = file;
}
CommonJSFormatter.prototype._moduleName = function (name) {
var fn = this.file.opts.moduleName;
if (fn) {
return fn(name);
} else {
return name;
}
};
CommonJSFormatter.prototype.import = function (node, nodes) {
// import "foo";
nodes.push(util.template("require", {
//inherits: node,
MODULE_NAME: node.source.raw
MODULE_NAME: this._moduleName(node.source.raw)
}, true));
};
@@ -33,7 +42,7 @@ CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes)
//inherits: node.specifiers.length === 1 && node,
VARIABLE_NAME: variableName,
MODULE_NAME: node.source.raw,
MODULE_NAME: this._moduleName(node.source.raw),
KEY: specifier.id
}));
};

View File

@@ -15,12 +15,13 @@ util.inherits(UMDFormatter, AMDFormatter);
UMDFormatter.prototype.transform = function (ast) {
var program = ast.program;
var body = program.body;
var self = this;
// build an array of module names
var names = [];
_.each(this.ids, function (id, name) {
names.push(t.literal(name));
names.push(t.literal(self._moduleName(name)));
});
// factory