mirror of
https://github.com/zhigang1992/nativewind.git
synced 2026-06-15 10:17:54 +08:00
fix: stop babel appending platform to TailwindProvider
This commit is contained in:
@@ -6,7 +6,7 @@ import { MotiText } from "moti";
|
||||
import { TestComponent } from "./test";
|
||||
export function Test() {
|
||||
return (
|
||||
<TailwindProvider platform="native">
|
||||
<TailwindProvider>
|
||||
<StyledComponent className="font-bold" component={Text}>
|
||||
Hello world!
|
||||
</StyledComponent>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { TailwindProvider } from "tailwindcss-react-native";
|
||||
import { MotiText } from "moti";
|
||||
export function Test() {
|
||||
return (
|
||||
<TailwindProvider platform="native">
|
||||
<TailwindProvider>
|
||||
<StyledComponent className="container" component={View}>
|
||||
<StyledComponent className="font-bold" component={Text}>
|
||||
Hello world!
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Text, View } from "react-native";
|
||||
import { TailwindProvider } from "tailwindcss-react-native";
|
||||
export function Test() {
|
||||
return (
|
||||
<TailwindProvider platform="native">
|
||||
<TailwindProvider>
|
||||
<StyledComponent tw="container" component={View}>
|
||||
<StyledComponent tw="font-bold" component={Text}>
|
||||
Hello world!
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Text, View } from "react-native";
|
||||
import { TailwindProvider } from "tailwindcss-react-native";
|
||||
export function Test() {
|
||||
return (
|
||||
<TailwindProvider platform="native">
|
||||
<TailwindProvider>
|
||||
<StyledComponent className="container" component={View}>
|
||||
<StyledComponent className="font-bold" component={Text}>
|
||||
Hello world!
|
||||
|
||||
@@ -7,7 +7,7 @@ export function Test({ isBold, isUnderline }) {
|
||||
if (isBold) classNames.push("font-bold");
|
||||
if (isUnderline) classNames.push("underline");
|
||||
return (
|
||||
<TailwindProvider platform="native">
|
||||
<TailwindProvider>
|
||||
<StyledComponent className={classNames.join(" ")} component={Text}>
|
||||
Hello world!
|
||||
</StyledComponent>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Text } from "react-native";
|
||||
import { TailwindProvider } from "tailwindcss-react-native";
|
||||
export function Test() {
|
||||
return (
|
||||
<TailwindProvider platform="native">
|
||||
<TailwindProvider>
|
||||
<StyledComponent className="" component={Text}>
|
||||
Hello world!
|
||||
</StyledComponent>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { StyleSheet, Text } from "react-native";
|
||||
import { TailwindProvider } from "tailwindcss-react-native";
|
||||
export function Test() {
|
||||
return (
|
||||
<TailwindProvider platform="native">
|
||||
<TailwindProvider>
|
||||
<StyledComponent
|
||||
className="font-bold"
|
||||
style={styles.test}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import { NodePath } from "@babel/core";
|
||||
import {
|
||||
jsxAttribute,
|
||||
JSXElement,
|
||||
jsxIdentifier,
|
||||
stringLiteral,
|
||||
} from "@babel/types";
|
||||
|
||||
export function appendPlatformAttribute(
|
||||
path: NodePath<JSXElement>,
|
||||
platform: string
|
||||
) {
|
||||
const openingElement = path.node.openingElement;
|
||||
|
||||
openingElement.attributes.push(
|
||||
jsxAttribute(jsxIdentifier("platform"), stringLiteral(platform))
|
||||
);
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import { getImportBlockedComponents } from "./utils/get-import-blocked-component
|
||||
import { someAttributes } from "./utils/has-attribute";
|
||||
|
||||
import { toStyledComponent } from "./transforms/to-component";
|
||||
import { appendPlatformAttribute } from "./transforms/append-platform-attribute";
|
||||
|
||||
import {
|
||||
AllowPathOptions,
|
||||
@@ -53,15 +52,11 @@ export const visitor: Visitor<VisitorState> = {
|
||||
);
|
||||
},
|
||||
JSXElement(path, state) {
|
||||
const { platform, blockList, canTransform } = state;
|
||||
const { blockList, canTransform } = state;
|
||||
const name = getJSXElementName(path.node.openingElement);
|
||||
|
||||
state.hasProvider ||= name === "TailwindProvider";
|
||||
|
||||
if (name === "TailwindProvider" && canTransform) {
|
||||
appendPlatformAttribute(path, platform);
|
||||
}
|
||||
|
||||
if (blockList.has(name) || name[0] !== name[0].toUpperCase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user