drop lone "use strict" in function body (#2963)

fixes #2961
This commit is contained in:
Alex Lam S.L
2018-02-26 15:22:52 +08:00
committed by GitHub
parent ba7bad0dbd
commit ace5811691
2 changed files with 39 additions and 0 deletions

View File

@@ -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;

View File

@@ -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() {
}
}
}
}