Skip to content
Discussion options

You must be logged in to vote

It looks like you’re not actually interested in parsing JavaScript using acorn. Your code parses a hardcoded string of JavaScript with JSX.

I recommend to paste the code into https://astexplorer.net (make sure to use the JavaScript language and acorn parser), then copy the JSON output on the side and strip any positional information.

I suspect this is a minimal scenario and your real use case contains some variables. Once you get used working with the AST you’ll find it to be much safer to use and more powerful than string manipulations. For an example of how to use this, you can have a look at remark-mdx-frontmatter.

If you really do need to parse JavaScript from a string and it may cont…

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
4 replies
@hahnbeelee
Comment options

@hahnbeelee
Comment options

@wooorm
Comment options

@ChristianMurphy
Comment options

Comment options

You must be logged in to vote
2 replies
@hahnbeelee
Comment options

@remcohaszing
Comment options

Answer selected by hahnbeelee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants