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

Comment inside return results in wrong code when AST gets printed #372

Closed
sltam opened this issue Dec 16, 2013 · 2 comments · Fixed by #2633
Closed

Comment inside return results in wrong code when AST gets printed #372

sltam opened this issue Dec 16, 2013 · 2 comments · Fixed by #2633

Comments

@sltam
Copy link

sltam commented Dec 16, 2013

$ cat input.js
function unequal(x, y) {
  return (
    // Either one
    x < y
  ||
    x > y
  );
}

$ uglifyjs input.js -b --comments=all
function unequal(x, y) {
    return // Either one
    x < y || x > y;
}

Now unequal(x, y) always evaluates to undefined, since semicolon is auto added after "return" when this generated code is evaluated.

@sltam
Copy link
Author

sltam commented Dec 18, 2013

I just happened to stumble upon #112

The fix there doesn't fix this case, as the returnNode's value is the "||" node, whose's start doesn't have comment. Only the "||" node's left's left has comment.

@mishoo mishoo closed this as completed in be55a09 Dec 18, 2013
@mishoo
Copy link
Owner

mishoo commented Dec 18, 2013

I pushed a better fix.

rvanvelzen pushed a commit to rvanvelzen/UglifyJS2 that referenced this issue Dec 23, 2013
avdg added a commit to avdg/UglifyJS2 that referenced this issue Jan 9, 2015
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Dec 21, 2017
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Dec 21, 2017
alexlamsl added a commit that referenced this issue Dec 21, 2017
- improve handling of comments right after `return`
- retain comments after `OutputStream`
- preserve trailing comments
- fix handling of new line before comments
- handle comments around parentheses

fixes #88
fixes #112
fixes #218
fixes #372
fixes #2629
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 a pull request may close this issue.

2 participants