styled-components-to-stylex-codemod 0.0.21 → 0.0.22

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.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as defineAdapter, i as AdapterInput, t as CollectedWarning } from "./logger-tKRY0yOA.mjs";
1
+ import { a as defineAdapter, i as AdapterInput, t as CollectedWarning } from "./logger-nDTvuKsY.mjs";
2
2
 
3
3
  //#region src/run.d.ts
4
4
  interface RunTransformOptions {
package/dist/index.mjs CHANGED
@@ -143,7 +143,7 @@ async function runTransform(options) {
143
143
  ].join("\n"));
144
144
  const { createModuleResolver } = await import("./resolve-imports-4bFqrkrQ.mjs");
145
145
  const sharedResolver = createModuleResolver();
146
- const { runPrepass } = await import("./run-prepass-BuYfEK4M.mjs");
146
+ const { runPrepass } = await import("./run-prepass-DtSt5v9e.mjs");
147
147
  const absoluteFiles = filePaths.map((f) => resolve(f));
148
148
  const absoluteConsumers = consumerFilePaths.map((f) => resolve(f));
149
149
  let prepassResult;
@@ -613,7 +613,7 @@ declare function defineAdapter<T extends AdapterInput>(adapter: T): T;
613
613
  //#endregion
614
614
  //#region src/internal/logger.d.ts
615
615
  type Severity = "info" | "warning" | "error";
616
- 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 contains unresolvable interpolation" | "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" | "createGlobalStyle is not supported in StyleX. Global styles should be handled separately (e.g., in a CSS file or using CSS reset libraries)" | "Dynamic styles inside pseudo elements (::before/::after) are not supported by StyleX. See https://github.com/facebook/stylex/issues/1396" | "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 contains unresolvable interpolation" | "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: 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: grouped reverse selector references different components" | "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" | "Sibling selector broadened: & + & (adjacent) becomes general sibling (~) in StyleX — interleaved non-matching elements will no longer block the match" | "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";
616
+ 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" | "createGlobalStyle is not supported in StyleX. Global styles should be handled separately (e.g., in a CSS file or using CSS reset libraries)" | "Dynamic styles inside pseudo elements (::before/::after) are not supported by StyleX. See https://github.com/facebook/stylex/issues/1396" | "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: 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: grouped reverse selector references different components" | "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" | "Sibling selector broadened: & + & (adjacent) becomes general sibling (~) in StyleX — interleaved non-matching elements will no longer block the match" | "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";
617
617
  interface WarningLog {
618
618
  severity: Severity;
619
619
  type: WarningType;
@@ -575,13 +575,20 @@ async function runPrepass(options) {
575
575
  wrappedName: m[2]
576
576
  });
577
577
  }
578
- if (hasAsProp) {
579
- JSX_AS_COMPONENT_RE.lastIndex = 0;
580
- for (const m of source.matchAll(JSX_AS_COMPONENT_RE)) if (m[1]) addToSetMap(asUsages, m[1], filePath);
581
- }
582
- if (hasRefProp) {
583
- JSX_REF_COMPONENT_RE.lastIndex = 0;
584
- for (const m of source.matchAll(JSX_REF_COMPONENT_RE)) if (m[1]) addToSetMap(refUsages, m[1], filePath);
578
+ if (hasAsProp || hasRefProp) {
579
+ let aliasMap;
580
+ const resolveTagName = (tagName) => {
581
+ aliasMap ??= buildLocalToImportedMap(source);
582
+ return aliasMap.get(tagName) ?? tagName;
583
+ };
584
+ if (hasAsProp) {
585
+ JSX_AS_COMPONENT_RE.lastIndex = 0;
586
+ for (const m of source.matchAll(JSX_AS_COMPONENT_RE)) if (m[1]) addToSetMap(asUsages, resolveTagName(m[1]), filePath);
587
+ }
588
+ if (hasRefProp) {
589
+ JSX_REF_COMPONENT_RE.lastIndex = 0;
590
+ for (const m of source.matchAll(JSX_REF_COMPONENT_RE)) if (m[1]) addToSetMap(refUsages, resolveTagName(m[1]), filePath);
591
+ }
585
592
  }
586
593
  }
