aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-02-26 15:22:52 +0800
committerGitHub <noreply@github.com>2018-02-26 15:22:52 +0800
commitace581169134d9b6d4cdf6b24880f7ce122fc88e (patch)
treed619a4eb43ffa22267557921388a1048948bddc3
parentba7bad0dbdc373493daa6f2fbb03418f77df563a (diff)
downloadtracifyjs-ace581169134d9b6d4cdf6b24880f7ce122fc88e.tar.gz
tracifyjs-ace581169134d9b6d4cdf6b24880f7ce122fc88e.zip
drop lone "use strict" in function body (#2963)
fixes #2961
-rw-r--r--lib/compress.js10
-rw-r--r--test/compress/functions.js29
2 files changed, 39 insertions, 0 deletions
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() {
+ }
+ }
+ }
+}