aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-04-01 07:39:51 +0100
committerGitHub <noreply@github.com>2021-04-01 14:39:51 +0800
commitcea1fb5c58a336fad3e34478ab563b66f0d26988 (patch)
treec7a771b9e3d5f17ccf3eaf245c34a1e41fd89834
parent1947a21824f3cbbb7a3c8267a15fa9c80b91fc59 (diff)
downloadtracifyjs-cea1fb5c58a336fad3e34478ab563b66f0d26988.tar.gz
tracifyjs-cea1fb5c58a336fad3e34478ab563b66f0d26988.zip
fix corner case in `properties` (#4832)
fixes #4831
-rw-r--r--lib/compress.js5
-rw-r--r--test/compress/classes.js34
-rw-r--r--test/compress/properties.js46
3 files changed, 83 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 5aeb910e..0433dd6a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -11460,7 +11460,10 @@ merge(Compressor.prototype, {
props = props.map(function(prop) {
return prop.value;
});
- if (prop instanceof AST_ObjectMethod && prop.value instanceof AST_Function) {
+ if (prop instanceof AST_ObjectMethod
+ && prop.value instanceof AST_Function
+ && !(compressor.parent() instanceof AST_Call)) {
+ if (prop.value.uses_arguments) break;
props[i] = make_node(AST_Arrow, prop.value, prop.value);
}
return make_node(AST_Sub, this, {
diff --git a/test/compress/classes.js b/test/compress/classes.js
index b428e0e1..8e7b1dc9 100644
--- a/test/compress/classes.js
+++ b/test/compress/classes.js
@@ -1345,7 +1345,7 @@ issue_4821_2: {
node_version: ">=12"
}
-issue_4829: {
+issue_4829_1: {
options = {
properties: true,
}
@@ -1368,3 +1368,35 @@ issue_4829: {
expect_stdout: "PASS"
node_version: ">=4"
}
+
+issue_4829_2: {
+ options = {
+ properties: true,
+ }
+ input: {
+ "use strict";
+ try {
+ class A extends {
+ f() {
+ return arguments;
+ },
+ }.f {}
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect: {
+ "use strict";
+ try {
+ class A extends {
+ f() {
+ return arguments;
+ },
+ }.f {}
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect_stdout: "PASS"
+ node_version: ">=4"
+}
diff --git a/test/compress/properties.js b/test/compress/properties.js
index eb47624a..2fc2cea5 100644
--- a/test/compress/properties.js
+++ b/test/compress/properties.js
@@ -1400,3 +1400,49 @@ object_super: {
expect_stdout: "PASS"
node_version: ">=4"
}
+
+issue_4831_1: {
+ options = {
+ properties: true,
+ }
+ input: {
+ console.log({
+ f() {
+ return arguments;
+ },
+ }.f("PASS")[0]);
+ }
+ expect: {
+ console.log([
+ function() {
+ return arguments;
+ },
+ ][0]("PASS")[0]);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=4"
+}
+
+issue_4831_2: {
+ options = {
+ properties: true,
+ }
+ input: {
+ var f = {
+ f() {
+ return arguments;
+ },
+ }.f;
+ console.log(f("PASS")[0]);
+ }
+ expect: {
+ var f = {
+ f() {
+ return arguments;
+ },
+ }.f;
+ console.log(f("PASS")[0]);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=4"
+}