From 2e20287f80f25bb2237d2c1c32358210c81bf2fc Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 22 Nov 2016 22:10:18 +0300 Subject: [PATCH] JS: fix operator priority when rendering `new` expression --- .../javascript/rendering/StatementRenderer.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java index ba607b3b3..0925e8ae0 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java @@ -1137,8 +1137,19 @@ public class StatementRenderer implements ExprVisitor, StatementVisitor { if (expr.getLocation() != null) { pushLocation(expr.getLocation()); } + + Precedence outerPrecedence = precedence; + if (outerPrecedence.ordinal() > Precedence.FUNCTION_CALL.ordinal()) { + writer.append('('); + } + precedence = Precedence.FUNCTION_CALL; + writer.append("new ").append(naming.getNameFor(expr.getConstructedClass())); + if (outerPrecedence.ordinal() > Precedence.FUNCTION_CALL.ordinal()) { + writer.append(')'); + } + if (expr.getLocation() != null) { popLocation(); }