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

Avoid invalid code when "else" branch is simplified #3421

Merged
merged 3 commits into from Mar 6, 2020

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 #3419

Description

This ensures that in a situation such as #3419, there is always whitespace or a similar separator between the "else" keyword and the following branch so that the expression can be transformed freely. This is a similar fix as was previously implemented for for..in and for..of statements.

…t statement to avoid invalid code when the alternate branch is simplified.
@codecov
Copy link

codecov bot commented Mar 5, 2020

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3421      +/-   ##
==========================================
+ Coverage   93.29%   93.29%   +<.01%     
==========================================
  Files         172      172              
  Lines        6112     6114       +2     
  Branches     1822     1823       +1     
==========================================
+ Hits         5702     5704       +2     
  Misses        218      218              
  Partials      192      192
Impacted Files Coverage Δ
src/ast/nodes/IfStatement.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 1e6284f...3494c6b. Read the comment docs.

@@ -82,6 +82,9 @@ export default class IfStatement extends StatementBase implements DeoptimizableE
}
if (this.alternate !== null) {
if (this.alternate.included) {
if (code.original.charCodeAt(this.alternate.start - 1) === 101 /* f */) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always up for a good puzzle... What's the significance of f? Or is it e?

$ node -p 'String.fromCharCode(101)'
e
$ node -p 'String.fromCharCode(102)'
f

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The beauty of comments. I definitely did NOT copy this code from for..of loop 😉

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.

Else without braces and spaces gets concatenated to function names
2 participants