diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-01-26 19:18:28 +0800 |
---|---|---|
committer | Richard van Velzen <rvanvelzen1@gmail.com> | 2017-01-26 12:18:28 +0100 |
commit | 1eaa211e0932105439d98d4f03a981f157f0a77c (patch) | |
tree | 3167d7068dbf72992dc9df6b6fcabdf9e3b87962 /test | |
parent | 0610c020b1544820be9898a285ab6c9066490552 (diff) | |
download | tracifyjs-1eaa211e0932105439d98d4f03a981f157f0a77c.tar.gz tracifyjs-1eaa211e0932105439d98d4f03a981f157f0a77c.zip |
fix mangling collision with keep_fnames (#1431)
* fix mangling collision with keep_fnames
fixes #1423
* pass mangle options to figure_out_scope()
bring command-line in line with minify()
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/issue-1431.js | 122 | ||||
-rw-r--r-- | test/input/issue-1431/sample.js | 14 | ||||
-rw-r--r-- | test/mocha/cli.js | 32 |
3 files changed, 167 insertions, 1 deletions
diff --git a/test/compress/issue-1431.js b/test/compress/issue-1431.js new file mode 100644 index 00000000..731ebba8 --- /dev/null +++ b/test/compress/issue-1431.js @@ -0,0 +1,122 @@ +level_one: { + options = { + keep_fnames: true + } + mangle = { + keep_fnames: true + } + input: { + function f(x) { + return function() { + function n(a) { + return a * a; + } + return x(n); + }; + } + } + expect: { + function f(r) { + return function() { + function n(n) { + return n * n; + } + return r(n); + }; + } + } +} + +level_two: { + options = { + keep_fnames: true + } + mangle = { + keep_fnames: true + } + input: { + function f(x) { + return function() { + function r(a) { + return a * a; + } + return function() { + function n(a) { + return a * a; + } + return x(n); + }; + }; + } + } + expect: { + function f(t) { + return function() { + function r(n) { + return n * n; + } + return function() { + function n(n) { + return n * n; + } + return t(n); + }; + }; + } + } +} + +level_three: { + options = { + keep_fnames: true + } + mangle = { + keep_fnames: true + } + input: { + function f(x) { + return function() { + function r(a) { + return a * a; + } + return [ + function() { + function t(a) { + return a * a; + } + return t; + }, + function() { + function n(a) { + return a * a; + } + return x(n); + } + ]; + }; + } + } + expect: { + function f(t) { + return function() { + function r(n) { + return n * n; + } + return [ + function() { + function t(n) { + return n * n; + } + return t; + }, + function() { + function n(n) { + return n * n; + } + return t(n); + } + ]; + }; + } + } +} diff --git a/test/input/issue-1431/sample.js b/test/input/issue-1431/sample.js new file mode 100644 index 00000000..32068cb2 --- /dev/null +++ b/test/input/issue-1431/sample.js @@ -0,0 +1,14 @@ +function f(x) { + return function() { + function n(a) { + return a * a; + } + return x(n); + }; +} + +function g(op) { + return op(1) + op(2); +} + +console.log(f(g)() == 5);
\ No newline at end of file diff --git a/test/mocha/cli.js b/test/mocha/cli.js index bebd4d9d..a8de05c5 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -55,7 +55,7 @@ describe("bin/uglifyjs", function () { exec(command, function (err, stdout) { if (err) throw err; - assert.strictEqual(stdout, "var bar=function(){function foo(bar){return bar}return foo}();\n" + + assert.strictEqual(stdout, "var bar=function(){function foo(bar){return bar}return foo}();\n" + "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMTMyMy9zYW1wbGUuanMiXSwibmFtZXMiOlsiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxHQUFJQSxLQUFNLFdBQ04sUUFBU0MsS0FBS0QsS0FDVixNQUFPQSxLQUdYLE1BQU9DIn0=\n"); done(); }); @@ -70,4 +70,34 @@ describe("bin/uglifyjs", function () { done(); }); }); + it("Should work with --keep-fnames (mangle only)", function (done) { + var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m'; + + exec(command, function (err, stdout) { + if (err) throw err; + + assert.strictEqual(stdout, "function f(r){return function(){function n(n){return n*n}return r(n)}}function g(n){return n(1)+n(2)}console.log(f(g)()==5);\n"); + done(); + }); + }); + it("Should work with --keep-fnames (mangle & compress)", function (done) { + var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m -c'; + + exec(command, function (err, stdout) { + if (err) throw err; + + assert.strictEqual(stdout, "function f(r){return function(){function n(n){return n*n}return r(n)}}function g(n){return n(1)+n(2)}console.log(5==f(g)());\n"); + done(); + }); + }); + it("Should work with keep_fnames under mangler options", function (done) { + var command = uglifyjscmd + ' test/input/issue-1431/sample.js -m keep_fnames=true'; + + exec(command, function (err, stdout) { + if (err) throw err; + + assert.strictEqual(stdout, "function f(r){return function(){function n(n){return n*n}return r(n)}}function g(n){return n(1)+n(2)}console.log(f(g)()==5);\n"); + done(); + }); + }); }); |