aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-12-11 06:39:46 +0800
committerGitHub <noreply@github.com>2019-12-11 06:39:46 +0800
commit74396acc86a3d36dda2db43a007aa93f40cf58f8 (patch)
tree2fcdb86957df033c1648734d1b136392c01cf42d /lib
parent036bca980caad83edbabca860c69515d8007bd11 (diff)
downloadtracifyjs-74396acc86a3d36dda2db43a007aa93f40cf58f8.tar.gz
tracifyjs-74396acc86a3d36dda2db43a007aa93f40cf58f8.zip
fix corner case in `loops` (#3635)
fixes #3634
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js14
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/compress.js b/lib/compress.js
index fb7e66de..3b40a5d3 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4719,7 +4719,10 @@ merge(Compressor.prototype, {
function if_break_in_loop(self, compressor) {
var first = first_statement(self.body);
- if (compressor.option("dead_code") && (breaks(first) || first instanceof AST_Exit)) {
+ if (compressor.option("dead_code")
+ && (first instanceof AST_Break
+ || first instanceof AST_Continue && external_target(first)
+ || first instanceof AST_Exit)) {
var body = [];
if (self.init instanceof AST_Statement) {
body.push(self.init);
@@ -4749,7 +4752,7 @@ merge(Compressor.prototype, {
}
if (first instanceof AST_If) {
var ab = first_statement(first.body);
- if (breaks(ab)) {
+ if (ab instanceof AST_Break && !external_target(ab)) {
if (self.condition) {
self.condition = make_node(AST_Binary, self.condition, {
left: self.condition,
@@ -4764,7 +4767,7 @@ merge(Compressor.prototype, {
return drop_it(body);
}
ab = first_statement(first.alternative);
- if (breaks(ab)) {
+ if (ab instanceof AST_Break && !external_target(ab)) {
if (self.condition) {
self.condition = make_node(AST_Binary, self.condition, {
left: self.condition,
@@ -4789,11 +4792,6 @@ merge(Compressor.prototype, {
return compressor.loopcontrol_target(node) !== compressor.self();
}
- function breaks(node) {
- return node instanceof AST_Break
- || node instanceof AST_Continue && external_target(node);
- }
-
function drop_it(rest) {
if (self.body instanceof AST_BlockStatement) {
self.body = self.body.clone();