diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-03-16 01:42:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-16 09:42:28 +0800 |
commit | 77c9116c91e8a758263ab68a7a7f720dcb7e0214 (patch) | |
tree | e9b496ea2c925d5315cf4d4de3229ba945220926 | |
parent | e821787095d856448940ab93a7a03febb7e644de (diff) | |
download | tracifyjs-77c9116c91e8a758263ab68a7a7f720dcb7e0214.tar.gz tracifyjs-77c9116c91e8a758263ab68a7a7f720dcb7e0214.zip |
fix corner case in `unsafe` (#4783)
-rw-r--r-- | lib/compress.js | 5 | ||||
-rw-r--r-- | test/compress/pure_getters.js | 46 |
2 files changed, 49 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index 563d09d9..da756774 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -8522,11 +8522,12 @@ merge(Compressor.prototype, { } else if (exp instanceof AST_Dot) switch (exp.property) { case "toString": // x.toString() ---> "" + x - if (self.args.length == 0 && !exp.expression.may_throw_on_access(compressor)) { + var expr = exp.expression; + if (self.args.length == 0 && !(expr.may_throw_on_access(compressor) || expr instanceof AST_Super)) { return make_node(AST_Binary, self, { operator: "+", left: make_node(AST_String, self, { value: "" }), - right: exp.expression, + right: expr, }).optimize(compressor); } break; diff --git a/test/compress/pure_getters.js b/test/compress/pure_getters.js index 13f9d4fe..bf6f73ef 100644 --- a/test/compress/pure_getters.js +++ b/test/compress/pure_getters.js @@ -1490,3 +1490,49 @@ issue_4751: { }; } } + +super_toString: { + options = { + pure_getters: true, + unsafe: true, + } + input: { + console.log({ + f() { + return super.toString(); + }, + }.f()); + } + expect: { + console.log({ + f() { + return super.toString(); + }, + }.f()); + } + expect_stdout: "[object Object]" + node_version: ">=4" +} + +this_toString: { + options = { + pure_getters: true, + unsafe: true, + } + input: { + console.log({ + f() { + return this.toString(); + }, + }.f()); + } + expect: { + console.log({ + f() { + return "" + this; + }, + }.f()); + } + expect_stdout: "[object Object]" + node_version: ">=4" +} |