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

Add missing spaces in certain statements and expressions to avoid invalid code #3173

Merged
merged 2 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 #3158

Description

This resolves some cases where missing white-space could lead to invalid code when an expression is simplified so that after simplification, it starts with a word character while before, it started with some punctuation.

This affects for..in loops , for..of loops and throw statements. The fix is the same as is already in place for return statements and yield expressions in that a space is inserted at the right position if there is none in the original code.

Examples of the broken code: https://rollupjs.org/repl/?version=1.23.1&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMiUyRiUyRiUyMCUyMyUyMGRpZmZlcmVudCUyMHNpbXBsaWZpZWQlMjBleHByZXNzaW9ucyU1Q24lNUNuJTJGJTJGJTIwc2VxdWVuY2UlNUNuZm9yKGNvbnN0JTIwd2F0JTIwaW4hMCUyQ2ZhbHNlKWNvbnNvbGUubG9nKCd3YXQnKSU1Q24lMkYlMkYlMjBjb25kaXRpb25hbCU1Q25mb3IoY29uc3QlMjB3YXQlMjBpbiEwJTNGZmFsc2UlM0FmYWxzZSljb25zb2xlLmxvZygnd2F0JyklNUNuJTJGJTJGJTIwbG9naWNhbCU1Q25mb3IoY29uc3QlMjB3YXQlMjBpbiEwJTI2JTI2ZmFsc2UpY29uc29sZS5sb2coJ3dhdCcpJTVDbiU1Q24lMkYlMkYlMjAlMjMlMjBkaWZmZXJlbnQlMjBzdXJyb3VuZGluZyUyMGV4cHJlc3Npb25zJTVDbiU1Q24lMkYlMkYlMjBmb3IlMjBvZiUyMGV4cHJlc3Npb24lNUNuZm9yKGNvbnN0JTIwd2F0JTIwb2YhMCUyNiUyNmZhbHNlKWNvbnNvbGUubG9nKCd3YXQnKSU1Q24lNUNuJTJGJTJGJTIwcmV0dXJuJTIwZXhwcmVzc2lvbiUyQyUyMGFscmVhZHklMjB3b3JraW5nJTVDbmZ1bmN0aW9uJTIwdGVzdCgpJTdCJTVDbiUyMCUyMHJldHVybiEwJTNGZmFsc2UlM0FmYWxzZSUzQiU1Q24lN0QlNUNuY29uc29sZS5sb2codGVzdCgpKSU1Q24lNUNuJTJGJTJGJTIweWllbGQlMjBzdGF0ZW1lbnQlMkMlMjBhbHJlYWR5JTIwd29ya2luZyU1Q25mdW5jdGlvbiUyMCp0ZXN0MigpJTdCJTVDbiU1Q3R5aWVsZCEwJTNGZmFsc2UlM0FmYWxzZSU1Q24lN0QlNUNuY29uc29sZS5sb2codGVzdDIoKSklNUNuJTVDbiUyRiUyRiUyMHRocm93JTIwc3RhdGVtZW50JTVDbmZ1bmN0aW9uJTIwdGVzdDMoKSU3QiU1Q24lMjAlMjB0aHJvdyEwJTNGZmFsc2UlM0FmYWxzZSUzQiU1Q24lN0QlNUNuY29uc29sZS5sb2codGVzdDMoKSklNUNuJTVDbiUyMiUyQyUyMmlzRW50cnklMjIlM0F0cnVlJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmVzbSUyMiUyQyUyMm5hbWUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmFtZCUyMiUzQSU3QiUyMmlkJTIyJTNBJTIyJTIyJTdEJTJDJTIyZ2xvYmFscyUyMiUzQSU3QiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE

@codecov
Copy link

codecov bot commented Oct 18, 2019

Codecov Report

Merging #3173 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #3173      +/-   ##
=========================================
+ Coverage   90.18%   90.2%   +0.01%     
=========================================
  Files         165     165              
  Lines        5902    5909       +7     
  Branches     1795    1799       +4     
=========================================
+ Hits         5323    5330       +7     
  Misses        350     350              
  Partials      229     229
Impacted Files Coverage Δ
src/ast/nodes/ThrowStatement.ts 100% <100%> (ø) ⬆️
src/ast/nodes/ForOfStatement.ts 100% <100%> (ø) ⬆️
src/ast/nodes/AwaitExpression.ts 100% <100%> (ø) ⬆️
src/ast/nodes/ForInStatement.ts 100% <100%> (ø) ⬆️

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 121a7f4...632fa84. Read the comment docs.

@lukastaegert lukastaegert force-pushed the missing-spaces-after-simplification branch from ce67aa7 to 7e66114 Compare October 18, 2019 10:56
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 can produce invalid syntax
1 participant