From: Alex Lam S.L Date: Tue, 2 Jan 2018 20:48:07 +0000 (+0800) Subject: extend `__PURE__` to `AST_New` (#2706) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=446fb0198bd737c8d34035cc40932ed24ca83bbb;p=UglifyJS.git extend `__PURE__` to `AST_New` (#2706) fixes #2705 --- diff --git a/lib/parse.js b/lib/parse.js index 5eb75441..03455348 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 d15bcca3..0df51e5f 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());", + ] +}