styled-components-to-stylex-codemod 0.0.38 → 0.0.39
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/{bridge-consumer-patcher-BzAIO9pC.mjs → bridge-consumer-patcher-31jI1854.mjs} +146 -1
- package/dist/{forwarded-as-consumer-patcher-Cs0X-olz.mjs → forwarded-as-consumer-patcher-BYCrqzRm.mjs} +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +5 -4
- package/dist/prop-usage-D6ZiDfzz.mjs +136 -0
- package/dist/{run-prepass-Us5SBTib.mjs → run-prepass-qEr_Mc3y.mjs} +172 -20
- package/dist/{string-utils-KggM5TNH.mjs → string-utils-DD9wdRHW.mjs} +16 -1
- package/dist/{transform-types--9qCqNSJ.d.mts → transform-types-DJpFQ5xm.d.mts} +16 -1
- package/dist/transform.d.mts +1 -1
- package/dist/transform.mjs +879 -346
- package/dist/{transient-prop-consumer-patcher-DLsKxg1R.mjs → transient-prop-consumer-patcher-DdIYPSFk.mjs} +1 -1
- package/package.json +4 -4
- package/dist/styled-css-BVR82jN5.mjs +0 -72
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as toRealPath } from "./path-utils-BIpoL4Ue.mjs";
|
|
2
|
-
import { r as escapeRegex } from "./string-utils-
|
|
2
|
+
import { r as escapeRegex } from "./string-utils-DD9wdRHW.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.
|
|
3
|
+
"version": "0.0.39",
|
|
4
4
|
"description": "Codemod to transform styled-components to StyleX",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemod",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"@codemirror/lang-javascript": "^6.2.5",
|
|
41
41
|
"@emotion/is-prop-valid": "^1.4.0",
|
|
42
42
|
"@storybook/react-vite": "^10.2.19",
|
|
43
|
-
"@stylexjs/babel-plugin": "^0.18.
|
|
43
|
+
"@stylexjs/babel-plugin": "^0.18.3",
|
|
44
44
|
"@stylexjs/eslint-plugin": "^0.18.1",
|
|
45
|
-
"@stylexjs/stylex": "^0.18.
|
|
46
|
-
"@stylexjs/unplugin": "^0.18.
|
|
45
|
+
"@stylexjs/stylex": "^0.18.3",
|
|
46
|
+
"@stylexjs/unplugin": "^0.18.3",
|
|
47
47
|
"@types/jscodeshift": "^17.3.0",
|
|
48
48
|
"@types/node": "^25.6.0",
|
|
49
49
|
"@types/react": "^19.2.14",
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { compile } from "stylis";
|
|
2
|
-
//#region src/internal/styled-css.ts
|
|
3
|
-
/** Matches `__SC_EXPR_N__` and captures the slot index in group 1. */
|
|
4
|
-
const PLACEHOLDER_RE = /__SC_EXPR_(\d+)__/;
|
|
5
|
-
function parseStyledTemplateLiteral(template) {
|
|
6
|
-
const parts = [];
|
|
7
|
-
const slots = [];
|
|
8
|
-
for (let i = 0; i < template.quasis.length; i++) {
|
|
9
|
-
const quasi = template.quasis[i];
|
|
10
|
-
parts.push(quasi.value.raw);
|
|
11
|
-
const expr = template.expressions[i];
|
|
12
|
-
if (!expr) continue;
|
|
13
|
-
const placeholder = makeInterpolationPlaceholder(i);
|
|
14
|
-
const startOffset = parts.join("").length;
|
|
15
|
-
parts.push(placeholder);
|
|
16
|
-
const endOffset = parts.join("").length;
|
|
17
|
-
slots.push({
|
|
18
|
-
index: i,
|
|
19
|
-
placeholder,
|
|
20
|
-
expression: expr,
|
|
21
|
-
startOffset,
|
|
22
|
-
endOffset
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
const rawCss = parts.join("");
|
|
26
|
-
return {
|
|
27
|
-
rawCss,
|
|
28
|
-
slots,
|
|
29
|
-
stylisAst: compile(terminateStandaloneInterpolationStatements(rawCss))
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function terminateStandaloneInterpolationStatements(css) {
|
|
33
|
-
let parenDepth = 0;
|
|
34
|
-
const lines = css.split(/(?<=\n)/);
|
|
35
|
-
const depthsBeforeLine = [];
|
|
36
|
-
for (const line of lines) {
|
|
37
|
-
depthsBeforeLine.push(parenDepth);
|
|
38
|
-
parenDepth = updateParenDepth(parenDepth, line);
|
|
39
|
-
}
|
|
40
|
-
return lines.map((line, index) => {
|
|
41
|
-
return depthsBeforeLine[index] === 0 && /^\s*__SC_EXPR_\d+__\s*$/.test(line) && isBeforeAtRule(lines, index) ? line.replace(/(\s*)$/, ";$1") : line;
|
|
42
|
-
}).join("");
|
|
43
|
-
}
|
|
44
|
-
function makeInterpolationPlaceholder(index) {
|
|
45
|
-
return `__SC_EXPR_${index}__`;
|
|
46
|
-
}
|
|
47
|
-
function isBeforeAtRule(lines, startIndex) {
|
|
48
|
-
for (let i = startIndex + 1; i < lines.length; i++) {
|
|
49
|
-
const trimmed = lines[i].trim();
|
|
50
|
-
if (!trimmed || /^__SC_EXPR_\d+__\s*;?$/.test(trimmed)) continue;
|
|
51
|
-
return trimmed.startsWith("@");
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
function updateParenDepth(startDepth, line) {
|
|
56
|
-
let depth = startDepth;
|
|
57
|
-
let inString = false;
|
|
58
|
-
for (let i = 0; i < line.length; i++) {
|
|
59
|
-
const ch = line[i];
|
|
60
|
-
if ((ch === "\"" || ch === "'") && line[i - 1] !== "\\") {
|
|
61
|
-
if (!inString) inString = ch;
|
|
62
|
-
else if (inString === ch) inString = false;
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
if (inString) continue;
|
|
66
|
-
if (ch === "(") depth++;
|
|
67
|
-
else if (ch === ")") depth = Math.max(0, depth - 1);
|
|
68
|
-
}
|
|
69
|
-
return depth;
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
|
-
export { parseStyledTemplateLiteral as n, terminateStandaloneInterpolationStatements as r, PLACEHOLDER_RE as t };
|