Skip to content

Commit

Permalink
Minify return statements used to implement breaks inside tails
Browse files Browse the repository at this point in the history
  • Loading branch information
rpetrich committed Oct 26, 2019
1 parent ff5a531 commit 1f941b2
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 9 deletions.
13 changes: 10 additions & 3 deletions async-to-promises.ts
Expand Up @@ -1550,9 +1550,16 @@ export default function({
blocks = [declaration].concat(blocks);
temporary = temporaryIdentifier;
}
blocks = removeUnnecessaryReturnStatements(
[types.ifStatement(exitCheck, returnStatement(temporary)) as Statement].concat(blocks)
);
if (temporary !== undefined) {
blocks = removeUnnecessaryReturnStatements(
[types.ifStatement(exitCheck, returnStatement(temporary)) as Statement].concat(blocks)
);
} else {
const minify = readConfigKey(generatorState.state.opts, "minify");
blocks = removeUnnecessaryReturnStatements(
[types.ifStatement(logicalNot(exitCheck, minify), blocks.length === 1 ? blocks[0] : blockStatement(blocks)) as Statement]
);
}
}
// Build a function expression for it
const fn = functionize(generatorState.state, temporary ? [temporary] : [], blockStatement(blocks), target);
Expand Down
2 changes: 1 addition & 1 deletion tests/break with multiple labeled statements/hoisted.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/break with multiple labeled statements/inlined.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/break with multiple labeled statements/output.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/while with inner break/hoisted.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/while with inner break/inlined.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/while with inner break/output.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1f941b2

Please sign in to comment.