[Pkg-javascript-commits] [uglifyjs] 54/190: Fixed RegExp literal in mozilla AST generation/output and added a --dump-spidermonkey-ast flag

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Aug 7 23:17:12 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 83db98ad3bc92797df7a1cde009893af9e3dbaf3
Author: kzc <zaxxon2011 at gmail.com>
Date:   Sun Nov 1 01:02:52 2015 -0400

    Fixed RegExp literal in mozilla AST generation/output and added a --dump-spidermonkey-ast flag
---
 bin/uglifyjs       | 40 +++++++++++++++++++++++-----------------
 lib/mozilla-ast.js | 15 ++++++++++++++-
 2 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/bin/uglifyjs b/bin/uglifyjs
index ca75f15..8d4fe4d 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -73,6 +73,7 @@ You need to pass an argument to this option to specify the name that your module
     .describe("mangle-regex", "Only mangle property names matching the regex")
     .describe("name-cache", "File to hold mangled names mappings")
     .describe("pure-funcs", "List of functions that can be safely removed if their return value is not used")
+    .describe("dump-spidermonkey-ast", "Dump SpiderMonkey AST to stdout.")
 
     .alias("p", "prefix")
     .alias("o", "output")
@@ -117,6 +118,7 @@ You need to pass an argument to this option to specify the name that your module
     .boolean("stats")
     .boolean("acorn")
     .boolean("spidermonkey")
+    .boolean("dump-spidermonkey-ast")
     .boolean("lint")
     .boolean("V")
     .boolean("version")
@@ -444,26 +446,30 @@ async.eachLimit(files, 1, function (file, cb) {
         }
     }
 
-    time_it("generate", function(){
-        TOPLEVEL.print(output);
-    });
+    if (ARGS.dump_spidermonkey_ast) {
+        print(JSON.stringify(TOPLEVEL.to_mozilla_ast(), null, 2));
+    } else {
+        time_it("generate", function(){
+            TOPLEVEL.print(output);
+        });
 
-    output = output.get();
+        output = output.get();
 
-    if (SOURCE_MAP) {
-        fs.writeFileSync(ARGS.source_map, SOURCE_MAP, "utf8");
-        var source_map_url = ARGS.source_map_url || (
-            P_RELATIVE
-                ? path.relative(path.dirname(OUTPUT_FILE), ARGS.source_map)
-                : ARGS.source_map
-        );
-        output += "\n//# sourceMappingURL=" + source_map_url;
-    }
+        if (SOURCE_MAP) {
+            fs.writeFileSync(ARGS.source_map, SOURCE_MAP, "utf8");
+            var source_map_url = ARGS.source_map_url || (
+                P_RELATIVE
+                    ? path.relative(path.dirname(OUTPUT_FILE), ARGS.source_map)
+                    : ARGS.source_map
+            );
+            output += "\n//# sourceMappingURL=" + source_map_url;
+        }
 
-    if (OUTPUT_FILE) {
-        fs.writeFileSync(OUTPUT_FILE, output, "utf8");
-    } else {
-        print(output);
+        if (OUTPUT_FILE) {
+            fs.writeFileSync(OUTPUT_FILE, output, "utf8");
+        } else {
+            print(output);
+        }
     }
 
     if (ARGS.stats) {
diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js
index ac53ca2..0a439a5 100644
--- a/lib/mozilla-ast.js
+++ b/lib/mozilla-ast.js
@@ -146,7 +146,7 @@
               case "boolean":
                 return new (val ? AST_True : AST_False)(args);
               default:
-                args.value = val;
+                args.value = M.regex && M.raw ? M.raw : val;
                 return new AST_RegExp(args);
             }
         },
@@ -334,6 +334,19 @@
         };
     });
 
+    def_to_moz(AST_RegExp, function To_Moz_Literal(M) {
+        var value = M.value;
+        return {
+            type: "Literal",
+            value: value,
+            raw: value.toString(),
+            regex: {
+                pattern: value.source,
+                flags: value.toString().match(/[gimuy]*$/)[0]
+            }
+        };
+    });
+
     def_to_moz(AST_Constant, function To_Moz_Literal(M) {
         var value = M.value;
         if (typeof value === 'number' && (value < 0 || (value === 0 && 1 / value < 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