From 50333c879cebb4958a0f5af8306b13cb03a5257a Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 16 Nov 2014 19:18:56 +1100 Subject: [PATCH] add comments and change single quotes in amd formatter getModuleName --- lib/6to5/transformation/modules/amd.js | 24 +++++++++++++----------- lib/6to5/transformation/modules/umd.js | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/6to5/transformation/modules/amd.js b/lib/6to5/transformation/modules/amd.js index 098c67e8ef..d6e3f50d71 100644 --- a/lib/6to5/transformation/modules/amd.js +++ b/lib/6to5/transformation/modules/amd.js @@ -29,7 +29,7 @@ AMDFormatter.prototype.transform = function (ast) { var params = _.values(this.ids); params.unshift(t.identifier("exports")); - var moduleName = this.getModuleName(this.file); + 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]); @@ -37,26 +37,28 @@ AMDFormatter.prototype.transform = function (ast) { program.body = [t.expressionStatement(call)]; }; -AMDFormatter.prototype.getModuleName = function (file) { - var opts = file.opts, - filenameRelative = opts.filenameRelative, - sourceRootRegEx, - moduleName; +AMDFormatter.prototype.getModuleName = function () { + var opts = this.file.opts; + var filenameRelative = opts.filenameRelative; + var moduleName = ""; if (opts.moduleRoot) { - moduleName = opts.moduleRoot + '/'; + moduleName = opts.moduleRoot + "/"; } if (!opts.filenameRelative) { - return moduleName + opts.filename.replace(/^\//, ''); + return moduleName + opts.filename.replace(/^\//, ""); } if (opts.sourceRoot) { - sourceRootRegEx = new RegExp('^' + opts.sourceRoot + '\/?'); - filenameRelative = filenameRelative.replace(sourceRootRegEx, ''); + // remove sourceRoot from filename + var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?"); + filenameRelative = filenameRelative.replace(sourceRootRegEx, ""); } - filenameRelative = filenameRelative.replace(/\.js$/, ''); + // remove extension + filenameRelative = filenameRelative.replace(/\.(.*?)$/, ""); + moduleName += filenameRelative; return moduleName; diff --git a/lib/6to5/transformation/modules/umd.js b/lib/6to5/transformation/modules/umd.js index 1da118ed1d..ea2f668a8e 100644 --- a/lib/6to5/transformation/modules/umd.js +++ b/lib/6to5/transformation/modules/umd.js @@ -32,7 +32,7 @@ UMDFormatter.prototype.transform = function (ast) { // runner - var moduleName = this.getModuleName(this.file); + var moduleName = this.getModuleName(); var runner = util.template("umd-runner-body", { AMD_ARGUMENTS: [t.literal(moduleName), t.arrayExpression([t.literal("exports")].concat(names))],