Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2512,4 +2512,24 @@ describe("simplify-plugin", () => {
const b = () => {};
`
);

thePlugin(
"should NOT remove block for early continue transforms - fix issue#560",
`
function foo() {
while (true) {
const {x} = a;
const {y} = b;
}
}
`,
`
function foo() {
for (; true;) {
const { x } = a;
const { y } = b;
}
}
`
);
});
5 changes: 3 additions & 2 deletions packages/babel-plugin-minify-simplify/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,8 @@ module.exports = ({ types: t }) => {
t.isTryStatement(parent) ||
t.isCatchClause(parent) ||
t.isSwitchStatement(parent) ||
(isSingleBlockScopeDeclaration(node) && t.isIfStatement(parent))
(isSingleBlockScopeDeclaration(node) &&
(t.isIfStatement(parent) || t.isLoop(parent)))
);
}

Expand Down Expand Up @@ -1581,7 +1582,7 @@ module.exports = ({ types: t }) => {
}

// We may have reduced the body to a single statement.
if (node.body.body.length === 1) {
if (node.body.body.length === 1 && !needsBlock(node.body, node)) {
path.get("body").replaceWith(node.body.body[0]);
}
}
Expand Down