From f25bd13be68152640af809bafe0a2ba3aa77eb0a Mon Sep 17 00:00:00 2001 From: kzc Date: Sun, 19 Nov 2017 00:53:42 -0500 Subject: [PATCH] fix keyword shorthand property output for `ecma` >= 6 (#2493) fixes #2491 --- lib/output.js | 3 ++- test/compress/harmony.js | 38 ++++++++++++++++++++++++++++++++++++++ test/mocha/cli.js | 2 +- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lib/output.js b/lib/output.js index f2386a97..649a3307 100644 --- a/lib/output.js +++ b/lib/output.js @@ -1624,7 +1624,8 @@ function OutputStream(options) { if (allowShortHand && self.value instanceof AST_Symbol && is_identifier_string(self.key) && - get_name(self.value) === self.key + get_name(self.value) === self.key && + is_identifier(self.key) ) { print_property_name(self.key, self.quote, output); diff --git a/test/compress/harmony.js b/test/compress/harmony.js index 17f70199..11b36b2d 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -937,3 +937,41 @@ issue_2349b: { ] node_version: ">=7" } + +shorthand_keywords: { + beautify = { + ecma: 6, + } + input: { + var foo = 0, + async = 1, + await = 2, + implements = 3, + package = 4, + private = 5, + protected = 6, + static = 7, + yield = 8; + console.log({ + foo: foo, + 0: 0, + NaN: NaN, + async: async, + await: await, + false: false, + implements: implements, + null: null, + package: package, + private: private, + protected: protected, + static: static, + this: this, + true: true, + undefined: undefined, + yield: yield, + }); + } + expect_exact: "var foo=0,async=1,await=2,implements=3,package=4,private=5,protected=6,static=7,yield=8;console.log({foo,0:0,NaN:NaN,async,await,false:false,implements:implements,null:null,package:package,private:private,protected:protected,static:static,this:this,true:true,undefined:void 0,yield});" + expect_stdout: true + node_version: ">=4" +} diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 4acf03d6..0825b808 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -10,7 +10,7 @@ function read(path) { describe("bin/uglifyjs", function () { var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs'; it("should produce a functional build when using --self", function (done) { - this.timeout(60000); + this.timeout(120000); var command = uglifyjscmd + ' --self -mc ecma='; command += semver.satisfies(process.version, ">=4") ? "6" : "5";