support exponentiation operator (#4593)
This commit is contained in:
@@ -684,6 +684,10 @@ function OutputStream(options) {
|
||||
|
||||
PARENS(AST_Unary, function(output) {
|
||||
var p = output.parent();
|
||||
// (-x) ** y
|
||||
if (p instanceof AST_Binary) return p.operator == "**" && p.left === this;
|
||||
// (x++).toString(3)
|
||||
// (typeof x).length
|
||||
return (p instanceof AST_Call || p instanceof AST_PropAccess) && p.expression === this;
|
||||
});
|
||||
|
||||
@@ -722,11 +726,14 @@ function OutputStream(options) {
|
||||
var p = output.parent();
|
||||
// await (foo && bar)
|
||||
if (p instanceof AST_Await) return true;
|
||||
// this deals with precedence: 3 * (2 + 1)
|
||||
// this deals with precedence:
|
||||
// 3 * (2 + 1)
|
||||
// 3 - (2 - 1)
|
||||
// (1 ** 2) ** 3
|
||||
if (p instanceof AST_Binary) {
|
||||
var po = p.operator, pp = PRECEDENCE[po];
|
||||
var so = this.operator, sp = PRECEDENCE[so];
|
||||
return pp > sp || (pp == sp && this === p.right);
|
||||
return pp > sp || (pp == sp && this === p[po == "**" ? "left" : "right"]);
|
||||
}
|
||||
// (foo && bar)()
|
||||
if (p instanceof AST_Call) return p.expression === this;
|
||||
@@ -818,6 +825,8 @@ function OutputStream(options) {
|
||||
|
||||
PARENS(AST_Await, function(output) {
|
||||
var p = output.parent();
|
||||
// (await x) ** y
|
||||
if (p instanceof AST_Binary) return p.operator == "**" && p.left === this;
|
||||
// new (await foo)
|
||||
// (await foo)(bar)
|
||||
if (p instanceof AST_Call) return p.expression === this;
|
||||
|
||||
Reference in New Issue
Block a user