Add missing spaces in certain statements and expressions to avoid invalid code #3173
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 #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=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMiUyRiUyRiUyMCUyMyUyMGRpZmZlcmVudCUyMHNpbXBsaWZpZWQlMjBleHByZXNzaW9ucyU1Q24lNUNuJTJGJTJGJTIwc2VxdWVuY2UlNUNuZm9yKGNvbnN0JTIwd2F0JTIwaW4hMCUyQ2ZhbHNlKWNvbnNvbGUubG9nKCd3YXQnKSU1Q24lMkYlMkYlMjBjb25kaXRpb25hbCU1Q25mb3IoY29uc3QlMjB3YXQlMjBpbiEwJTNGZmFsc2UlM0FmYWxzZSljb25zb2xlLmxvZygnd2F0JyklNUNuJTJGJTJGJTIwbG9naWNhbCU1Q25mb3IoY29uc3QlMjB3YXQlMjBpbiEwJTI2JTI2ZmFsc2UpY29uc29sZS5sb2coJ3dhdCcpJTVDbiU1Q24lMkYlMkYlMjAlMjMlMjBkaWZmZXJlbnQ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