aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-01-03 04:48:07 +0800
committerGitHub <noreply@github.com>2018-01-03 04:48:07 +0800
commit446fb0198bd737c8d34035cc40932ed24ca83bbb (patch)
treed4f3d841ec67e45500f67f89df46384f9cfbfa84
parent7d3cddf9d624d169c6667a52e8d6f313d1b30159 (diff)
downloadtracifyjs-446fb0198bd737c8d34035cc40932ed24ca83bbb.tar.gz
tracifyjs-446fb0198bd737c8d34035cc40932ed24ca83bbb.zip
extend `__PURE__` to `AST_New` (#2706)
fixes #2705
-rw-r--r--lib/parse.js6
-rw-r--r--test/compress/pure_funcs.js121
2 files changed, 125 insertions, 2 deletions
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());",
+ ]
+}