From 9c306406f14087ad0a62141bf7bb9e12afcc1a75 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 8 Jun 2017 03:27:03 +0800 Subject: fix iteration over object with inherited properties (#2068) fixes #2055 --- test/mocha/minify.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/mocha/minify.js') diff --git a/test/mocha/minify.js b/test/mocha/minify.js index 519b725c..638e79f7 100644 --- a/test/mocha/minify.js +++ b/test/mocha/minify.js @@ -13,6 +13,13 @@ describe("minify", function() { assert.strictEqual(result.code, 'function foo(n){return n?3:7}'); }); + it("Should skip inherited keys from `files`", function() { + var files = Object.create({ skip: this }); + files[0] = "alert(1 + 1)"; + var result = Uglify.minify(files); + assert.strictEqual(result.code, "alert(2);"); + }); + describe("keep_quoted_props", function() { it("Should preserve quotes in object literals", function() { var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; @@ -207,5 +214,17 @@ describe("minify", function() { assert.ok(err instanceof Error); assert.strictEqual(err.stack.split(/\n/)[0], "Error: Can't handle expression: debugger"); }); + it("should skip inherited properties", function() { + var foo = Object.create({ skip: this }); + foo.bar = 42; + var result = Uglify.minify("alert(FOO);", { + compress: { + global_defs: { + FOO: foo + } + } + }); + assert.strictEqual(result.code, "alert({bar:42});"); + }); }); }); -- cgit v1.2.3