aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js3
-rw-r--r--lib/output.js13
-rw-r--r--lib/parse.js6
3 files changed, 18 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js
index d79c1cce..ac380cf3 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4168,6 +4168,9 @@ merge(Compressor.prototype, {
case "<=" : result = left <= right; break;
case ">" : result = left > right; break;
case ">=" : result = left >= right; break;
+ case "**":
+ result = Math.pow(left, right);
+ break;
case "in":
if (right && typeof right == "object" && HOP(right, left)) {
result = true;
diff --git a/lib/output.js b/lib/output.js
index f2748e9e..8521d7ef 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -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;
diff --git a/lib/parse.js b/lib/parse.js
index 64307a95..38c56d8f 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -81,6 +81,7 @@ var OPERATORS = makePredicate([
"*",
"/",
"%",
+ "**",
">>",
"<<",
">>>",
@@ -630,7 +631,8 @@ var PRECEDENCE = function(a, ret) {
["<", ">", "<=", ">=", "in", "instanceof"],
[">>", "<<", ">>>"],
["+", "-"],
- ["*", "/", "%"]
+ ["*", "/", "%"],
+ ["**"],
], {});
var ATOMIC_START_TOKEN = makePredicate("atom bigint num regexp string");
@@ -1860,7 +1862,7 @@ function parse($TEXT, options) {
var prec = op != null ? PRECEDENCE[op] : null;
if (prec != null && prec > min_prec) {
next();
- var right = expr_op(maybe_await(), prec, no_in);
+ var right = expr_op(maybe_await(), op == "**" ? prec - 1 : prec, no_in);
return expr_op(new AST_Binary({
start : left.start,
left : left,