From 2be2e4e1aefd93f8ce1fb0fea65899f2601c5159 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sat, 18 Oct 2014 15:46:15 +1100 Subject: [PATCH] simplify bin/6to5 util methods and fix double compilation bug with eval in 6to5-node --- bin/6to5-node | 4 +--- bin/6to5/dir.js | 2 +- bin/6to5/file.js | 4 ++-- bin/6to5/util.js | 10 +++++----- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/bin/6to5-node b/bin/6to5-node index c55ff4eda0..c79ce0e17d 100755 --- a/bin/6to5-node +++ b/bin/6to5-node @@ -41,9 +41,7 @@ var _eval = function (code, filename) { }; if (commander.eval) { - var code = to5.transform(commander.eval, { filename: "eval" }).code; - - var result = _eval(code, "eval"); + var result = _eval(commander.eval, "eval"); if (commander.print) console.log(result); } else { var filenames = commander.args; diff --git a/bin/6to5/dir.js b/bin/6to5/dir.js index 90860077f0..9854f33472 100644 --- a/bin/6to5/dir.js +++ b/bin/6to5/dir.js @@ -13,7 +13,7 @@ module.exports = function (commander, filenames, opts) { var write = function (src, relative) { var dest = path.join(commander.outDir, relative); - var data = util.compile(src, dest); + var data = util.compile(src, { sourceMapName: dest }); var up = path.normalize(dest + "/.."); mkdirp.sync(up); diff --git a/bin/6to5/file.js b/bin/6to5/file.js index 34a6e796ea..1afc7587a2 100644 --- a/bin/6to5/file.js +++ b/bin/6to5/file.js @@ -100,8 +100,8 @@ module.exports = function (commander, filenames, opts) { } }); - _.each(_filenames, function (filename) { - results.push(util.compile(filename)); + _.each(_filenames, function (filename, i) { + results.push(util.compile(filename, { _noStrict: i != 0 })); }); output(); diff --git a/bin/6to5/util.js b/bin/6to5/util.js index ccec63ee7d..367f6326c3 100644 --- a/bin/6to5/util.js +++ b/bin/6to5/util.js @@ -9,9 +9,9 @@ exports.readdirFilter = function (filename) { return readdir(filename).filter(util.canCompile); }; -exports.transform = function (filename, code, to) { - var opts = _.extend({ filename: filename }, index.opts); - if (to) opts.sourceMapName = to; +exports.transform = function (filename, code, opts) { + opts = _.extend(opts || {}, index.opts); + opts.filename = filename; var result = to5.transform(code, opts); result.filename = filename; @@ -19,7 +19,7 @@ exports.transform = function (filename, code, to) { return result; }; -exports.compile = function (filename, to) { +exports.compile = function (filename, opts) { var code = fs.readFileSync(filename, "utf8"); - return exports.transform(filename, code, to); + return exports.transform(filename, code, opts); };