render comments in custom ASTs gracefully (#3393)

fixes #3246
This commit is contained in:
Alex Lam S.L
2019-05-02 13:50:51 +08:00
committed by GitHub
parent 429d2b56b7
commit a89d424a0b
3 changed files with 42 additions and 16 deletions

View File

@@ -260,6 +260,23 @@ describe("comments", function() {
].join("\n"));
});
it("Should handle programmatic AST insertions gracefully", function() {
var ast = UglifyJS.parse([
"function f() {",
" //foo",
" bar;",
" return;",
"}",
].join("\n"));
ast.body[0].body[0] = new UglifyJS.AST_Throw({value: ast.body[0].body[0].body});
ast.body[0].body[1].value = new UglifyJS.AST_Number({value: 42});
assert.strictEqual(ast.print_to_string({comments: "all"}), [
"function f(){",
"//foo",
"throw bar;return 42}",
].join("\n"));
});
describe("comment before constant", function() {
var js = 'function f() { /*c1*/ var /*c2*/ foo = /*c3*/ false; return foo; }';