estools / escodegen

ECMAScript code generator
BSD 2-Clause "Simplified" License
2.66k stars 334 forks source link

Bug: Printing if statement inside bracketless if-else #344

Open adiba opened 7 years ago

adiba commented 7 years ago

See https://github.com/benjamn/recast/issues/416 Same issue with escodegen.generate(ast)

michaelficarra commented 7 years ago

That is not a program.

adiba commented 7 years ago

I am confused. What is not a program? Is escodegen only intended for code rewrite and not AST modification? Do you want me to provide JSON? I still don't see why you closed this issue.

michaelficarra commented 7 years ago

The AST you referenced does not represent a program. What program do you think it represents? If you add the curly braces you suggested in the linked issue, that is a different AST. We could possibly throw when passed non-programs, but it would make the common case slower, so :-1:.

Try using esvalid before passing the AST to escodegen so you know what you get from escodegen is meaningful.

adiba commented 7 years ago

Thank you for that hint.

adiba commented 7 years ago

I think mentioning in the readme that escodegen accepts any program without warning would be helpful.

michaelficarra commented 7 years ago

@adiba I agree. Would you like to send a PR?