update exponentiation operator precedence - fixes #2431
This commit is contained in:
parent
3c2208cdf6
commit
8748ff0802
@ -15,12 +15,14 @@ See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 6.0.14
|
||||
|
||||
* **Spec Compliancy**
|
||||
* Update exponentiation operator precedence.
|
||||
* Fix parser bug where arrow functions have a higher precedence than they should.
|
||||
* **Bug Fix**
|
||||
* Fix SystemJS module formatter exporting function parameters.
|
||||
* Ensure that invalid identifier JSX attribute keys are quoted when transforming to calls.
|
||||
* Fix ES3 property literal plugin.
|
||||
* Fix parameters after defaults in arrow functions refering to the wrong `arguments`.
|
||||
* Fix parser bug where arrow functions have a higher precedence than they should.
|
||||
|
||||
## 6.0.13
|
||||
|
||||
|
||||
@ -173,10 +173,18 @@ pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
|
||||
let node = this.startNodeAt(leftStartPos, leftStartLoc);
|
||||
node.left = left;
|
||||
node.operator = this.state.value;
|
||||
|
||||
if (node.operator === "**" && left.type === "UnaryExpression" && left.extra && !left.extra.parenthesizedArgument) {
|
||||
this.raise(left.argument.start, "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.");
|
||||
}
|
||||
|
||||
let op = this.state.type;
|
||||
this.next();
|
||||
let startPos = this.state.start, startLoc = this.state.startLoc;
|
||||
|
||||
let startPos = this.state.start;
|
||||
let startLoc = this.state.startLoc;
|
||||
node.right = this.parseExprOp(this.parseMaybeUnary(), startPos, startLoc, op.rightAssociative ? prec - 1 : prec, noIn);
|
||||
|
||||
this.finishNode(node, (op === tt.logicalOR || op === tt.logicalAND) ? "LogicalExpression" : "BinaryExpression");
|
||||
return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn);
|
||||
}
|
||||
@ -188,17 +196,26 @@ pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
|
||||
|
||||
pp.parseMaybeUnary = function (refShorthandDefaultPos) {
|
||||
if (this.state.type.prefix) {
|
||||
let node = this.startNode(), update = this.match(tt.incDec);
|
||||
let node = this.startNode();
|
||||
let update = this.match(tt.incDec);
|
||||
node.operator = this.state.value;
|
||||
node.prefix = true;
|
||||
this.next();
|
||||
|
||||
let argType = this.state.type;
|
||||
this.addExtra(node, "parenthesizedArgument", argType === tt.parenL);
|
||||
node.argument = this.parseMaybeUnary();
|
||||
if (refShorthandDefaultPos && refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start);
|
||||
|
||||
if (refShorthandDefaultPos && refShorthandDefaultPos.start) {
|
||||
this.unexpected(refShorthandDefaultPos.start);
|
||||
}
|
||||
|
||||
if (update) {
|
||||
this.checkLVal(node.argument);
|
||||
} else if (this.state.strict && node.operator === "delete" && node.argument.type === "Identifier") {
|
||||
this.raise(node.start, "Deleting local variable in strict mode");
|
||||
}
|
||||
|
||||
return this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
|
||||
}
|
||||
|
||||
|
||||
3
packages/babylon/test/fixtures/experimental/exponentiation-operator/options.json
vendored
Normal file
3
packages/babylon/test/fixtures/experimental/exponentiation-operator/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["exponentiationOperator"]
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
-5 ** 6;
|
||||
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:1)"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user