-
Notifications
You must be signed in to change notification settings - Fork 145
fix: TS to JS conversion - Ability to spread props within components & allow for empty tags (fragments) #2816
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -212,18 +212,18 @@ const es2017GeneratorJSX = { | |||
| }, | ||||
| // {...props} | ||||
| JSXSpreadAttribute(node, state) { | ||||
| state.write('...('); | ||||
| state.write(' {...'); | ||||
| if (node.argument.type === 'LogicalExpression') { | ||||
| state.write('('); | ||||
| this[node.argument.left.type](node.argument.left, state); | ||||
| state.write(' '); | ||||
| state.write(node.argument.operator); | ||||
| state.write(' '); | ||||
| state.write(` ${node.argument.operator} `); | ||||
| this[node.argument.right.type](node.argument.right, state); | ||||
| state.write(')'); | ||||
| } | ||||
| else { | ||||
| this[node.argument.type](node.argument, state); | ||||
| } | ||||
| state.write(')'); | ||||
| state.write('}'); | ||||
| }, | ||||
| // <></> | ||||
| JSXFragment(node, state) { | ||||
|
|
@@ -232,8 +232,17 @@ const es2017GeneratorJSX = { | |||
| attributes: [], | ||||
| name: { | ||||
| type: 'JSXIdentifier', | ||||
| name: 'React.Fragment' | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this still parse React.Fragment correctly?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did try both, and both are still working. There is an additional block for using
|
||||
| } | ||||
| name: '' | ||||
| }, | ||||
| type: 'JSXOpeningElement' | ||||
| }, | ||||
| closingElement: { | ||||
| attributes: [], | ||||
| name: { | ||||
| type: 'JSXIdentifier', | ||||
| name: '' | ||||
| }, | ||||
| type: 'JSXClosingElement' | ||||
| }, | ||||
| children: node.children | ||||
| }, state); | ||||
|
|
||||
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.
Sorry for not explaining clearly. The
state.write('(');should be abovethis[node.argument.left.type](node.argument.left, state);and thestate.write(')');should be belowthis[node.argument.right.type](node.argument.right, state);, so it will wrap the whole expression in this way. And we should better keep these 2state.write(' ');here because we still need the space between the props and the logical operator. So the whole if statement should be like:Or you can even combine the center 3
state.writetogether to be like:The situation in this if statement is not very commonly seen, many generators don't even consider it, but it's great to keep it here. Hope this makes sense 🙂