[Pkg-javascript-commits] [uglifyjs] 117/228: fix top-level directives in compress tests (#1615)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:22 UTC 2017


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

js pushed a commit to branch master
in repository uglifyjs.

commit fb092839c26ddaa0614df5295be85ea207bda9f7
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sat Mar 18 01:56:15 2017 +0800

    fix top-level directives in compress tests (#1615)
    
    `input` and `expect` are parsed as `AST_BlockStatement` which does not support `AST_Directive` by default.
    
    Emulate that by transforming preceding `AST_SimpleStatement`s of `AST_String` into `AST_Directive`.
---
 test/compress/issue-1202.js |  1 -
 test/compress/screw-ie8.js  | 31 ++++++++++++++++++++-----------
 test/run-tests.js           | 17 +++++++++--------
 3 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/test/compress/issue-1202.js b/test/compress/issue-1202.js
index 136515f..27bc424 100644
--- a/test/compress/issue-1202.js
+++ b/test/compress/issue-1202.js
@@ -49,4 +49,3 @@ mangle_keep_fnames_true: {
         }
     }
 }
-
diff --git a/test/compress/screw-ie8.js b/test/compress/screw-ie8.js
index 4fbb95c..0fb68c2 100644
--- a/test/compress/screw-ie8.js
+++ b/test/compress/screw-ie8.js
@@ -1,20 +1,29 @@
 do_screw: {
-    options = { screw_ie8: true };
+    options = {
+        screw_ie8: true,
+    }
     beautify = {
         screw_ie8: true,
-        ascii_only: true
-    };
-
-    input: f("\v");
-    expect_exact: 'f("\\v");';
+        ascii_only: true,
+    }
+    input: {
+        f("\v");
+    }
+    expect_exact: 'f("\\v");'
 }
 
 dont_screw: {
-    options = { screw_ie8: false };
-    beautify = { screw_ie8: false, ascii_only: true };
-
-    input: f("\v");
-    expect_exact: 'f("\\x0B");';
+    options = {
+        screw_ie8: false,
+    }
+    beautify = {
+        screw_ie8: false,
+        ascii_only: true,
+    }
+    input: {
+        f("\v");
+    }
+    expect_exact: 'f("\\x0B");'
 }
 
 do_screw_constants: {
diff --git a/test/run-tests.js b/test/run-tests.js
index 898bb79..c3c142d 100755
--- a/test/run-tests.js
+++ b/test/run-tests.js
@@ -72,10 +72,15 @@ function test_directory(dir) {
 }
 
 function as_toplevel(input, mangle_options) {
-    if (input instanceof U.AST_BlockStatement) input = input.body;
-    else if (input instanceof U.AST_Statement) input = [ input ];
-    else throw new Error("Unsupported input syntax");
-    var toplevel = new U.AST_Toplevel({ body: input });
+    if (!(input instanceof U.AST_BlockStatement))
+        throw new Error("Unsupported input syntax");
+    for (var i = 0; i < input.body.length; i++) {
+        var stat = input.body[i];
+        if (stat instanceof U.AST_SimpleStatement && stat.body instanceof U.AST_String)
+            input.body[i] = new U.AST_Directive(stat.body);
+        else break;
+    }
+    var toplevel = new U.AST_Toplevel(input);
     toplevel.figure_out_scope(mangle_options);
     return toplevel;
 }
@@ -299,10 +304,6 @@ function parse_test(file) {
                     })
                 );
                 var stat = node.body;
-                if (stat instanceof U.AST_BlockStatement) {
-                    if (stat.body.length == 1) stat = stat.body[0];
-                    else if (stat.body.length == 0) stat = new U.AST_EmptyStatement();
-                }
                 if (label.name == "expect_exact") {
                     test[label.name] = read_string(stat);
                 } else if (label.name == "expect_stdout") {

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