From 0a3fac6e684eb2bd484602e39615cd1f067588d5 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 28 Dec 2017 05:07:19 +0800 Subject: [PATCH] fix parenthesis output of `AST_ClassExpression` (#2677) fixes #2676 --- lib/output.js | 8 +------- test/compress/harmony.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/output.js b/lib/output.js index b57eb3a8..2f8faf7d 100644 --- a/lib/output.js +++ b/lib/output.js @@ -730,15 +730,9 @@ function OutputStream(options) { return p instanceof AST_PropAccess && p.expression === this; }); - PARENS(AST_ClassExpression, function(output){ - return output.parent() instanceof AST_SimpleStatement; - }); - // same goes for an object literal, because otherwise it would be // interpreted as a block of code. - PARENS(AST_Object, function(output){ - return first_in_statement(output); - }); + PARENS([ AST_ClassExpression, AST_Object ], first_in_statement); PARENS(AST_Unary, function(output){ var p = output.parent(); diff --git a/test/compress/harmony.js b/test/compress/harmony.js index fd0212dd..c094ff54 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -1197,3 +1197,18 @@ class_method_using_arguments: { expect_stdout: "PASS" node_version: ">=6" } + +issue_2676: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + class A {} + A.a = 42; + } + expect: { + (class {}).a = 42; + } +}