stdweb icon indicating copy to clipboard operation
stdweb copied to clipboard

Write a procedural macro to replace the `js!` macro on nightly (without parsing the JavaScript)

Open koute opened this issue 8 years ago • 4 comments

The js! macro is truly a thing of terror, however we don't have much choice if we want to work on stable.

That said, it would we worthwhile to convert it to a nightly-only procedural macro to prepare for the future where procedural macros will be stabilized.

This will also help with the compile times, which are negatively impacted by the way the current js! macro is implemented.

  • Write a nightly-only js! procedural macro.
  • Add nightly optional feature to Cargo.toml and use the procedural js! only when that feature is switched on.

koute avatar Apr 26 '17 16:04 koute

Does the js! macro and the set of bindings to web APIs belong in the same crate?

I'm not very familiar with the architecture of stdweb, but it seems to me that generating JS from Rust and calling JS APIs from WASM/asm.js-compiled Rust are orthogonal. I'd imagine that applications would be written predominantly with one or the other!

LPGhatguy avatar Dec 28 '17 08:12 LPGhatguy

@LPGhatguy Well, they're not completely orthogonal, although, yes, the js! could be in its own crate on which the API bindings would depend on.

If you look at our src directory you can clearly see this split - basic JS interop is in the src/webcore, while API bindings are in src/webapi. It would be possible to split these two directories into two separate crates, however I don't want to do that yet as it would only increase friction without any real benefits. (The compiler is pretty good at eliminating dead code, so even if you only use the js! macro you're not paying for the rest of the stdweb you're not using.)

koute avatar Dec 28 '17 15:12 koute

It looks like procedural macros are planned for stabilization in Rust 2018. Has there been any progress on this issue?

Kwarrtz avatar Jul 26 '18 18:07 Kwarrtz

@Kwarrtz Nope. But I do plan to do this once procedural macros are actually stabilized.

koute avatar Jul 26 '18 20:07 koute