aboutsummaryrefslogtreecommitdiff
path: root/test/mocha
diff options
context:
space:
mode:
authorShrey Banga <shrey@quip.com>2016-05-05 13:44:59 -0700
committerRichard van Velzen <rvanvelzen1@gmail.com>2016-06-19 21:13:31 +0200
commite645ba84cfc950183a222c2cce2ea6b94fe51226 (patch)
tree9ca5d7b1d55c36adb14f0468d4442f2a3a0aeb2d /test/mocha
parent6c99816855b650c6804a67f4891c339a3e8970f4 (diff)
downloadtracifyjs-e645ba84cfc950183a222c2cce2ea6b94fe51226.tar.gz
tracifyjs-e645ba84cfc950183a222c2cce2ea6b94fe51226.zip
Respect quote style in object literals
The option added in fbbaa42ee55a7f753f7cab9b1a905ccf73cf26d5 wasn't being respected inside object literals, so quoted property names would still be stripped out with this option. This is mostly a corner-case, but useful when the output is passed to something like the Closure compiler, where quoted property names can be used to prevent mangling.
Diffstat (limited to 'test/mocha')
-rw-r--r--test/mocha/minify.js53
1 files changed, 52 insertions, 1 deletions
diff --git a/test/mocha/minify.js b/test/mocha/minify.js
index bbf188c4..02d31558 100644
--- a/test/mocha/minify.js
+++ b/test/mocha/minify.js
@@ -7,5 +7,56 @@ 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};');
+ });
+ });
+
+ describe("mangleProperties", function() {
+ it("Shouldn't mangle quoted properties", function() {
+ var js = 'a["foo"] = "bar"; a.color = "red"; x = {"bar": 10};';
+ var result = Uglify.minify(js, {
+ fromString: true,
+ compress: {
+ properties: false
+ },
+ mangleProperties: {
+ ignore_quoted: true
+ },
+ output: {
+ keep_quoted_props: true,
+ quote_style: 3
+ }
+ });
+ assert.strictEqual(result.code,
+ 'a["foo"]="bar",a.a="red",x={"bar":10};');
+ });
+ });
+});