Remix.run Logo
apatheticonion 15 hours ago

I explored JS decorators in the past but decorators are different in that they are a runtime operation that can't be statically compiled and can't be used on non-class properties.

You probably know this already but macros on the other hand are just dumb expansions/computations of syntax transformed at compile time, like

    let result = add!(1 + 2);
Would compile into

    let result = 3;
Including macros into the JavaScript spec is a bit weird because it's an interpreted language so compile-time concepts don't really make sense (which is probably why decorators were proposed).

But JavaScript is compiled more frequently than it isn't and we apply a crazy amount of transformations to it (typescript, tsx, path manipulation, styled-components, etc). IMO standardized compile-time manipulation with LSP integration would go a long way for language ergonomics.

That would also mean transformations for things like jsx could be run _in the browser_ allowing people who don't want to use a bundler to run their code without one.

    // Removed by the bundler, can also be used in the browser
    import jsx from "react/jsx" 

    const App = () => jsx!(<div>>Foo</div>)
Projects like this : https://github.com/developit/htm are an expression/symptom of that need
b_e_n_t_o_n 14 hours ago | parent [-]

Oh yeah I agree it would be useful.