Comment by apatheticonion
Comment by apatheticonion 8 hours ago
One of the issues I find is that JavaScript itself holds back the ability of tool makers to experiment with practical novel alternatives.
TypeScript's tsx macro is designed with React-like libraries in mind and alternative frameworks need to create custom file types and LSPs just to get off the ground.
I'd love to see the JavaScript spec define a generic macro system to enable experimentation (with IDE support) for alternative frameworks.
For example, jsx/tsx could be expressed with an inline macro
export App() {
return jsx!(<div>Hello World</div>)
}
While something like Vue or Svelte could implement their own inline macros rather than investing in tooling for their custom file types export class App {
#[onChange] // <- makes the prop a getter/setter
value = Hello World
constructor() {
setTimeout(() => {this.value = "updated"}, 1000)
}
render() {
return vue!(<div>{{this.value}}</div>)
}
}
If it's part of the spec, the browser could interpret it without a preprocessor and compilers like tsc/swc etc could precalculate the transformations and ship the transformed JavaScript (like we do today with tsx)
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.