You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, if we wanted to modify module semantics, we had to customize the complex configuration of the tool like bundlers. But now it can be done at module level.
For example, in the import statement for an image asset we could do this:
However, its behavior isn't semantically equivalent to await import("foo.wasm", { type: "module", with: { type: "webassembly" } }). The ReScript version always requires additional loading of JavaScript modules, which adds unnecessary waterfall.
Maybe we need to reconsider its design or extra syntax to directly import assets.
CommonJS
There is no equivalent semantics in CommonJS. Users can still use the syntax, but the output will not change.
Exports
There are no specific use cases for exports attributes. Since ReScript's expression and output are always about JavaScript.
Uh oh!
There was an error while loading. Please reload this page.
Background
ESM Import Attributes has reached stage 3 (Import Assertion is deprecated, so it will never get standardized)
This is important because it can be massively used by various tools around the JavaScript ecosystem and even native ESM modules.
Previously, if we wanted to modify module semantics, we had to customize the complex configuration of the tool like bundlers. But now it can be done at module level.
For example, in the import statement for an image asset we could do this:
Another example is importing WebAssembly assets:
ReScript
@module
FFI currently lacks the resolution for this.Detailed Design
This proposes a way to express import attributes by extending the existing FFI syntax.
@module
syntaxIf import attribute is needed, add
{ with: { ... } }
argument to the@module
directive.The argument payload should be validated as a record type
should be compiled to:
Dynamic imports
Dynamic imports include full module import (
module mod = await MyModule
) and partial import syntax (Js.import(MyModule.fn)
).Because ReScript modules are always JavaScript modules, the dynamic imports syntax doesn't need import attributes.
Note on dynamic imports of external modules
will be compiled to
Which is legit.
However, its behavior isn't semantically equivalent to
await import("foo.wasm", { type: "module", with: { type: "webassembly" } })
. The ReScript version always requires additional loading of JavaScript modules, which adds unnecessary waterfall.Maybe we need to reconsider its design or extra syntax to directly import assets.
CommonJS
There is no equivalent semantics in CommonJS. Users can still use the syntax, but the output will not change.
Exports
There are no specific use cases for exports attributes. Since ReScript's expression and output are always about JavaScript.Maybe useful some integration cases
https://twitter.com/KrComet/status/1750541534074925441
The text was updated successfully, but these errors were encountered: