make system module formatter modules anonymous by default - fixes #347

This commit is contained in:
Sebastian McKenzie
2014-12-29 01:55:30 +11:00
parent d4fbfbbe47
commit 52ffc65a06
6 changed files with 18 additions and 11 deletions

View File

@@ -35,6 +35,7 @@ File.normaliseOptions = function (opts) {
experimental: false,
playground: false,
whitespace: true,
moduleIds: opts.amdModuleIds || false,
blacklist: [],
whitelist: [],
sourceMap: false,

View File

@@ -55,7 +55,7 @@ AMDFormatter.prototype.transform = function (ast) {
*/
AMDFormatter.prototype.getModuleName = function () {
if (this.file.opts.amdModuleIds) {
if (this.file.opts.moduleIds) {
return DefaultFormatter.prototype.getModuleName.apply(this, arguments);
} else {
return null;

View File

@@ -12,14 +12,10 @@ function SystemFormatter(file) {
this.noInteropRequire = true;
AMDFormatter.apply(this, arguments);
this.moduleNameLiteral = t.literal(this.getModuleName());
}
util.inherits(SystemFormatter, AMDFormatter);
SystemFormatter.prototype.getModuleName = DefaultFormatter.prototype.getModuleName;
SystemFormatter.prototype._exportsWildcard = function (objectIdentifier) {
var leftIdentifier = t.identifier("i");
var valIdentifier = t.memberExpression(objectIdentifier, leftIdentifier, true);
@@ -67,8 +63,11 @@ SystemFormatter.prototype.buildRunnerSetters = function () {
SystemFormatter.prototype.transform = function (ast) {
var program = ast.program;
var moduleName = this.getModuleName();
var moduleNameLiteral = t.literal(moduleName);
var runner = util.template("system", {
MODULE_NAME: this.moduleNameLiteral,
MODULE_NAME: moduleNameLiteral,
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()),
EXPORT_IDENTIFIER: this.exportIdentifier,
SETTERS: this.buildRunnerSetters(),
@@ -76,6 +75,8 @@ SystemFormatter.prototype.transform = function (ast) {
}, true);
var handlerBody = runner.expression.arguments[2].body.body;
if (!moduleName) runner.expression.arguments.shift();
var returnStatement = handlerBody.pop();
// hoist up function declarations for circular references