diff --git a/bin/6to5 b/bin/6to5 index 79618ffb93..6629d551e8 100755 --- a/bin/6to5 +++ b/bin/6to5 @@ -69,17 +69,19 @@ var mainOpts = { var data = []; -var transform = function (filename, code) { +var transform = function (filename, code, to) { var opts = _.extend({ filename: filename }, mainOpts); + if (to) opts.sourceMapName = to; + var result = to5.transform(code, opts); result.filename = filename; result.actual = code; return result; }; -var compile = function (filename) { +var compile = function (filename, to) { var code = fs.readFileSync(filename, "utf8"); - return transform(filename, code); + return transform(filename, code, to); }; if (commander.outDir) { @@ -88,10 +90,10 @@ if (commander.outDir) { } var write = function (src, relative) { - var data = compile(src); - var dest = path.join(commander.outDir, relative); + var data = compile(src, dest); + var up = path.normalize(dest + "/.."); mkdirp.sync(up); diff --git a/test/bin-fixtures/6to5-node/--eval/options.json b/test/bin-fixtures/6to5-node/--eval/options.json new file mode 100644 index 0000000000..09d27772df --- /dev/null +++ b/test/bin-fixtures/6to5-node/--eval/options.json @@ -0,0 +1,4 @@ +{ + "args": ["--eval", "console.log([1, 2, 3].map(x => x * x));"], + "stdout": "[ 1, 4, 9 ]" +} diff --git a/test/bin-fixtures/6to5-node/--print/options.json b/test/bin-fixtures/6to5-node/--print/options.json new file mode 100644 index 0000000000..df235fd4d2 --- /dev/null +++ b/test/bin-fixtures/6to5-node/--print/options.json @@ -0,0 +1,4 @@ +{ + "args": ["--print", "--eval", "([1, 2, 3].map(x => x * x))"], + "stdout": "[ 1, 4, 9 ]" +} diff --git a/test/bin-fixtures/6to5-node/directory/in-files/foo/index.js b/test/bin-fixtures/6to5-node/directory/in-files/foo/index.js new file mode 100644 index 0000000000..6cbc6fbcfb --- /dev/null +++ b/test/bin-fixtures/6to5-node/directory/in-files/foo/index.js @@ -0,0 +1,2 @@ +var foo = () => console.log("foo"); +foo(); diff --git a/test/bin-fixtures/6to5-node/directory/options.json b/test/bin-fixtures/6to5-node/directory/options.json new file mode 100644 index 0000000000..36b991ad38 --- /dev/null +++ b/test/bin-fixtures/6to5-node/directory/options.json @@ -0,0 +1,3 @@ +{ + "args": ["foo"] +} diff --git a/test/bin-fixtures/6to5-node/directory/stdout.txt b/test/bin-fixtures/6to5-node/directory/stdout.txt new file mode 100644 index 0000000000..257cc5642c --- /dev/null +++ b/test/bin-fixtures/6to5-node/directory/stdout.txt @@ -0,0 +1 @@ +foo diff --git a/test/bin-fixtures/6to5-node/filename/in-files/foo.js b/test/bin-fixtures/6to5-node/filename/in-files/foo.js new file mode 100644 index 0000000000..6cbc6fbcfb --- /dev/null +++ b/test/bin-fixtures/6to5-node/filename/in-files/foo.js @@ -0,0 +1,2 @@ +var foo = () => console.log("foo"); +foo(); diff --git a/test/bin-fixtures/6to5-node/filename/options.json b/test/bin-fixtures/6to5-node/filename/options.json new file mode 100644 index 0000000000..36b991ad38 --- /dev/null +++ b/test/bin-fixtures/6to5-node/filename/options.json @@ -0,0 +1,3 @@ +{ + "args": ["foo"] +} diff --git a/test/bin-fixtures/6to5-node/filename/stdout.txt b/test/bin-fixtures/6to5-node/filename/stdout.txt new file mode 100644 index 0000000000..257cc5642c --- /dev/null +++ b/test/bin-fixtures/6to5-node/filename/stdout.txt @@ -0,0 +1 @@ +foo diff --git a/test/bin-fixtures/6to5-node/filenames/in-files/bar.js b/test/bin-fixtures/6to5-node/filenames/in-files/bar.js new file mode 100644 index 0000000000..5e0f4fd877 --- /dev/null +++ b/test/bin-fixtures/6to5-node/filenames/in-files/bar.js @@ -0,0 +1,2 @@ +var bar = () => console.log("bar"); +bar(); diff --git a/test/bin-fixtures/6to5-node/filenames/in-files/foo.js b/test/bin-fixtures/6to5-node/filenames/in-files/foo.js new file mode 100644 index 0000000000..6cbc6fbcfb --- /dev/null +++ b/test/bin-fixtures/6to5-node/filenames/in-files/foo.js @@ -0,0 +1,2 @@ +var foo = () => console.log("foo"); +foo(); diff --git a/test/bin-fixtures/6to5-node/filenames/options.json b/test/bin-fixtures/6to5-node/filenames/options.json new file mode 100644 index 0000000000..4caf67b360 --- /dev/null +++ b/test/bin-fixtures/6to5-node/filenames/options.json @@ -0,0 +1,3 @@ +{ + "args": ["foo", "bar"] +} diff --git a/test/bin-fixtures/6to5-node/filenames/stdout.txt b/test/bin-fixtures/6to5-node/filenames/stdout.txt new file mode 100644 index 0000000000..3bd1f0e297 --- /dev/null +++ b/test/bin-fixtures/6to5-node/filenames/stdout.txt @@ -0,0 +1,2 @@ +foo +bar diff --git a/test/bin-fixtures/6to5-node/require/in-files/bar.js b/test/bin-fixtures/6to5-node/require/in-files/bar.js new file mode 100644 index 0000000000..5e0f4fd877 --- /dev/null +++ b/test/bin-fixtures/6to5-node/require/in-files/bar.js @@ -0,0 +1,2 @@ +var bar = () => console.log("bar"); +bar(); diff --git a/test/bin-fixtures/6to5-node/require/in-files/foo.js b/test/bin-fixtures/6to5-node/require/in-files/foo.js new file mode 100644 index 0000000000..93e493942c --- /dev/null +++ b/test/bin-fixtures/6to5-node/require/in-files/foo.js @@ -0,0 +1,4 @@ +var foo = () => console.log("foo"); +foo(); + +import "./bar"; diff --git a/test/bin-fixtures/6to5-node/require/options.json b/test/bin-fixtures/6to5-node/require/options.json new file mode 100644 index 0000000000..36b991ad38 --- /dev/null +++ b/test/bin-fixtures/6to5-node/require/options.json @@ -0,0 +1,3 @@ +{ + "args": ["foo"] +} diff --git a/test/bin-fixtures/6to5-node/require/stdout.txt b/test/bin-fixtures/6to5-node/require/stdout.txt new file mode 100644 index 0000000000..3bd1f0e297 --- /dev/null +++ b/test/bin-fixtures/6to5-node/require/stdout.txt @@ -0,0 +1,2 @@ +foo +bar diff --git a/test/bin-fixtures/6to5/--blacklist/options.json b/test/bin-fixtures/6to5/--blacklist/options.json new file mode 100644 index 0000000000..2a2e8ffde1 --- /dev/null +++ b/test/bin-fixtures/6to5/--blacklist/options.json @@ -0,0 +1,3 @@ +{ + "args": ["--blacklist", "arrowFunctions"] +} diff --git a/test/bin-fixtures/6to5/blacklist/stdin.js b/test/bin-fixtures/6to5/--blacklist/stdin.txt similarity index 100% rename from test/bin-fixtures/6to5/blacklist/stdin.js rename to test/bin-fixtures/6to5/--blacklist/stdin.txt diff --git a/test/bin-fixtures/6to5/blacklist/stdout.js b/test/bin-fixtures/6to5/--blacklist/stdout.txt similarity index 100% rename from test/bin-fixtures/6to5/blacklist/stdout.js rename to test/bin-fixtures/6to5/--blacklist/stdout.txt diff --git a/test/bin-fixtures/6to5/--whitelist/options.json b/test/bin-fixtures/6to5/--whitelist/options.json new file mode 100644 index 0000000000..9528c05503 --- /dev/null +++ b/test/bin-fixtures/6to5/--whitelist/options.json @@ -0,0 +1,3 @@ +{ + "args": ["--whitelist", "arrowFunctions"] +} diff --git a/test/bin-fixtures/6to5/out-file/stdin.js b/test/bin-fixtures/6to5/--whitelist/stdin.txt similarity index 100% rename from test/bin-fixtures/6to5/out-file/stdin.js rename to test/bin-fixtures/6to5/--whitelist/stdin.txt diff --git a/test/bin-fixtures/6to5/whitelist/stdout.js b/test/bin-fixtures/6to5/--whitelist/stdout.txt similarity index 100% rename from test/bin-fixtures/6to5/whitelist/stdout.js rename to test/bin-fixtures/6to5/--whitelist/stdout.txt diff --git a/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/in-files/src/bar/bar.js b/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/in-files/src/bar/bar.js new file mode 100644 index 0000000000..45842c5e26 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/in-files/src/bar/bar.js @@ -0,0 +1,3 @@ +class Test { + +} diff --git a/test/bin-fixtures/6to5/whitelist/stdin.js b/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/in-files/src/foo.js similarity index 61% rename from test/bin-fixtures/6to5/whitelist/stdin.js rename to test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/in-files/src/foo.js index 030f13f9fa..4bc9539528 100644 --- a/test/bin-fixtures/6to5/whitelist/stdin.js +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/in-files/src/foo.js @@ -1,2 +1 @@ -let MULTIPLER = 5; arr.map(x => x * MULTIPLIER); diff --git a/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/options.json b/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/options.json new file mode 100644 index 0000000000..c1a895be21 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/options.json @@ -0,0 +1,3 @@ +{ + "args": ["src", "--source-maps-inline", "--out-dir", "lib"] +} diff --git a/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/out-files/lib/bar/bar.js b/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/out-files/lib/bar/bar.js new file mode 100644 index 0000000000..c74c6a104b --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/out-files/lib/bar/bar.js @@ -0,0 +1,5 @@ +var Test = function() { + function Test() {} + return Test; +}(); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGliL2Jhci9iYXIuanMiLCJzb3VyY2VzIjpbInNyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJJQUFNLENBQUMsQ0FBQyxDQUFDO1dBQUgsQ0FBQyxDQUFDLENBQUM7U0FBSCxDQUFDLENBQUMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIFRlc3Qge1xuXG59Il19 diff --git a/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/out-files/lib/foo.js b/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/out-files/lib/foo.js new file mode 100644 index 0000000000..dd723202cc --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/out-files/lib/foo.js @@ -0,0 +1,4 @@ +arr.map(function(x) { + return x * MULTIPLIER; +}); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGliL2Zvby5qcyIsInNvdXJjZXMiOlsic3JjL2Zvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLFVBQUM7U0FBSyxFQUFFLEVBQUUsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7Q0FBQyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0= diff --git a/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/stdout.txt b/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/stdout.txt new file mode 100644 index 0000000000..a3d53cf84a --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps-inline/stdout.txt @@ -0,0 +1,2 @@ +src/bar/bar.js -> lib/bar/bar.js +src/foo.js -> lib/foo.js diff --git a/test/bin-fixtures/6to5/dir --out-dir --source-maps/in-files/src/bar/bar.js b/test/bin-fixtures/6to5/dir --out-dir --source-maps/in-files/src/bar/bar.js new file mode 100644 index 0000000000..45842c5e26 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps/in-files/src/bar/bar.js @@ -0,0 +1,3 @@ +class Test { + +} diff --git a/test/bin-fixtures/6to5/dir --out-dir --source-maps/in-files/src/foo.js b/test/bin-fixtures/6to5/dir --out-dir --source-maps/in-files/src/foo.js new file mode 100644 index 0000000000..4bc9539528 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps/in-files/src/foo.js @@ -0,0 +1 @@ +arr.map(x => x * MULTIPLIER); diff --git a/test/bin-fixtures/6to5/dir --out-dir --source-maps/options.json b/test/bin-fixtures/6to5/dir --out-dir --source-maps/options.json new file mode 100644 index 0000000000..e7e56fba31 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps/options.json @@ -0,0 +1,3 @@ +{ + "args": ["src", "--source-maps", "--out-dir", "lib"] +} diff --git a/test/bin-fixtures/6to5/dir --out-dir --source-maps/out-files/lib/bar/bar.js b/test/bin-fixtures/6to5/dir --out-dir --source-maps/out-files/lib/bar/bar.js new file mode 100644 index 0000000000..e07233acc3 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps/out-files/lib/bar/bar.js @@ -0,0 +1,4 @@ +var Test = function() { + function Test() {} + return Test; +}(); diff --git a/test/bin-fixtures/6to5/dir --out-dir --source-maps/out-files/lib/bar/bar.js.map b/test/bin-fixtures/6to5/dir --out-dir --source-maps/out-files/lib/bar/bar.js.map new file mode 100644 index 0000000000..5ab2c365f2 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps/out-files/lib/bar/bar.js.map @@ -0,0 +1 @@ +{"version":3,"file":"lib/bar/bar.js","sources":["src/bar/bar.js"],"names":[],"mappings":"IAAM,CAAC,CAAC,CAAC;WAAH,CAAC,CAAC,CAAC;SAAH,CAAC,CAAC,CAAC","sourcesContent":["class Test {\n\n}"]} diff --git a/test/bin-fixtures/6to5/dir --out-dir --source-maps/out-files/lib/foo.js b/test/bin-fixtures/6to5/dir --out-dir --source-maps/out-files/lib/foo.js new file mode 100644 index 0000000000..a075212f08 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps/out-files/lib/foo.js @@ -0,0 +1,3 @@ +arr.map(function(x) { + return x * MULTIPLIER; +}); diff --git a/test/bin-fixtures/6to5/dir --out-dir --source-maps/out-files/lib/foo.js.map b/test/bin-fixtures/6to5/dir --out-dir --source-maps/out-files/lib/foo.js.map new file mode 100644 index 0000000000..d477110472 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps/out-files/lib/foo.js.map @@ -0,0 +1 @@ +{"version":3,"file":"lib/foo.js","sources":["src/foo.js"],"names":[],"mappings":"AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAC;SAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAC,CAAC","sourcesContent":["arr.map(x => x * MULTIPLIER);"]} diff --git a/test/bin-fixtures/6to5/dir --out-dir --source-maps/stdout.txt b/test/bin-fixtures/6to5/dir --out-dir --source-maps/stdout.txt new file mode 100644 index 0000000000..a3d53cf84a --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir --source-maps/stdout.txt @@ -0,0 +1,2 @@ +src/bar/bar.js -> lib/bar/bar.js +src/foo.js -> lib/foo.js diff --git a/test/bin-fixtures/6to5/dir --out-dir/in-files/src/bar/bar.js b/test/bin-fixtures/6to5/dir --out-dir/in-files/src/bar/bar.js new file mode 100644 index 0000000000..45842c5e26 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir/in-files/src/bar/bar.js @@ -0,0 +1,3 @@ +class Test { + +} diff --git a/test/bin-fixtures/6to5/dir --out-dir/in-files/src/foo.js b/test/bin-fixtures/6to5/dir --out-dir/in-files/src/foo.js new file mode 100644 index 0000000000..4bc9539528 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir/in-files/src/foo.js @@ -0,0 +1 @@ +arr.map(x => x * MULTIPLIER); diff --git a/test/bin-fixtures/6to5/dir --out-dir/options.json b/test/bin-fixtures/6to5/dir --out-dir/options.json new file mode 100644 index 0000000000..0aeb1496b7 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir/options.json @@ -0,0 +1,3 @@ +{ + "args": ["src", "--out-dir", "lib"] +} diff --git a/test/bin-fixtures/6to5/dir --out-dir/out-files/lib/bar/bar.js b/test/bin-fixtures/6to5/dir --out-dir/out-files/lib/bar/bar.js new file mode 100644 index 0000000000..e07233acc3 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir/out-files/lib/bar/bar.js @@ -0,0 +1,4 @@ +var Test = function() { + function Test() {} + return Test; +}(); diff --git a/test/bin-fixtures/6to5/dir --out-dir/out-files/lib/foo.js b/test/bin-fixtures/6to5/dir --out-dir/out-files/lib/foo.js new file mode 100644 index 0000000000..a075212f08 --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir/out-files/lib/foo.js @@ -0,0 +1,3 @@ +arr.map(function(x) { + return x * MULTIPLIER; +}); diff --git a/test/bin-fixtures/6to5/dir --out-dir/stdout.txt b/test/bin-fixtures/6to5/dir --out-dir/stdout.txt new file mode 100644 index 0000000000..a3d53cf84a --- /dev/null +++ b/test/bin-fixtures/6to5/dir --out-dir/stdout.txt @@ -0,0 +1,2 @@ +src/bar/bar.js -> lib/bar/bar.js +src/foo.js -> lib/foo.js diff --git a/test/bin-fixtures/6to5/filename --out-file --source-maps-inline/in-files/script.js b/test/bin-fixtures/6to5/filename --out-file --source-maps-inline/in-files/script.js new file mode 100644 index 0000000000..4bc9539528 --- /dev/null +++ b/test/bin-fixtures/6to5/filename --out-file --source-maps-inline/in-files/script.js @@ -0,0 +1 @@ +arr.map(x => x * MULTIPLIER); diff --git a/test/bin-fixtures/6to5/filename --out-file --source-maps-inline/options.json b/test/bin-fixtures/6to5/filename --out-file --source-maps-inline/options.json new file mode 100644 index 0000000000..45b018e525 --- /dev/null +++ b/test/bin-fixtures/6to5/filename --out-file --source-maps-inline/options.json @@ -0,0 +1,3 @@ +{ + "args": ["script.js", "--source-maps-inline", "--out-file", "script2.js"] +} diff --git a/test/bin-fixtures/6to5/filename --out-file --source-maps-inline/out-files/script2.js b/test/bin-fixtures/6to5/filename --out-file --source-maps-inline/out-files/script2.js new file mode 100644 index 0000000000..39576f49e1 --- /dev/null +++ b/test/bin-fixtures/6to5/filename --out-file --source-maps-inline/out-files/script2.js @@ -0,0 +1,5 @@ +arr.map(function(x) { + return x * MULTIPLIER; +}); + +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLFVBQUM7U0FBSyxFQUFFLEVBQUUsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7Q0FBQyxDQUFDIiwiZmlsZSI6InNjcmlwdDIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJhcnIubWFwKHggPT4geCAqIE1VTFRJUExJRVIpOyJdfQ== diff --git a/test/bin-fixtures/6to5/filename --out-file/in-files/script.js b/test/bin-fixtures/6to5/filename --out-file/in-files/script.js new file mode 100644 index 0000000000..4bc9539528 --- /dev/null +++ b/test/bin-fixtures/6to5/filename --out-file/in-files/script.js @@ -0,0 +1 @@ +arr.map(x => x * MULTIPLIER); diff --git a/test/bin-fixtures/6to5/filename --out-file/options.json b/test/bin-fixtures/6to5/filename --out-file/options.json new file mode 100644 index 0000000000..edce769297 --- /dev/null +++ b/test/bin-fixtures/6to5/filename --out-file/options.json @@ -0,0 +1,3 @@ +{ + "args": ["script.js", "--out-file", "script2.js"] +} diff --git a/test/bin-fixtures/6to5/filename --out-file/out-files/script2.js b/test/bin-fixtures/6to5/filename --out-file/out-files/script2.js new file mode 100644 index 0000000000..a075212f08 --- /dev/null +++ b/test/bin-fixtures/6to5/filename --out-file/out-files/script2.js @@ -0,0 +1,3 @@ +arr.map(function(x) { + return x * MULTIPLIER; +}); diff --git a/test/bin-fixtures/6to5/filenames --out-file --source-maps-inline/in-files/script.js b/test/bin-fixtures/6to5/filenames --out-file --source-maps-inline/in-files/script.js new file mode 100644 index 0000000000..45842c5e26 --- /dev/null +++ b/test/bin-fixtures/6to5/filenames --out-file --source-maps-inline/in-files/script.js @@ -0,0 +1,3 @@ +class Test { + +} diff --git a/test/bin-fixtures/6to5/filenames --out-file --source-maps-inline/in-files/script2.js b/test/bin-fixtures/6to5/filenames --out-file --source-maps-inline/in-files/script2.js new file mode 100644 index 0000000000..4bc9539528 --- /dev/null +++ b/test/bin-fixtures/6to5/filenames --out-file --source-maps-inline/in-files/script2.js @@ -0,0 +1 @@ +arr.map(x => x * MULTIPLIER); diff --git a/test/bin-fixtures/6to5/filenames --out-file --source-maps-inline/options.json b/test/bin-fixtures/6to5/filenames --out-file --source-maps-inline/options.json new file mode 100644 index 0000000000..4c5998f346 --- /dev/null +++ b/test/bin-fixtures/6to5/filenames --out-file --source-maps-inline/options.json @@ -0,0 +1,3 @@ +{ + "args": ["script.js", "script2.js", "--source-maps-inline", "--out-file", "script3.js"] +} diff --git a/test/bin-fixtures/6to5/filenames --out-file --source-maps-inline/out-files/script3.js b/test/bin-fixtures/6to5/filenames --out-file --source-maps-inline/out-files/script3.js new file mode 100644 index 0000000000..c4b4a4c281 --- /dev/null +++ b/test/bin-fixtures/6to5/filenames --out-file --source-maps-inline/out-files/script3.js @@ -0,0 +1,9 @@ +var Test = function() { + function Test() {} + return Test; +}(); +arr.map(function(x) { + return x * MULTIPLIER; +}); + +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IklBQU0sQ0FBQyxDQUFDLENBQUM7V0FBSCxDQUFDLENBQUMsQ0FBQztTQUFILENBQUMsQ0FBQyxDQUFDOzs7QUNBVCxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLFVBQUM7U0FBSyxFQUFFLEVBQUUsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7Q0FBQyxDQUFDIiwiZmlsZSI6InNjcmlwdDMuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjbGFzcyBUZXN0IHtcblxufSIsImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19 diff --git a/test/bin-fixtures/6to5/filenames --out-file --source-maps/in-files/script.js b/test/bin-fixtures/6to5/filenames --out-file --source-maps/in-files/script.js new file mode 100644 index 0000000000..45842c5e26 --- /dev/null +++ b/test/bin-fixtures/6to5/filenames --out-file --source-maps/in-files/script.js @@ -0,0 +1,3 @@ +class Test { + +} diff --git a/test/bin-fixtures/6to5/filenames --out-file --source-maps/in-files/script2.js b/test/bin-fixtures/6to5/filenames --out-file --source-maps/in-files/script2.js new file mode 100644 index 0000000000..4bc9539528 --- /dev/null +++ b/test/bin-fixtures/6to5/filenames --out-file --source-maps/in-files/script2.js @@ -0,0 +1 @@ +arr.map(x => x * MULTIPLIER); diff --git a/test/bin-fixtures/6to5/filenames --out-file --source-maps/options.json b/test/bin-fixtures/6to5/filenames --out-file --source-maps/options.json new file mode 100644 index 0000000000..15308d9c7f --- /dev/null +++ b/test/bin-fixtures/6to5/filenames --out-file --source-maps/options.json @@ -0,0 +1,3 @@ +{ + "args": ["script.js", "script2.js", "--source-maps", "--out-file", "script3.js"] +} diff --git a/test/bin-fixtures/6to5/filenames --out-file --source-maps/out-files/script3.js b/test/bin-fixtures/6to5/filenames --out-file --source-maps/out-files/script3.js new file mode 100644 index 0000000000..09f0396320 --- /dev/null +++ b/test/bin-fixtures/6to5/filenames --out-file --source-maps/out-files/script3.js @@ -0,0 +1,7 @@ +var Test = function() { + function Test() {} + return Test; +}(); +arr.map(function(x) { + return x * MULTIPLIER; +}); diff --git a/test/bin-fixtures/6to5/filenames --out-file --source-maps/out-files/script3.js.map b/test/bin-fixtures/6to5/filenames --out-file --source-maps/out-files/script3.js.map new file mode 100644 index 0000000000..445d4e39b1 --- /dev/null +++ b/test/bin-fixtures/6to5/filenames --out-file --source-maps/out-files/script3.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["script.js","script2.js"],"names":[],"mappings":"IAAM,CAAC,CAAC,CAAC;WAAH,CAAC,CAAC,CAAC;SAAH,CAAC,CAAC,CAAC;;;ACAT,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAC;SAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAC,CAAC","file":"script3.js","sourcesContent":["class Test {\n\n}","arr.map(x => x * MULTIPLIER);"]} diff --git a/test/bin-fixtures/6to5/filenames --out-file/in-files/script.js b/test/bin-fixtures/6to5/filenames --out-file/in-files/script.js new file mode 100644 index 0000000000..45842c5e26 --- /dev/null +++ b/test/bin-fixtures/6to5/filenames --out-file/in-files/script.js @@ -0,0 +1,3 @@ +class Test { + +} diff --git a/test/bin-fixtures/6to5/filenames --out-file/in-files/script2.js b/test/bin-fixtures/6to5/filenames --out-file/in-files/script2.js new file mode 100644 index 0000000000..4bc9539528 --- /dev/null +++ b/test/bin-fixtures/6to5/filenames --out-file/in-files/script2.js @@ -0,0 +1 @@ +arr.map(x => x * MULTIPLIER); diff --git a/test/bin-fixtures/6to5/filenames --out-file/options.json b/test/bin-fixtures/6to5/filenames --out-file/options.json new file mode 100644 index 0000000000..a68e72ddec --- /dev/null +++ b/test/bin-fixtures/6to5/filenames --out-file/options.json @@ -0,0 +1,3 @@ +{ + "args": ["script.js", "script2.js", "--out-file", "script3.js"] +} diff --git a/test/bin-fixtures/6to5/filenames --out-file/out-files/script3.js b/test/bin-fixtures/6to5/filenames --out-file/out-files/script3.js new file mode 100644 index 0000000000..09f0396320 --- /dev/null +++ b/test/bin-fixtures/6to5/filenames --out-file/out-files/script3.js @@ -0,0 +1,7 @@ +var Test = function() { + function Test() {} + return Test; +}(); +arr.map(function(x) { + return x * MULTIPLIER; +}); diff --git a/test/bin-fixtures/6to5/stdin --filename/options.json b/test/bin-fixtures/6to5/stdin --filename/options.json new file mode 100644 index 0000000000..4274d9a296 --- /dev/null +++ b/test/bin-fixtures/6to5/stdin --filename/options.json @@ -0,0 +1,4 @@ +{ + "args": ["--filename", "test.js"], + "stderrContains": true +} diff --git a/test/bin-fixtures/6to5/stdin --filename/stderr.txt b/test/bin-fixtures/6to5/stdin --filename/stderr.txt new file mode 100644 index 0000000000..47680350a1 --- /dev/null +++ b/test/bin-fixtures/6to5/stdin --filename/stderr.txt @@ -0,0 +1 @@ +Error: test.js: Line 2: Unexpected token ILLEGAL diff --git a/test/bin-fixtures/6to5/stdin --filename/stdin.txt b/test/bin-fixtures/6to5/stdin --filename/stdin.txt new file mode 100644 index 0000000000..c79fc370db --- /dev/null +++ b/test/bin-fixtures/6to5/stdin --filename/stdin.txt @@ -0,0 +1,3 @@ +arr.map(x => { + $@! +}); diff --git a/test/bin-fixtures/6to5/stdin --out-file --source-maps/options.json b/test/bin-fixtures/6to5/stdin --out-file --source-maps/options.json new file mode 100644 index 0000000000..8fa500178b --- /dev/null +++ b/test/bin-fixtures/6to5/stdin --out-file --source-maps/options.json @@ -0,0 +1,3 @@ +{ + "args": ["--source-maps", "--out-file", "test.js"] +} diff --git a/test/bin-fixtures/6to5/stdin --out-file --source-maps/out-files/test.js b/test/bin-fixtures/6to5/stdin --out-file --source-maps/out-files/test.js new file mode 100644 index 0000000000..2522e0b627 --- /dev/null +++ b/test/bin-fixtures/6to5/stdin --out-file --source-maps/out-files/test.js @@ -0,0 +1,3 @@ +arr.map(function(x) { + return x * x; +}); diff --git a/test/bin-fixtures/6to5/stdin --out-file --source-maps/out-files/test.js.map b/test/bin-fixtures/6to5/stdin --out-file --source-maps/out-files/test.js.map new file mode 100644 index 0000000000..890457fe53 --- /dev/null +++ b/test/bin-fixtures/6to5/stdin --out-file --source-maps/out-files/test.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["stdin"],"names":[],"mappings":"AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAC;SAAK,EAAE,EAAE;CAAC,CAAC","file":"test.js","sourcesContent":["arr.map(x => x * x);"]} diff --git a/test/bin-fixtures/6to5/stdin --out-file --source-maps/stdin.txt b/test/bin-fixtures/6to5/stdin --out-file --source-maps/stdin.txt new file mode 100644 index 0000000000..adc9848407 --- /dev/null +++ b/test/bin-fixtures/6to5/stdin --out-file --source-maps/stdin.txt @@ -0,0 +1 @@ +arr.map(x => x * x); diff --git a/test/bin-fixtures/6to5/stdin --out-file/options.json b/test/bin-fixtures/6to5/stdin --out-file/options.json new file mode 100644 index 0000000000..5c5b1a4baa --- /dev/null +++ b/test/bin-fixtures/6to5/stdin --out-file/options.json @@ -0,0 +1,3 @@ +{ + "args": ["--out-file", "script.js"] +} diff --git a/test/bin-fixtures/6to5/stdin --out-file/out-files/script.js b/test/bin-fixtures/6to5/stdin --out-file/out-files/script.js new file mode 100644 index 0000000000..a075212f08 --- /dev/null +++ b/test/bin-fixtures/6to5/stdin --out-file/out-files/script.js @@ -0,0 +1,3 @@ +arr.map(function(x) { + return x * MULTIPLIER; +}); diff --git a/test/bin-fixtures/6to5/stdin --out-file/stdin.txt b/test/bin-fixtures/6to5/stdin --out-file/stdin.txt new file mode 100644 index 0000000000..4bc9539528 --- /dev/null +++ b/test/bin-fixtures/6to5/stdin --out-file/stdin.txt @@ -0,0 +1 @@ +arr.map(x => x * MULTIPLIER); diff --git a/test/bin-fixtures/6to5/stdin --source-maps-inline/options.json b/test/bin-fixtures/6to5/stdin --source-maps-inline/options.json new file mode 100644 index 0000000000..a0d3fe33fb --- /dev/null +++ b/test/bin-fixtures/6to5/stdin --source-maps-inline/options.json @@ -0,0 +1,3 @@ +{ + "args": ["--source-maps-inline"] +} diff --git a/test/bin-fixtures/6to5/stdin --source-maps-inline/stdin.txt b/test/bin-fixtures/6to5/stdin --source-maps-inline/stdin.txt new file mode 100644 index 0000000000..adc9848407 --- /dev/null +++ b/test/bin-fixtures/6to5/stdin --source-maps-inline/stdin.txt @@ -0,0 +1 @@ +arr.map(x => x * x); diff --git a/test/bin-fixtures/6to5/stdin --source-maps-inline/stdout.txt b/test/bin-fixtures/6to5/stdin --source-maps-inline/stdout.txt new file mode 100644 index 0000000000..78fab9f691 --- /dev/null +++ b/test/bin-fixtures/6to5/stdin --source-maps-inline/stdout.txt @@ -0,0 +1,5 @@ +arr.map(function(x) { + return x * x; +}); + +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsVUFBQztTQUFLLEVBQUUsRUFBRTtDQUFDLENBQUMiLCJmaWxlIjoic3Rkb3V0Iiwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiB4KTsiXX0= diff --git a/test/bin-fixtures/6to5/stdin/stdin.txt b/test/bin-fixtures/6to5/stdin/stdin.txt new file mode 100644 index 0000000000..4bc9539528 --- /dev/null +++ b/test/bin-fixtures/6to5/stdin/stdin.txt @@ -0,0 +1 @@ +arr.map(x => x * MULTIPLIER); diff --git a/test/bin-fixtures/6to5/stdin/stdout.txt b/test/bin-fixtures/6to5/stdin/stdout.txt new file mode 100644 index 0000000000..a075212f08 --- /dev/null +++ b/test/bin-fixtures/6to5/stdin/stdout.txt @@ -0,0 +1,3 @@ +arr.map(function(x) { + return x * MULTIPLIER; +}); diff --git a/test/bin.js b/test/bin.js index 057a04b43b..d61a43526c 100644 --- a/test/bin.js +++ b/test/bin.js @@ -1,24 +1,79 @@ -var assert = require("assert"); -var child = require("child_process"); -var path = require("path"); -var fs = require("fs"); -var _ = require("lodash"); +var readdir = require("fs-readdir-recursive"); +var assert = require("assert"); +var rimraf = require("rimraf"); +var mkdirp = require("mkdirp"); +var child = require("child_process"); +var path = require("path"); +var fs = require("fs"); +var _ = require("lodash"); var fixtureLoc = __dirname + "/bin-fixtures"; var tmpLoc = __dirname + "/tmp"; -var build = function (binName, testName, opts) { - var testFixtureLoc = fixtureLoc + "/" + binName + "/" + testName; - if (fs.existsSync(testFixtureLoc)) { - _.each(fs.readdirSync(testFixtureLoc), function (filename) { - var key = path.basename(filename, path.extname(filename)); - var file = fs.readFileSync(testFixtureLoc + "/" + filename, "utf8").trim(); - opts[key] = file; +var readFile = function (filename) { + return fs.readFileSync(filename, "utf8").trim(); +}; + +var readDir = function (loc) { + var files = {}; + if (fs.existsSync(loc)) { + _.each(readdir(loc), function (filename) { + var contents = readFile(loc + "/" + filename); + files[filename] = contents; }); } + return files; +}; + +var saveInFiles = function (files) { + _.each(files, function (content, filename) { + var up = path.normalize(filename + "/.."); + mkdirp.sync(up); + + fs.writeFileSync(filename, content); + }); +}; + +var assertTest = function (stdout, stderr, opts) { + var expectStderr = opts.stderr.trim(); + stderr = stderr.trim(); + + if (opts.stderr) { + if (opts.stderrContains) { + assert.ok(_.contains(stderr, expectStderr), "stderr didn't contain " + JSON.stringify(expectStderr)); + } else { + assert.equal(stderr, expectStderr, "stderr didn't match"); + } + } else if (stderr) { + throw new Error("stderr: " + JSON.stringify(stderr)); + } + + var expectStdout = opts.stdout.trim(); + stdout = stdout.trim(); + + if (opts.stdout) { + if (opts.stdoutContains) { + assert.ok(_.contains(stdout, expectStdout), "stdout didn't contain " + JSON.stringify(expectStdout)); + } else { + assert.equal(stdout, expectStdout, "stdout didn't match"); + } + } else if (stdout) { + throw new Error("stdout: " + JSON.stringify(stdout)); + } + + _.each(opts.outFiles, function (expect, filename) { + var actual = readFile(filename); + assert.equal(actual, expect, "out-file " + filename); + }); +}; + +var build = function (binName, testName, opts) { + var binLoc = path.normalize(__dirname + "/../bin/" + binName); return function (callback) { - var args = [__dirname + "/../bin/" + binName].concat(opts.args); + saveInFiles(opts.inFiles); + + var args = [binLoc].concat(opts.args); var spawn = child.spawn(process.execPath, args); var stderr = ""; @@ -34,26 +89,17 @@ var build = function (binName, testName, opts) { spawn.on("close", function () { var err; + try { - if (opts.stderr) { - assert.equal(stderr.trim(), opts.stderr); - } else if (stderr) { - throw new Error("stderr: " + stderr); - } - - if (opts.stdout) { - assert.equal(stdout.trim(), opts.stdout); - } else if (stdout) { - throw new Error("stdout: " + stdout); - } - - _.each(opts.files, function (expect, filename) { - var actual = fs.readFileSync(filename, "utf8"); - assert.equal(actual, expect); - }); + assertTest(stdout, stderr, opts); } catch (e) { err = e; } + + if (err) { + err.message = args.join(" ") + ": " + err.message; + } + callback(err); }); @@ -65,41 +111,45 @@ var build = function (binName, testName, opts) { }; before(function () { - if (!fs.existsSync(tmpLoc)) fs.mkdirSync(tmpLoc); + if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc); + fs.mkdirSync(tmpLoc); process.chdir(tmpLoc); }); -suite("bin/6to5", function () { - test("--source-maps-inline"); +_.each(fs.readdirSync(fixtureLoc), function (binName) { + if (binName[0] === ".") return; - test("--source-maps"); + var suiteLoc = fixtureLoc + "/" + binName; + suite("bin/" + binName, function () { + _.each(fs.readdirSync(fixtureLoc + "/" + binName), function (testName) { + if (testName[0] === ".") return; - test("--whitelist", build("6to5", "whitelist", { - args: ["--whitelist", "arrowFunctions"] - })); + var testLoc = suiteLoc + "/" + testName; - test("--blacklist", build("6to5", "blacklist", { - args: ["--blacklist", "arrowFunctions"] - })); + var opts = { + args: [] + }; - test("--out-file", build("6to5", "out-file", { - args: ["--out-file", "script.js"], - files: { - "script.js": "(function() {\n var MULTIPLER = 5;\n arr.map(function(x) {\n return x * MULTIPLIER;\n });\n})();" - } - })); + var optionsLoc = testLoc + "/options.json" + if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc)); - test("--out-dir"); + _.each(["stdout", "stdin", "stderr"], function (key) { + var loc = testLoc + "/" + key + ".txt"; + if (fs.existsSync(loc)) { + opts[key] = readFile(loc); + } else { + opts[key] = opts[key] || ""; + } + }); + + opts.outFiles = readDir(testLoc + "/out-files"); + opts.inFiles = readDir(testLoc + "/in-files"); + + test(testName, build(binName, testName, opts)); + }); + }); }); -suite("bin/6to5-node", function () { - test("--eval", build("6to5-node", "eval", { - args: ["--eval", "console.log([1, 2, 3].map(x => x * x));"], - stdout: "[ 1, 4, 9 ]" - })); - - test("--print", build("6to5-node", "print", { - args: ["--print", "--eval", "([1, 2, 3].map(x => x * x))"], - stdout: "[ 1, 4, 9 ]" - })); +after(function () { + rimraf.sync(tmpLoc); });