Announcing js-macros: Quickly prototype Rust procedural macros using JavaScript or TypeScript!

28 points TheVultix

Repo

Have you ever thought "this would be a great use case for a procedural macro," but didn't want to go through all the effort? This crate is the perfect fix for you!

As an example, creating a custom derive(Copy) macro is as easy as adding this javascript file to your project:

//! JS_MACRO: derive(Copy)

const type = /(?:struct|enum) (.*?)\\s/.exec(MACRO_INPUT)[1];

MACRO_OUTPUT = `impl Copy for ${type} {}`;

Usage is as simple as #[derive(js_macros::Copy)]