fix class expression statements (#2051)

- class expression statements require parentheses
- allow unused class expression statements to be dropped

fixes #1782
closes #1784
This commit is contained in:
kzc
2017-06-03 14:45:26 -04:00
committed by Alex Lam S.L
parent 753932b302
commit 82fefc5d29
3 changed files with 50 additions and 0 deletions

View File

@@ -2610,6 +2610,7 @@ merge(Compressor.prototype, {
def(AST_Accessor, return_null);
def(AST_Function, return_null);
def(AST_Arrow, return_null);
def(AST_ClassExpression, return_null);
def(AST_Binary, function(compressor, first_in_statement){
var right = this.right.drop_side_effect_free(compressor);
if (!right) return this.left.drop_side_effect_free(compressor, first_in_statement);

View File

@@ -642,6 +642,10 @@ 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){