jsx support without readtable via template syntax?
Closed this issue · 2 comments
vegansk commented
Is there any way to implement macro that produces jsx code from template syntax? Something like:
syntax jsx = function(ctx) {
// This doesn't work :-(
let v = ctx.expand('TemplateExpression');
return #`{v}`;
};
const el = jsx`<h1/>`;
that produces:
const el = <h1/>;
disnet commented
After all macros have been expanded the code must be valid JavaScript so you can't have a macro expand to <h1/>
since that would be a parse error.
However, if you are willing to use a prefix to implement something like jsx you can do:
syntax jsx = ctx => {
if (/* consume the syntax <h1/> */) {
return #`createH1()`; // or whatever the API is, I don't know jsx
}
}
const el = jsx <h1/>;
vegansk commented
Hm, yes. I guess, I can try to attach babel with JSX plugin and use it like this. Thanks!