Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle optional control flow in labeled statements, remove unused labels #3170

Merged
merged 5 commits into from Oct 18, 2019

Conversation

lukastaegert
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

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.

@codecov
Copy link

codecov bot commented Oct 18, 2019

Codecov Report

Merging #3170 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3170      +/-   ##
==========================================
+ Coverage   90.17%   90.18%   +<.01%     
==========================================
  Files         165      165              
  Lines        5896     5902       +6     
  Branches     1794     1795       +1     
==========================================
+ Hits         5317     5323       +6     
  Misses        350      350              
  Partials      229      229
Impacted Files Coverage Δ
src/ast/nodes/WhileStatement.ts 100% <100%> (ø) ⬆️
src/ast/nodes/ThrowStatement.ts 100% <100%> (ø) ⬆️
src/ast/nodes/SwitchCase.ts 100% <100%> (ø) ⬆️
src/ast/nodes/shared/FunctionNode.ts 100% <100%> (ø) ⬆️
src/ast/nodes/TryStatement.ts 100% <100%> (ø) ⬆️
src/ast/ExecutionContext.ts 100% <100%> (ø) ⬆️
src/ast/nodes/BlockStatement.ts 100% <100%> (ø) ⬆️
src/ast/nodes/ArrowFunctionExpression.ts 100% <100%> (ø) ⬆️
src/ast/nodes/ForStatement.ts 100% <100%> (ø) ⬆️
src/ast/nodes/ContinueStatement.ts 100% <100%> (ø) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 836a106...50957a6. Read the comment docs.

# Conflicts:
#	src/ast/nodes/BreakStatement.ts
#	src/ast/nodes/ContinueStatement.ts
#	src/ast/nodes/DoWhileStatement.ts
#	src/ast/nodes/ForInStatement.ts
#	src/ast/nodes/ForStatement.ts
#	src/ast/nodes/SwitchStatement.ts
#	src/ast/nodes/WhileStatement.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Treeshaking Removes Critical React DOM Code
1 participant