-
Notifications
You must be signed in to change notification settings - Fork 463
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
RFC: conditional module FFI #6946
Comments
Yes, that's a great catch and would be very useful. I'm all for it 👍 |
This is great! I am not sure I like the name "cond" though. |
Maybe we should call it the same as we are calling it in |
That's "module" (the format), already duplicated with "cond" is inspired by Node.js' and bundlers' "conditions" Some tools does something similar with "env" or "mode". It's basically a flag to customize full config. Rust has "target", which is probably the most common way to express compilation conditions. |
This should be relaxed based on the actual project configuration. Then implementation is a bit more complex, but it helps to maintain forward compatibility with future targets. |
Looks good to me! |
I think for the example with |
But the feature is also very nice and will be useful in any way |
Or what about @module({ type: "esmodule", from: "./rescript_error.mjs" }) |
Personally, I don't prefer to call the "targeted module format" config as just "type" And it might be confusing with the standard @module({ type_: "esmodule", with: { type_: "json", from: "./file.json" } })
@val external content: Json.t = "default" |
Ok, and what about @module({ format: "esmodule", from: "./rescript_error.mjs" }) ? |
I think that it's good if its mental model is the format of the |
I like |
Ok, seems people like |
Background
Imagine a class statement written from external JS.
This is a pretty common situation because ReScript doesn't support ES classes.
However, ReScript's current FFI approach cannot select the appropriate resolution by its syntax.
This can be solved today using bundlers' module alias or Node.js' conditional exports/imports resolution, but these are all platform-dependent features.
The toolchain must be able to produce output that is appropriate for its target. That's true even for FFIs.
Suggested Solution
There are currently two module specs:
esmoudle
andcommonjs
(a composite of the two,dual
, will be added in the future #6209).Users can specify either of these two as
target
in the@module
statement.The library may not support all conditions. The compiler should raise an error if it cannot find a target that matches a module in the project.
If
target
omitted, the*
pattern is implicitly used.The text was updated successfully, but these errors were encountered: