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

fix auto import error with whitespace JSXText #11354

Merged
merged 1 commit into from Apr 1, 2020

Conversation

lunaruan
Copy link
Contributor

@lunaruan lunaruan commented Apr 1, 2020

The new JSX auto import React has a bug where it ignores valid whitespace text when calculating whether to import jsx or jsxs. This fixes it by stripping JSXText the same way that t.react.buildChildren strips JSXText so that the children calculated are consistent with each other.

@existentialism existentialism added PR: Bug Fix 🐛 A type of pull request used for our changelog categories area: jsx labels Apr 1, 2020
!(t.isJSXText(child) && child.value.trim() === ""),
);

const validChildren = openingPath.parent.children.filter(child => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse t.react.buildChildren?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.react.buildChildren mutates the node. I can refactor it to return a value instead of mutating if that's okay with you.

Copy link
Contributor

@JLHwung JLHwung Apr 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can refactor it to return a value instead of mutating if that's okay with you.

I am okay with that if it turns out we does not depend on its mutation behaviors. BTW t.react.buildChildren is undocumented so it is likely only used by our plugins.

Since t.react.buildChildren is also scattered in this plugin. It will be of great help to maintainers if we can preserve consistency or we clearly identify the different scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah actually maybe you're right. Let me update this diff


class MobileHomeActivityTaskPriorityIcon extends React.PureComponent {
render() {
return <Text>&nbsp;{this.props.value}nbsp;</Text>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be &nbsp;?

Suggested change
return <Text>&nbsp;{this.props.value}nbsp;</Text>;
return <Text>&nbsp;{this.props.value}&nbsp;</Text>;


class MobileHomeActivityTaskPriorityIcon extends React.PureComponent {
render() {
return <Text>&nbsp;{this.props.value}nbsp;</Text>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Suggested change
return <Text>&nbsp;{this.props.value}nbsp;</Text>;
return <Text>&nbsp;{this.props.value}&nbsp;</Text>;

@nicolo-ribaudo nicolo-ribaudo merged commit 9444713 into babel:master Apr 1, 2020
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 2, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: jsx outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants