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

fix: don't remove comments when removing trailing empty returns #295

Conversation

alangpierce
Copy link
Member

Before this commit, the comment after a removed return statement would be
destroyed:
http://decaffeinate-project.org/repl/#?evaluate=true&code=-%3E%0A%20%20a%20%20%23%20foo%0A%20%20return

Now, the code is a little more careful by deleting up to the start of the line
or the previous semicolon. Also, the code now exits early and doesn't patch the
return node or insert a semicolon at the end, since that was causing a
semicolon at the end of the comment.

This also fixes a crash on this type of input that I ran into when using
magic-string with Rich-Harris/magic-string#89 applied.

Before this commit, the comment after a removed return statement would be
destroyed:
http://decaffeinate-project.org/repl/#?evaluate=true&code=-%3E%0A%20%20a%20%20%23%20foo%0A%20%20return

Now, the code is a little more careful by deleting up to the start of the line
or the previous semicolon. Also, the code now exits early and doesn't patch the
`return` node or insert a semicolon at the end, since that was causing a
semicolon at the end of the comment.

This also fixes a crash on this type of input that I ran into when using
magic-string with  Rich-Harris/magic-string#89 applied.
@eventualbuddha eventualbuddha merged commit a0cf8ba into decaffeinate:master Jul 10, 2016
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.

None yet

2 participants