From 5923f5b5df7d2038c2e2f45abbcaacb0cb9e6c94 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 13 Jul 2016 19:36:39 +0300 Subject: [PATCH] Fix `beautify` when passed as an object. --- Gruntfile.js | 12 ++++++++++++ tasks/lib/uglify.js | 18 ++++++++---------- test/fixtures/expected/beautify.js | 2 ++ test/uglify_test.js | 1 + 4 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 test/fixtures/expected/beautify.js diff --git a/Gruntfile.js b/Gruntfile.js index 392a3725..cca33d75 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -374,6 +374,18 @@ module.exports = function(grunt) { 'tmp/mangle.js': ['test/fixtures/src/simple.js'] }, mangle: true + }, + beautify_Object: { + files: { + 'tmp/beautify.js': ['test/fixtures/src/localization.js', 'test/fixtures/src/simple.js'] + }, + options: { + beautify: { + 'ascii_only': true, + 'indent_start': 2, + 'max_line_len': 40 + } + } } }, diff --git a/tasks/lib/uglify.js b/tasks/lib/uglify.js index 772a7639..4465f5d5 100644 --- a/tasks/lib/uglify.js +++ b/tasks/lib/uglify.js @@ -220,16 +220,6 @@ exports.init = function(grunt) { outputOptions.preamble = options.banner; } - if (options.beautify) { - if (_.isObject(options.beautify)) { - // beautify options sent as an object are merged - // with outputOptions and passed to the OutputStream - _.assign(outputOptions, options.beautify); - } else { - outputOptions.beautify = true; - } - } - if (options.screwIE8) { outputOptions.screw_ie8 = true; } @@ -277,6 +267,14 @@ exports.init = function(grunt) { outputOptions.comments = options.preserveComments; } + if (options.beautify) { + if (_.isObject(options.beautify)) { + _.assign(outputOptions, options.beautify); + } else { + outputOptions.beautify = true; + } + } + return outputOptions; }; diff --git a/test/fixtures/expected/beautify.js b/test/fixtures/expected/beautify.js new file mode 100644 index 00000000..665339da --- /dev/null +++ b/test/fixtures/expected/beautify.js @@ -0,0 +1,2 @@ +function longFunctionC(a,b){return longNameA+longNameB+a+b; +}var set=["This is a random set of ch\u03b1racters and strings.","\u8fd9\u662f\u4e00\u7ec4\u968f\u673a\u5b57\u7b26\u548c\u5b57\u7b26\u4e32\u3002","\u042d\u0442\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438 \u0441\u0442\u0440\u043e\u043a","\u0426\xe9 \u0432\u0438\u043f\u0430\u0434\u043a\u043e\u0432\u0438\u0439 \u043d\u0430\u0431\u0456\u0440 \u0441\u0438\u043c\u0432\u043e\u043b\u0456\u0432 \u0442\u0430 \u0440\u044f\u0434\u043a\u0456\u0432"],answer=set[Math.floor(Math.random()*set.length)],longNameA=1,longNameB=2,result=longFunctionC(3,4); \ No newline at end of file diff --git a/test/uglify_test.js b/test/uglify_test.js index 77be4ec9..05ad08b9 100644 --- a/test/uglify_test.js +++ b/test/uglify_test.js @@ -12,6 +12,7 @@ exports.contrib_uglify = { preuglified_files: function(test) { var files = [ + 'beautify.js', 'comments.js', 'compress.js', 'compress_explicit.js',