From 80cdfd41874a9f7bdbb6f88fdef13fab72f0922d Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 5 Oct 2015 18:57:11 -0700 Subject: [PATCH] Fix emitting parenthesis when downlevel --- src/compiler/emitter.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index db3cef27aa3..6a09006d3e3 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2508,7 +2508,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } /** - * Emit exponentiation operator down-level using Math.pow + * Emit ES7 exponentiation operator downlevel using Math.pow * @param node {BinaryExpression} a binary expression node containing exponentiationOperator (**, **=) */ function emitExponentiationOperator(node: BinaryExpression) { @@ -2516,12 +2516,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (node.operatorToken.kind === SyntaxKind.AsteriskAsteriskEqualsToken) { let synthesizedLHS: ElementAccessExpression | PropertyAccessExpression; // TODO (yuisu) : comment - let shouldEmitParenthesis = node.parent.kind === SyntaxKind.VariableDeclaration || node.parent.kind === SyntaxKind.BinaryExpression; + let shouldEmitParenthesis = false; if (isElementAccessExpression(leftHandSideExpression)) { + shouldEmitParenthesis = node.parent.kind === SyntaxKind.VariableDeclaration || node.parent.kind === SyntaxKind.BinaryExpression; + if (shouldEmitParenthesis) { write("("); } + synthesizedLHS = createSynthesizedNode(SyntaxKind.ElementAccessExpression, /*startsOnNewLine*/ false); let tempExpression = createAndRecordTempVariable(TempFlags.Auto); emitAssignment(tempExpression, leftHandSideExpression.expression, /*shouldEmitCommaBeforeAssignment*/ false); @@ -2539,9 +2542,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(", "); } else if (isPropertyAccessExpression(leftHandSideExpression)) { + shouldEmitParenthesis = node.parent.kind === SyntaxKind.VariableDeclaration || node.parent.kind === SyntaxKind.BinaryExpression; + if (shouldEmitParenthesis) { write("("); } + synthesizedLHS = createSynthesizedNode(SyntaxKind.PropertyAccessExpression, /*startsOnNewLine*/ false); let tempExpression = createAndRecordTempVariable(TempFlags.Auto); synthesizedLHS.expression = tempExpression