From 8d156b51fe72906800189ec70a4b8ba23e6db937 Mon Sep 17 00:00:00 2001 From: kzc Date: Thu, 21 Dec 2017 04:50:26 -0500 Subject: [PATCH] `arrows` fix for object literal methods containing `arguments` (#2632) fixes #2631 --- lib/compress.js | 2 ++ test/compress/harmony.js | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index 59307905..2158191c 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -5414,6 +5414,8 @@ merge(Compressor.prototype, { // p(){return x;} ---> p:()=>x if (compressor.option("arrows") && compressor.parent() instanceof AST_Object + && !self.value.uses_arguments + && !self.value.uses_eval && self.value.body.length == 1 && self.value.body[0] instanceof AST_Return && self.value.body[0].value diff --git a/test/compress/harmony.js b/test/compress/harmony.js index ad57e06a..fd0212dd 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -1153,3 +1153,47 @@ array_literal_with_spread_4: { ] node_version: ">=6" } + +object_literal_method_using_arguments: { + options = { + arrows: true, + } + input: { + console.log(({ + m() { + return arguments[0]; + } + }).m("PASS")); + } + expect: { + console.log(({ + m() { + return arguments[0]; + } + }).m("PASS")); + } + expect_stdout: "PASS" + node_version: ">=6" +} + +class_method_using_arguments: { + options = { + arrows: true, + } + input: { + console.log(new class { + m() { + return arguments[0]; + } + }().m("PASS")); + } + expect: { + console.log(new class { + m() { + return arguments[0]; + } + }().m("PASS")); + } + expect_stdout: "PASS" + node_version: ">=6" +}