Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

resolved conflict

  • Loading branch information...
commit 56c62d97a552ef96d33e21ca9c181144259560e7 2 parents b32b6a1 + bf2cbf5
@mishoo mishoo authored
View
24 lib/process.js
@@ -599,6 +599,13 @@ function empty(b) {
return !b || (b[0] == "block" && (!b[1] || b[1].length == 0));
};
+function is_string(node) {
+ return (node[0] == "string" ||
+ node[0] == "unary-prefix" && node[1] == "typeof" ||
+ node[0] == "binary" && node[1] == "+" &&
+ (is_string(node[2]) || is_string(node[3])));
+};
+
var when_constant = (function(){
var $NOT_CONSTANT = {};
@@ -667,7 +674,15 @@ var when_constant = (function(){
}
return yes.call(expr, ast, val);
} catch(ex) {
- if (ex === $NOT_CONSTANT) return no ? no.call(expr, expr) : null;
+ if (ex === $NOT_CONSTANT) {
+ if (expr[0] == "binary"
+ && (expr[1] == "===" || expr[1] == "!==")
+ && ((is_string(expr[2]) && is_string(expr[3]))
+ || (boolean_expr(expr[2]) && boolean_expr(expr[3])))) {
+ expr[1] = expr[1].substr(0, 2);
+ }
+ return no ? no.call(expr, expr) : null;
+ }
else throw ex;
}
};
@@ -954,11 +969,10 @@ function ast_squeeze(ast, options) {
if (body) return rmblock([ "block", tighten(MAP(body, walk)) ]);
},
"binary": function(op, left, right) {
- var best = [ "binary", op, walk(left), walk(right) ];
- return when_constant(this, function yes(c){
- return best_of(walk(c), best_of(this, best));
+ return when_constant([ "binary", op, walk(left), walk(right) ], function yes(c){
+ return best_of(walk(c), this);
}, function no() {
- return best;
+ return this;
});
},
"conditional": function(c, t, e) {
View
1  test/unit/compress/expected/strict-equals.js
@@ -0,0 +1 @@
+typeof a=="string",b+""!=c+"",d<e==f<g
View
3  test/unit/compress/test/strict-equals.js
@@ -0,0 +1,3 @@
+typeof a === 'string'
+b + "" !== c + ""
+d < e === f < g
Please sign in to comment.
Something went wrong with that request. Please try again.