From ace581169134d9b6d4cdf6b24880f7ce122fc88e Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 26 Feb 2018 15:22:52 +0800 Subject: [PATCH] drop lone "use strict" in function body (#2963) fixes #2961 --- lib/compress.js | 10 ++++++++++ test/compress/functions.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index c402e3ba..f9382f0d 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3024,6 +3024,16 @@ merge(Compressor.prototype, { return self; }); + OPT(AST_Lambda, function(self, compressor){ + tighten_body(self.body, compressor); + if (compressor.option("side_effects") + && self.body.length == 1 + && self.body[0] === compressor.has_directive("use strict")) { + self.body.length = 0; + } + return self; + }); + AST_Scope.DEFMETHOD("drop_unused", function(compressor){ if (!compressor.option("unused")) return; if (compressor.has_directive("use asm")) return; diff --git a/test/compress/functions.js b/test/compress/functions.js index 5d0be0f9..ddf5fe05 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -2022,3 +2022,32 @@ deduplicate_parenthesis: { } expect_exact: "({}).a=b;({}.a=b)();(function(){}).a=b;(function(){}.a=b)();" } + +drop_lone_use_strict: { + options = { + side_effects: true, + } + input: { + function f1() { + "use strict"; + } + function f2() { + "use strict"; + function f3() { + "use strict"; + } + } + (function f4() { + "use strict"; + })(); + } + expect: { + function f1() { + } + function f2() { + "use strict"; + function f3() { + } + } + } +} -- 2.34.1