lydell / eslump

Fuzz testing JavaScript parsers and suchlike programs.
MIT License
57 stars 6 forks source link

Expose codegen #3

Closed RReverser closed 6 years ago

RReverser commented 6 years ago

I need access to both AST and code for validation (and to avoid reparsing same input with shift when fuzzer already produced an AST), and also would like to reuse own fuzzer state.

The easiest way to achieve this would be to expose the codegen class from the library, so that it could be used directly by consumer.

lydell commented 6 years ago

First, make sure to read through the Disclaimer in the readme, if you haven't already. If you still feel fine using this module, we can move on with this discussion :)

Which part of the code would you like to see exposed, exactly?

Could you provide a snippet of code showing what you would like to do, which uses your suggested exposed stuff from this module?

RReverser commented 6 years ago

I certainly have read it and using it without issues otherwise, just minor inconvenience :)

I'm not sure I can provide full script at the moment (I can try to reduce it tomorrow), but basically I'd like to be able to access CustomFormattedCodegen directly as it would allow me to:

1) Generate random AST using shift-fuzzer APIs directly (with my own state and options) 2) Convert it to code with random whitespaces, comments etc. using CustomFormattedCodegen 3) Pass the generated code to custom tool (it exposes only (string) => string interface, just like formatters). 4) Parse the output using shift-parser. 5) Compare original and resulting ASTs and verify that they did what they were supposed to.

Right now I have to workaround (1) by using generateRandomJS and parsing it back using shift-parser, which works, just somewhat slower and less convenient due to the roundtrip.

lydell commented 6 years ago

I think you also need CustomTokenStream. It actually sounds like you want the codeGen function, not those classes. What do you think?

RReverser commented 6 years ago

Oh yeah, you're right. Exposing codeGen function sounds great.

lydell commented 6 years ago

I'll try to look into this tomorrow.

RReverser commented 6 years ago

Thanks!

lydell commented 6 years ago

See #4.