Handle optional control flow in labeled statements, remove unused labels #3170
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Resolves #3168
Description
The original PR to handle tree-shaking after break/return/throw did not consider that of course, labeled break statements are a means of conditional control flow so that here:
https://rollupjs.org/repl/?version=1.24.0&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmElM0ElMjAlN0IlNUNuJTIwJTIwZm9yJTIwKGNvbnN0JTIweCUyMG9mJTIweSklMjAlN0IlNUNuJTIwJTIwJTIwJTIwaWYlMjAoY29uZGl0aW9uKHgpKSUyMCU3QiU1Q24lMjAlMjAlMjAlMjAlMjAlMjBicmVhayUyMGElM0IlNUNuJTIwJTIwJTIwJTIwJTdEJTVDbiUyMCUyMCU3RCU1Q24lMjAlMjB0aHJvdyUyMG5ldyUyMEVycm9yKCklM0IlNUNuJTdEJTVDbiU1Q25jb25zb2xlLmxvZygndGhpcyUyMGlzJTIwbm90JTIwZGVhZCUyMGNvZGUnKSUzQiU1Q24lMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlMjJmb3JtYXQlMjIlM0ElMjJlc20lMjIlMkMlMjJuYW1lJTIyJTNBJTIybXlCdW5kbGUlMjIlMkMlMjJhbWQlMjIlM0ElN0IlMjJpZCUyMiUzQSUyMiUyMiU3RCUyQyUyMmdsb2JhbHMlMjIlM0ElN0IlN0QlN0QlMkMlMjJleGFtcGxlJTIyJTNBbnVsbCU3RA==
code after the labeled statement CAN be executed even though the labeled statement ends with an error. Incidentally, fixing this made the logic much simpler in some places as we no longer need to track individual labels when tracking broken control flow but can treat labeled break and continue identical to return and throw as all of those will be reset by a surrounding labeled statement.
UNLESS of course there is no included labeled break or continue inside the labeled statement. To that end, we track which labels are actually used and remove the ones that are unused.