styled-components-to-stylex-codemod 0.0.31 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -254,6 +254,9 @@ const DEFAULT_THEME_HOOK = {
|
|
|
254
254
|
* // Emit sx={} JSX attributes instead of {...stylex.props()} spreads (requires StyleX ≥0.18)
|
|
255
255
|
* useSxProp: false,
|
|
256
256
|
*
|
|
257
|
+
* // Opt out of logical properties — use paddingTop/Right/Bottom/Left instead of Block/Inline
|
|
258
|
+
* // usePhysicalProperties: true,
|
|
259
|
+
*
|
|
257
260
|
* // Optional: customize runtime theme hook import/call used by emitted wrappers
|
|
258
261
|
* themeHook: {
|
|
259
262
|
* functionName: "useTheme",
|
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as assertValidAdapterInput, n as defineAdapter, o as describeValue } from "./adapter-
|
|
1
|
+
import { a as assertValidAdapterInput, n as defineAdapter, o as describeValue } from "./adapter-Cu-LRuPc.mjs";
|
|
2
2
|
import { t as Logger } from "./logger-C2O81VeU.mjs";
|
|
3
3
|
import { run } from "jscodeshift/src/Runner.js";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
@@ -196,13 +196,15 @@ async function runTransform(options) {
|
|
|
196
196
|
styleMerger: resolvedAdapter.styleMerger,
|
|
197
197
|
themeHook: resolvedAdapter.themeHook,
|
|
198
198
|
useSxProp: resolvedAdapter.useSxProp,
|
|
199
|
+
usePhysicalProperties: resolvedAdapter.usePhysicalProperties,
|
|
199
200
|
externalInterface(ctx) {
|
|
200
201
|
return resolvedAdapter.externalInterface(ctx);
|
|
201
202
|
},
|
|
202
203
|
resolveValue: resolveValueWithLogging,
|
|
203
204
|
resolveCall: resolveCallWithLogging,
|
|
204
205
|
resolveSelector: resolveSelectorWithLogging,
|
|
205
|
-
resolveBaseComponent: adapterInput.resolveBaseComponent ? resolveBaseComponentWithLogging : void 0
|
|
206
|
+
resolveBaseComponent: adapterInput.resolveBaseComponent ? resolveBaseComponentWithLogging : void 0,
|
|
207
|
+
resolveThemeCall: resolvedAdapter.resolveThemeCall
|
|
206
208
|
};
|
|
207
209
|
const transformPath = (() => {
|
|
208
210
|
const adjacent = join(__dirname, "transform.mjs");
|
|
@@ -139,6 +139,22 @@ type CallResolveContext = {
|
|
|
139
139
|
*/
|
|
140
140
|
cssProperty?: string;
|
|
141
141
|
};
|
|
142
|
+
/**
|
|
143
|
+
* Context for `adapter.resolveThemeCall(...)`.
|
|
144
|
+
*
|
|
145
|
+
* This handles patterns like `props.theme.highlightVariant(props.theme.color.bgBorderSolid)`
|
|
146
|
+
* where a method on the theme object is called with theme-dependent arguments.
|
|
147
|
+
*/
|
|
148
|
+
type ThemeCallResolveContext = {
|
|
149
|
+
/** Absolute path of the file being transformed. */callSiteFilePath: string; /** The method name on the theme object (e.g., "highlightVariant"). */
|
|
150
|
+
methodName: string; /** Call arguments (same format as CallResolveContext.args). */
|
|
151
|
+
args: CallResolveContext["args"]; /** Source location of the call. */
|
|
152
|
+
loc?: {
|
|
153
|
+
line: number;
|
|
154
|
+
column: number;
|
|
155
|
+
}; /** CSS property being set (when available). */
|
|
156
|
+
cssProperty?: string;
|
|
157
|
+
};
|
|
142
158
|
/**
|
|
143
159
|
* Context for `adapter.resolveValue(...)` (theme + css variables + imported values).
|
|
144
160
|
*
|
|
@@ -600,6 +616,18 @@ interface Adapter {
|
|
|
600
616
|
* ```
|
|
601
617
|
*/
|
|
602
618
|
styleMerger: StyleMergerConfig | null;
|
|
619
|
+
/**
|
|
620
|
+
* Optional resolver for theme method calls like `props.theme.highlightVariant(...)`.
|
|
621
|
+
*
|
|
622
|
+
* Called when the codemod encounters a call expression on the theme object that
|
|
623
|
+
* cannot be resolved via simple theme property access.
|
|
624
|
+
*
|
|
625
|
+
* Return:
|
|
626
|
+
* - `{ preserveRuntimeCall: true }` to preserve the call at runtime
|
|
627
|
+
* - `{ expr, imports }` to resolve to a static StyleX value
|
|
628
|
+
* - `undefined` to bail (theme method call is not supported)
|
|
629
|
+
*/
|
|
630
|
+
resolveThemeCall?: (context: ThemeCallResolveContext) => CallResolveResult | undefined;
|
|
603
631
|
/**
|
|
604
632
|
* Optional theme hook import/call customization for wrapper code that needs runtime theme access.
|
|
605
633
|
*
|
|
@@ -619,6 +647,18 @@ interface Adapter {
|
|
|
619
647
|
*
|
|
620
648
|
*/
|
|
621
649
|
useSxProp: boolean;
|
|
650
|
+
/**
|
|
651
|
+
* Use physical CSS properties (`paddingTop`/`paddingRight`/`paddingBottom`/`paddingLeft`)
|
|
652
|
+
* instead of logical properties (`paddingBlock`/`paddingInline`) when expanding
|
|
653
|
+
* 2-value CSS shorthands like `padding: 4px 8px`.
|
|
654
|
+
*
|
|
655
|
+
* By default, the codemod uses logical properties which adapt to the writing direction
|
|
656
|
+
* (RTL/LTR), matching StyleX's ESLint plugin recommendations. Enable this if your
|
|
657
|
+
* codebase needs RTL support or prefer physical properties.
|
|
658
|
+
*
|
|
659
|
+
* @default false
|
|
660
|
+
*/
|
|
661
|
+
usePhysicalProperties?: boolean;
|
|
622
662
|
}
|
|
623
663
|
/**
|
|
624
664
|
* User-facing adapter input type accepted by `defineAdapter()`.
|
|
@@ -641,9 +681,11 @@ interface AdapterInput {
|
|
|
641
681
|
* in `runTransform()`).
|
|
642
682
|
*/
|
|
643
683
|
externalInterface: "auto" | Adapter["externalInterface"];
|
|
684
|
+
resolveThemeCall?: Adapter["resolveThemeCall"];
|
|
644
685
|
styleMerger: Adapter["styleMerger"];
|
|
645
686
|
themeHook?: Adapter["themeHook"];
|
|
646
687
|
useSxProp: Adapter["useSxProp"];
|
|
688
|
+
usePhysicalProperties?: Adapter["usePhysicalProperties"];
|
|
647
689
|
}
|
|
648
690
|
/**
|
|
649
691
|
* Helper for nicer user authoring + type inference.
|
|
@@ -707,6 +749,9 @@ interface AdapterInput {
|
|
|
707
749
|
* // Emit sx={} JSX attributes instead of {...stylex.props()} spreads (requires StyleX ≥0.18)
|
|
708
750
|
* useSxProp: false,
|
|
709
751
|
*
|
|
752
|
+
* // Opt out of logical properties — use paddingTop/Right/Bottom/Left instead of Block/Inline
|
|
753
|
+
* // usePhysicalProperties: true,
|
|
754
|
+
*
|
|
710
755
|
* // Optional: customize runtime theme hook import/call used by emitted wrappers
|
|
711
756
|
* themeHook: {
|
|
712
757
|
* functionName: "useTheme",
|
|
@@ -718,7 +763,7 @@ declare function defineAdapter<T extends AdapterInput>(adapter: T): T;
|
|
|
718
763
|
//#endregion
|
|
719
764
|
//#region src/internal/logger.d.ts
|
|
720
765
|
type Severity = "info" | "warning" | "error";
|
|
721
|
-
type WarningType = "`css` helper function switch must return css templates in all branches" | "`css` helper usage as a function call (css(...)) is not supported" | "`css` helper used outside of a styled component template cannot be statically transformed" | "Adapter helper call in border interpolation did not resolve to a single CSS value" | "Adapter resolveCall returned an unparseable styles expression" | "Adapter resolveCall returned an unparseable value expression" | "Adapter resolveCall returned StyleX styles for helper call where a CSS value was expected" | "Adapter resolveCall returned undefined for helper call" | "Adapter resolveBaseComponent threw an error" | "Adapter resolved StyleX styles cannot be applied under nested selectors/at-rules" | "Adapter resolved StyleX styles inside pseudo selector but did not provide cssText for property expansion — add cssText to resolveCall result to enable pseudo-wrapping" | 'Adapter resolveCall cssText could not be parsed as CSS declarations — expected semicolon-separated property: value pairs (e.g. "white-space: nowrap; overflow: hidden;")' | "Adapter resolveValue returned an unparseable value expression" | "Adapter resolveValue returned undefined for imported value" | "Arrow function: body is not a recognized pattern (expected ternary, logical, call, or member expression)" | "Arrow function: conditional branches could not be resolved to static or theme values" | "Arrow function: helper call body is not supported" | "Arrow function: indexed theme lookup pattern not matched" | "Arrow function: logical expression pattern not supported" | "Arrow function: prop access cannot be converted to style function for this CSS property" | "Arrow function: theme access path could not be resolved" | "Component selectors like `${OtherComponent}:hover &` are not directly representable in StyleX. Manual refactor is required" | "Conditional `css` block: !important is not supported in StyleX" | "Conditional `css` block: @-rules (e.g., @media, @supports) are not supported" | "CSS block contains unsupported at-rule (only @media and @container are supported; @supports, etc. require manual handling)" | "Conditional `css` block: dynamic interpolation could not be resolved to a single component prop" | "Conditional `css` block: failed to parse expression" | "Conditional `css` block: missing CSS property name" | "Conditional `css` block: missing interpolation expression" | "Conditional `css` block: mixed static/dynamic values with non-theme expressions cannot be safely transformed" | "Conditional `css` block: multiple interpolation slots in a single property value" | "Conditional `css` block: ternary branch value could not be resolved (imported values require adapter support)" | "Conditional `css` block: ternary expressions inside pseudo selectors are not supported" | "Conditional `css` block: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)" | "Conditional `css` block: unsupported selector" | "Directional border helper styles are not supported" | "Multi-slot border interpolation could not be resolved" | "Resolved border helper value could not be expanded to longhand properties" | "Resolved conditional border variant could not be expanded to longhand properties" | "createGlobalStyle is not supported in StyleX. Global styles should be handled separately (e.g., in a CSS file or using CSS reset libraries)" | "Failed to parse theme expressions" | "Heterogeneous background values (mix of gradients and colors) not currently supported" | "Higher-order styled factory wrappers (e.g. hoc(styled)) are not supported" | "Imported CSS helper mixins: cannot determine inherited properties for correct pseudo selector handling" | "Local helper function returns CSS that cannot be decomposed into individual properties" | "Local helper function computes CSS values that cannot be statically traced to the component prop" | "Styled-components specificity hacks like `&&` / `&&&` are not representable in StyleX" | "Theme-dependent block-level conditional could not be fully resolved (branches may contain dynamic interpolations)" | "Theme-dependant call expression could not be resolved (e.g. theme helper calls like theme.highlight() are not supported)" | "Theme value with fallback (props.theme.X ?? / || default) cannot be resolved statically — use adapter.resolveValue to map theme paths to StyleX tokens" | "Theme-dependent nested prop access requires a project-specific theme source (e.g. useTheme())" | "Theme-dependent template literals require a project-specific theme source (e.g. useTheme())" | "Theme prop overrides on styled components are not supported" | "Universal selectors (`*`) are currently unsupported" | "Unsupported call expression (expected imported helper(...) or imported helper(...)(...))" | "Unsupported conditional test in shouldForwardProp" | "Unsupported shouldForwardProp pattern (only !prop.startsWith(), ![].includes(prop), and prop !== are supported)" | "Unsupported interpolation: arrow function" | "Unsupported interpolation: call expression" | "Unsupported interpolation: identifier" | "Unsupported interpolation: member expression" | "Unsupported interpolation: property" | "Unsupported interpolation: unknown" | "Unsupported nested conditional interpolation" | "Unsupported prop-based inline style expression cannot be safely inlined" | "Unsupported prop-based inline style props.theme access is not supported" | "Unsupported selector interpolation: imported value in selector position" | "Unsupported: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)" | "Unsupported selector: class selector" | "Unsupported selector: comma-separated selectors must all be simple pseudos or pseudo-elements" | "Unsupported selector: descendant pseudo selector (space before pseudo)" | "Unsupported selector: descendant/child/sibling selector" | "Unsupported selector: interpolated pseudo selector" | "Unsupported selector: sibling combinator" | "Unsupported selector: unresolved interpolation in sibling selector" | "Unsupported selector: ambiguous element selector" | "Unsupported selector: attribute selector on unsupported element" | "Unsupported selector: element selector on exported component" | "Unsupported selector: element selector with combined ancestor and child pseudos" | "Unsupported selector: element selector with dynamic children" | "Unsupported selector: element selector with plain intrinsic children" | "Unsupported selector: element selector pseudo collision" | "Unsupported selector: cross-file component selector target has no JSX usage in this file" | "Unsupported selector: unresolved interpolation in cross-file component selector" | "Unsupported selector: unresolved interpolation in descendant component selector" | "Unsupported selector: unresolved interpolation in element selector" | "Unsupported selector: unresolved interpolation in reverse component selector" | "Unsupported selector: unresolved interpolation in cross-component sibling selector" | "Unsupported selector: grouped reverse selector references different components" | "Unsupported selector: computed media query inside cross-component sibling selector" | "Unsupported selector: computed media query inside sibling selector" | "Unsupported selector: unknown component selector" | "Unsupported css`` mixin: after-base mixin style is not a plain object" | "Unsupported css`` mixin: nested contextual conditions in after-base mixin" | "Unsupported css`` mixin: cannot infer base default for after-base contextual override (base value is non-literal)" | "css`` helper function interpolation references closure variable that cannot be hoisted" | "Using styled-components components as mixins is not supported; use css`` mixins or strings instead" | "styled(ImportedComponent) wraps a component whose file contains internal styled-components — convert the base component's file first to avoid CSS cascade conflicts" | "Transient $-prefixed props renamed on exported component — update consumer call sites to use the new prop names" | "Shorthand property has an opaque value that StyleX will expand to longhands — use `directional` in resolveValue to return separate longhand tokens";
|
|
766
|
+
type WarningType = "`css` helper function switch must return css templates in all branches" | "`css` helper usage as a function call (css(...)) is not supported" | "`css` helper used outside of a styled component template cannot be statically transformed" | "Adapter helper call in border interpolation did not resolve to a single CSS value" | "Adapter resolveCall returned an unparseable styles expression" | "Adapter resolveCall returned an unparseable value expression" | "Adapter resolveCall returned StyleX styles for helper call where a CSS value was expected" | "Adapter resolveCall returned undefined for helper call" | "Adapter resolveBaseComponent threw an error" | "Adapter resolved StyleX styles cannot be applied under nested selectors/at-rules" | "Adapter resolved StyleX styles inside pseudo selector but did not provide cssText for property expansion — add cssText to resolveCall result to enable pseudo-wrapping" | 'Adapter resolveCall cssText could not be parsed as CSS declarations — expected semicolon-separated property: value pairs (e.g. "white-space: nowrap; overflow: hidden;")' | "Adapter resolveValue returned an unparseable value expression" | "Adapter resolveValue returned undefined for imported value" | "Arrow function: body is not a recognized pattern (expected ternary, logical, call, or member expression)" | "Arrow function: conditional branches could not be resolved to static or theme values" | "Arrow function: helper call body is not supported" | "Arrow function: indexed theme lookup pattern not matched" | "Arrow function: logical expression pattern not supported" | "Arrow function: prop access cannot be converted to style function for this CSS property" | "Arrow function: theme access path could not be resolved" | "Component selectors like `${OtherComponent}:hover &` are not directly representable in StyleX. Manual refactor is required" | "Conditional `css` block: !important is not supported in StyleX" | "Conditional `css` block: @-rules (e.g., @media, @supports) are not supported" | "CSS block contains unsupported at-rule (only @media and @container are supported; @supports, etc. require manual handling)" | "Conditional `css` block: dynamic interpolation could not be resolved to a single component prop" | "Conditional `css` block: failed to parse expression" | "Conditional `css` block: missing CSS property name" | "Conditional `css` block: missing interpolation expression" | "Conditional `css` block: mixed static/dynamic values with non-theme expressions cannot be safely transformed" | "Conditional `css` block: multiple interpolation slots in a single property value" | "Conditional `css` block: ternary branch value could not be resolved (imported values require adapter support)" | "Conditional `css` block: ternary expressions inside pseudo selectors are not supported" | "Conditional `css` block: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)" | "Conditional `css` block: unsupported selector" | "Directional border helper styles are not supported" | "Multi-slot border interpolation could not be resolved" | "Resolved border helper value could not be expanded to longhand properties" | "Resolved conditional border variant could not be expanded to longhand properties" | "createGlobalStyle is not supported in StyleX. Global styles should be handled separately (e.g., in a CSS file or using CSS reset libraries)" | "Failed to parse theme expressions" | "Heterogeneous background values (mix of gradients and colors) not currently supported" | "Higher-order styled factory wrappers (e.g. hoc(styled)) are not supported" | "Imported CSS helper mixins: cannot determine inherited properties for correct pseudo selector handling" | "Local helper function returns CSS that cannot be decomposed into individual properties" | "Local helper function computes CSS values that cannot be statically traced to the component prop" | "Styled-components specificity hacks like `&&` / `&&&` are not representable in StyleX" | "Theme-dependent block-level conditional could not be fully resolved (branches may contain dynamic interpolations)" | "Theme-dependant call expression could not be resolved (e.g. theme helper calls like theme.highlight() are not supported)" | "Theme value with fallback (props.theme.X ?? / || default) cannot be resolved statically — use adapter.resolveValue to map theme paths to StyleX tokens" | "Theme-dependent nested prop access requires a project-specific theme source (e.g. useTheme())" | "Theme-dependent template literals require a project-specific theme source (e.g. useTheme())" | "Theme prop overrides on styled components are not supported" | "Universal selectors (`*`) are currently unsupported" | "Unsupported call expression (expected imported helper(...) or imported helper(...)(...))" | "Unsupported conditional test in shouldForwardProp" | "Unsupported shouldForwardProp pattern (only !prop.startsWith(), ![].includes(prop), and prop !== are supported)" | "Unsupported interpolation: arrow function" | "Unsupported interpolation: call expression" | "Unsupported interpolation: identifier" | "Unsupported interpolation: member expression" | "Unsupported interpolation: property" | "Unsupported interpolation: unknown" | "Unsupported nested conditional interpolation" | "Unsupported prop-based inline style expression cannot be safely inlined" | "Unsupported prop-based inline style props.theme access is not supported" | "Unsupported selector interpolation: imported value in selector position" | "Unsupported: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)" | "Unsupported selector: class selector" | "Unsupported selector: comma-separated selectors must all be simple pseudos or pseudo-elements" | "Unsupported selector: descendant pseudo selector (space before pseudo)" | "Unsupported selector: descendant/child/sibling selector" | "Unsupported selector: interpolated pseudo selector" | "Unsupported selector: sibling combinator" | "Unsupported selector: unresolved interpolation in sibling selector" | "Unsupported selector: ambiguous element selector" | "Unsupported selector: attribute selector on unsupported element" | "Unsupported selector: element selector on exported component" | "Unsupported selector: element selector with combined ancestor and child pseudos" | "Unsupported selector: element selector with dynamic children" | "Unsupported selector: element selector with plain intrinsic children" | "Unsupported selector: element selector pseudo collision" | "Unsupported selector: cross-file component selector target has no JSX usage in this file" | "Unsupported selector: unresolved interpolation in cross-file component selector" | "Unsupported selector: unresolved interpolation in descendant component selector" | "Unsupported selector: unresolved interpolation in element selector" | "Unsupported selector: unresolved interpolation in reverse component selector" | "Unsupported selector: unresolved interpolation in cross-component sibling selector" | "Unsupported selector: grouped reverse selector references different components" | "Unsupported selector: computed media query inside ancestor attribute selector" | "Unsupported selector: computed media query inside cross-component sibling selector" | "Unsupported selector: computed media query inside sibling selector" | "Unsupported selector: computed media query inside :has() component selector" | "Unsupported selector: cross-file :has() component selector not yet supported" | "Unsupported selector: unresolved interpolation in :has() component selector" | "Unsupported selector: unknown component selector" | "Unsupported css`` mixin: after-base mixin style is not a plain object" | "Unsupported css`` mixin: nested contextual conditions in after-base mixin" | "Unsupported css`` mixin: cannot infer base default for after-base contextual override (base value is non-literal)" | "css`` helper function interpolation references closure variable that cannot be hoisted" | "Using styled-components components as mixins is not supported; use css`` mixins or strings instead" | "styled(ImportedComponent) wraps a component whose file contains internal styled-components — convert the base component's file first to avoid CSS cascade conflicts" | "Transient $-prefixed props renamed on exported component — update consumer call sites to use the new prop names" | "Shorthand property has an opaque value that StyleX will expand to longhands — use `directional` in resolveValue to return separate longhand tokens";
|
|
722
767
|
interface WarningLog {
|
|
723
768
|
severity: Severity;
|
|
724
769
|
type: WarningType;
|
package/dist/transform.d.mts
CHANGED