styled-components-to-stylex-codemod 0.0.44 → 0.0.45

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.
Files changed (2) hide show
  1. package/dist/transform.mjs +823 -59
  2. package/package.json +1 -1
@@ -7429,7 +7429,7 @@ function findUniversalSelectorLineOffset(rawCss) {
7429
7429
  * @internal Exported for testing
7430
7430
  */
7431
7431
  function findSelectorLineOffset(rawCss, selector) {
7432
- const directMatch = rawCss.match(new RegExp(escapeRegExp(selector)));
7432
+ const directMatch = rawCss.match(new RegExp(escapeRegExp$1(selector)));
7433
7433
  if (directMatch) return countNewlinesBefore(rawCss, directMatch.index);
7434
7434
  const pseudoMatch = selector.match(/::?[a-z-]+(?:\([^)]*\))?/i);
7435
7435
  if (pseudoMatch) {
@@ -7449,7 +7449,7 @@ function findSelectorLineOffset(rawCss, selector) {
7449
7449
  }
7450
7450
  const stripped = selector.replace(/^&\s+/, "").replace(/^&\s*[>+~]\s*/, "");
7451
7451
  if (stripped !== selector) {
7452
- const tagMatch = rawCss.match(new RegExp(`(?:^|[\\s>+~])${escapeRegExp(stripped)}\\s*[{,]`, "m"));
7452
+ const tagMatch = rawCss.match(new RegExp(`(?:^|[\\s>+~])${escapeRegExp$1(stripped)}\\s*[{,]`, "m"));
7453
7453
  if (tagMatch) return countNewlinesBefore(rawCss, tagMatch.index + 1);
7454
7454
  }
7455
7455
  return 0;
@@ -7472,7 +7472,7 @@ function countNewlinesBefore(str, position) {
7472
7472
  for (let i = 0; i < position && i < str.length; i++) if (str[i] === "\n") count++;
7473
7473
  return count;
7474
7474
  }
7475
- function escapeRegExp(str) {
7475
+ function escapeRegExp$1(str) {
7476
7476
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
7477
7477
  }
7478
7478
  //#endregion
@@ -11353,7 +11353,7 @@ function collectKeyframesReferencedBySkippedDecls(ctx) {
11353
11353
  function buildDuplicateKeyframesNames(ctx, preservedNames) {
11354
11354
  const duplicates = /* @__PURE__ */ new Map();
11355
11355
  if (preservedNames.size === 0) return duplicates;
11356
- const usedNames = collectBindingNames$1(ctx);
11356
+ const usedNames = collectBindingNames$2(ctx);
11357
11357
  const transformedReferences = collectKeyframesReferencedByDecls(ctx, (decl) => !decl.skipTransform);
11358
11358
  for (const name of transformedReferences) {
11359
11359
  if (!preservedNames.has(name) || duplicates.has(name)) continue;
@@ -11376,23 +11376,23 @@ function collectKeyframesReferencedByDecls(ctx, shouldVisitDecl) {
11376
11376
  }
11377
11377
  return referencedNames;
11378
11378
  }
11379
- function collectBindingNames$1(ctx) {
11379
+ function collectBindingNames$2(ctx) {
11380
11380
  const names = new Set(ctx.keyframesNames);
11381
11381
  ctx.root.find(ctx.j.VariableDeclarator).forEach((path) => {
11382
- collectPatternBindingNames(path.node.id, names);
11382
+ collectPatternBindingNames$1(path.node.id, names);
11383
11383
  });
11384
11384
  ctx.root.find(ctx.j.FunctionDeclaration).forEach((path) => {
11385
- collectPatternBindingNames(path.node.id, names);
11385
+ collectPatternBindingNames$1(path.node.id, names);
11386
11386
  });
11387
11387
  ctx.root.find(ctx.j.ClassDeclaration).forEach((path) => {
11388
- collectPatternBindingNames(path.node.id, names);
11388
+ collectPatternBindingNames$1(path.node.id, names);
11389
11389
  });
11390
11390
  return names;
11391
11391
  }
11392
- function collectPatternBindingNames(node, names) {
11392
+ function collectPatternBindingNames$1(node, names) {
11393
11393
  if (!node || typeof node !== "object") return;
11394
11394
  if (Array.isArray(node)) {
11395
- for (const child of node) collectPatternBindingNames(child, names);
11395
+ for (const child of node) collectPatternBindingNames$1(child, names);
11396
11396
  return;
11397
11397
  }
11398
11398
  const typed = node;
@@ -11403,7 +11403,7 @@ function collectPatternBindingNames(node, names) {
11403
11403
  if (typed.type === "MemberExpression" || typed.type === "OptionalMemberExpression" || typed.type === "TSQualifiedName") return;
11404
11404
  for (const key of Object.keys(node)) {
11405
11405
  if (key === "loc" || key === "comments" || key === "leadingComments") continue;
11406
- collectPatternBindingNames(node[key], names);
11406
+ collectPatternBindingNames$1(node[key], names);
11407
11407
  }
11408
11408
  }
11409
11409
  function makeUniqueKeyframesDuplicateName(name, usedNames) {
@@ -14294,10 +14294,10 @@ function appendSxArrayArg(j, sxArgs, arg) {
14294
14294
  sxArgs.push(normalizeOptionalSxArg(j, arg));
14295
14295
  }
14296
14296
  function normalizeOptionalSxArg(j, arg) {
14297
- if (isUndefinedIdentifier(arg)) return j.nullLiteral();
14297
+ if (isUndefinedIdentifier$1(arg)) return j.nullLiteral();
14298
14298
  if (isLogicalAndExpression(arg)) return j.conditionalExpression(arg.left, normalizeOptionalSxArg(j, arg.right), j.nullLiteral());
14299
14299
  if (isConditionalExpression(arg)) {
14300
- const alternate = isUndefinedIdentifier(arg.alternate) ? j.nullLiteral() : normalizeOptionalSxArg(j, arg.alternate);
14300
+ const alternate = isUndefinedIdentifier$1(arg.alternate) ? j.nullLiteral() : normalizeOptionalSxArg(j, arg.alternate);
14301
14301
  return j.conditionalExpression(arg.test, normalizeOptionalSxArg(j, arg.consequent), alternate);
14302
14302
  }
14303
14303
  return arg;
@@ -14314,7 +14314,7 @@ function isConditionalExpression(arg) {
14314
14314
  function isExpressionField(node, field) {
14315
14315
  return !!node && typeof node === "object" && isPlainArrayElement(node[field]);
14316
14316
  }
14317
- function isUndefinedIdentifier(node) {
14317
+ function isUndefinedIdentifier$1(node) {
14318
14318
  return getNodeType(node) === "Identifier" && node.name === "undefined";
14319
14319
  }
14320
14320
  function getNodeType(node) {
@@ -15879,7 +15879,7 @@ var WrapperEmitter = class {
15879
15879
  return used.has("*") || used.has("style");
15880
15880
  }
15881
15881
  shouldAllowSxProp(d) {
15882
- return (d.supportsExternalStyles ?? false) || d.typeScriptSupportsSxProp === true;
15882
+ return (d.supportsExternalStyles ?? false) || d.typeScriptSupportsSxProp === true || this.shouldAllowClassNameProp(d) || this.shouldAllowStyleProp(d);
15883
15883
  }
15884
15884
  typedComponentHasProp(componentLocalName, propName) {
15885
15885
  const metadata = this.typeScriptComponentMetadataFor(componentLocalName);
@@ -15893,7 +15893,7 @@ var WrapperEmitter = class {
15893
15893
  }
15894
15894
  /**
15895
15895
  * Returns true when the wrapped component's prepass metadata proves it does
15896
- * NOT accept the given style prop (className/style) — i.e. the prop is
15896
+ * NOT accept the given external style prop (className/style/sx) — i.e. the prop is
15897
15897
  * missing from both explicit and resolved props AND the component has no
15898
15898
  * index signature. Used to decide whether to lift the prop onto the wrapper.
15899
15899
  *
@@ -16556,15 +16556,16 @@ var WrapperEmitter = class {
16556
16556
  return true;
16557
16557
  }
16558
16558
  inferredComponentWrapperPropsTypeText(args) {
16559
- const { d, allowClassNameProp, allowStyleProp, allowSxProp, wrappedComponentIsInternalWrapper, hasExplicitPropsType, forceClassNameOptional, forceStyleOptional, wrappedComponent, forwardedAsPropTypeText = "React.ElementType", attrsProvidedPropOptions } = args;
16559
+ const { d, allowClassNameProp, allowStyleProp, allowSxProp, wrappedComponentIsInternalWrapper, wrappedComponentIsStyledWrapper, hasExplicitPropsType, forceClassNameOptional, forceStyleOptional, wrappedComponent, forwardedAsPropTypeText = "React.ElementType", attrsProvidedPropOptions } = args;
16560
16560
  const lines = [];
16561
16561
  const shouldAddStyleProps = d.supportsExternalStyles && !wrappedComponentIsInternalWrapper && !hasExplicitPropsType;
16562
16562
  const liftableContext = !hasExplicitPropsType && !wrappedComponentIsInternalWrapper && Boolean(wrappedComponent);
16563
16563
  const liftClassNameForUnsupportedWrapped = liftableContext && allowClassNameProp && this.wrappedRejectsStyleProp(wrappedComponent, "className");
16564
16564
  const liftStyleForUnsupportedWrapped = liftableContext && allowStyleProp && this.wrappedRejectsStyleProp(wrappedComponent, "style");
16565
+ const shouldAddOwnSxProp = !hasExplicitPropsType && !wrappedComponentIsStyledWrapper && allowSxProp;
16565
16566
  if (shouldAddStyleProps && allowClassNameProp || forceClassNameOptional || liftClassNameForUnsupportedWrapped) lines.push("className?: string");
16566
16567
  if (shouldAddStyleProps && allowStyleProp || forceStyleOptional || liftStyleForUnsupportedWrapped) lines.push("style?: React.CSSProperties");
16567
- if (shouldAddStyleProps && allowSxProp) lines.push(SX_PROP_TYPE_TEXT);
16568
+ if (shouldAddOwnSxProp) lines.push(SX_PROP_TYPE_TEXT);
16568
16569
  if (this.hasForwardedAsUsage(d.localName)) lines.push(`forwardedAs?: ${forwardedAsPropTypeText}`);
16569
16570
  const propsTarget = d.attrsInfo?.attrsAsTag ?? d.base.ident;
16570
16571
  const base = this.componentPropsBaseType(propsTarget);
@@ -16922,7 +16923,7 @@ function rewriteNode(j, node, propNames, propsIdentifier, shadowedNames) {
16922
16923
  renameIdentifierReferences(n.body, propsIdentifier, replacementName);
16923
16924
  }
16924
16925
  const nextShadowedNames = new Set(shadowedNames);
16925
- for (const param of readArray(n.params)) collectBindingNames(param, nextShadowedNames);
16926
+ for (const param of readArray(n.params)) collectBindingNames$1(param, nextShadowedNames);
16926
16927
  rewriteNode(j, n.body, propNames, propsIdentifier, nextShadowedNames);
16927
16928
  return;
16928
16929
  }
@@ -16951,10 +16952,10 @@ function isFunctionLike(node) {
16951
16952
  }
16952
16953
  function functionBindsName(node, name) {
16953
16954
  const bindingNames = /* @__PURE__ */ new Set();
16954
- for (const param of readArray(node.params)) collectBindingNames(param, bindingNames);
16955
+ for (const param of readArray(node.params)) collectBindingNames$1(param, bindingNames);
16955
16956
  return bindingNames.has(name);
16956
16957
  }
16957
- function collectBindingNames(node, names) {
16958
+ function collectBindingNames$1(node, names) {
16958
16959
  if (!node || typeof node !== "object") return;
16959
16960
  const n = node;
16960
16961
  if (n.type === "Identifier" && typeof n.name === "string") {
@@ -16962,21 +16963,21 @@ function collectBindingNames(node, names) {
16962
16963
  return;
16963
16964
  }
16964
16965
  if (n.type === "RestElement") {
16965
- collectBindingNames(n.argument, names);
16966
+ collectBindingNames$1(n.argument, names);
16966
16967
  return;
16967
16968
  }
16968
16969
  if (n.type === "AssignmentPattern") {
16969
- collectBindingNames(n.left, names);
16970
+ collectBindingNames$1(n.left, names);
16970
16971
  return;
16971
16972
  }
16972
16973
  if (n.type === "ObjectPattern") {
16973
16974
  for (const property of readArray(n.properties)) {
16974
16975
  const typedProperty = property;
16975
- collectBindingNames(typedProperty.type === "Property" || typedProperty.type === "ObjectProperty" ? typedProperty.value : property, names);
16976
+ collectBindingNames$1(typedProperty.type === "Property" || typedProperty.type === "ObjectProperty" ? typedProperty.value : property, names);
16976
16977
  }
16977
16978
  return;
16978
16979
  }
16979
- if (n.type === "ArrayPattern") for (const element of readArray(n.elements)) collectBindingNames(element, names);
16980
+ if (n.type === "ArrayPattern") for (const element of readArray(n.elements)) collectBindingNames$1(element, names);
16980
16981
  }
16981
16982
  function renameBindingName(node, fromName, toName) {
16982
16983
  if (!node || typeof node !== "object") return;
@@ -17027,7 +17028,7 @@ function renameIdentifierReferences(node, fromName, toName) {
17027
17028
  }
17028
17029
  if (n.type === "VariableDeclarator") {
17029
17030
  const bindingNames = /* @__PURE__ */ new Set();
17030
- collectBindingNames(n.id, bindingNames);
17031
+ collectBindingNames$1(n.id, bindingNames);
17031
17032
  if (!bindingNames.has(fromName)) renameIdentifierReferences(n.init, fromName, toName);
17032
17033
  return;
17033
17034
  }
@@ -17038,23 +17039,23 @@ function renameIdentifierReferences(node, fromName, toName) {
17038
17039
  }
17039
17040
  function uniqueIdentifierName(node, baseName) {
17040
17041
  const names = /* @__PURE__ */ new Set();
17041
- collectIdentifierNames(node, names);
17042
+ collectIdentifierNames$1(node, names);
17042
17043
  if (!names.has(baseName)) return baseName;
17043
17044
  let index = 1;
17044
17045
  while (names.has(`${baseName}${index}`)) index++;
17045
17046
  return `${baseName}${index}`;
17046
17047
  }
17047
- function collectIdentifierNames(node, names) {
17048
+ function collectIdentifierNames$1(node, names) {
17048
17049
  if (!node || typeof node !== "object") return;
17049
17050
  if (Array.isArray(node)) {
17050
- for (const item of node) collectIdentifierNames(item, names);
17051
+ for (const item of node) collectIdentifierNames$1(item, names);
17051
17052
  return;
17052
17053
  }
17053
17054
  const n = node;
17054
17055
  if (n.type === "Identifier" && typeof n.name === "string") names.add(n.name);
17055
17056
  for (const key of Object.keys(n)) {
17056
17057
  if (IGNORED_KEYS.has(key)) continue;
17057
- collectIdentifierNames(n[key], names);
17058
+ collectIdentifierNames$1(n[key], names);
17058
17059
  }
17059
17060
  }
17060
17061
  function replaceNode(target, replacement) {
@@ -17268,6 +17269,8 @@ function emitComponentWrappers(emitter) {
17268
17269
  const explicitPropsTypeRef = resolveTypeReferenceName(d.propsType ?? null);
17269
17270
  const wrapperReusesWrappedPropsType = explicitPropsTypeRef?.kind === "identifier" && explicitPropsTypeRef.name === emitter.resolveWrappedExplicitPropsTypeRef(renderedComponent)?.name;
17270
17271
  const wrapperPropsExposeSx = wrappedAcceptsSx && !attrsProvidedPropNames.has("sx") && (wrappedLocalDecl && d.propsType && !wrapperReusesWrappedPropsType && !propsTypeOmitsProp(d.propsType, "sx") || propsTypeExposesForwardedSx(d.propsType, wrappedComponent) || !d.propsType || !wrappedLocalDecl);
17272
+ const exposeSxProp = wrapperPropsExposeSx || allowSxProp;
17273
+ const shouldAddOwnSxProp = exposeSxProp && !wrapperPropsExposeSx;
17271
17274
  const wrappedClassNameRequired = allowClassNameProp && wrappedHasClassName && (baseComponentPropsType ? emitter.isPropRequiredInPropsTypeLiteral(baseComponentPropsType, "className") : emitter.typedComponentProp(wrappedComponent, "className")?.optional === false);
17272
17275
  const wrappedStyleRequired = allowStyleProp && wrappedHasStyle && (baseComponentPropsType ? emitter.isPropRequiredInPropsTypeLiteral(baseComponentPropsType, "style") : emitter.typedComponentProp(wrappedComponent, "style")?.optional === false);
17273
17276
  const forceClassNameOptional = !!wrappedClassNameRequired;
@@ -17309,7 +17312,7 @@ function emitComponentWrappers(emitter) {
17309
17312
  const optionalProps = [];
17310
17313
  if (forceClassNameOptional) optionalProps.push("className?: string");
17311
17314
  if (forceStyleOptional) optionalProps.push("style?: React.CSSProperties");
17312
- if (allowSxProp) optionalProps.push(SX_PROP_TYPE_TEXT);
17315
+ if (shouldAddOwnSxProp) optionalProps.push(SX_PROP_TYPE_TEXT);
17313
17316
  if (hasForwardedAsUsage) optionalProps.push(`forwardedAs?: ${forwardedAsPropTypeText}`);
17314
17317
  if (emitter.extendExistingInterface(explicitTypeName, baseWithOmit)) {
17315
17318
  if (optionalProps.length > 0) emitter.injectMembersIntoInterface(explicitTypeName, optionalProps);
@@ -17326,7 +17329,7 @@ function emitComponentWrappers(emitter) {
17326
17329
  appendAttrsProvidedPropOmissions(omitted, d.attrsInfo, attrsProvidedPropOptions);
17327
17330
  const intrinsicBase = defaultTag ? `Omit<React.ComponentPropsWithRef<"${defaultTag}">, keyof ${explicitTypeName}${omitted.length ? ` | ${omitted.join(" | ")}` : ""}>` : null;
17328
17331
  const optionalProps = [];
17329
- if (allowSxProp) optionalProps.push(SX_PROP_TYPE_TEXT);
17332
+ if (shouldAddOwnSxProp) optionalProps.push(SX_PROP_TYPE_TEXT);
17330
17333
  if (hasForwardedAsUsage) optionalProps.push(`forwardedAs?: ${forwardedAsPropTypeText}`);
17331
17334
  inlineTypeText = emitter.joinIntersection(transformExplicitPropsTypeText({
17332
17335
  canMutateExplicitType,
@@ -17349,7 +17352,7 @@ function emitComponentWrappers(emitter) {
17349
17352
  const optionalStyleProps = [];
17350
17353
  if (forceClassNameOptional) optionalStyleProps.push("className?: string");
17351
17354
  if (forceStyleOptional) optionalStyleProps.push("style?: React.CSSProperties");
17352
- if (allowSxProp) optionalStyleProps.push(SX_PROP_TYPE_TEXT);
17355
+ if (shouldAddOwnSxProp) optionalStyleProps.push(SX_PROP_TYPE_TEXT);
17353
17356
  const typeText = [
17354
17357
  baseProps,
17355
17358
  `Omit<React.ComponentPropsWithRef<C>, ${buildOmitUnion([
@@ -17371,14 +17374,16 @@ function emitComponentWrappers(emitter) {
17371
17374
  ].join(" & ");
17372
17375
  emitNamedPropsType(d.localName, typeText, `C extends React.ElementType = typeof ${wrappedComponent}`);
17373
17376
  } else {
17374
- const skipStyleProps = wrapperDecls.some((decl) => decl.localName === wrappedComponent) || wrappedHasClassName && wrappedHasStyle;
17377
+ const wrappedComponentIsStyledWrapper = wrapperDecls.some((decl) => decl.localName === wrappedComponent);
17378
+ const skipStyleProps = wrappedComponentIsStyledWrapper || wrappedHasClassName && wrappedHasStyle;
17375
17379
  const hasExplicitPropsType = !!explicit;
17376
17380
  const inferred = emitter.inferredComponentWrapperPropsTypeText({
17377
17381
  d,
17378
17382
  allowClassNameProp,
17379
17383
  allowStyleProp,
17380
- allowSxProp,
17384
+ allowSxProp: shouldAddOwnSxProp,
17381
17385
  wrappedComponentIsInternalWrapper: skipStyleProps,
17386
+ wrappedComponentIsStyledWrapper,
17382
17387
  hasExplicitPropsType,
17383
17388
  forceClassNameOptional,
17384
17389
  forceStyleOptional,
@@ -17394,10 +17399,13 @@ function emitComponentWrappers(emitter) {
17394
17399
  const wrappedRejectsStyle = !!wrappedComponent && emitter.wrappedRejectsStyleProp(wrappedComponent, "style");
17395
17400
  const shouldLiftClassNameOntoExplicit = !skipStyleProps && allowClassNameProp && wrappedRejectsClassName;
17396
17401
  const shouldLiftStyleOntoExplicit = !skipStyleProps && allowStyleProp && wrappedRejectsStyle;
17397
- if (explicitWithExtras && (d.supportsExternalStyles || shouldLiftClassNameOntoExplicit || shouldLiftStyleOntoExplicit)) explicitWithExtras = injectStylePropsIntoTypeLiteralString(explicitWithExtras, {
17398
- className: !skipStyleProps && allowClassNameProp && (!wrappedHasClassName || wrappedRejectsClassName),
17399
- style: !skipStyleProps && allowStyleProp && (!wrappedHasStyle || wrappedRejectsStyle),
17400
- sx: allowSxProp
17402
+ const shouldLiftSxOntoExplicit = !wrappedComponentIsStyledWrapper && shouldAddOwnSxProp;
17403
+ const shouldInjectClassNameOntoExplicit = !skipStyleProps && allowClassNameProp && (d.supportsExternalStyles && !wrappedHasClassName || shouldLiftClassNameOntoExplicit);
17404
+ const shouldInjectStyleOntoExplicit = !skipStyleProps && allowStyleProp && (d.supportsExternalStyles && !wrappedHasStyle || shouldLiftStyleOntoExplicit);
17405
+ if (explicitWithExtras && (shouldInjectClassNameOntoExplicit || shouldInjectStyleOntoExplicit || shouldLiftClassNameOntoExplicit || shouldLiftStyleOntoExplicit || shouldLiftSxOntoExplicit)) explicitWithExtras = injectStylePropsIntoTypeLiteralString(explicitWithExtras, {
17406
+ className: shouldInjectClassNameOntoExplicit,
17407
+ style: shouldInjectStyleOntoExplicit,
17408
+ sx: shouldLiftSxOntoExplicit
17401
17409
  });
17402
17410
  const explicitWithRef = (explicitWithExtras ? transformExplicitPropsTypeText({
17403
17411
  canMutateExplicitType,
@@ -17408,7 +17416,7 @@ function emitComponentWrappers(emitter) {
17408
17416
  }) : null) ?? (refElementType ? `{ ref?: React.Ref<${refElementType}>; }` : null);
17409
17417
  const typeText = explicitWithRef ? emitter.joinIntersection(explicitWithRef, inferred) : inferred;
17410
17418
  const hasNoCustomProps = !explicitWithRef;
17411
- if (hasNoCustomProps && shouldLowerForwardedAs && renderedAsProp?.baseTypeText && !allowSxProp && !forceClassNameOptional && !forceStyleOptional) emitNamedPropsType(d.localName, emitter.joinIntersection(renderedAsProp.baseTypeText, `{ forwardedAs?: ${renderedAsProp.typeText} }`));
17419
+ if (hasNoCustomProps && shouldLowerForwardedAs && renderedAsProp?.baseTypeText && !exposeSxProp && !forceClassNameOptional && !forceStyleOptional) emitNamedPropsType(d.localName, emitter.joinIntersection(renderedAsProp.baseTypeText, `{ forwardedAs?: ${renderedAsProp.typeText} }`));
17412
17420
  else if (hasNoCustomProps || explicitAttrsOmitUnion && explicitTypeExists) inlineTypeText = typeText;
17413
17421
  else if (!emitNamedPropsType(d.localName, typeText)) inlineTypeText = typeText;
17414
17422
  }
@@ -17519,7 +17527,7 @@ function emitComponentWrappers(emitter) {
17519
17527
  if (node.type !== "TSTypeReference") return;
17520
17528
  const typeName = resolveTypeIdentifierName(node);
17521
17529
  if (!typeName) {
17522
- for (const param of getTypeReferenceParams(node)) collectFromTypeNode(param);
17530
+ for (const param of getTypeReferenceParams$1(node)) collectFromTypeNode(param);
17523
17531
  return;
17524
17532
  }
17525
17533
  if (visitedTypeNames.has(typeName)) return;
@@ -17637,14 +17645,14 @@ function emitComponentWrappers(emitter) {
17637
17645
  const componentId = j.identifier("Component");
17638
17646
  const forwardedAsId = j.identifier("forwardedAs");
17639
17647
  const wrappedComponentExpr = buildWrappedComponentExpr();
17640
- if (allowSxProp || wrapperPropsExposeSx) styleArgs.push(sxId);
17648
+ if (exposeSxProp) styleArgs.push(sxId);
17641
17649
  if (attrsSxExpr) styleArgs.push(attrsSxExpr);
17642
17650
  for (const attr of defaultAttrs) if (!destructureProps.includes(attr.jsxProp)) destructureProps.push(attr.jsxProp);
17643
17651
  for (const attr of dynamicAttrs) if (!destructureProps.includes(attr.jsxProp)) destructureProps.push(attr.jsxProp);
17644
17652
  const canForwardClassNameStyleThroughRest = wrappedAcceptsSx && !(staticClassNameExpr || attrsStaticStyleExpr || d.inlineStyleProps?.length);
17645
17653
  const destructureClassName = allowClassNameProp && !canForwardClassNameStyleThroughRest;
17646
17654
  const destructureStyle = allowStyleProp && !canForwardClassNameStyleThroughRest;
17647
- const destructureSx = allowSxProp || wrapperPropsExposeSx;
17655
+ const destructureSx = exposeSxProp;
17648
17656
  const destructurePropsForPattern = needsUseTheme ? destructureProps.filter((name) => name !== "theme") : destructureProps;
17649
17657
  const patternProps = emitter.buildDestructurePatternProps({
17650
17658
  baseProps: [
@@ -17670,7 +17678,7 @@ function emitComponentWrappers(emitter) {
17670
17678
  styleId,
17671
17679
  allowClassNameProp,
17672
17680
  allowStyleProp,
17673
- allowSxProp,
17681
+ allowSxProp: exposeSxProp,
17674
17682
  inlineStyleProps: d.inlineStyleProps ?? [],
17675
17683
  staticStyleExpr: attrsStaticStyleExpr,
17676
17684
  staticClassNameExpr,
@@ -17909,16 +17917,16 @@ function buildRenamedTransientPropTypes(sourceTypeText, transientPropRenames) {
17909
17917
  function parenthesizeTypeForIndexedAccess(typeText) {
17910
17918
  return `(${typeText})`;
17911
17919
  }
17912
- function getTypeReferenceParams(type) {
17920
+ function getTypeReferenceParams$1(type) {
17913
17921
  const typed = type;
17914
17922
  return typed.typeParameters?.params ?? typed.typeArguments?.params ?? [];
17915
17923
  }
17916
17924
  function getUtilitySourceTypeParams(type) {
17917
- if (!isUtilityTypeReference(resolveTypeReferenceName(type))) return null;
17918
- const sourceType = getTypeReferenceParams(type)[0];
17925
+ if (!isUtilityTypeReference$1(resolveTypeReferenceName(type))) return null;
17926
+ const sourceType = getTypeReferenceParams$1(type)[0];
17919
17927
  return sourceType ? [sourceType] : [];
17920
17928
  }
17921
- function isUtilityTypeReference(typeName) {
17929
+ function isUtilityTypeReference$1(typeName) {
17922
17930
  if (!typeName) return false;
17923
17931
  if (typeName.kind === "qualified") return typeName.namespace === "React" && typeName.name === "PropsWithChildren";
17924
17932
  return [
@@ -18066,7 +18074,7 @@ function removeAttrsMembersInExistingType(emitter, typeName, attrsProvidedPropNa
18066
18074
  for (const part of typed.types) visitType(part);
18067
18075
  return;
18068
18076
  }
18069
- if (typed.type === "TSTypeReference") for (const param of getTypeReferenceParams(node)) visitType(param);
18077
+ if (typed.type === "TSTypeReference") for (const param of getTypeReferenceParams$1(node)) visitType(param);
18070
18078
  };
18071
18079
  root.find(j.TSTypeAliasDeclaration, { id: {
18072
18080
  type: "Identifier",
@@ -18118,30 +18126,33 @@ function resolveTypeIdentifierName(type) {
18118
18126
  function resolveTypeReferenceName(type) {
18119
18127
  if (type?.type !== "TSTypeReference") return null;
18120
18128
  const typeName = type.typeName;
18121
- return getTypeReferenceName(typeName);
18129
+ return getTypeReferenceName$1(typeName);
18122
18130
  }
18123
18131
  function typeReferenceIsComponentPropsOfWrapped(type, wrappedComponent) {
18124
18132
  if (type.type !== "TSTypeReference") return false;
18125
18133
  const node = type;
18126
- const typeName = getTypeReferenceName(node.typeName);
18134
+ const typeName = getTypeReferenceName$1(node.typeName);
18127
18135
  if (!typeName) return false;
18128
- if (!(typeName.kind === "identifier" && typeName.name.startsWith("ComponentProps") || typeName.kind === "qualified" && typeName.namespace === "React" && typeName.name.startsWith("ComponentProps"))) return false;
18136
+ if (!(typeName.kind === "identifier" && isReactComponentPropsUtilityName$1(typeName.name) || typeName.kind === "qualified" && typeName.namespace === "React" && isReactComponentPropsUtilityName$1(typeName.name))) return false;
18129
18137
  return (node.typeParameters?.params ?? []).some((param) => {
18130
18138
  const query = param;
18131
- return query.type === "TSTypeQuery" && getTypeQueryExpressionName(query.exprName) === wrappedComponent;
18139
+ return query.type === "TSTypeQuery" && getTypeQueryExpressionName$1(query.exprName) === wrappedComponent;
18132
18140
  });
18133
18141
  }
18142
+ function isReactComponentPropsUtilityName$1(name) {
18143
+ return name === "ComponentProps" || name === "ComponentPropsWithRef" || name === "ComponentPropsWithoutRef";
18144
+ }
18134
18145
  function isIntrinsicPassthroughType(emitter, type) {
18135
18146
  const text = emitter.stringifyTsType(type);
18136
18147
  return text !== null && /^React\.ComponentProps(?:WithRef)?<"[^"]+">$/.test(text);
18137
18148
  }
18138
- function getTypeQueryExpressionName(exprName) {
18149
+ function getTypeQueryExpressionName$1(exprName) {
18139
18150
  const node = exprName;
18140
18151
  if (!node) return null;
18141
18152
  if (node.type === "Identifier" && node.name) return node.name;
18142
18153
  if (node.type !== "TSQualifiedName") return null;
18143
- const left = getTypeQueryExpressionName(node.left);
18144
- const right = getTypeQueryExpressionName(node.right);
18154
+ const left = getTypeQueryExpressionName$1(node.left);
18155
+ const right = getTypeQueryExpressionName$1(node.right);
18145
18156
  return left && right ? `${left}.${right}` : null;
18146
18157
  }
18147
18158
  function propsTypeOmitsProp(propsType, propName) {
@@ -18150,7 +18161,7 @@ function propsTypeOmitsProp(propsType, propName) {
18150
18161
  visitAst(propsType, (node) => {
18151
18162
  if (found || node.type !== "TSTypeReference") return;
18152
18163
  const typeReference = node;
18153
- const typeName = getTypeReferenceName(typeReference.typeName);
18164
+ const typeName = getTypeReferenceName$1(typeReference.typeName);
18154
18165
  if (typeName?.kind !== "identifier" || typeName.name !== "Omit") return;
18155
18166
  if ((typeReference.typeParameters?.params ?? []).some((param) => typeNodeContainsStringLiteral(param, propName))) found = true;
18156
18167
  });
@@ -18174,7 +18185,7 @@ function visitAst(node, visitor) {
18174
18185
  else if (child && typeof child === "object") visitAst(child, visitor);
18175
18186
  }
18176
18187
  }
18177
- function getTypeReferenceName(typeName) {
18188
+ function getTypeReferenceName$1(typeName) {
18178
18189
  if (typeName?.type === "Identifier" && typeName.name) return {
18179
18190
  kind: "identifier",
18180
18191
  name: typeName.name
@@ -18210,7 +18221,7 @@ function membersExposeProp(members, propName) {
18210
18221
  function getHeritageTypeReferenceName(heritage) {
18211
18222
  if (!heritage || typeof heritage !== "object") return null;
18212
18223
  const node = heritage;
18213
- return getTypeReferenceName(node.expression) ?? getTypeReferenceName(node.typeName);
18224
+ return getTypeReferenceName$1(node.expression) ?? getTypeReferenceName$1(node.typeName);
18214
18225
  }
18215
18226
  function importedPropsTypeExposesForwardedSx(args) {
18216
18227
  const { emitter, typeName, wrappedComponent, seenTypeNames } = args;
@@ -28068,6 +28079,7 @@ function finalizeDeclProcessing(ctx) {
28068
28079
  convertStyleFnsToPropsPattern(state.j, styleFnDecls, styleFnFromProps, decl.styleKey);
28069
28080
  alignComputedCallArgStyleFnParams(styleFnDecls, styleFnFromProps);
28070
28081
  unionStyleFnParamsFromStyleFnFromProps(state.j, decl, styleFnDecls, styleFnFromProps);
28082
+ narrowGuardedStyleFnParamTypes(state.j, decl, styleFnDecls, styleFnFromProps);
28071
28083
  insertStyleFnDeclsAfterComponent(resolvedStyleObjects, styleFnDecls, {
28072
28084
  styleKey: decl.styleKey,
28073
28085
  extraStyleObjects,
@@ -28127,6 +28139,154 @@ function unionStyleFnParamsFromStyleFnFromProps(j, decl, styleFnDecls, styleFnFr
28127
28139
  }
28128
28140
  }
28129
28141
  }
28142
+ function narrowGuardedStyleFnParamTypes(j, decl, styleFnDecls, styleFnFromProps) {
28143
+ const entriesByFnKey = /* @__PURE__ */ new Map();
28144
+ for (const entry of styleFnFromProps) {
28145
+ const entries = entriesByFnKey.get(entry.fnKey) ?? [];
28146
+ entries.push(entry);
28147
+ entriesByFnKey.set(entry.fnKey, entries);
28148
+ }
28149
+ for (const fnKey of styleFnDecls.keys()) {
28150
+ const fnAst = styleFnDecls.get(fnKey);
28151
+ if (!isArrowFunctionWithParams(fnAst)) continue;
28152
+ const firstParam = fnAst.params[0];
28153
+ if (!firstParam) continue;
28154
+ const entries = entriesByFnKey.get(fnKey);
28155
+ const paramName = readParamName(firstParam);
28156
+ const variantWhens = Object.entries(decl.variantStyleKeys ?? {}).filter(([, key]) => key === fnKey).map(([when]) => when);
28157
+ const extraStylexCalls = collectExtraStylexPropsArgCalls(decl, fnKey);
28158
+ const variantCallIsGuarded = paramName !== null && variantWhens.length > 0 && variantWhens.every((when) => conditionWhenGuardsProp(when, paramName));
28159
+ const extraStylexCallIsGuarded = extraStylexCalls.length > 0 && extraStylexCalls.every((call) => extraStylexCallGuardsPrimaryArg(call));
28160
+ if (!(entries ? entries.every(styleFnEntryGuardsPrimaryArg) : variantCallIsGuarded || extraStylexCallIsGuarded)) continue;
28161
+ removeUndefinedFromParamType(j, firstParam);
28162
+ }
28163
+ }
28164
+ function styleFnEntryGuardsPrimaryArg(entry) {
28165
+ if (entry.jsxProp === "__props" || entry.jsxProp === "__helper") return false;
28166
+ if (!styleFnEntryPrimaryArgIsProp(entry)) return false;
28167
+ if (entry.condition === "truthy") return true;
28168
+ if (entry.condition === "always") return false;
28169
+ return entry.conditionWhen ? conditionWhenGuardsProp(entry.conditionWhen, entry.jsxProp) : false;
28170
+ }
28171
+ function styleFnEntryPrimaryArgIsProp(entry) {
28172
+ if (!entry.callArg) return true;
28173
+ const argName = readIdentifierLikeName(entry.callArg);
28174
+ return argName !== null && normalizePropName(argName) === normalizePropName(entry.jsxProp);
28175
+ }
28176
+ function conditionWhenGuardsProp(when, propName) {
28177
+ const prop = escapeRegExp(normalizePropName(propName));
28178
+ const trimmed = when.trim();
28179
+ return new RegExp(`^${prop}$`).test(trimmed) || new RegExp(`^${prop}\\s*\\|\\|\\s*false$`).test(trimmed) || new RegExp(`^${prop}\\s*!=\\s*null$`).test(trimmed) || new RegExp(`^${prop}\\s*!==?\\s*undefined$`).test(trimmed);
28180
+ }
28181
+ function collectExtraStylexPropsArgCalls(decl, fnKey) {
28182
+ const calls = [];
28183
+ for (const entry of decl.extraStylexPropsArgs ?? []) {
28184
+ const call = readExtraStylexPropsArgCall(entry.expr);
28185
+ if (call?.fnKey === fnKey) calls.push({
28186
+ when: entry.when,
28187
+ condition: call.condition,
28188
+ argName: call.argName
28189
+ });
28190
+ }
28191
+ return calls;
28192
+ }
28193
+ function extraStylexCallGuardsPrimaryArg(call) {
28194
+ if (call.argName === null) return false;
28195
+ if (call.when !== void 0) return conditionWhenGuardsProp(call.when, call.argName);
28196
+ return call.condition !== null && conditionExprGuardsProp(call.condition, call.argName);
28197
+ }
28198
+ function readExtraStylexPropsArgCall(expr) {
28199
+ const direct = readStyleFnCall(expr);
28200
+ if (direct) return {
28201
+ ...direct,
28202
+ condition: null
28203
+ };
28204
+ if (!expr || typeof expr !== "object" || expr.type !== "ConditionalExpression") return null;
28205
+ const conditional = expr;
28206
+ if (!conditional.test || !conditional.consequent) return null;
28207
+ const consequentCall = readStyleFnCall(conditional.consequent);
28208
+ return consequentCall ? {
28209
+ ...consequentCall,
28210
+ condition: conditional.test
28211
+ } : null;
28212
+ }
28213
+ function readStyleFnCall(expr) {
28214
+ if (!expr || typeof expr !== "object" || expr.type !== "CallExpression") return null;
28215
+ const call = expr;
28216
+ const callee = call.callee;
28217
+ if (!callee || typeof callee !== "object") return null;
28218
+ const member = callee;
28219
+ if (member.type !== "MemberExpression" || member.computed) return null;
28220
+ const property = member.property;
28221
+ const fnKey = property && typeof property === "object" && property.type === "Identifier" ? property.name ?? null : null;
28222
+ if (!fnKey) return null;
28223
+ return {
28224
+ fnKey,
28225
+ argName: call.arguments?.[0] ? readIdentifierLikeName(call.arguments[0]) : null
28226
+ };
28227
+ }
28228
+ function conditionExprGuardsProp(condition, propName) {
28229
+ if (!condition || typeof condition !== "object") return false;
28230
+ const normalizedProp = normalizePropName(propName);
28231
+ const conditionName = readIdentifierLikeName(condition);
28232
+ if (conditionName !== null) return normalizePropName(conditionName) === normalizedProp;
28233
+ const typed = condition;
28234
+ if (typed.type === "LogicalExpression" && typed.operator === "||") return typed.left !== void 0 && typed.right !== void 0 && conditionExprGuardsProp(typed.left, propName) && isFalseLiteral(typed.right);
28235
+ if (typed.type === "BinaryExpression" && typed.left && typed.right) {
28236
+ const leftName = readIdentifierLikeName(typed.left);
28237
+ if (!(leftName !== null && normalizePropName(leftName) === normalizedProp)) return false;
28238
+ return typed.operator === "!=" && isNullLiteral(typed.right) || (typed.operator === "!==" || typed.operator === "!=") && isUndefinedIdentifier(typed.right);
28239
+ }
28240
+ return false;
28241
+ }
28242
+ function isFalseLiteral(node) {
28243
+ return !!node && typeof node === "object" && (node.type === "BooleanLiteral" && node.value === false || node.type === "Literal" && node.value === false);
28244
+ }
28245
+ function isNullLiteral(node) {
28246
+ return !!node && typeof node === "object" && (node.type === "NullLiteral" || node.type === "Literal" && node.value === null);
28247
+ }
28248
+ function isUndefinedIdentifier(node) {
28249
+ return !!node && typeof node === "object" && node.type === "Identifier" && node.name === "undefined";
28250
+ }
28251
+ function readIdentifierLikeName(node) {
28252
+ let current = node;
28253
+ while (current && typeof current === "object") {
28254
+ const typed = current;
28255
+ if (typed.type === "Identifier") return typed.name ?? null;
28256
+ if (typed.type === "ParenthesizedExpression" || typed.type === "TSAsExpression" || typed.type === "TSNonNullExpression") {
28257
+ current = typed.expression;
28258
+ continue;
28259
+ }
28260
+ if (typed.type === "TemplateLiteral" && typed.expressions?.length === 1) {
28261
+ current = typed.expressions[0];
28262
+ continue;
28263
+ }
28264
+ break;
28265
+ }
28266
+ return null;
28267
+ }
28268
+ function normalizePropName(name) {
28269
+ return name.startsWith("$") ? name.slice(1) : name;
28270
+ }
28271
+ function escapeRegExp(value) {
28272
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
28273
+ }
28274
+ function isArrowFunctionWithParams(node) {
28275
+ return !!node && typeof node === "object" && node.type === "ArrowFunctionExpression" && Array.isArray(node.params);
28276
+ }
28277
+ function readParamName(param) {
28278
+ return param && typeof param === "object" && param.type === "Identifier" ? param.name ?? null : null;
28279
+ }
28280
+ function removeUndefinedFromParamType(j, param) {
28281
+ const typedParam = param;
28282
+ const typeAnnotation = typedParam.typeAnnotation?.typeAnnotation;
28283
+ if (!typeAnnotation || typeof typeAnnotation !== "object") return;
28284
+ const typeNode = typeAnnotation;
28285
+ if (typeNode.type !== "TSUnionType" || !typeNode.types) return;
28286
+ const narrowedTypes = typeNode.types.filter((member) => !(member && typeof member === "object" && member.type === "TSUndefinedKeyword"));
28287
+ if (narrowedTypes.length === typeNode.types.length || narrowedTypes.length === 0) return;
28288
+ typedParam.typeAnnotation = narrowedTypes.length === 1 ? j.tsTypeAnnotation(narrowedTypes[0]) : j.tsTypeAnnotation(j.tsUnionType(narrowedTypes));
28289
+ }
28130
28290
  function buildStyleFnParam(j, decl, propName) {
28131
28291
  const param = j.identifier(propName);
28132
28292
  const typeNode = typeNodeFromPropTypeText(j, decl.typeScriptPropTypes?.get(propName));
@@ -37190,6 +37350,609 @@ function isNonJsxTypeScriptModule(path) {
37190
37350
  return false;
37191
37351
  }
37192
37352
  //#endregion
37353
+ //#region src/internal/transform-steps/propagate-sx-from-classname.ts
37354
+ /**
37355
+ * Adds an `sx` prop to typed wrapper components that pass their `className`
37356
+ * prop through to converted styled-component wrappers.
37357
+ */
37358
+ function propagateSxFromClassNameStep(ctx) {
37359
+ const convertedWrappers = collectConvertedWrappers(ctx);
37360
+ if (convertedWrappers.names.size === 0) return CONTINUE;
37361
+ const stylexStyleImports = collectStylexStyleImports(ctx);
37362
+ const components = collectComponentCandidates(ctx);
37363
+ for (const component of components) {
37364
+ if (convertedWrappers.names.has(component.name)) continue;
37365
+ const propsBinding = getPropsBinding(component.fn);
37366
+ if (!propsBinding) continue;
37367
+ const propsType = getPropsType(ctx, propsBinding.typeName, component.fnPath, convertedWrappers.names, stylexStyleImports);
37368
+ if (!propsType) continue;
37369
+ const classNameMember = propsType.kind === "mutable" ? getPropsTypeMember(propsType.members, "className") : null;
37370
+ const sxMember = propsType.kind === "mutable" ? getPropsTypeMember(propsType.members, "sx") : null;
37371
+ const propsTypeAlreadyHasSx = propsType.kind === "mutable" ? Boolean(sxMember) : propsType.hasSx;
37372
+ const propsTypeHasCompatibleSx = propsType.kind === "mutable" ? !sxMember || isStylexSxMember(sxMember, stylexStyleImports) : propsType.hasSx;
37373
+ if (!(propsType.kind === "mutable" ? Boolean(classNameMember) : propsType.hasClassName) || !propsTypeHasCompatibleSx) continue;
37374
+ const sxExpression = buildSxExpression(ctx.j, propsBinding);
37375
+ if (!addSxToForwardedChildren({
37376
+ ctx,
37377
+ fn: component.fn,
37378
+ fnPath: component.fnPath,
37379
+ convertedWrapperBindings: convertedWrappers.bindings,
37380
+ propsBinding,
37381
+ sxExpression
37382
+ })) continue;
37383
+ if (propsType.kind === "mutable" && classNameMember && !propsTypeAlreadyHasSx) addSxMemberAfterClassName({
37384
+ j: ctx.j,
37385
+ propsType,
37386
+ classNameMember
37387
+ });
37388
+ addSxDestructure(ctx, propsBinding);
37389
+ ctx.markChanged();
37390
+ }
37391
+ return CONTINUE;
37392
+ }
37393
+ function collectConvertedWrappers(ctx) {
37394
+ const names = /* @__PURE__ */ new Set();
37395
+ const styledDecls = ctx.styledDecls;
37396
+ for (const decl of styledDecls ?? []) if (decl.needsWrapperComponent && !decl.isCssHelper && !decl.skipTransform) names.add(decl.localName);
37397
+ return {
37398
+ names,
37399
+ bindings: collectTopLevelBindingPaths(ctx, names)
37400
+ };
37401
+ }
37402
+ function collectStylexStyleImports(ctx) {
37403
+ const namespaceNames = /* @__PURE__ */ new Set();
37404
+ const styleTypeNames = /* @__PURE__ */ new Set();
37405
+ ctx.root.find(ctx.j.ImportDeclaration, { source: { value: "@stylexjs/stylex" } }).forEach((path) => {
37406
+ for (const specifier of path.node.specifiers ?? []) if (specifier.type === "ImportNamespaceSpecifier" && specifier.local?.name) namespaceNames.add(specifier.local.name);
37407
+ else if (specifier.type === "ImportSpecifier" && specifier.imported?.type === "Identifier" && specifier.imported.name === "StyleXStyles" && specifier.local?.name) styleTypeNames.add(specifier.local.name);
37408
+ });
37409
+ return {
37410
+ namespaceNames,
37411
+ styleTypeNames
37412
+ };
37413
+ }
37414
+ function collectTopLevelBindingPaths(ctx, names) {
37415
+ const bindings = /* @__PURE__ */ new Map();
37416
+ const { root, j } = ctx;
37417
+ root.find(j.FunctionDeclaration).forEach((path) => {
37418
+ const name = path.node.id?.name;
37419
+ if (!name || !names.has(name) || !isTopLevelValueBindingPath(path)) return;
37420
+ bindings.set(name, path);
37421
+ });
37422
+ root.find(j.VariableDeclarator).forEach((path) => {
37423
+ const name = path.node.id?.type === "Identifier" ? path.node.id.name : void 0;
37424
+ if (!name || !names.has(name) || !isTopLevelValueBindingPath(path)) return;
37425
+ bindings.set(name, path);
37426
+ });
37427
+ return bindings;
37428
+ }
37429
+ function collectComponentCandidates(ctx) {
37430
+ const candidates = [];
37431
+ const { root, j } = ctx;
37432
+ root.find(j.FunctionDeclaration).forEach((path) => {
37433
+ const name = path.node.id?.name;
37434
+ if (name) candidates.push({
37435
+ name,
37436
+ fn: path.node,
37437
+ fnPath: path
37438
+ });
37439
+ });
37440
+ root.find(j.VariableDeclarator).forEach((path) => {
37441
+ const name = path.node.id?.type === "Identifier" ? path.node.id.name : void 0;
37442
+ const init = path.node.init;
37443
+ if (name && init && (init.type === "ArrowFunctionExpression" || init.type === "FunctionExpression")) candidates.push({
37444
+ name,
37445
+ fn: init,
37446
+ fnPath: path.get("init")
37447
+ });
37448
+ });
37449
+ return candidates;
37450
+ }
37451
+ function getPropsBinding(fn) {
37452
+ const firstParam = fn.params?.[0];
37453
+ if (!firstParam) return null;
37454
+ const typeName = getTypeReferenceName(firstParam.typeAnnotation?.typeAnnotation);
37455
+ if (!typeName) return null;
37456
+ if (firstParam.type === "ObjectPattern") {
37457
+ const classNameLocal = getObjectPatternValueName((firstParam.properties ?? []).find((prop) => getObjectPatternKeyName(prop) === "className"));
37458
+ if (!classNameLocal) return null;
37459
+ const hasSx = hasObjectPatternProp(firstParam, "sx");
37460
+ return {
37461
+ kind: "destructured",
37462
+ pattern: firstParam,
37463
+ typeName,
37464
+ classNameLocal,
37465
+ sxLocal: hasSx ? getExistingSxLocal(firstParam) : getAvailableSxLocalName(fn),
37466
+ restLocal: hasSx ? null : getObjectPatternRestLocal(firstParam)
37467
+ };
37468
+ }
37469
+ if (firstParam.type === "Identifier") return {
37470
+ kind: "propsObject",
37471
+ propsLocal: firstParam.name,
37472
+ typeName
37473
+ };
37474
+ return null;
37475
+ }
37476
+ function getTypeReferenceName(typeAnnotation) {
37477
+ if (typeAnnotation?.type === "TSTypeReference" && typeAnnotation.typeName?.type === "Identifier") return typeAnnotation.typeName.name;
37478
+ return null;
37479
+ }
37480
+ function getPropsType(ctx, typeName, referencePath, convertedWrapperNames, stylexStyleImports) {
37481
+ if (isTypeParameterInScope(referencePath, typeName)) return null;
37482
+ const { root, j } = ctx;
37483
+ let bestPath;
37484
+ let bestDepth = -1;
37485
+ const considerTypePath = (path) => {
37486
+ const containerPath = getLexicalContainerPath(path);
37487
+ if (!containerPath || !pathContains(containerPath, referencePath)) return;
37488
+ const depth = pathDepth(containerPath);
37489
+ if (depth > bestDepth) {
37490
+ bestPath = path;
37491
+ bestDepth = depth;
37492
+ }
37493
+ };
37494
+ root.find(j.TSInterfaceDeclaration, { id: {
37495
+ type: "Identifier",
37496
+ name: typeName
37497
+ } }).forEach((path) => {
37498
+ considerTypePath(path);
37499
+ });
37500
+ root.find(j.TSTypeAliasDeclaration, { id: {
37501
+ type: "Identifier",
37502
+ name: typeName
37503
+ } }).forEach((path) => {
37504
+ considerTypePath(path);
37505
+ });
37506
+ const matched = bestPath?.node;
37507
+ if (!matched) return null;
37508
+ if (matched.type === "TSInterfaceDeclaration") return {
37509
+ kind: "mutable",
37510
+ members: matched.body?.body ?? [],
37511
+ replaceMembers(members) {
37512
+ matched.body.body = members;
37513
+ }
37514
+ };
37515
+ if (matched.type !== "TSTypeAliasDeclaration") return null;
37516
+ if (matched.typeAnnotation?.type !== "TSTypeLiteral") return getReadonlyAliasPropsType(matched.typeAnnotation, convertedWrapperNames, stylexStyleImports);
37517
+ return {
37518
+ kind: "mutable",
37519
+ members: matched.typeAnnotation.members ?? [],
37520
+ replaceMembers(members) {
37521
+ matched.typeAnnotation.members = members;
37522
+ }
37523
+ };
37524
+ }
37525
+ function getReadonlyAliasPropsType(typeAnnotation, convertedWrapperNames, stylexStyleImports) {
37526
+ const surface = getPropsSurface(typeAnnotation, convertedWrapperNames, stylexStyleImports);
37527
+ if (!surface?.hasClassName || surface.sx !== "stylex") return null;
37528
+ return {
37529
+ kind: "readonly",
37530
+ hasClassName: true,
37531
+ hasSx: true
37532
+ };
37533
+ }
37534
+ function getPropsSurface(typeAnnotation, convertedWrapperNames, stylexStyleImports) {
37535
+ if (!typeAnnotation) return null;
37536
+ if (isComponentPropsOfConvertedWrapper(typeAnnotation, convertedWrapperNames)) return {
37537
+ hasClassName: true,
37538
+ sx: "stylex"
37539
+ };
37540
+ if (typeAnnotation.type === "TSIntersectionType") {
37541
+ let hasSurface = false;
37542
+ let hasClassName = false;
37543
+ let sx = "missing";
37544
+ for (const part of typeAnnotation.types ?? []) {
37545
+ const partSurface = getPropsSurface(part, convertedWrapperNames, stylexStyleImports);
37546
+ if (!partSurface) continue;
37547
+ hasSurface = true;
37548
+ hasClassName ||= partSurface.hasClassName;
37549
+ sx = mergeSxSurfaces(sx, partSurface.sx);
37550
+ }
37551
+ return hasSurface ? {
37552
+ hasClassName,
37553
+ sx
37554
+ } : null;
37555
+ }
37556
+ if (typeAnnotation.type === "TSParenthesizedType") return getPropsSurface(typeAnnotation.typeAnnotation, convertedWrapperNames, stylexStyleImports);
37557
+ if (typeAnnotation.type === "TSTypeLiteral") {
37558
+ const members = typeAnnotation.members ?? [];
37559
+ const sxMember = getPropsTypeMember(members, "sx");
37560
+ return {
37561
+ hasClassName: propsTypeHasProp(members, "className"),
37562
+ sx: sxMember ? getSxMemberSurface(sxMember, stylexStyleImports) : "missing"
37563
+ };
37564
+ }
37565
+ if (isOmitTypeReference(typeAnnotation)) {
37566
+ const params = getTypeReferenceParams(typeAnnotation);
37567
+ const sourceSurface = getPropsSurface(params[0], convertedWrapperNames, stylexStyleImports);
37568
+ const omittedProps = getStringLiteralTypeNames(params[1]);
37569
+ if (!sourceSurface || !omittedProps) return null;
37570
+ return {
37571
+ hasClassName: sourceSurface.hasClassName && !omittedProps.has("className"),
37572
+ sx: omittedProps.has("sx") ? "missing" : sourceSurface.sx
37573
+ };
37574
+ }
37575
+ if (isPickTypeReference(typeAnnotation)) {
37576
+ const params = getTypeReferenceParams(typeAnnotation);
37577
+ const sourceSurface = getPropsSurface(params[0], convertedWrapperNames, stylexStyleImports);
37578
+ const pickedProps = getStringLiteralTypeNames(params[1]);
37579
+ if (!sourceSurface || !pickedProps) return null;
37580
+ return {
37581
+ hasClassName: sourceSurface.hasClassName && pickedProps.has("className"),
37582
+ sx: pickedProps.has("sx") ? sourceSurface.sx : "missing"
37583
+ };
37584
+ }
37585
+ return null;
37586
+ }
37587
+ function mergeSxSurfaces(left, right) {
37588
+ if (left === "nonStylex" || right === "nonStylex") return "nonStylex";
37589
+ if (left === "stylex" || right === "stylex") return "stylex";
37590
+ return "missing";
37591
+ }
37592
+ function isComponentPropsOfConvertedWrapper(typeAnnotation, convertedWrapperNames) {
37593
+ if (typeAnnotation?.type !== "TSTypeReference" || !isComponentPropsTypeName(typeAnnotation)) return false;
37594
+ return getTypeReferenceParams(typeAnnotation).some((param) => {
37595
+ if (param?.type !== "TSTypeQuery") return false;
37596
+ const componentName = getTypeQueryExpressionName(param.exprName);
37597
+ return componentName ? convertedWrapperNames.has(componentName) : false;
37598
+ });
37599
+ }
37600
+ function isComponentPropsTypeName(typeReference) {
37601
+ const typeName = typeReference.typeName;
37602
+ if (typeName?.type === "Identifier") return isReactComponentPropsUtilityName(typeName.name);
37603
+ return typeName?.type === "TSQualifiedName" && typeName.left?.type === "Identifier" && typeName.left.name === "React" && typeName.right?.type === "Identifier" && isReactComponentPropsUtilityName(typeName.right.name);
37604
+ }
37605
+ function isReactComponentPropsUtilityName(name) {
37606
+ return name === "ComponentProps" || name === "ComponentPropsWithRef" || name === "ComponentPropsWithoutRef";
37607
+ }
37608
+ function isOmitTypeReference(typeAnnotation) {
37609
+ return isUtilityTypeReference(typeAnnotation, "Omit");
37610
+ }
37611
+ function isPickTypeReference(typeAnnotation) {
37612
+ return isUtilityTypeReference(typeAnnotation, "Pick");
37613
+ }
37614
+ function isUtilityTypeReference(typeAnnotation, name) {
37615
+ return typeAnnotation?.type === "TSTypeReference" && typeAnnotation.typeName?.type === "Identifier" && typeAnnotation.typeName.name === name;
37616
+ }
37617
+ function getTypeReferenceParams(typeReference) {
37618
+ return typeReference.typeParameters?.params ?? typeReference.typeArguments?.params ?? [];
37619
+ }
37620
+ function getTypeQueryExpressionName(exprName) {
37621
+ if (exprName?.type === "Identifier") return exprName.name;
37622
+ return null;
37623
+ }
37624
+ function getStringLiteralTypeNames(typeAnnotation) {
37625
+ if (!typeAnnotation) return null;
37626
+ if (typeAnnotation.type === "TSLiteralType") {
37627
+ const value = typeAnnotation.literal?.value;
37628
+ return typeof value === "string" ? new Set([value]) : null;
37629
+ }
37630
+ if (typeAnnotation.type === "TSUnionType") {
37631
+ const names = /* @__PURE__ */ new Set();
37632
+ for (const part of typeAnnotation.types ?? []) {
37633
+ const partNames = getStringLiteralTypeNames(part);
37634
+ if (!partNames) return null;
37635
+ for (const name of partNames) names.add(name);
37636
+ }
37637
+ return names;
37638
+ }
37639
+ return null;
37640
+ }
37641
+ function getLexicalContainerPath(path) {
37642
+ let current = path.parentPath;
37643
+ while (current) {
37644
+ if (current.node?.type === "Program" || current.node?.type === "BlockStatement" || current.node?.type === "TSModuleBlock") return current;
37645
+ current = current.parentPath;
37646
+ }
37647
+ return null;
37648
+ }
37649
+ function isTypeParameterInScope(referencePath, typeName) {
37650
+ let current = referencePath;
37651
+ while (current) {
37652
+ if (hasTypeParameterNamed(current.node, typeName)) return true;
37653
+ current = current.parentPath;
37654
+ }
37655
+ return false;
37656
+ }
37657
+ function hasTypeParameterNamed(node, typeName) {
37658
+ if (!node || typeof node !== "object") return false;
37659
+ return (node.typeParameters?.params ?? []).some((param) => getTypeParameterName(param) === typeName);
37660
+ }
37661
+ function getTypeParameterName(param) {
37662
+ if (!param || typeof param !== "object") return null;
37663
+ const node = param;
37664
+ if (typeof node.name === "string") return node.name;
37665
+ return typeof node.id?.name === "string" ? node.id.name : null;
37666
+ }
37667
+ function pathContains(containerPath, descendantPath) {
37668
+ let current = descendantPath;
37669
+ while (current) {
37670
+ if (current.node === containerPath.node) return true;
37671
+ current = current.parentPath;
37672
+ }
37673
+ return false;
37674
+ }
37675
+ function pathDepth(path) {
37676
+ let depth = 0;
37677
+ let current = path.parentPath;
37678
+ while (current) {
37679
+ depth++;
37680
+ current = current.parentPath;
37681
+ }
37682
+ return depth;
37683
+ }
37684
+ function propsTypeHasProp(members, propName) {
37685
+ return members.some((member) => getMemberName(member) === propName);
37686
+ }
37687
+ function getPropsTypeMember(members, propName) {
37688
+ return members.find((member) => getMemberName(member) === propName) ?? null;
37689
+ }
37690
+ function getMemberName(member) {
37691
+ const key = member?.key;
37692
+ if (!key) return null;
37693
+ if (key.type === "Identifier") return key.name;
37694
+ if (key.type === "StringLiteral" || key.type === "Literal") return typeof key.value === "string" ? key.value : null;
37695
+ return null;
37696
+ }
37697
+ function getSxMemberSurface(member, stylexStyleImports) {
37698
+ return isStylexSxMember(member, stylexStyleImports) ? "stylex" : "nonStylex";
37699
+ }
37700
+ function isStylexSxMember(member, stylexStyleImports) {
37701
+ return isStylexStylesType(member?.typeAnnotation?.typeAnnotation, stylexStyleImports);
37702
+ }
37703
+ function isStylexStylesType(typeAnnotation, stylexStyleImports) {
37704
+ if (!typeAnnotation) return false;
37705
+ if (typeAnnotation.type === "TSParenthesizedType") return isStylexStylesType(typeAnnotation.typeAnnotation, stylexStyleImports);
37706
+ if (typeAnnotation.type !== "TSTypeReference") return false;
37707
+ const typeName = typeAnnotation.typeName;
37708
+ if (typeName?.type === "Identifier") return stylexStyleImports.styleTypeNames.has(typeName.name);
37709
+ return typeName?.type === "TSQualifiedName" && typeName.left?.type === "Identifier" && stylexStyleImports.namespaceNames.has(typeName.left.name) && typeName.right?.type === "Identifier" && typeName.right.name === "StyleXStyles";
37710
+ }
37711
+ function addSxMemberAfterClassName(args) {
37712
+ const { j, propsType, classNameMember } = args;
37713
+ const sxMember = createSxMember(j, classNameMember.comments);
37714
+ const nextMembers = [];
37715
+ for (const member of propsType.members) {
37716
+ nextMembers.push(member);
37717
+ if (member === classNameMember) nextMembers.push(sxMember);
37718
+ }
37719
+ propsType.replaceMembers(nextMembers);
37720
+ }
37721
+ function createSxMember(j, sourceComments) {
37722
+ const parsed = j("type _Props = { sx?: stylex.StyleXStyles }").find(j.TSPropertySignature).nodes()[0];
37723
+ parsed.comments = cloneSxComments(sourceComments);
37724
+ return parsed;
37725
+ }
37726
+ function cloneSxComments(sourceComments) {
37727
+ if (!sourceComments || sourceComments.length === 0) return;
37728
+ return sourceComments.map((comment) => ({
37729
+ ...comment,
37730
+ value: rewriteClassNameComment(comment.value)
37731
+ }));
37732
+ }
37733
+ function rewriteClassNameComment(value) {
37734
+ if (typeof value !== "string") return value;
37735
+ return value.replace(/\bAdditional\s+className\s+for\b/gi, "StyleX styles applied to").replace(/\bAdditional\s+class\s+name\s+for\b/gi, "StyleX styles applied to").replace(/\bclassName\b/gi, "StyleX styles").replace(/\bclass name\b/gi, "StyleX styles");
37736
+ }
37737
+ function buildSxExpression(j, propsBinding) {
37738
+ if (propsBinding.kind === "destructured") {
37739
+ if (propsBinding.restLocal) return j.memberExpression(j.identifier(propsBinding.restLocal), j.identifier("sx"));
37740
+ return j.identifier(propsBinding.sxLocal);
37741
+ }
37742
+ return j.memberExpression(j.identifier(propsBinding.propsLocal), j.identifier("sx"));
37743
+ }
37744
+ function addSxToForwardedChildren(args) {
37745
+ const { ctx, fn, fnPath, convertedWrapperBindings, propsBinding, sxExpression } = args;
37746
+ if (!fn.body) return false;
37747
+ const propsBindingScope = findPropsBindingScope(fnPath, propsBinding);
37748
+ if (!propsBindingScope) return false;
37749
+ let changed = false;
37750
+ ctx.j(fnPath).find(ctx.j.JSXOpeningElement).forEach((path) => {
37751
+ const opening = path.node;
37752
+ const childName = opening.name?.type === "JSXIdentifier" ? opening.name.name : void 0;
37753
+ const convertedBindingScope = childName ? convertedWrapperBindings.get(childName) : void 0;
37754
+ if (!childName || !convertedBindingScope || !isConvertedChildBinding(ctx, path, childName, convertedBindingScope) || hasJsxAttr(opening, "sx")) return;
37755
+ const classNameAttr = getJsxAttr(opening, "className");
37756
+ if (!classNameAttr || !isForwardedClassNameAttr(classNameAttr, propsBinding) || !isInPropsBindingScope(path, propsBinding, propsBindingScope)) return;
37757
+ insertSxAttribute(ctx, opening, sxExpression);
37758
+ changed = true;
37759
+ });
37760
+ return changed;
37761
+ }
37762
+ function insertSxAttribute(ctx, opening, sxExpression) {
37763
+ const sxAttr = ctx.j.jsxAttribute(ctx.j.jsxIdentifier("sx"), ctx.j.jsxExpressionContainer(cloneExpression(sxExpression)));
37764
+ const attributes = opening.attributes ?? [];
37765
+ const firstSpreadIndex = attributes.findIndex((attr) => attr?.type === "JSXSpreadAttribute");
37766
+ const insertionIndex = firstSpreadIndex === -1 ? attributes.length : firstSpreadIndex;
37767
+ opening.attributes = [
37768
+ ...attributes.slice(0, insertionIndex),
37769
+ sxAttr,
37770
+ ...attributes.slice(insertionIndex)
37771
+ ];
37772
+ }
37773
+ function isConvertedChildBinding(ctx, path, childName, convertedBindingPath) {
37774
+ return findNearestValueBindingPath(ctx, path, childName)?.node === convertedBindingPath.node;
37775
+ }
37776
+ function findNearestValueBindingPath(ctx, referencePath, name) {
37777
+ let bestPath = null;
37778
+ let bestDepth = -1;
37779
+ const considerBindingPath = (bindingPath, containerPath) => {
37780
+ if (!containerPath || !pathContains(containerPath, referencePath)) return;
37781
+ const depth = pathDepth(containerPath);
37782
+ if (depth > bestDepth) {
37783
+ bestPath = bindingPath;
37784
+ bestDepth = depth;
37785
+ }
37786
+ };
37787
+ ctx.root.find(ctx.j.FunctionDeclaration).forEach((path) => {
37788
+ if (path.node.id?.name === name) considerBindingPath(path, getLexicalContainerPath(path));
37789
+ if (functionHasParamBinding(path.node, name)) considerBindingPath(path, path);
37790
+ });
37791
+ ctx.root.find(ctx.j.FunctionExpression).forEach((path) => {
37792
+ if (functionHasParamBinding(path.node, name)) considerBindingPath(path, path);
37793
+ });
37794
+ ctx.root.find(ctx.j.ArrowFunctionExpression).forEach((path) => {
37795
+ if (functionHasParamBinding(path.node, name)) considerBindingPath(path, path);
37796
+ });
37797
+ ctx.root.find(ctx.j.ClassDeclaration).forEach((path) => {
37798
+ if (path.node.id?.name === name) considerBindingPath(path, getLexicalContainerPath(path));
37799
+ });
37800
+ ctx.root.find(ctx.j.ClassExpression).forEach((path) => {
37801
+ if (path.node.id?.name === name) considerBindingPath(path, path);
37802
+ });
37803
+ ctx.root.find(ctx.j.VariableDeclarator).forEach((path) => {
37804
+ if (patternHasBindingName(path.node.id, name)) considerBindingPath(path, getLexicalContainerPath(path));
37805
+ });
37806
+ return bestPath;
37807
+ }
37808
+ function isTopLevelValueBindingPath(path) {
37809
+ return getLexicalContainerPath(path)?.node?.type === "Program";
37810
+ }
37811
+ function functionHasParamBinding(fn, name) {
37812
+ return (fn.params ?? []).some((param) => patternHasBindingName(param, name));
37813
+ }
37814
+ function patternHasBindingName(node, name) {
37815
+ const names = /* @__PURE__ */ new Set();
37816
+ collectPatternBindingNames(node, names);
37817
+ return names.has(name);
37818
+ }
37819
+ function findPropsBindingScope(fnPath, propsBinding) {
37820
+ return findBindingScope(fnPath, propsBinding.kind === "destructured" ? propsBinding.classNameLocal : propsBinding.propsLocal);
37821
+ }
37822
+ function isInPropsBindingScope(path, propsBinding, bindingScope) {
37823
+ return isInBindingScope(path, propsBinding.kind === "destructured" ? propsBinding.classNameLocal : propsBinding.propsLocal, bindingScope);
37824
+ }
37825
+ function findBindingScope(path, bindingName) {
37826
+ let scope;
37827
+ try {
37828
+ scope = path.scope?.lookup?.(bindingName);
37829
+ } catch {
37830
+ return null;
37831
+ }
37832
+ return scope && typeof scope === "object" ? scope : null;
37833
+ }
37834
+ function isInBindingScope(path, bindingName, bindingScope) {
37835
+ return findBindingScope(path, bindingName) === bindingScope;
37836
+ }
37837
+ function addSxDestructure(ctx, propsBinding) {
37838
+ if (propsBinding.kind !== "destructured" || propsBinding.restLocal || hasObjectPatternProp(propsBinding.pattern, "sx")) return;
37839
+ const properties = [...propsBinding.pattern.properties ?? []];
37840
+ const restIndex = properties.findIndex(isObjectPatternRestElement);
37841
+ properties.splice(restIndex === -1 ? properties.length : restIndex, 0, ctx.patternProp("sx", ctx.j.identifier(propsBinding.sxLocal)));
37842
+ propsBinding.pattern.properties = properties;
37843
+ }
37844
+ function isObjectPatternRestElement(prop) {
37845
+ return prop?.type === "RestElement" || prop?.type === "RestProperty";
37846
+ }
37847
+ function getObjectPatternRestLocal(pattern) {
37848
+ const rest = (pattern.properties ?? []).find(isObjectPatternRestElement);
37849
+ return rest?.argument?.type === "Identifier" ? rest.argument.name : null;
37850
+ }
37851
+ function getJsxAttr(opening, attrName) {
37852
+ return (opening.attributes ?? []).find((attr) => attr?.type === "JSXAttribute" && attr.name?.name === attrName) ?? null;
37853
+ }
37854
+ function hasJsxAttr(opening, attrName) {
37855
+ return Boolean(getJsxAttr(opening, attrName));
37856
+ }
37857
+ function isForwardedClassNameAttr(attr, propsBinding) {
37858
+ const expr = attr.value?.type === "JSXExpressionContainer" ? attr.value.expression : null;
37859
+ if (!expr) return false;
37860
+ if (propsBinding.kind === "destructured") return expr.type === "Identifier" && expr.name === propsBinding.classNameLocal;
37861
+ return expr.type === "MemberExpression" && expr.object?.type === "Identifier" && expr.object.name === propsBinding.propsLocal && expr.property?.type === "Identifier" && expr.property.name === "className";
37862
+ }
37863
+ function getObjectPatternKeyName(prop) {
37864
+ if (prop?.type !== "Property" && prop?.type !== "ObjectProperty") return null;
37865
+ const key = prop.key;
37866
+ if (key?.type === "Identifier") return key.name;
37867
+ if (key?.type === "StringLiteral" || key?.type === "Literal") return typeof key.value === "string" ? key.value : null;
37868
+ return null;
37869
+ }
37870
+ function getObjectPatternValueName(prop) {
37871
+ if (!prop) return null;
37872
+ const value = prop.value;
37873
+ if (value?.type === "Identifier") return value.name;
37874
+ if (value?.type === "AssignmentPattern" && value.left?.type === "Identifier") return value.left.name;
37875
+ return null;
37876
+ }
37877
+ function hasObjectPatternProp(pattern, propName) {
37878
+ return (pattern.properties ?? []).some((prop) => getObjectPatternKeyName(prop) === propName);
37879
+ }
37880
+ function getExistingSxLocal(pattern) {
37881
+ return getObjectPatternValueName((pattern.properties ?? []).find((prop) => getObjectPatternKeyName(prop) === "sx")) ?? "sx";
37882
+ }
37883
+ function getAvailableSxLocalName(fn) {
37884
+ const usedNames = /* @__PURE__ */ new Set();
37885
+ for (const param of fn.params ?? []) {
37886
+ collectPatternBindingNames(param, usedNames);
37887
+ collectIdentifierNames(param, usedNames);
37888
+ }
37889
+ collectBindingNames(fn.body, usedNames);
37890
+ collectIdentifierNames(fn.body, usedNames);
37891
+ if (!usedNames.has("sx")) return "sx";
37892
+ if (!usedNames.has("sxProp")) return "sxProp";
37893
+ let suffix = 2;
37894
+ while (usedNames.has(`sxProp${suffix}`)) suffix++;
37895
+ return `sxProp${suffix}`;
37896
+ }
37897
+ function collectIdentifierNames(node, names, visited = /* @__PURE__ */ new WeakSet()) {
37898
+ if (!node || typeof node !== "object") return;
37899
+ if (visited.has(node)) return;
37900
+ visited.add(node);
37901
+ const astNode = node;
37902
+ if (astNode.type === "Identifier" && typeof astNode.name === "string") {
37903
+ names.add(astNode.name);
37904
+ return;
37905
+ }
37906
+ for (const value of Object.values(astNode)) {
37907
+ if (!value) continue;
37908
+ if (Array.isArray(value)) for (const item of value) collectIdentifierNames(item, names, visited);
37909
+ else if (typeof value === "object") collectIdentifierNames(value, names, visited);
37910
+ }
37911
+ }
37912
+ function collectBindingNames(node, names, visited = /* @__PURE__ */ new WeakSet()) {
37913
+ if (!node || typeof node !== "object") return;
37914
+ if (visited.has(node)) return;
37915
+ visited.add(node);
37916
+ const astNode = node;
37917
+ if (astNode.type === "Identifier" && typeof astNode.name === "string") return;
37918
+ if (typeof astNode.id === "object" && astNode.id !== null) collectPatternBindingNames(astNode.id, names);
37919
+ if (Array.isArray(astNode.params)) for (const param of astNode.params) collectPatternBindingNames(param, names);
37920
+ for (const value of Object.values(astNode)) {
37921
+ if (!value || value === astNode.id || value === astNode.params) continue;
37922
+ if (Array.isArray(value)) for (const item of value) collectBindingNames(item, names, visited);
37923
+ else if (typeof value === "object") collectBindingNames(value, names, visited);
37924
+ }
37925
+ }
37926
+ function collectPatternBindingNames(node, names) {
37927
+ if (!node || typeof node !== "object") return;
37928
+ const astNode = node;
37929
+ if (astNode.type === "Identifier" && typeof astNode.name === "string") {
37930
+ names.add(astNode.name);
37931
+ return;
37932
+ }
37933
+ if (astNode.type === "RestElement") {
37934
+ collectPatternBindingNames(astNode.argument, names);
37935
+ return;
37936
+ }
37937
+ if (astNode.type === "AssignmentPattern") {
37938
+ collectPatternBindingNames(astNode.left, names);
37939
+ return;
37940
+ }
37941
+ if (astNode.type === "ArrayPattern") {
37942
+ for (const element of astNode.elements ?? []) collectPatternBindingNames(element, names);
37943
+ return;
37944
+ }
37945
+ if (astNode.type === "ObjectPattern") for (const property of astNode.properties ?? []) {
37946
+ if (!property || typeof property !== "object") continue;
37947
+ const prop = property;
37948
+ if (prop.type === "RestElement") collectPatternBindingNames(prop.argument, names);
37949
+ else collectPatternBindingNames(prop.value, names);
37950
+ }
37951
+ }
37952
+ function cloneExpression(expression) {
37953
+ return JSON.parse(JSON.stringify(expression));
37954
+ }
37955
+ //#endregion
37193
37956
  //#region src/internal/transform-steps/reinsert-static-props.ts
37194
37957
  /**
37195
37958
  * Step: reinsert static property assignments after wrapper emission.
@@ -38301,6 +39064,7 @@ function transformWithWarnings(file, api, options) {
38301
39064
  rewriteJsxStep,
38302
39065
  emitWrappersStep,
38303
39066
  emitBridgeExportsStep,
39067
+ propagateSxFromClassNameStep,
38304
39068
  upgradePolymorphicAsPropTypesStep,
38305
39069
  ensureMergerImportStep,
38306
39070
  reinsertStaticPropsStep,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "styled-components-to-stylex-codemod",
3
- "version": "0.0.44",
3
+ "version": "0.0.45",
4
4
  "description": "Codemod to transform styled-components to StyleX",
5
5
  "keywords": [
6
6
  "codemod",