diff --git a/lib/output.js b/lib/output.js index 431e6a01..1ac5ea8e 100644 --- a/lib/output.js +++ b/lib/output.js @@ -64,7 +64,8 @@ function OutputStream(options) { preserve_line : false, screw_ie8 : false, preamble : null, - quote_style : 0 + quote_style : 0, + keep_quoted_props: false }, true); var indentation = 0; @@ -1142,7 +1143,7 @@ function OutputStream(options) { && parseFloat(key) >= 0) { output.print(make_num(key)); } else if (RESERVED_WORDS(key) ? output.option("screw_ie8") : is_identifier_string(key)) { - if (quote && output.option("quote_style")) { + if (quote && output.option("keep_quoted_props")) { output.print_string(key, quote); } else { output.print_name(key); diff --git a/test/mocha/minify.js b/test/mocha/minify.js index bbf188c4..66fd8885 100644 --- a/test/mocha/minify.js +++ b/test/mocha/minify.js @@ -7,5 +7,35 @@ describe("minify", function() { var result = Uglify.minify(js, {fromString: true}); assert.strictEqual(result.code, 'function foo(n){return n?3:7}'); }); -}); + describe("keep_quoted_props", function() { + it("Should preserve quotes in object literals", function() { + var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; + var result = Uglify.minify(js, { + fromString: true, output: { + keep_quoted_props: true + }}); + assert.strictEqual(result.code, 'var foo={"x":1,y:2,"z":3};'); + }); + + it("Should preserve quote styles when quote_style is 3", function() { + var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; + var result = Uglify.minify(js, { + fromString: true, output: { + keep_quoted_props: true, + quote_style: 3 + }}); + assert.strictEqual(result.code, 'var foo={"x":1,y:2,\'z\':3};'); + }); + + it("Should not preserve quotes in object literals when disabled", function() { + var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; + var result = Uglify.minify(js, { + fromString: true, output: { + keep_quoted_props: false, + quote_style: 3 + }}); + assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3};'); + }); + }); +});