diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-12-11 22:45:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-12 06:45:59 +0800 |
commit | fd0d28e4652b8709d41031ef94594a50266f7c01 (patch) | |
tree | a00efbbb387ad536b55041da790903c9658e51c0 | |
parent | 2123f38394d4c98fcb4acdc0378ffd86fd9bec9a (diff) | |
download | tracifyjs-fd0d28e4652b8709d41031ef94594a50266f7c01.tar.gz tracifyjs-fd0d28e4652b8709d41031ef94594a50266f7c01.zip |
fix corner case in `spread` (#4370)
-rw-r--r-- | lib/compress.js | 9 | ||||
-rw-r--r-- | test/compress/spread.js | 29 |
2 files changed, 31 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js index cc601bfb..96589686 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -10051,13 +10051,14 @@ merge(Compressor.prototype, { found = true; var exp = prop.expression; if (compressor.option("spread") && exp instanceof AST_Object && all(exp.properties, function(prop) { - return !(prop instanceof AST_ObjectGetter - || prop instanceof AST_ObjectSetter && prop.key instanceof AST_Node - || prop instanceof AST_Spread); + return !(prop instanceof AST_ObjectGetter || prop instanceof AST_Spread); })) { changed = true; exp.properties.forEach(function(prop) { - if (prop instanceof AST_ObjectKeyVal) process(prop); + process(prop instanceof AST_ObjectSetter ? make_node(AST_ObjectKeyVal, prop, { + key: prop.key, + value: make_node(AST_Undefined, prop).optimize(compressor) + }) : prop); }); } else { generated = true; diff --git a/test/compress/spread.js b/test/compress/spread.js index 78348758..41715514 100644 --- a/test/compress/spread.js +++ b/test/compress/spread.js @@ -250,6 +250,31 @@ reduce_vars_2: { node_version: ">=6" } +convert_setter: { + options = { + objects: true, + spread: true, + } + input: { + var o = { + ...{ + set PASS(v) {}, + }, + }; + for (var k in o) + console.log(k, o[k]); + } + expect: { + var o = { + PASS: void 0, + }; + for (var k in o) + console.log(k, o[k]); + } + expect_stdout: "PASS undefined" + node_version: ">=8" +} + keep_getter_1: { options = { side_effects: true, @@ -773,9 +798,7 @@ issue_4363: { } expect: { ({ - ...{ - set [console.log("PASS")](v) {}, - }, + [console.log("PASS")]: void 0, }); } expect_stdout: "PASS" |