-
Notifications
You must be signed in to change notification settings - Fork 334
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
feat: add jsx support #391
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no JSX expert, I just wanted to get serialization support in assetgraph. Thanks a lot for picking this up!
I tried npm link
ing escodegen in with this change, and it seems to do the job! 👍
Would be nice to get support for JSXFragment
while you're at it. It's not supported by esprima yet, but you can test that with acorn or espree, for example.
if (expr.value.type === 'JSXExpressionContainer') { | ||
result.push(this.generateExpression(expr.value.expression, precedence, flags)); | ||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need to handle expr.value.type === 'JSXElement'
here.
> require('escodegen').generate(require('esprima').parse('(<Foo bar=<Quux/>/>)', {jsx: true}));
'<Foo undefined />;'
And JSXFragment
as well, if you go for that: https://github.com/facebook/jsx/blob/master/AST.md#jsx-attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally forgot about boolean attributes, good catch 👍
Missed it, used to be `[space, '/>]`, forgot to drop the array. Co-Authored-By: erquhart <[email protected]>
Haven't forgotten about this, will circle back soon. |
@erquhart how I can help you to finish this update? |
Just a matter of when, haven't circled back yet. An old fork (https://github.com/ng-vu/escodegen-jsx) that introduced (incompatible) jsx support had some things that felt necessary, so the plan has been to pull in the more thorough bits from there. If you want to take this across the finish line, by all means please do! |
Is JSX going to be supported or is there any other way to do it? |
What if we added this https://github.com/wallabyjs/escodegen? |
Adds JSX support.
Notes
value
andraw
Todo
generateExpression()
Closes #333.