escodegen icon indicating copy to clipboard operation
escodegen copied to clipboard

Bug: Printing if statement inside bracketless if-else

Open adiba opened this issue 8 years ago • 6 comments

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

adiba avatar Jun 27 '17 16:06 adiba

That is not a program.

michaelficarra avatar Jun 27 '17 16:06 michaelficarra

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.

adiba avatar Jun 27 '17 16:06 adiba

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.

michaelficarra avatar Jun 27 '17 17:06 michaelficarra

Thank you for that hint.

adiba avatar Jun 27 '17 17:06 adiba

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

adiba avatar Jun 27 '17 17:06 adiba

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

michaelficarra avatar Jun 27 '17 17:06 michaelficarra