▲ | b_e_n_t_o_n 15 hours ago | |||||||
Js has decorators for class fields so you wouldn't even need a macro for that. `@state accessor value = "hello world"` works. I do like the idea of macros in general though. | ||||||||
▲ | apatheticonion 15 hours ago | parent [-] | |||||||
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
Would compile into
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.
Projects like this : https://github.com/developit/htm are an expression/symptom of that need | ||||||||
|