-
Notifications
You must be signed in to change notification settings - Fork 469
Add reprint ReScript source command #6682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Very nice to have! Thanks! |
jscomp/bsc/rescript_compiler_main.ml
Outdated
exit 1); | ||
parseResult.parsetree | ||
|> Js_implementation.implementationForReprinting | ||
|> Res_printer.printImplementation ~width:80 ~comments:parseResult.comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like width is only specified in 2 places: here and in the playground.
Everywhere else it defaults to 100.
Wondering whether we should even have a width parameter, or have it always be an optional arg which is never called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's a good point. I should change it to 100 regardless here or the results might not be 100% correct.
jscomp/core/js_implementation.ml
Outdated
@@ -172,6 +172,20 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) = | |||
Lam_compile_main.lambda_as_module js_program outputprefix); | |||
process_with_gentype (outputprefix ^ ".cmt")) | |||
|
|||
let implementationForReprinting structure = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these functions need to be here because of dependencies?
Asking as since there's a single user, then perhaps they could go directly there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I see similar code is used in this file, except for init_path
, so perhaps they can be refactored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps not worth it. Just ignore.
…d PPXes, and then print the transformed source back to stdout
62dca4e
to
5d7f38e
Compare
@cristianoc I simplified a lot, have another look please. |
Add simple command for transforming a ReScript file using the provided PPXes, and then print the transformed source back to stdout.
Example command:
Useful when you want to "eject" from PPXes, or otherwise just see what source the PPXes actually produce.
Could for example be used to "eject" from old PPXes that won't support uncurried mode. Ejecting to source can fix a lot of uncurried mode issues given that uncurried is done at the syntax level, which we then get access to thanks to the code produced by the PPX now being actual ReScript code and not an AST transformation.
Could also be used to power an editor integration for seeing the expanded PPX source. And so on.