styled-components-to-stylex-codemod 0.0.49 → 0.0.51

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.
@@ -1,5 +1,5 @@
1
1
  import { r as toRealPath } from "./path-utils-BC4U8X_q.mjs";
2
- import { r as escapeRegex } from "./string-utils-DD9wdRHW.mjs";
2
+ import { r as escapeRegex } from "./string-utils-BYTEHwNg.mjs";
3
3
  import { basename, dirname, relative } from "node:path";
4
4
  import { readFileSync } from "node:fs";
5
5
  //#region src/internal/transient-prop-consumer-patcher.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "styled-components-to-stylex-codemod",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "description": "Codemod to transform styled-components to StyleX",
5
5
  "keywords": [
6
6
  "codemod",
@@ -1,79 +0,0 @@
1
- //#region src/internal/utilities/jsx-static-literal.ts
2
- function readStaticJsxLiteral(attr) {
3
- if (!isObjectRecord(attr) || attr.type !== "JSXAttribute") return;
4
- if (!("value" in attr) || attr.value == null) return true;
5
- const directLiteral = readLiteralNodeValue(attr.value);
6
- if (directLiteral !== void 0) return directLiteral;
7
- if (!isObjectRecord(attr.value) || attr.value.type !== "JSXExpressionContainer") return;
8
- return readLiteralNodeValue(attr.value.expression);
9
- }
10
- function readLiteralNodeValue(node) {
11
- if (!isObjectRecord(node)) return;
12
- if (node.type === "StringLiteral" || node.type === "NumericLiteral" || node.type === "BooleanLiteral") return isStaticLiteral(node.value) ? node.value : void 0;
13
- if (node.type === "Literal") return isStaticLiteral(node.value) ? node.value : void 0;
14
- if (node.type === "UnaryExpression" && node.operator === "-") {
15
- const value = readLiteralNodeValue(node.argument);
16
- return typeof value === "number" ? -value : void 0;
17
- }
18
- }
19
- function isObjectRecord(value) {
20
- return typeof value === "object" && value !== null;
21
- }
22
- function isStaticLiteral(value) {
23
- return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
24
- }
25
- //#endregion
26
- //#region src/internal/utilities/prop-usage.ts
27
- const KNOWN_NON_ELEMENT_PROPS = new Set([
28
- "className",
29
- "style",
30
- "as",
31
- "ref",
32
- "forwardedAs",
33
- "key",
34
- "children"
35
- ]);
36
- function createComponentPropUsageInfo(name) {
37
- return {
38
- componentName: name,
39
- usageCount: 0,
40
- hasUnknownUsage: false,
41
- props: {}
42
- };
43
- }
44
- function mergeComponentPropUsage(info, usage) {
45
- info.usageCount += 1;
46
- if (usage.hasSpread) info.hasUnknownUsage = true;
47
- const presentProps = new Set(Object.keys(usage.props));
48
- for (const [propName, propInfo] of Object.entries(info.props)) if (!presentProps.has(propName)) propInfo.omittedCount += 1;
49
- for (const [propName, value] of Object.entries(usage.props)) {
50
- const propInfo = info.props[propName] ?? (info.props[propName] = {
51
- values: [],
52
- hasUnknown: false,
53
- usageCount: 0,
54
- omittedCount: info.usageCount - 1
55
- });
56
- propInfo.usageCount += 1;
57
- if (value.kind === "unknown") {
58
- propInfo.hasUnknown = true;
59
- continue;
60
- }
61
- if (!propInfo.values.some((existing) => existing === value.value)) propInfo.values.push(value.value);
62
- }
63
- }
64
- /**
65
- * Formats a `prop === value` JS condition for an observed static variant bucket,
66
- * quoting strings and emitting numbers bare. Shared by every observed-variant emitter.
67
- */
68
- function formatObservedVariantCondition(propName, value) {
69
- return `${propName} === ${typeof value === "number" ? String(value) : JSON.stringify(value)}`;
70
- }
71
- function getExhaustiveObservedStaticValues(info, propName) {
72
- const propUsage = info?.props[propName];
73
- if (!info || info.hasUnknownUsage || !propUsage || propUsage.hasUnknown) return null;
74
- if (propUsage.values.length < 1) return null;
75
- const values = propUsage.values.filter((value) => typeof value === "string" || typeof value === "number");
76
- return values.length === propUsage.values.length ? values : null;
77
- }
78
- //#endregion
79
- export { mergeComponentPropUsage as a, getExhaustiveObservedStaticValues as i, createComponentPropUsageInfo as n, readStaticJsxLiteral as o, formatObservedVariantCondition as r, KNOWN_NON_ELEMENT_PROPS as t };