aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-04-06 17:10:36 +0800
committerGitHub <noreply@github.com>2018-04-06 17:10:36 +0800
commitdb49daf365598986106c95def10e619e4e6ba4a0 (patch)
treea0db2e633a151de5fe1b6cb8fa30bbf1b0795abb
parent923deeff35b708e49c4d8bcfa64dc53832cd4b5a (diff)
downloadtracifyjs-db49daf365598986106c95def10e619e4e6ba4a0.tar.gz
tracifyjs-db49daf365598986106c95def10e619e4e6ba4a0.zip
mangle `Object.defineProperty()` (#3059)
fixes #869
-rw-r--r--lib/propmangle.js8
-rw-r--r--test/compress/properties.js58
2 files changed, 66 insertions, 0 deletions
diff --git a/lib/propmangle.js b/lib/propmangle.js
index ffc8faf8..1bca1ad4 100644
--- a/lib/propmangle.js
+++ b/lib/propmangle.js
@@ -150,6 +150,10 @@ function mangle_properties(ast, options) {
else if (node instanceof AST_Sub) {
addStrings(node.property, add);
}
+ else if (node instanceof AST_Call
+ && node.expression.print_to_string() == "Object.defineProperty") {
+ addStrings(node.args[1], add);
+ }
}));
// step 2: transform the tree, renaming properties
@@ -167,6 +171,10 @@ function mangle_properties(ast, options) {
else if (!options.keep_quoted && node instanceof AST_Sub) {
node.property = mangleStrings(node.property);
}
+ else if (node instanceof AST_Call
+ && node.expression.print_to_string() == "Object.defineProperty") {
+ node.args[1] = mangleStrings(node.args[1]);
+ }
}));
// only function declarations after this line
diff --git a/test/compress/properties.js b/test/compress/properties.js
index 419c7f85..ec99c090 100644
--- a/test/compress/properties.js
+++ b/test/compress/properties.js
@@ -1640,3 +1640,61 @@ issue_2893_2: {
}
expect_stdout: "PASS"
}
+
+issue_869_1: {
+ mangle = {
+ properties: {
+ reserved: [ "get" ]
+ },
+ }
+ input: {
+ var o = { p: "FAIL" };
+ Object.defineProperty(o, "p", {
+ get: function() {
+ return "PASS";
+ }
+ });
+ console.log(o.p);
+ }
+ expect: {
+ var o = { o: "FAIL" };
+ Object.defineProperty(o, "o", {
+ get: function() {
+ return "PASS";
+ }
+ });
+ console.log(o.o);
+ }
+ expect_stdout: "PASS"
+}
+
+issue_869_2: {
+ mangle = {
+ properties: {
+ reserved: [ "get" ]
+ },
+ }
+ input: {
+ var o = { p: "FAIL" };
+ Object.defineProperties(o, {
+ p: {
+ get: function() {
+ return "PASS";
+ }
+ }
+ });
+ console.log(o.p);
+ }
+ expect: {
+ var o = { o: "FAIL" };
+ Object.defineProperties(o, {
+ o: {
+ get: function() {
+ return "PASS";
+ }
+ }
+ });
+ console.log(o.o);
+ }
+ expect_stdout: "PASS"
+}