Fix exponential operator to behave according to spec (#75)

This commit is contained in:
Daniel Tschinder
2016-07-17 11:08:12 +02:00
committed by GitHub
parent f5df4b9411
commit 97325592fa
11 changed files with 378 additions and 2 deletions

View File

@@ -188,7 +188,13 @@ pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
node.left = left;
node.operator = this.state.value;
if (node.operator === "**" && left.type === "UnaryExpression" && left.extra && !left.extra.parenthesizedArgument) {
if (
node.operator === "**" &&
left.type === "UnaryExpression" &&
left.extra &&
!left.extra.parenthesizedArgument &&
!left.extra.parenthesized
) {
this.raise(left.argument.start, "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.");
}
@@ -217,9 +223,10 @@ pp.parseMaybeUnary = function (refShorthandDefaultPos) {
this.next();
let argType = this.state.type;
this.addExtra(node, "parenthesizedArgument", argType === tt.parenL);
node.argument = this.parseMaybeUnary();
this.addExtra(node, "parenthesizedArgument", argType === tt.parenL && (!node.argument.extra || !node.argument.extra.parenthesized));
if (refShorthandDefaultPos && refShorthandDefaultPos.start) {
this.unexpected(refShorthandDefaultPos.start);
}