How to render literals inside an expession?
cah4a opened this issue · comments
There is no Literal
component, which I expected from that library.
Tried to use Smart component:
<CallExpression
name="fn"
arguments={
<Smart code="'a'"/>
}/>
that gave totally unexpected output for me: fn('a';);
Ok, I'll see if I can add that feature to this.
@cah4a We've made a small but important update in react-ast version 0.4.1
<CallExpression
name="fn"
arguments={
<StringLiteral>a</StringLiteral>
}
/>
That's cool! Thanks!
BooleanLiterals, BigIntLiteral, RegExpLiteral might be useful too.
Maybe we could have the Literal Component with value: unknown
, so it will render whatever you pass in?
@cah4a can you explain what you mean by value: unknown
. You mean like a <Smart />
component, but one that doesn't add the semi-colon?
I mean something like this:
<CallExpression
name="fn"
arguments={
<Literal value={argument}/>
}/>
where an argument could be string, number, boolean, bigint, object, symbol, null, or undefined.
I have a feeling the library should be able to render any javascript code, not a subset.
Gotcha, yeah I think we can make that work. We just finished a big refactor to update all the modules to the latest. Should be able to get to this soon.