-
Notifications
You must be signed in to change notification settings - Fork 38
Move React ppx from compiler repo, add tests #124
Conversation
@jchavarri This is great! Will take a look at your PR. Long term we want to merge the jsx ppx with the parser itself, i.e. do the syntax transform in the parser. |
Thanks for the responsiveness @IwanKaramazow! Much appreciated :)
I realized while working on this that there is no need to have it as a separate step now. It makes sense to do so, although maybe in mid-long term? e.g. 6-12 months. I mention that because I guess that merging the ppx with the parser would potentially break conversion between code in Reason and ReScript syntaxes? 🤔 Which is really useful while this transitions happens. Also, I don't know if it's possible, but it'd be great to keep it as a separate module, so that tools like https://jchavarri.github.io/ppx-explorer/ that rely on a PPX-like API can keep updates with upstream easily, e.g here. |
Hey Javier! It's been a while |
@chenglou hey! long time indeed :) Could you elaborate, please? This PR doesn't change the ppx semantics, and it does not contain any breaking changes in the ppx code. All changes in If there is some breaking change planned for the future for the ppx, this PR should actually help @rickyvetter and any other authors build and release that change, because once there are more tests, we will know exactly what cases are breaking after the change. In other words, if this PR gets merged, nobody should notice anything, except the ppx maintainers and contributors, who would get a quality of life improvement thanks to the ppx now being part of the testing infrastructure in this repo. |
Oh, I think I see what you mean. If PPX lives in compiler repo, then it's easy to configure Maybe the parser could offer a way to switch between syntaxes per file with an attribute, like Reason parser is doing: https://github.com/facebook/reason/pull/2605/files#diff-2f961a549953a72af3a11bb3b36ecc49R4975. This would be helpful not only for ppx of course, but any breaking syntax change. |
@chenglou I thought more about this. Because |
@jchavarri Ricky (@rickyvetter) owns the module. |
@bobzhang There should be no impact in old Reason syntax. From the compiler perspective, this PR can be considered for all effects and purposes like moving a file from one folder to another. |
As long as it does not make the main maintainer’s life more difficult, I am
fine with it.
But keep in mind this module is used by reason syntax too
Javier Chávarri <[email protected]>于2020年8月31日 周一下午9:03写道:
@bobzhang <https://github.com/bobzhang> There should be no impact in old
Reason syntax. From the compiler perspective, this PR can be considered for
all effects and purposes like moving a file from one folder to another.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#124 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFWMK52VPL4VL46JZEICSDSDONTHANCNFSM4QPX2FPQ>
.
--
Regards
-- Hongbo Zhang
|
I created a draft PR to show how minimal the impact downstream for the compiler is: rescript-lang/rescript#4660. Hopefully that and the comments above help unblock the PR 🙏 |
I think this move could make maintaining quite a bit cleaner but I want to clarify setup. In the near future we need to make a series of major breaking changes to the ppx and need to ship both versions to the compiler so that folks can update their ppx version independently of their compiler version. Would you propose just exposing both versions as different modules here and then doing the switch logic in the compiler based on config? |
Hey @rickyvetter ! 👋
Yes, exactly. The companion PR in the compiler repo shows how the ppx module is available just like before (see If there is a new version of the ppx, there can be another module added next to the one in this PR. Keeping these modules close to the testing infra might be beneficial too to guarantee the migration is smooth, and new tests can also be added from user reports. It seems the compiler still keeps the ppx version handling from bsconfig option. The only thing that will change from previous setup is that every time there is a fix or update in the ppx, the compiler repo will have to sync the submodule version, while before the file could be just directly updated in-repo. I hope this is not a deal breaker. Maybe I'm missing something :) Please let me know if there's anything else that I'm not accounting for 👍 |
Gotcha. Seems like a win to me. @chenglou you seemed hesitant at first - okay with this plan? |
updated the PR with the following:
lmk what you think :) |
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.
Left a couple of questions, what do you think?
@@ -243,8 +251,12 @@ module CliArgProcessor = struct | |||
else exit 1 | |||
end | |||
else | |||
let parsetree = match ppx with |
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.
Can we keep this a string and match on the string for now? Does this extra conversion give us something in the end?
Makefile
Outdated
@@ -49,6 +50,8 @@ lib/rescript.exe: $(CLI_FILES) | |||
|
|||
build-native: lib/refmt.exe lib/rescript.exe depend | |||
|
|||
build-ppx: src/reactjs_jsx_ppx.cmx |
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.
why does the ppx need a separate build-ppx
rule? If it's a part "API_FILES", is this sufficient?
src/res_cli.ml
Outdated
@@ -178,6 +179,7 @@ end = struct | |||
let origin = ref "" | |||
let interface = ref false | |||
let report = ref "pretty" | |||
let ppx = ref "none" |
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.
can we default this to the empty string ""
?
src/res_cli.ml
Outdated
@@ -227,6 +230,11 @@ module CliArgProcessor = struct | |||
| _ -> false | |||
in | |||
|
|||
let ppx = match ppx with |
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.
See comment down, this conversion doesn't add that much value?
tests/runner.js
Outdated
@@ -204,15 +202,16 @@ let makeReproducibleFilename = (txt) => { | |||
}) | |||
}; | |||
|
|||
global.runPrinter = (dirname) => { | |||
global.runPrinter = (dirname, ppx = "none") => { |
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.
Can we make this the empty string or just keep it undefined as default value?
tests/runner.js
Outdated
@@ -226,7 +225,7 @@ Make sure the test input is syntactically valid.`; | |||
expect(result).toMatchSnapshot(); | |||
} | |||
|
|||
if (process.env.ROUNDTRIP_TEST) { | |||
if (process.env.ROUNDTRIP_TEST && ppx === "none") { |
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.
Can you add a comment here on why we don't run ppx'es in the roundtrip tests?
@@ -0,0 +1,101 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP |
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.
I wonder if we should make a separate folder for ppx tests: tests/ppx/...
? What do you think?
with | ||
| Failure txt -> | ||
prerr_string txt; | ||
prerr_newline(); | ||
exit 1 | ||
| _ -> exit 1 | ||
[@@raises exit] | ||
[@@raises Invalid_argument, exit] |
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.
What raises Invalid_argument
?
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.
The existing react ppx uses that exception to note cases with unexpected situations. I can count at least 19 different places, e.g.
Lines 351 to 354 in 23336db
raise | |
(Invalid_argument | |
"Key cannot be accessed inside of a component. Don't worry - you can always key a component from its \ | |
parent!") |
@IwanKaramazow I think I tackled all the comments, let me know if there's anything missing :) |
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.
@jchavarri Looking good, thank you for all the work.
This is not finished since the removal of jsx ppx is not done in the compiler. After some thoughts, I think this may make your test workflow more difficult, @rickyvetter , since now you make changes to the ppx, you need update the syntax submodule to test your new changes |
@bobzhang I'll take care of it. |
@bobzhang I had created a companion PR in rescript-lang/rescript#4660 that included the compiler changes. I didn't continue working on this because @chenglou mentioned on DM a few days after this PR was merged that the move to the PPX to the parser might be rethought / retracted because of the new jsx transform. |
Let's sync up on this first. |
I talked to @IwanKaramazow and these are the steps to take before this is finished:
|
I find myself wanting to contribute to React ppx but always end up giving up because of the lack of infrastructure. By moving the file here, we can leverage the testing infrastructure and keeping it more in sync with the parser.
If this makes sense and gets merged, I will update the compiler repo to read from new file.
Hopefully this change makes sense as well from organizational perspective, as the React ppx is a syntax transformation.
Summary of changes:
https://github.com/rescript-lang/rescript-compiler/blob/4f4812aa4e1411029392f6dbcacc580e755d68d5/jscomp/syntax/reactjs_jsx_ppx.cppo.ml, and then applied these changes:
@raise
annotations#ifdef BINARY
Ast_mapper.register
callreactjs_jsx_ppx.mli
file-reactJsx
option torescript.exe
(for now I didn't added it to command-help
output as I'm not sure if it should be exposed).react.res
andreact.resi
Thanks to these changes, I already found 2 bugs:
<Foo.bar />
elements are not supported by new parser