styled-components-to-stylex-codemod 0.0.35 → 0.0.36

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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { o as assertValidAdapterInput, r as defineAdapter, s as describeValue, t as mergeMarkerDeclarations } from "./merge-markers-Bp-ELxFV.mjs";
1
+ import { o as assertValidAdapterInput, r as defineAdapter, s as describeValue, t as mergeMarkerDeclarations } from "./merge-markers-B4EyveCx.mjs";
2
2
  import { t as Logger } from "./logger-fIHHMZYO.mjs";
3
3
  import { run } from "jscodeshift/src/Runner.js";
4
4
  import { fileURLToPath } from "node:url";
@@ -107,10 +107,7 @@ function assertAdapterShape(candidate, where, allowAutoExtIf) {
107
107
  "",
108
108
  `Docs/examples: ${ADAPTER_DOCS_URL}`
109
109
  ].join("\n"));
110
- if (!(typeof externalInterface === "function" || allowAutoExtIf && externalInterface === "auto")) {
111
- const expected = allowAutoExtIf ? "adapter.externalInterface must be a function or \"auto\"." : "adapter.externalInterface must be a function.";
112
- throw new Error([`${where}: ${expected}`, `Received: externalInterface=${describeValue(externalInterface)}`].join("\n"));
113
- }
110
+ if (!(typeof externalInterface === "function" || allowAutoExtIf && externalInterface === "auto")) throw new Error([`${where}: ${allowAutoExtIf ? "adapter.externalInterface must be a function or \"auto\"." : "adapter.externalInterface must be a function."}`, `Received: externalInterface=${describeValue(externalInterface)}`].join("\n"));
114
111
  const styleMerger = obj?.styleMerger;
