Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Undo commit 133b36f

Using the tokenizer there slows down the code generator by orders of
magnitude (26s instead of 2s for 600K code).  It's not worth to trade so
many seconds for a couple extra-parens.

I hope the tree is in good shape now, except for issue #368.
  • Loading branch information...
commit 59ce11d0abab902ca05bf5aee1138af13e1837db 1 parent f834ec6
Mihai Bazon authored
20 lib/process.js
@@ -1508,7 +1508,7 @@ function gen_code(ast, options) {
1508 1508
1509 1509 function parenthesize(expr) {
1510 1510 var gen = make(expr);
1511   - if (!has_parens(gen)) for (var i = 1; i < arguments.length; ++i) {
  1511 + for (var i = 1; i < arguments.length; ++i) {
1512 1512 var el = arguments[i];
1513 1513 if ((el instanceof Function && el(expr)) || expr[0] == el)
1514 1514 return "(" + gen + ")";
@@ -1553,22 +1553,6 @@ function gen_code(ast, options) {
1553 1553 return !HOP(DOT_CALL_NO_PARENS, expr[0]);
1554 1554 };
1555 1555
1556   - function has_parens(expr) {
1557   - var parentheses = 0, position = 0, token;
1558   - do {
1559   - token = jsp.tokenizer("(" + expr.slice(position) + ")")();
1560   - position += token.endpos;
1561   - if (token.type == "punc") {
1562   - if (token.value == "(") {
1563   - ++parentheses;
1564   - } else if (token.value == ")") {
1565   - --parentheses;
1566   - }
1567   - }
1568   - } while (position < expr.length && parentheses > 0);
1569   - return position == expr.length && parentheses == 0;
1570   - }
1571   -
1572 1556 function make_num(num) {
1573 1557 var str = num.toString(10), a = [ str.replace(/^0\./, ".") ], m;
1574 1558 if (Math.floor(num) === num) {
@@ -1679,7 +1663,7 @@ function gen_code(ast, options) {
1679 1663 if (expr[0] == "num") {
1680 1664 if (!/[a-f.]/i.test(out))
1681 1665 out += ".";
1682   - } else if (expr[0] != "function" && !has_parens(out) && needs_parens(expr))
  1666 + } else if (expr[0] != "function" && needs_parens(expr))
1683 1667 out = "(" + out + ")";
1684 1668 while (i < arguments.length)
1685 1669 out += "." + make_name(arguments[i++]);
1  test/unit/compress/expected/issue368.js
... ... @@ -1 +0,0 @@
1   -({}).constructor,new((0,Math)?Function:Math),((0,0)&0).valueOf()
3  test/unit/compress/test/issue368.js
... ... @@ -1,3 +0,0 @@
1   -({}.constructor);
2   -new ((0, Math) ? Function : Math)();
3   -((0, 0) & 0).valueOf();

0 comments on commit 59ce11d

Please sign in to comment.
Something went wrong with that request. Please try again.