feat: new babel modes

BREAKING CHANGE: skipTransform: true has been changed to mode: "compileOnly"
This commit is contained in:
Mark Lawlor
2022-05-05 11:51:55 +10:00
parent 659b11d53e
commit 4c5741fff6
7 changed files with 27 additions and 10 deletions

View File

@@ -0,0 +1,3 @@
{
"mode": "compileOnly"
}

View File

@@ -1,3 +0,0 @@
{
"skipTransform": true
}

View File

@@ -42,15 +42,31 @@ export default function rootVisitor(
return;
}
let canCompile = true;
let canTransform = true;
switch (state.opts.mode) {
case "compileOnly": {
canTransform = false;
break;
}
case "transformOnly": {
canCompile = false;
break;
}
}
const visitorState: VisitorState = {
rem: 16,
tailwindConfigPath: "tailwind.config.js",
platform: "native",
hmr: true,
skipTransform: false,
mode: "compileAndTransform",
blockModuleTransform: [],
hasStyledComponentImport: false,
hasClassNames: false,
canCompile,
canTransform,
...state,
...state.opts,
allowModuleTransform,
@@ -70,7 +86,6 @@ export default function rootVisitor(
hasProvider,
hasStyledComponentImport,
hasClassNames,
skipTransform,
hmr,
} = visitorState;
@@ -90,7 +105,7 @@ export default function rootVisitor(
const bodyNode = path.node.body;
if (!hasStyledComponentImport && !skipTransform) {
if (!hasStyledComponentImport && canTransform) {
prependImport(
bodyNode,
"StyledComponent",

View File

@@ -6,7 +6,7 @@ export interface TailwindcssReactNativeBabelOptions {
allowModuleTransform?: AllowPathOptions;
blockModuleTransform?: string[];
platform?: "web" | "native";
skipTransform?: false;
mode?: "compileAndTransform" | "compileOnly" | "transformOnly";
rem?: number;
tailwindConfigPath?: string;
hmr?: boolean;

View File

@@ -25,6 +25,8 @@ export interface VisitorState
hasProvider: boolean;
hasStyleSheetImport: boolean;
tailwindConfig: TailwindConfig;
canCompile: boolean;
canTransform: boolean;
}
/**
@@ -55,12 +57,12 @@ export const visitor: Visitor<VisitorState> = {
);
},
JSXElement(path, state) {
const { skipTransform, platform, blockList } = state;
const { platform, blockList, canTransform } = state;
const name = getJSXElementName(path.node.openingElement);
state.hasProvider ||= name === "TailwindProvider";
if (name === "TailwindProvider" && !skipTransform) {
if (name === "TailwindProvider" && canTransform) {
appendPlatformAttribute(path, platform);
}
@@ -69,7 +71,7 @@ export const visitor: Visitor<VisitorState> = {
}
if (someAttributes(path, ["className", "tw"])) {
if (!skipTransform) toStyledComponent(path);
if (canTransform) toStyledComponent(path);
state.hasClassNames = true;
}
},