Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to render literals inside an expession? #8

Open
cah4a opened this issue Nov 17, 2023 · 6 comments
Open

How to render literals inside an expession? #8

cah4a opened this issue Nov 17, 2023 · 6 comments

Comments

@cah4a
Copy link

cah4a commented Nov 17, 2023

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';);

@clayrisser
Copy link
Owner

Ok, I'll see if I can add that feature to this.

@dharmendraboddeda
Copy link
Contributor

dharmendraboddeda commented Nov 28, 2023

@cah4a We've made a small but important update in react-ast version 0.4.1

<CallExpression 
           name="fn" 
           arguments={ 
    <StringLiteral>a</StringLiteral>
  } 
/>

@cah4a
Copy link
Author

cah4a commented Nov 28, 2023

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?

@clayrisser
Copy link
Owner

@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?

@clayrisser clayrisser reopened this Nov 28, 2023
@cah4a
Copy link
Author

cah4a commented Nov 28, 2023

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.

@clayrisser
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants