Skip to content

Commit

Permalink
fix auto import error with whitespace JSXText
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaruan committed Apr 1, 2020
1 parent 548cb3e commit 873b2e2
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 6 deletions.
Expand Up @@ -303,12 +303,15 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
"JSXElement|JSXFragment"(path) {
if (path.type === "JSXFragment") imports.add("Fragment");
const openingPath = path.get("openingElement");
const validChildren = openingPath.parent.children.filter(
child =>
!t.isJSXEmptyExpression(child) &&
!(t.isJSXText(child) && child.value.trim() === ""),
);

const validChildren = openingPath.parent.children.filter(child => {
if (t.isJSXText(child)) {
const args = [];
t.react.cleanJSXElementLiteralChild(child, args);
return args.length > 0;
} else {
return !t.isJSXEmptyExpression(child);
}
});
let importName;
if (path.type === "JSXElement" && shouldUseCreateElement(path)) {
importName = "createElement";
Expand Down
@@ -0,0 +1,5 @@
class MobileHomeActivityTaskPriorityIcon extends React.PureComponent {
render() {
return <Text>&nbsp;{this.props.value}&nbsp;</Text>;
}
}
@@ -0,0 +1,10 @@
import { jsxs as _jsxs } from "react/jsx-runtime";

class MobileHomeActivityTaskPriorityIcon extends React.PureComponent {
render() {
return /*#__PURE__*/_jsxs(Text, {
children: ["\xA0", this.props.value, "\xA0"]
});
}

}
@@ -0,0 +1,7 @@
/** @jsxRuntime classic */

class MobileHomeActivityTaskPriorityIcon extends React.PureComponent {
render() {
return <Text>&nbsp;{this.props.value}nbsp;</Text>;
}
}
@@ -0,0 +1,7 @@
/** @jsxRuntime classic */
class MobileHomeActivityTaskPriorityIcon extends React.PureComponent {
render() {
return /*#__PURE__*/React.createElement(Text, null, "\xA0", this.props.value, "nbsp;");
}

}
@@ -0,0 +1,7 @@
/** @jsxRuntime classic */

class MobileHomeActivityTaskPriorityIcon extends React.PureComponent {
render() {
return <Text>&nbsp;{this.props.value}nbsp;</Text>;
}
}
@@ -0,0 +1,7 @@
/** @jsxRuntime classic */
class MobileHomeActivityTaskPriorityIcon extends React.PureComponent {
render() {
return /*#__PURE__*/React.createElement(Text, null, "\xA0", this.props.value, "nbsp;");
}

}
2 changes: 2 additions & 0 deletions packages/babel-types/src/index.js
Expand Up @@ -2,6 +2,7 @@
import isReactComponent from "./validators/react/isReactComponent";
import isCompatTag from "./validators/react/isCompatTag";
import buildChildren from "./builders/react/buildChildren";
import cleanJSXElementLiteralChild from "./utils/react/cleanJSXElementLiteralChild";

// asserts
export { default as assertNode } from "./asserts/assertNode";
Expand Down Expand Up @@ -93,4 +94,5 @@ export const react = {
isReactComponent,
isCompatTag,
buildChildren,
cleanJSXElementLiteralChild,
};

0 comments on commit 873b2e2

Please sign in to comment.