From: kzc Date: Wed, 20 Sep 2017 16:52:48 +0000 (-0400) Subject: fix "use asm" numeric output (#2328) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=7e3e9da860d9da4fa3d5e37bea4d3bd399194c02;p=UglifyJS.git fix "use asm" numeric output (#2328) fixes #2324 --- diff --git a/lib/output.js b/lib/output.js index 315bfafd..1aa63450 100644 --- a/lib/output.js +++ b/lib/output.js @@ -482,13 +482,17 @@ function OutputStream(options) { nodetype.DEFMETHOD("_codegen", generator); }; - var use_asm = false; var in_directive = false; + var active_scope = null; + var use_asm = null; AST_Node.DEFMETHOD("print", function(stream, force_parens){ - var self = this, generator = self._codegen, prev_use_asm = use_asm; - if (self instanceof AST_Directive && self.value == "use asm" && stream.parent() instanceof AST_Scope) { - use_asm = true; + var self = this, generator = self._codegen; + if (self instanceof AST_Scope) { + active_scope = self; + } + else if (!use_asm && self instanceof AST_Directive && self.value == "use asm") { + use_asm = active_scope; } function doit() { self.add_comments(stream); @@ -502,8 +506,8 @@ function OutputStream(options) { doit(); } stream.pop_node(); - if (self instanceof AST_Scope) { - use_asm = prev_use_asm; + if (self === use_asm) { + use_asm = null; } }); AST_Node.DEFMETHOD("_print", AST_Node.prototype.print); diff --git a/test/compress/asm.js b/test/compress/asm.js index 9b227326..527e6b43 100644 --- a/test/compress/asm.js +++ b/test/compress/asm.js @@ -104,3 +104,65 @@ asm_mixed: { } } +asm_toplevel: { + options = {} + input: { + "use asm"; + 0.0; + function f() { + 0.0; + (function(){ + 0.0; + }); + } + 0.0; + } + expect_exact: '"use asm";0.0;function f(){0.0;(function(){0.0})}0.0;' +} + +asm_function_expression: { + options = {} + input: { + 0.0; + var a = function() { + "use asm"; + 0.0; + } + function f() { + 0.0; + return function(){ + "use asm"; + 0.0; + } + 0.0; + } + 0.0; + } + expect_exact: '0;var a=function(){"use asm";0.0};function f(){0;return function(){"use asm";0.0};0}0;' +} + +asm_nested_functions: { + options = {} + input: { + 0.0; + function a() { + "use asm"; + 0.0; + } + 0.0; + function b() { + 0.0; + function c(){ + "use asm"; + 0.0; + } + 0.0; + function d(){ + 0.0; + } + 0.0; + } + 0.0; + } + expect_exact: '0;function a(){"use asm";0.0}0;function b(){0;function c(){"use asm";0.0}0;function d(){0}0}0;' +}