[Pkg-javascript-commits] [uglifyjs] 38/491: deprecate low level API (#1877)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:20 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 4f8ca4626efb15dc986785c89c51cbb3061e5f32
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Mon May 8 03:24:42 2017 +0800

    deprecate low level API (#1877)
    
    fixes #1872
---
 bin/uglifyjs                      |  4 ++--
 {tools => test}/exports.js        |  2 --
 test/mocha/accessorTokens-1492.js |  2 +-
 test/mocha/arguments.js           |  2 +-
 test/mocha/cli.js                 |  2 +-
 test/mocha/comment-filter.js      |  2 +-
 test/mocha/comment.js             |  2 +-
 test/mocha/directives.js          |  2 +-
 test/mocha/getter-setter.js       |  2 +-
 test/mocha/line-endings.js        |  2 +-
 test/mocha/minify.js              |  9 ---------
 test/mocha/number-literal.js      |  2 +-
 test/mocha/operator.js            |  2 +-
 test/mocha/spidermonkey.js        | 15 ++-------------
 test/mocha/string-literal.js      |  2 +-
 test/mocha/with.js                |  2 +-
 test/mozilla-ast.js               |  2 +-
 test/node.js                      |  6 ++++++
 test/run-tests.js                 |  2 +-
 test/sourcemaps.js                |  2 +-
 test/ufuzz.js                     |  2 +-
 tools/exports.js                  | 13 +------------
 tools/node.js                     | 18 +++++++++++-------
 23 files changed, 38 insertions(+), 61 deletions(-)

diff --git a/bin/uglifyjs b/bin/uglifyjs
index c4f9dc5..b67eb6b 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -89,7 +89,7 @@ if (program.mangleProps) {
         if (typeof program.mangleProps != "object") program.mangleProps = {};
         if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = [];
         require("../tools/domprops").forEach(function(name) {
-            UglifyJS.push_uniq(program.mangleProps.reserved, name);
+            UglifyJS._push_uniq(program.mangleProps.reserved, name);
         });
     }
     if (typeof options.mangle != "object") options.mangle = {};
@@ -187,7 +187,7 @@ function run() {
         }
         var result = UglifyJS.minify(files, options);
     } catch (ex) {
-        if (ex instanceof UglifyJS.JS_Parse_Error) {
+        if (ex.name == "SyntaxError") {
             console.error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col);
             var col = ex.col;
             var lines = files[ex.filename].split(/\r?\n/);
diff --git a/tools/exports.js b/test/exports.js
similarity index 87%
copy from tools/exports.js
copy to test/exports.js
index fec003d..f50b772 100644
--- a/tools/exports.js
+++ b/test/exports.js
@@ -1,5 +1,4 @@
 exports["Compressor"] = Compressor;
-exports["Dictionary"] = Dictionary;
 exports["JS_Parse_Error"] = JS_Parse_Error;
 exports["OutputStream"] = OutputStream;
 exports["SourceMap"] = SourceMap;
@@ -9,7 +8,6 @@ exports["defaults"] = defaults;
 exports["mangle_properties"] = mangle_properties;
 exports["minify"] = minify;
 exports["parse"] = parse;
-exports["push_uniq"] = push_uniq;
 exports["string_template"] = string_template;
 exports["tokenizer"] = tokenizer;
 exports["is_identifier"] = is_identifier;
diff --git a/test/mocha/accessorTokens-1492.js b/test/mocha/accessorTokens-1492.js
index 861414e..2b5bbea 100644
--- a/test/mocha/accessorTokens-1492.js
+++ b/test/mocha/accessorTokens-1492.js
@@ -1,4 +1,4 @@
-var UglifyJS = require('../../');
+var UglifyJS = require("../node");
 var assert = require("assert");
 
 describe("Accessor tokens", function() {
diff --git a/test/mocha/arguments.js b/test/mocha/arguments.js
index 73993a7..998978e 100644
--- a/test/mocha/arguments.js
+++ b/test/mocha/arguments.js
@@ -1,4 +1,4 @@
-var UglifyJS = require('../../');
+var UglifyJS = require("../node");
 var assert = require("assert");
 
 describe("arguments", function() {
diff --git a/test/mocha/cli.js b/test/mocha/cli.js
index 9d8d496..cac920d 100644
--- a/test/mocha/cli.js
+++ b/test/mocha/cli.js
@@ -19,7 +19,7 @@ describe("bin/uglifyjs", function () {
             eval(stdout);
 
             assert.strictEqual(typeof WrappedUglifyJS, 'object');
-            assert.strictEqual(true, WrappedUglifyJS.parse('foo;') instanceof WrappedUglifyJS.AST_Node);
+            assert.strictEqual(WrappedUglifyJS.minify("foo([true,,2+3]);").code, "foo([!0,,5]);");
 
             done();
         });
diff --git a/test/mocha/comment-filter.js b/test/mocha/comment-filter.js
index 4b74ebf..0e4f3df 100644
--- a/test/mocha/comment-filter.js
+++ b/test/mocha/comment-filter.js
@@ -1,4 +1,4 @@
-var UglifyJS = require('../../');
+var UglifyJS = require("../node");
 var assert = require("assert");
 
 describe("comment filters", function() {
diff --git a/test/mocha/comment.js b/test/mocha/comment.js
index acad369..6b5428d 100644
--- a/test/mocha/comment.js
+++ b/test/mocha/comment.js
@@ -1,5 +1,5 @@
 var assert = require("assert");
-var uglify = require("../../");
+var uglify = require("../node");
 
 describe("Comment", function() {
     it("Should recognize eol of single line comments", function() {
diff --git a/test/mocha/directives.js b/test/mocha/directives.js
index 16279a5..ab8ad57 100644
--- a/test/mocha/directives.js
+++ b/test/mocha/directives.js
@@ -1,5 +1,5 @@
 var assert = require("assert");
-var uglify = require("../../");
+var uglify = require("../node");
 
 describe("Directives", function() {
     it ("Should allow tokenizer to store directives state", function() {
diff --git a/test/mocha/getter-setter.js b/test/mocha/getter-setter.js
index 641a202..83bf579 100644
--- a/test/mocha/getter-setter.js
+++ b/test/mocha/getter-setter.js
@@ -1,4 +1,4 @@
-var UglifyJS = require('../../');
+var UglifyJS = require("../node");
 var assert = require("assert");
 
 describe("Getters and setters", function() {
diff --git a/test/mocha/line-endings.js b/test/mocha/line-endings.js
index 379ee2b..6b66681 100644
--- a/test/mocha/line-endings.js
+++ b/test/mocha/line-endings.js
@@ -1,4 +1,4 @@
-var Uglify = require('../../');
+var Uglify = require("../node");
 var assert = require("assert");
 
 describe("line-endings", function() {
diff --git a/test/mocha/minify.js b/test/mocha/minify.js
index 18840a5..d69ef59 100644
--- a/test/mocha/minify.js
+++ b/test/mocha/minify.js
@@ -183,13 +183,4 @@ describe("minify", function() {
             });
         });
     });
-
-    describe("Compressor", function() {
-        it("should be backward compatible with ast.transform(compressor)", function() {
-            var ast = Uglify.parse("function f(a){for(var i=0;i<a;i++)console.log(i)}");
-            ast.figure_out_scope();
-            ast = ast.transform(Uglify.Compressor());
-            assert.strictEqual(ast.print_to_string(), "function f(a){for(var i=0;i<a;i++)console.log(i)}");
-        });
-    })
 });
diff --git a/test/mocha/number-literal.js b/test/mocha/number-literal.js
index e80a531..f4e2f5d 100644
--- a/test/mocha/number-literal.js
+++ b/test/mocha/number-literal.js
@@ -1,5 +1,5 @@
 var assert = require("assert");
-var uglify = require("../../");
+var uglify = require("../node");
 
 describe("Number literals", function () {
     it("Should not allow legacy octal literals in strict mode", function() {
diff --git a/test/mocha/operator.js b/test/mocha/operator.js
index adef3ab..64db02c 100644
--- a/test/mocha/operator.js
+++ b/test/mocha/operator.js
@@ -1,4 +1,4 @@
-var UglifyJS = require("../../");
+var UglifyJS = require("../node");
 var assert = require("assert");
 
 describe("operator", function() {
diff --git a/test/mocha/spidermonkey.js b/test/mocha/spidermonkey.js
index e5bf45a..4071a13 100644
--- a/test/mocha/spidermonkey.js
+++ b/test/mocha/spidermonkey.js
@@ -1,6 +1,6 @@
 var assert = require("assert");
 var exec = require("child_process").exec;
-var uglify = require("../../");
+var uglify = require("../node");
 
 describe("spidermonkey export/import sanity test", function() {
     it("should produce a functional build when using --self with spidermonkey", function(done) {
@@ -15,18 +15,7 @@ describe("spidermonkey export/import sanity test", function() {
 
             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]);");
+            assert.strictEqual(SpiderUglify.minify("foo([true,,2+3]);").code, "foo([!0,,5]);");
 
             done();
         });
diff --git a/test/mocha/string-literal.js b/test/mocha/string-literal.js
index 6e337a2..fde6db5 100644
--- a/test/mocha/string-literal.js
+++ b/test/mocha/string-literal.js
@@ -1,4 +1,4 @@
-var UglifyJS = require('../../');
+var UglifyJS = require("../node");
 var assert = require("assert");
 
 describe("String literals", function() {
diff --git a/test/mocha/with.js b/test/mocha/with.js
index a74ef41..72fd76e 100644
--- a/test/mocha/with.js
+++ b/test/mocha/with.js
@@ -1,5 +1,5 @@
 var assert = require("assert");
-var uglify = require("../../");
+var uglify = require("../node");
 
 describe("With", function() {
     it("Should throw syntaxError when using with statement in strict mode", function() {
diff --git a/test/mozilla-ast.js b/test/mozilla-ast.js
index e4c84df..544ce8b 100644
--- a/test/mozilla-ast.js
+++ b/test/mozilla-ast.js
@@ -1,7 +1,7 @@
 // Testing UglifyJS <-> SpiderMonkey AST conversion
 // through generative testing.
 
-var UglifyJS = require(".."),
+var UglifyJS = require("./node"),
     escodegen = require("escodegen"),
     esfuzz = require("esfuzz"),
     estraverse = require("estraverse"),
diff --git a/test/node.js b/test/node.js
new file mode 100644
index 0000000..22bf325
--- /dev/null
+++ b/test/node.js
@@ -0,0 +1,6 @@
+var fs = require("fs");
+
+new Function("MOZ_SourceMap", "exports", require("../tools/node").FILES.map(function(file) {
+    if (/exports\.js$/.test(file)) file = require.resolve("./exports");
+    return fs.readFileSync(file, "utf8");
+}).join("\n\n"))(require("source-map"), exports);
diff --git a/test/run-tests.js b/test/run-tests.js
index f3c62e7..05afc1b 100755
--- a/test/run-tests.js
+++ b/test/run-tests.js
@@ -1,6 +1,6 @@
 #! /usr/bin/env node
 
-var U = require("../tools/node");
+var U = require("./node");
 var path = require("path");
 var fs = require("fs");
 var assert = require("assert");
diff --git a/test/sourcemaps.js b/test/sourcemaps.js
index 7db4672..4757d1e 100644
--- a/test/sourcemaps.js
+++ b/test/sourcemaps.js
@@ -1,4 +1,4 @@
-var UglifyJS = require("..");
+var UglifyJS = require("./node");
 var ok = require("assert");
 
 module.exports = function () {
diff --git a/test/ufuzz.js b/test/ufuzz.js
index 48e33f7..b2ec9e0 100644
--- a/test/ufuzz.js
+++ b/test/ufuzz.js
@@ -12,7 +12,7 @@
         stream._handle.setBlocking(true);
 });
 
-var UglifyJS = require("..");
+var UglifyJS = require("./node");
 var randomBytes = require("crypto").randomBytes;
 var sandbox = require("./sandbox");
 
diff --git a/tools/exports.js b/tools/exports.js
index fec003d..0ffff65 100644
--- a/tools/exports.js
+++ b/tools/exports.js
@@ -1,15 +1,4 @@
-exports["Compressor"] = Compressor;
 exports["Dictionary"] = Dictionary;
-exports["JS_Parse_Error"] = JS_Parse_Error;
-exports["OutputStream"] = OutputStream;
-exports["SourceMap"] = SourceMap;
 exports["TreeWalker"] = TreeWalker;
-exports["base54"] = base54;
-exports["defaults"] = defaults;
-exports["mangle_properties"] = mangle_properties;
 exports["minify"] = minify;
-exports["parse"] = parse;
-exports["push_uniq"] = push_uniq;
-exports["string_template"] = string_template;
-exports["tokenizer"] = tokenizer;
-exports["is_identifier"] = is_identifier;
+exports["_push_uniq"] = push_uniq;
diff --git a/tools/node.js b/tools/node.js
index 9c82e74..227c23b 100644
--- a/tools/node.js
+++ b/tools/node.js
@@ -18,15 +18,19 @@ var FILES = UglifyJS.FILES = [
     return require.resolve(file);
 });
 
-new Function("MOZ_SourceMap", "exports", FILES.map(function(file){
-    return fs.readFileSync(file, "utf8");
-}).join("\n\n"))(
+new Function("MOZ_SourceMap", "exports", function() {
+    var code = FILES.map(function(file) {
+        return fs.readFileSync(file, "utf8");
+    });
+    code.push("exports.describe_ast = " + describe_ast.toString());
+    return code.join("\n\n");
+}())(
     require("source-map"),
     UglifyJS
 );
 
-UglifyJS.describe_ast = function() {
-    var out = UglifyJS.OutputStream({ beautify: true });
+function describe_ast() {
+    var out = OutputStream({ beautify: true });
     function doitem(ctor) {
         out.print("AST_" + ctor.TYPE);
         var props = ctor.SELF_PROPS.filter(function(prop){
@@ -56,6 +60,6 @@ UglifyJS.describe_ast = function() {
             });
         }
     };
-    doitem(UglifyJS.AST_Node);
+    doitem(AST_Node);
     return out + "";
-};
+}

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