purescript-playwright icon indicating copy to clipboard operation
purescript-playwright copied to clipboard

Codegen the bindings

Open jvliwanag opened this issue 5 years ago • 1 comments

Hi @klntsky , wondering if you've had some thoughts on using code generation to build bindings for playwright.

There have been prior work:

React Basic React Basic MUI AWS - not working at the moment, but I aim to fix this

Looking specifically at playwright - the doclint seems to be helpful - https://github.com/microsoft/playwright/tree/master/utils/doclint . In particular, it looks like it parses the AST and checks the docs for completeness. I'm thinking this can also be utilized to come up with purescript bindings.

Now there's - https://github.com/purescript-codegen/purescript-ps-cst to generate purescript code. I'm currently building simpler bindings for it over at https://github.com/purescript-codegen/purescript-cst-simple but still a WIP.

jvliwanag avatar Nov 08 '20 12:11 jvliwanag

I have already considered codegen.

There are some places where it's not possible to write type-safe bindings at all, e.g. browserContext.exposeBinding type changes depending on the value of its options.handle argument.

Functions that accept pageFunction callback as argument can only deal with function code as string.

Some functions would benefit from returning Maybe x instead of null |+| x - these require manual wrapping. Because of these edge cases any codegen solution would cover only 90%, not 100%.

I made some machinery that is helpful enough, though. It allows me to only write types and a single line of boilerplate for each function.

klntsky avatar Nov 08 '20 13:11 klntsky