[Pkg-javascript-commits] [uglifyjs] 179/190: Fix spidermonkey AST (ESTree) export and import, Array holes

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Aug 7 23:17:24 UTC 2016


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

terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.

commit 335b72df03fb6593d4bac8ddcde7d1b128eb3c4e
Author: kzc <zaxxon2011 at gmail.com>
Date:   Thu Jun 23 12:54:38 2016 -0400

    Fix spidermonkey AST (ESTree) export and import, Array holes
    
    Fixes: #1156 #1161
    
    Also add test to exercise Uglify after spidermonkey export/import of itself.
---
 lib/compress.js            |  2 +-
 lib/mozilla-ast.js         | 17 ++++++++++++++++-
 test/mocha/spidermonkey.js | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 4152bd0..527b8e6 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -190,7 +190,7 @@ merge(Compressor.prototype, {
             if ((1 / val) < 0) {
                 return make_node(AST_UnaryPrefix, orig, {
                     operator: "-",
-                    expression: make_node(AST_Number, null, { value: -val })
+                    expression: make_node(AST_Number, orig, { value: -val })
                 });
             }
 
diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js
index c1b2b68..3433221 100644
--- a/lib/mozilla-ast.js
+++ b/lib/mozilla-ast.js
@@ -94,6 +94,15 @@
                 return new AST_ObjectGetter(args);
             }
         },
+        ArrayExpression: function(M) {
+            return new AST_Array({
+                start    : my_start_token(M),
+                end      : my_end_token(M),
+                elements : M.elements.map(function(elem){
+                    return elem === null ? new AST_Hole() : from_moz(elem);
+                })
+            });
+        },
         ObjectExpression: function(M) {
             return new AST_Object({
                 start      : my_start_token(M),
@@ -206,7 +215,6 @@
     map("CatchClause", AST_Catch, "param>argname, body%body");
 
     map("ThisExpression", AST_This);
-    map("ArrayExpression", AST_Array, "elements at elements");
     map("FunctionExpression", AST_Function, "id>name, params at argnames, body%body");
     map("BinaryExpression", AST_Binary, "operator=operator, left>left, right>right");
     map("LogicalExpression", AST_Binary, "operator=operator, left>left, right>right");
@@ -302,6 +310,13 @@
         };
     });
 
+    def_to_moz(AST_Array, function To_Moz_ArrayExpression(M) {
+        return {
+            type: "ArrayExpression",
+            elements: M.elements.map(to_moz)
+        };
+    });
+
     def_to_moz(AST_Object, function To_Moz_ObjectExpression(M) {
         return {
             type: "ObjectExpression",
diff --git a/test/mocha/spidermonkey.js b/test/mocha/spidermonkey.js
new file mode 100644
index 0000000..f507ad1
--- /dev/null
+++ b/test/mocha/spidermonkey.js
@@ -0,0 +1,33 @@
+var assert = require("assert");
+var exec = require("child_process").exec;
+
+describe("spidermonkey export/import sanity test", function() {
+    it("should produce a functional build when using --self with spidermonkey", function (done) {
+        this.timeout(20000);
+
+        var uglifyjs = '"' + process.argv[0] + '" bin/uglifyjs';
+        var command = uglifyjs + " --self -cm --wrap SpiderUglify --dump-spidermonkey-ast | " +
+            uglifyjs + " --spidermonkey -cm";
+
+        exec(command, function (err, stdout) {
+            if (err) throw err;
+
+            eval(stdout);
+            assert.strictEqual(typeof SpiderUglify, "object");
+
+            var ast = SpiderUglify.parse("foo([true,,2+3]);");
+            assert.strictEqual(true, ast instanceof SpiderUglify.AST_Node);
+
+            ast.figure_out_scope();
+            ast = SpiderUglify.Compressor({}).compress(ast);
+            assert.strictEqual(true, ast instanceof SpiderUglify.AST_Node);
+
+            var stream = SpiderUglify.OutputStream({});
+            ast.print(stream);
+            var code = stream.toString();
+            assert.strictEqual(code, "foo([!0,,5]);");
+
+            done();
+        });
+    });
+});

-- 
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