[Pkg-javascript-commits] [uglifyjs] 386/491: extend `__PURE__` to `AST_New` (#2706)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:55 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 446fb0198bd737c8d34035cc40932ed24ca83bbb
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Wed Jan 3 04:48:07 2018 +0800

    extend `__PURE__` to `AST_New` (#2706)
    
    fixes #2705
---
 lib/parse.js                |   6 ++-
 test/compress/pure_funcs.js | 121 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 125 insertions(+), 2 deletions(-)

diff --git a/lib/parse.js b/lib/parse.js
index 5eb7544..0345534 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -1225,12 +1225,14 @@ function parse($TEXT, options) {
         } else {
             args = [];
         }
-        return subscripts(new AST_New({
+        var call = new AST_New({
             start      : start,
             expression : newexp,
             args       : args,
             end        : prev()
-        }), allow_calls);
+        });
+        mark_pure(call);
+        return subscripts(call, allow_calls);
     };
 
     function as_atom_node() {
diff --git a/test/compress/pure_funcs.js b/test/compress/pure_funcs.js
index d15bcca..0df51e5 100644
--- a/test/compress/pure_funcs.js
+++ b/test/compress/pure_funcs.js
@@ -414,3 +414,124 @@ issue_2638: {
         "/* */(a()||b())(c(),d());",
     ]
 }
+
+issue_2705_1: {
+    options = {
+        side_effects: true,
+    }
+    beautify = {
+        comments: "all",
+    }
+    input: {
+        /*@__PURE__*/ new a();
+        /*@__PURE__*/ (new b());
+        new (/*@__PURE__*/ c)();
+        (/*@__PURE__*/ new d());
+    }
+    expect_exact: [
+        "new/* */c;",
+    ]
+}
+
+issue_2705_2: {
+    options = {
+        side_effects: true,
+    }
+    beautify = {
+        comments: "all",
+    }
+    input: {
+        /*@__PURE__*/ new a(1)(2)(3);
+        /*@__PURE__*/ new (b(1))(2)(3);
+        /*@__PURE__*/ new (c(1)(2))(3);
+        /*@__PURE__*/ new (d(1)(2)(3));
+        new (/*@__PURE__*/ e)(1)(2)(3);
+        (/*@__PURE__*/ new f(1))(2)(3);
+        (/*@__PURE__*/ new g(1)(2))(3);
+        (/*@__PURE__*/ new h(1)(2)(3));
+    }
+    expect_exact: [
+        "new/* */e(1)(2)(3);",
+        "/* */new f(1)(2)(3);",
+        "/* */new g(1)(2)(3);",
+    ]
+}
+
+issue_2705_3: {
+    options = {
+        side_effects: true,
+    }
+    beautify = {
+        comments: "all",
+    }
+    input: {
+        /*@__PURE__*/ new a.x(1).y(2).z(3);
+        /*@__PURE__*/ new (b.x)(1).y(2).z(3);
+        /*@__PURE__*/ new (c.x(1)).y(2).z(3);
+        /*@__PURE__*/ new (d.x(1).y)(2).z(3);
+        /*@__PURE__*/ new (e.x(1).y(2)).z(3);
+        /*@__PURE__*/ new (f.x(1).y(2).z)(3);
+        /*@__PURE__*/ new (g.x(1).y(2).z(3));
+        new (/*@__PURE__*/ h).x(1).y(2).z(3);
+        /* */ new (/*@__PURE__*/ i.x)(1).y(2).z(3);
+        (/*@__PURE__*/ new j.x(1)).y(2).z(3);
+        (/*@__PURE__*/ new k.x(1).y)(2).z(3);
+        (/*@__PURE__*/ new l.x(1).y(2)).z(3);
+        (/*@__PURE__*/ new m.x(1).y(2).z)(3);
+        (/*@__PURE__*/ new n.x(1).y(2).z(3));
+    }
+    expect_exact: [
+        "new/* */h.x(1).y(2).z(3);",
+        "/* */new/* */i.x(1).y(2).z(3);",
+        "/* */new j.x(1).y(2).z(3);",
+        "/* */new k.x(1).y(2).z(3);",
+        "/* */new l.x(1).y(2).z(3);",
+        "/* */new m.x(1).y(2).z(3);",
+    ]
+}
+
+issue_2705_4: {
+    options = {
+        side_effects: true,
+    }
+    input: {
+        (/*@__PURE__*/ new x(), y());
+        (w(), /*@__PURE__*/ new x(), y());
+    }
+    expect: {
+        y();
+        w(), y();
+    }
+}
+
+issue_2705_5: {
+    options = {
+        side_effects: true,
+    }
+    input: {
+        [ /*@__PURE__*/ new x() ];
+        [ /*@__PURE__*/ new x(), y() ];
+        [ w(), /*@__PURE__*/ new x(), y() ];
+    }
+    expect: {
+        y();
+        w(), y();
+    }
+}
+
+issue_2705_6: {
+    options = {
+        side_effects: true,
+    }
+    beautify = {
+        comments: "all",
+    }
+    input: {
+        /*@__PURE__*/new (g() || h())(x(), y());
+        /* */ new (/*@__PURE__*/ (a() || b()))(c(), d());
+    }
+    expect_exact: [
+        "/* */x(),y();",
+        "/* */new(/* */a()||b())(c(),d());",
+    ]
+}

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