diff --git a/lib/compress.js b/lib/compress.js index 7d20a4ea..db448563 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -89,13 +89,15 @@ merge(Compressor.prototype, { }, before: function(node, descend, in_list) { if (node._squeezed) return node; - var was_scope = false; + // asm.js: drop unused only, leave everything else as is inside "use asm" scope + var asm = this.has_directive("use asm"), + was_scope = false; if (node instanceof AST_Scope) { - node = node.hoist_declarations(this); + if (!asm) node = node.hoist_declarations(this); was_scope = true; } descend(node, this); - node = node.optimize(this); + if (!asm) node = node.optimize(this); if (was_scope && node instanceof AST_Scope) { node.drop_unused(this); descend(node, this); @@ -893,6 +895,15 @@ merge(Compressor.prototype, { def(AST_Constant, function(compressor){ return false }); def(AST_This, function(compressor){ return false }); + // asm.js: `new stdlib.XYZ` inside "use asm" scope are always pure + def(AST_New, function(compressor){ + if (compressor.has_directive("use asm")) return false; + // AST_Call fallback + var pure = compressor.option("pure_funcs"); + if (!pure) return true; + return pure.indexOf(this.expression.print_to_string()) < 0; + }); + def(AST_Call, function(compressor){ var pure = compressor.option("pure_funcs"); if (!pure) return true;