sweet-js / sweet-core

Sweeten your JavaScript.
https://www.sweetjs.org
BSD 2-Clause "Simplified" License
4.59k stars 211 forks source link

Can sweetjs be configured to output exactly what I want it to, even if it's not valid JS? #728

Closed MaxPleaner closed 7 years ago

MaxPleaner commented 7 years ago

I would like to output coffeescript using sweetjs. The functionality seems to all be there, the only thing not working is that the output is checked in order to verify that it's valid JS.

Also, it seems to be somewhat coerced into JS, too, which I wouldn't want in this case. For example:

#`console.log 'hello world'` 

outputs:

console.log;
'hello world';

I'm not asking for a check for if the output is valid language X; but I do think it'd be beneficial if there was an option to turn off output linting. This would enable the project to be used to convert Javascript source to a larger range of outputs.

disnet commented 7 years ago

This isn't really possible. Sweet doesn't just check validity at the end of expansion, parsing of the JavaScript grammar is entwined with expansion in order to get hygiene and all the grammar matching correct.

If you want to render the AST to something other than JavaScript you could always use Sweet's parse function to get just the AST and then do an AST transform and codegen to whatever you target is.

Closing this issue since I don't think we can do anything.