[Pkg-javascript-commits] [uglifyjs] 217/491: fix "use asm" numeric output (#2328)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:37 UTC 2018


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit 7e3e9da860d9da4fa3d5e37bea4d3bd399194c02
Author: kzc <kzc at users.noreply.github.com>
Date:   Wed Sep 20 12:52:48 2017 -0400

    fix "use asm" numeric output (#2328)
    
    fixes #2324
---
 lib/output.js        | 16 +++++++++-----
 test/compress/asm.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 6 deletions(-)

diff --git a/lib/output.js b/lib/output.js
index 315bfaf..1aa6345 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 9b22732..527e6b4 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;'
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list