587
594
  const styledFileCount = fileContents.size;
@@ -746,11 +753,14 @@ const IMPORT_ALIAS_ENTRY_RE = /\b(\w+)\s+as\s+(\w+)/g;
746
753
  /**
747
754
  * Build a mapping from local alias names to original imported names for a source file.
748
755
  * Only includes PascalCase names that differ from their original (actual aliases).
756
+ * Scans only import declarations to avoid false positives from TypeScript `as` casts
757
+ * (e.g., `foo as Button` would incorrectly map `Button → foo`).
749
758
  */
750
759
  function buildLocalToImportedMap(source) {
760
+ const importText = collectImportDeclarationText(source);
751
761
  const map = /* @__PURE__ */ new Map();
752
762
  IMPORT_ALIAS_ENTRY_RE.lastIndex = 0;
753
- for (const m of source.matchAll(IMPORT_ALIAS_ENTRY_RE)) {
763
+ for (const m of importText.matchAll(IMPORT_ALIAS_ENTRY_RE)) {
754
764
  const original = m[1];
755
765
  const local = m[2];
756
766
  if (original !== local && /^[A-Z]/.test(local)) map.set(local, original);
@@ -1,4 +1,4 @@
1
- import { n as WarningLog, r as Adapter } from "./logger-tKRY0yOA.mjs";
1
+ import { n as WarningLog, r as Adapter } from "./logger-nDTvuKsY.mjs";
2
2
  import "stylis";
3
3
  import { API, FileInfo, Options } from "jscodeshift";
4
4
 
@@ -5933,6 +5933,61 @@ function expandStaticAnimationShorthand(value, inlineKeyframeNames, j, styleObj,
5933
5933
  if (classified.iteration) styleObj.animationIterationCount = classified.iteration;
5934
5934
  return true;
5935
5935
  }
5936
+ /**
5937
+ * Resolves an interpolated animation declaration whose slot expressions
5938
+ * reference keyframes identifiers.
5939
+ *
5940
+ * Supports both the `animation` shorthand and `animation-name` longhand.
5941
+ * For shorthands, replaces each `__SC_EXPR_N__` placeholder with the
5942
+ * corresponding keyframes name, then delegates to
5943
+ * `expandStaticAnimationShorthand`. For `animation-name`, resolves the
5944
+ * single slot directly to a JS identifier.
5945
+ *
5946
+ * Bails (returns null) on comma-separated multi-animation shorthands,
5947
+ * which the single-tuple parser cannot correctly model.
5948
+ */
5949
+ function expandInterpolatedAnimationShorthand(args) {
5950
+ const { property = "animation", valueRaw, slotExprById, keyframesNames, j, inlineKeyframeNameMap } = args;
5951
+ if (property === "animation-name") return resolveAnimationNameSlot(valueRaw, slotExprById, keyframesNames, j);
5952
+ if (valueRaw.includes(",")) return null;
5953
+ return resolveAnimationShorthandSlots(valueRaw, slotExprById, keyframesNames, j, inlineKeyframeNameMap);
5954
+ }
5955
+ /** Resolves `animation-name: ${kf}` where the sole slot is a keyframes identifier. */
5956
+ function resolveAnimationNameSlot(valueRaw, slotExprById, keyframesNames, j) {
5957
+ const kfName = extractKeyframesIdentifierFromSlot(valueRaw, slotExprById, keyframesNames);
5958
+ if (!kfName) return null;
5959
+ return { animationName: j.identifier(kfName) };
5960
+ }
5961
+ /** Resolves `animation: ${kf} 1.6s ease-in-out infinite` by replacing placeholders and expanding. */
5962
+ function resolveAnimationShorthandSlots(valueRaw, slotExprById, keyframesNames, j, inlineKeyframeNameMap) {
5963
+ let modifiedValue = valueRaw;
5964
+ const usedKeyframeNames = /* @__PURE__ */ new Set();
5965
+ const placeholderRe = /__SC_EXPR_(\d+)__/g;
5966
+ let match;
5967
+ while (match = placeholderRe.exec(valueRaw)) {
5968
+ const slotId = Number(match[1]);
5969
+ const expr = slotExprById.get(slotId);
5970
+ if (!expr || expr.type !== "Identifier" || !expr.name || !keyframesNames.has(expr.name)) return null;
5971
+ modifiedValue = modifiedValue.replace(match[0], expr.name);
5972
+ usedKeyframeNames.add(expr.name);
5973
+ }
5974
+ if (usedKeyframeNames.size === 0) return null;
5975
+ const expanded = {};
5976
+ if (expandStaticAnimationShorthand(modifiedValue, usedKeyframeNames, j, expanded, inlineKeyframeNameMap)) return expanded;
5977
+ return null;
5978
+ }
5979
+ /**
5980
+ * If `valueRaw` is exactly a single `__SC_EXPR_N__` placeholder whose slot
5981
+ * expression is a keyframes identifier, returns the identifier name.
5982
+ */
5983
+ function extractKeyframesIdentifierFromSlot(valueRaw, slotExprById, keyframesNames) {
5984
+ const m = valueRaw.match(/^__SC_EXPR_(\d+)__$/);
5985
+ if (!m) return null;
5986
+ const slotId = Number(m[1]);
5987
+ const expr = slotExprById.get(slotId);
5988
+ if (!expr || expr.type !== "Identifier" || !expr.name || !keyframesNames.has(expr.name)) return null;
5989
+ return expr.name;
5990
+ }
5936
5991
 
5937
5992
  //#endregion
5938
5993
  //#region src/internal/transform-steps/convert-keyframes.ts
@@ -10350,7 +10405,7 @@ function emitSimpleWithConfigWrappers(ctx) {
10350
10405
  allowAsProp,
10351
10406
  allowClassNameProp: false,
10352
10407
  allowStyleProp: false,
10353
- includeRefProp: d.supportsRefProp ?? false,
10408
+ includeRefProp: (d.supportsRefProp ?? false) || !includeRest && willForwardRef,
10354
10409
  includeRest,
10355
10410
  defaultAttrs: d.attrsInfo?.defaultAttrs ?? [],
10356
10411
  conditionalAttrs: d.attrsInfo?.conditionalAttrs ?? [],
@@ -10757,7 +10812,7 @@ function emitSimpleExportedIntrinsicWrappers(ctx) {
10757
10812
  ...allowClassNameProp ? [ctx.patternProp("className", classNameId)] : [],
10758
10813
  ...includeChildren ? [ctx.patternProp("children", childrenId)] : [],
10759
10814
  ...allowStyleProp ? [ctx.patternProp("style", styleId)] : [],
10760
- ...d.supportsRefProp ?? false ? [ctx.patternProp("ref", refId)] : [],
10815
+ ...(d.supportsRefProp ?? false) || !restId && willForwardRef ? [ctx.patternProp("ref", refId)] : [],
10761
10816
  ...allowSxProp ? [ctx.patternProp("sx", sxId)] : []
10762
10817
  ],
10763
10818
  destructureProps,
@@ -10789,7 +10844,7 @@ function emitSimpleExportedIntrinsicWrappers(ctx) {
10789
10844
  attrsInfo: attrsInfoWithoutForwardedAsStatic,
10790
10845
  propExprFor: (prop) => j.identifier(prop)
10791
10846
  }),
10792
- ...d.supportsRefProp ?? false ? [j.jsxAttribute(j.jsxIdentifier("ref"), j.jsxExpressionContainer(refId))] : [],
10847
+ ...(d.supportsRefProp ?? false) || !restId && willForwardRef ? [j.jsxAttribute(j.jsxIdentifier("ref"), j.jsxExpressionContainer(refId))] : [],
10793
10848
  ...restId ? [j.jsxSpreadAttribute(restId)] : [],
10794
10849
  ...includesForwardedAs ? [j.jsxAttribute(j.jsxIdentifier("as"), j.jsxExpressionContainer(buildForwardedAsValueExpr(forwardedAsId, forwardedAsStaticFallback)))] : []
10795
10850
  ];
@@ -10825,7 +10880,7 @@ function emitSimpleExportedIntrinsicWrappers(ctx) {
10825
10880
  allowAsProp,
10826
10881
  allowClassNameProp: false,
10827
10882
  allowStyleProp: false,
10828
- includeRefProp: d.supportsRefProp ?? false,
10883
+ includeRefProp: (d.supportsRefProp ?? false) || !shouldIncludeRest && willForwardRef,
10829
10884
  includeRest: shouldIncludeRest,
10830
10885
  defaultAttrs: d.attrsInfo?.defaultAttrs ?? [],
10831
10886
  conditionalAttrs: d.attrsInfo?.conditionalAttrs ?? [],
@@ -14108,7 +14163,7 @@ function createCssHelperResolver(args) {
14108
14163
  filePath,
14109
14164
  resolverImports
14110
14165
  });
14111
- if (resolved === null) return bail("Conditional `css` block: media query contains unresolvable interpolation");
14166
+ if (resolved === null) return bail("Conditional `css` block: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)");
14112
14167
  if (resolved.kind === "static") media = resolved.value;
14113
14168
  else {
14114
14169
  computedMediaKey = resolved;
@@ -14185,6 +14240,20 @@ function createCssHelperResolver(args) {
14185
14240
  continue;
14186
14241
  }
14187
14242
  if (d.important) return bail("Conditional `css` block: !important is not supported in StyleX", { property: d.property });
14243
+ if ((d.property === "animation" || d.property === "animation-name") && args.keyframesNames && args.keyframesNames.size > 0 && args.j) {
14244
+ const expanded = expandInterpolatedAnimationShorthand({
14245
+ property: d.property,
14246
+ valueRaw: d.valueRaw,
14247
+ slotExprById,
14248
+ keyframesNames: args.keyframesNames,
14249
+ j: args.j,
14250
+ inlineKeyframeNameMap: args.inlineKeyframeNameMap
14251
+ });
14252
+ if (expanded) {
14253
+ for (const [prop, value] of Object.entries(expanded)) target[prop] = mergeIntoContext(value, prop, target);
14254
+ continue;
14255
+ }
14256
+ }
14188
14257
  const parts = d.value.parts ?? [];
14189
14258
  const slotParts = parts.filter((p) => p.kind === "slot");
14190
14259
  if (slotParts.length !== 1) return bail("Conditional `css` block: multiple interpolation slots in a single property value", { property: d.property });
@@ -17320,6 +17389,20 @@ function resolveTemplateLiteralBranch(ctx, args) {
17320
17389
  continue;
17321
17390
  }
17322
17391
  if (d.value.kind !== "interpolated") return null;
17392
+ if ((d.property === "animation" || d.property === "animation-name") && ctx.keyframesNames && ctx.keyframesNames.size > 0) {
17393
+ const expanded = expandInterpolatedAnimationShorthand({
17394
+ property: d.property,
17395
+ valueRaw: d.valueRaw,
17396
+ slotExprById,
17397
+ keyframesNames: ctx.keyframesNames,
17398
+ j,
17399
+ inlineKeyframeNameMap: ctx.inlineKeyframeNameMap
17400
+ });
17401
+ if (expanded) {
17402
+ for (const [prop, value] of Object.entries(expanded)) setStyleValue(prop, value);
17403
+ continue;
17404
+ }
17405
+ }
17323
17406
  const parts = d.value.parts ?? [];
17324
17407
  const slotParts = parts.filter((p) => p.kind === "slot");
17325
17408
  if (slotParts.length === 0) return null;
@@ -18194,11 +18277,21 @@ function createCssHelperConditionalHandler(ctx) {
18194
18277
  }
18195
18278
  }
18196
18279
  if ((rule.selector ?? "").trim() !== "&") return null;
18280
+ const applyExpandedAnimation = (expanded) => {
18281
+ for (const [prop, value] of Object.entries(expanded)) setValueForProp(prop, typeof value === "string" || typeof value === "number" ? staticValueToLiteral(j, value) : value, media, computedMediaKeyExpr);
18282
+ };
18197
18283
  for (const d of rule.declarations) {
18198
18284
  if (!d.property) return null;
18199
18285
  if (d.property.includes("__SC_EXPR_")) return null;
18200
18286
  if (d.important) return null;
18201
18287
  if (d.value.kind === "static") {
18288
+ if (d.property === "animation" && ctx.keyframesNames && ctx.keyframesNames.size > 0) {
18289
+ const expanded = {};
18290
+ if (expandStaticAnimationShorthand(d.valueRaw, ctx.keyframesNames, j, expanded, ctx.inlineKeyframeNameMap)) {
18291
+ applyExpandedAnimation(expanded);
18292
+ continue;
18293
+ }
18294
+ }
18202
18295
  for (const mapped of cssDeclarationToStylexDeclarations(d)) {
18203
18296
  let value = cssValueToJs(mapped.value, d.important, mapped.prop);
18204
18297
  if (mapped.prop === "content" && typeof value === "string") {
@@ -18212,6 +18305,20 @@ function createCssHelperConditionalHandler(ctx) {
18212
18305
  continue;
18213
18306
  }
18214
18307
  if (d.value.kind !== "interpolated") return null;
18308
+ if ((d.property === "animation" || d.property === "animation-name") && ctx.keyframesNames && ctx.keyframesNames.size > 0) {
18309
+ const expanded = expandInterpolatedAnimationShorthand({
18310
+ property: d.property,
18311
+ valueRaw: d.valueRaw,
18312
+ slotExprById,
18313
+ keyframesNames: ctx.keyframesNames,
18314
+ j,
18315
+ inlineKeyframeNameMap: ctx.inlineKeyframeNameMap
18316
+ });
18317
+ if (expanded) {
18318
+ applyExpandedAnimation(expanded);
18319
+ continue;
18320
+ }
18321
+ }
18215
18322
  const slotParts = (d.value.parts ?? []).filter((p) => p.kind === "slot");
18216
18323
  if (slotParts.length !== 1) return null;
18217
18324
  const slotExpr = slotExprById.get(slotParts[0].slotId);
@@ -23165,7 +23272,7 @@ function processDeclRules(ctx) {
23165
23272
  state.markBail();
23166
23273
  warnings.push({
23167
23274
  severity: "warning",
23168
- type: "Unsupported: media query contains unresolvable interpolation",
23275
+ type: "Unsupported: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)",
23169
23276
  loc: computeSelectorWarningLoc(decl.loc, decl.rawCss, rule.selector)
23170
23277
  });
23171
23278
  break;
@@ -23789,7 +23896,7 @@ function handleSiblingSelector(selector, rule, ctx) {
23789
23896
  if (resolved === null) {
23790
23897
  warnings.push({
23791
23898
  severity: "warning",
23792
- type: "Unsupported: media query contains unresolvable interpolation",
23899
+ type: "Unsupported: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)",
23793
23900
  loc: computeSelectorWarningLoc(decl.loc, decl.rawCss, rule.selector)
23794
23901
  });
23795
23902
  return "break";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "styled-components-to-stylex-codemod",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Codemod to transform styled-components to StyleX",
5
5
  "keywords": [
6
6
  "codemod",