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

Comments are only output the first time an AST is serialized #218

Closed
papandreou opened this issue Jun 1, 2013 · 1 comment · Fixed by #2633
Closed

Comments are only output the first time an AST is serialized #218

papandreou opened this issue Jun 1, 2013 · 1 comment · Fixed by #2633

Comments

@papandreou
Copy link
Contributor

var uglifyJs = require('uglify-js');

function serialize(ast) {
    var outputStream = uglifyJs.OutputStream({comments: true});
    ast.print(outputStream);
    return outputStream.get();
}

var ast = uglifyJs.parse('/*foo*/ var isIe = /*@cc_on true ||*/ false;');

console.warn("first time:", serialize(ast));
console.warn("second time:", serialize(ast));

Output:

first time: /*foo*/var isIe=/*@cc_on true ||*/false;
second time: var isIe=false;

The error occurs because start._comments_dumped isn't reset after the serialization: https://github.com/mishoo/UglifyJS2/blob/master/lib/output.js#L384-L385

@papandreou
Copy link
Contributor Author

@mishoo This bug is still present. Could you please comment?

@kzc kzc mentioned this issue Mar 24, 2017
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.

1 participant