115
112
  if (styleMerger !== null && styleMerger !== void 0) {
116
113
  if (typeof styleMerger !== "object") throw new Error([
@@ -1,6 +1,5 @@
1
1
  import { n as WarningLog, r as Adapter } from "./logger-BoGU2nCP.mjs";
2
2
  import { API, FileInfo, Options } from "jscodeshift";
3
-
4
3
  //#region src/internal/transform-types.d.ts
5
4
  /** A sidecar .stylex.ts file containing defineMarker() declarations. */
6
5
  interface SidecarFile {
@@ -1,5 +1,5 @@
1
1
  import { t as createModuleResolver } from "./resolve-imports-BlxKezSJ.mjs";
2
- import { a as assertValidAdapter, i as isDirectionalResult, n as DEFAULT_THEME_HOOK, t as mergeMarkerDeclarations } from "./merge-markers-Bp-ELxFV.mjs";
2
+ import { a as assertValidAdapter, i as isDirectionalResult, n as DEFAULT_THEME_HOOK, t as mergeMarkerDeclarations } from "./merge-markers-B4EyveCx.mjs";
3
3
  import { t as Logger } from "./logger-fIHHMZYO.mjs";
4
4
  import { a as isPrettierIgnoreComment, c as looksLikeLength, d as sanitizeIdentifier, i as isBackgroundImageValue, l as lowerFirst, n as capitalize, o as isValidIdentifierName, r as escapeRegex, s as kebabToCamelCase, t as camelToKebabCase, u as normalizeWhitespace } from "./string-utils-Bq7DbB2x.mjs";
5
5
  import { n as parseStyledTemplateLiteral, t as PLACEHOLDER_RE } from "./styled-css-Bu2bjAUW.mjs";
@@ -1366,20 +1366,50 @@ function rewriteCssVarsInAstNodeRoot(args) {
1366
1366
  }
1367
1367
  function rewriteCssVarsInStyleObjectImpl(obj, ctx) {
1368
1368
  for (const [k, v] of Object.entries(obj)) {
1369
- if (v && typeof v === "object") {
1370
- if (isAstNode(v)) {
1371
- const replacement = rewriteCssVarsInAstNodeAndMaybeSimplify(v, ctx);
1372
- if (replacement) obj[k] = replacement;
1369
+ if (k.startsWith("--")) {
1370
+ const rewrittenValue = rewriteCssVarsInStyleObjectValue(v, ctx);
1371
+ const result = ctx.resolveValue({
1372
+ kind: "cssVariable",
1373
+ name: k,
1374
+ filePath: ctx.filePath,
1375
+ ...typeof v === "string" ? { definedValue: v } : {}
1376
+ });
1377
+ if (!result) {
1378
+ obj[k] = rewrittenValue;
1379
+ continue;
1380
+ }
1381
+ delete obj[k];
1382
+ if (result.dropDefinition) continue;
1383
+ const keyExpr = ctx.parseExpr(result.expr);
1384
+ if (!keyExpr) {
1385
+ obj[k] = rewrittenValue;
1373
1386
  continue;
1374
1387
  }
1375
- rewriteCssVarsInStyleObjectImpl(v, ctx);
1388
+ for (const imp of result.imports ?? []) ctx.addImport(imp);
1389
+ const computedKeys = Array.isArray(obj.__computedKeys) ? obj.__computedKeys : [];
1390
+ computedKeys.push({
1391
+ keyExpr,
1392
+ value: rewrittenValue,
1393
+ prepend: true,
1394
+ originalCssVariableName: k
1395
+ });
1396
+ obj.__computedKeys = computedKeys;
1376
1397
  continue;
1377
1398
  }
1378
- if (typeof v === "string") obj[k] = rewriteCssVarsInString({
1379
- raw: v,
1380
- ...ctx
1381
- });
1399
+ obj[k] = rewriteCssVarsInStyleObjectValue(v, ctx);
1400
+ }
1401
+ }
1402
+ function rewriteCssVarsInStyleObjectValue(value, ctx) {
1403
+ if (value && typeof value === "object") {
1404
+ if (isAstNode(value)) return rewriteCssVarsInAstNodeAndMaybeSimplify(value, ctx) ?? value;
1405
+ rewriteCssVarsInStyleObjectImpl(value, ctx);
1406
+ return value;
1382
1407
  }
1408
+ if (typeof value === "string") return rewriteCssVarsInString({
1409
+ raw: value,
1410
+ ...ctx
1411
+ });
1412
+ return value;
1383
1413
  }
1384
1414
  /**
1385
1415
  * Walks an AST node (e.g. TemplateLiteral, ArrowFunctionExpression) to find `var(...)`
@@ -6826,6 +6856,11 @@ function objectToAst(j, obj) {
6826
6856
  const computedKeys = Array.isArray(computedKeysRaw) ? computedKeysRaw : [];
6827
6857
  const props = [];
6828
6858
  for (const s of spreads) props.push(j.spreadElement(j.identifier(s)));
6859
+ for (const entry of computedKeys) {
6860
+ if (!entry.prepend) continue;
6861
+ const prop = computedKeyEntryToProp(j, entry);
6862
+ if (prop) props.push(prop);
6863
+ }
6829
6864
  for (const [key, value] of Object.entries(obj)) {
6830
6865
  if (key === "__spreads") continue;
6831
6866
  if (key === "__propComments") continue;
@@ -6858,20 +6893,25 @@ function objectToAst(j, obj) {
6858
6893
  props.push(prop);
6859
6894
  }
6860
6895
  for (const entry of computedKeys) {
6861
- if (!entry.keyExpr || !isAstNode(entry.keyExpr)) continue;
6862
- const valueAst = entry.value && typeof entry.value === "object" && !isAstNode(entry.value) ? objectToAst(j, entry.value) : literalToAst(j, entry.value);
6863
- const prop = j.property("init", entry.keyExpr, valueAst);
6864
- prop.computed = true;
6865
- if (entry.leadingComment) prop.comments = [{
6866
- type: "CommentLine",
6867
- value: ` ${entry.leadingComment}`,
6868
- leading: true,
6869
- trailing: false
6870
- }];
6871
- props.push(prop);
6896
+ if (entry.prepend) continue;
6897
+ const prop = computedKeyEntryToProp(j, entry);
6898
+ if (prop) props.push(prop);
6872
6899
  }
6873
6900
  return j.objectExpression(props);
6874
6901
  }
6902
+ function computedKeyEntryToProp(j, entry) {
6903
+ if (!entry.keyExpr || !isAstNode(entry.keyExpr)) return null;
6904
+ const valueAst = entry.value && typeof entry.value === "object" && !isAstNode(entry.value) ? objectToAst(j, entry.value) : literalToAst(j, entry.value);
6905
+ const prop = j.property("init", entry.keyExpr, valueAst);
6906
+ prop.computed = true;
6907
+ if (entry.leadingComment) prop.comments = [{
6908
+ type: "CommentLine",
6909
+ value: ` ${entry.leadingComment}`,
6910
+ leading: true,
6911
+ trailing: false
6912
+ }];
6913
+ return prop;
6914
+ }
6875
6915
  function literalToAst(j, value) {
6876
6916
  if (isAstNode(value)) return value;
6877
6917
  if (value === null) return j.literal(null);
@@ -23182,7 +23222,7 @@ function finalizeDeclProcessing(ctx) {
23182
23222
  ];
23183
23223
  for (const bucket of bucketsForVarRewrite) rewriteCssVarsInStyleObject(bucket, localVarValues, varsToDrop);
23184
23224
  for (const fnAst of styleFnDecls.values()) if (fnAst && typeof fnAst === "object" && isAstNode(fnAst)) rewriteCssVarsInAstNode(fnAst, localVarValues, varsToDrop);
23185
- for (const name of varsToDrop) for (const bucket of bucketsForVarRewrite) delete bucket[name];
23225
+ for (const name of varsToDrop) for (const bucket of bucketsForVarRewrite) dropCssVariableDefinitionsFromBucket(bucket, name);
23186
23226
  const hasPseudoBlockInterpolation = (() => {
23187
23227
  if (!decl.rawCss) return false;
23188
23228
  const pseudoBlockRe = /&:[a-z-]+(?:\([^)]*\))?\s*\{([^}]*)\}/gi;
@@ -23431,6 +23471,31 @@ function finalizeDeclProcessing(ctx) {
23431
23471
  if (styleFnDecls.has(decl.styleKey) && Object.keys(styleObj).length === 0) decl.skipBaseStyleRef = true;
23432
23472
  if (inlineStyleProps.length) decl.inlineStyleProps = inlineStyleProps;
23433
23473
  }
23474
+ function dropCssVariableDefinitionsFromBucket(bucket, name) {
23475
+ delete bucket[name];
23476
+ const computedKeys = bucket.__computedKeys;
23477
+ if (Array.isArray(computedKeys)) {
23478
+ const retained = computedKeys.filter((entry) => {
23479
+ return readComputedEntryCssVariableName(entry) !== name;
23480
+ });
23481
+ if (retained.length === 0) delete bucket.__computedKeys;
23482
+ else if (retained.length !== computedKeys.length) bucket.__computedKeys = retained;
23483
+ }
23484
+ for (const [key, value] of Object.entries(bucket)) {
23485
+ if (key.startsWith("__")) continue;
23486
+ if (!isStyleObjectForCssVarDrop(value)) continue;
23487
+ dropCssVariableDefinitionsFromBucket(value, name);
23488
+ }
23489
+ }
23490
+ function readComputedEntryCssVariableName(entry) {
23491
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) return null;
23492
+ if (!("originalCssVariableName" in entry)) return null;
23493
+ const cssVariableName = entry.originalCssVariableName;
23494
+ return typeof cssVariableName === "string" ? cssVariableName : null;
23495
+ }
23496
+ function isStyleObjectForCssVarDrop(value) {
23497
+ return Boolean(value && typeof value === "object" && !Array.isArray(value) && !isAstNode(value));
23498
+ }
23434
23499
  /**
23435
23500
  * Inserts styleFnDecls entries into resolvedStyleObjects right after the last
23436
23501
  * entry belonging to the current component. This ensures dynamic style functions
@@ -29495,7 +29560,18 @@ function createLowerRulesState(ctx) {
29495
29560
  enumValueMap,
29496
29561
  crossFileSelectorsByLocal,
29497
29562
  inlineKeyframeNameMap: void 0,
29563
+ /**
29564
+ * File-level bail flag. Used only for bails that cannot be scoped to a single
29565
+ * declaration (e.g. invariant violations before per-decl processing begins).
29566
+ * Per-decl bails set `currentDecl.skipTransform = true` instead so the file
29567
+ * can still be partially transformed.
29568
+ */
29498
29569
  bail: false,
29570
+ /**
29571
+ * Set at the start of each decl's processing loop iteration. When a handler
29572
+ * calls markBail/bailUnsupported, this is the decl that gets marked skipped.
29573
+ * When null, markBail falls back to the file-level bail flag.
29574
+ */
29499
29575
  currentDecl: null,
29500
29576
  markBail: () => {
29501
29577
  if (state.currentDecl) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "styled-components-to-stylex-codemod",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "description": "Codemod to transform styled-components to StyleX",
5
5
  "keywords": [
6
6
  "codemod",