Skip to content

Commit 02ca084

Browse files
authored
refactor: upgrade to csstree v3 (#5455)
The new version is aware of modern colors and other new css features.
1 parent 1662637 commit 02ca084

File tree

24 files changed

+1044
-326
lines changed

24 files changed

+1044
-326
lines changed

@types/css-tree.d.ts

Lines changed: 772 additions & 0 deletions
Large diffs are not rendered by default.

apps/builder/app/shared/style-object-model.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { generate, walk } from "css-tree";
1+
import { generate, walk, List, type CssNode } from "css-tree";
22
import type { HtmlTags } from "html-tags";
33
import {
44
camelCaseProperty,
@@ -294,13 +294,14 @@ const substituteVars = (
294294
enter(node, item, list) {
295295
if (node.type === "Function" && node.name === "var") {
296296
const varValue = parseCssVar(node);
297-
if (varValue) {
297+
if (varValue && item) {
298298
const newValue = mapper(varValue);
299-
list.replace(
299+
list?.replace(
300300
item,
301-
node.children.createItem({
301+
List.createItem<CssNode>({
302302
type: "Raw",
303303
value: toValue(newValue),
304+
loc: null,
304305
})
305306
);
306307
}

apps/builder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"change-case": "^5.4.4",
8989
"colord": "^2.9.3",
9090
"cookie": "^1.0.1",
91-
"css-tree": "^2.3.1",
91+
"css-tree": "^3.1.0",
9292
"debug": "^4.3.7",
9393
"downshift": "^6.1.7",
9494
"entrijs": "^0.0.11",

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"@storybook/addon-controls": "^8.6.4",
3737
"@storybook/react": "^8.6.4",
3838
"@storybook/react-vite": "^8.6.4",
39-
"@types/css-tree": "^2.3.1",
4039
"@types/node": "^22.13.10",
4140
"@types/react": "^18.2.70",
4241
"esbuild": "^0.25.3",
@@ -85,8 +84,6 @@
8584
},
8685
"patchedDependencies": {
8786
"@stitches/[email protected]": "patches/@[email protected]",
88-
89-
"@types/[email protected]": "patches/@[email protected]",
9087
"@radix-ui/[email protected]": "patches/@[email protected]",
9188
"@remix-run/dev": "patches/@remix-run__dev.patch"
9289
}

packages/css-data/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"css-to-ws": "./bin/css-to-ws.ts"
1717
},
1818
"devDependencies": {
19-
"@types/css-tree": "^2.3.1",
2019
"@webstudio-is/tsconfig": "workspace:*",
2120
"html-tags": "^4.0.0",
2221
"mdn-data": "2.23.0",
@@ -36,7 +35,7 @@
3635
"@webstudio-is/css-engine": "workspace:*",
3736
"change-case": "^5.4.4",
3837
"colord": "^2.9.3",
39-
"css-tree": "^2.3.1",
38+
"css-tree": "^3.1.0",
4039
"openai": "^3.2.1",
4140
"p-retry": "^6.2.1",
4241
"warn-once": "^0.1.1"

packages/css-data/src/parse-css-value.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ export const parseCssVar = (node: FunctionNode): undefined | VarValue => {
219219
const [name, _comma, ...fallback] = node.children;
220220
const fallbackString = generate({
221221
type: "Value",
222+
loc: null,
222223
children: new List<CssNode>().fromArray(fallback),
223224
}).trim();
224225
if (name.type === "Identifier") {
@@ -380,7 +381,7 @@ const parseLiteral = (
380381
type: "function",
381382
args: parseShadow(
382383
node.children.toArray(),
383-
generate({ type: "Value", children: node.children })
384+
generate({ type: "Value", loc: null, children: node.children })
384385
),
385386
name: node.name,
386387
};
@@ -469,6 +470,7 @@ export const parseCssValue = (
469470
value: splitRepeated(nodes).map((nodes) => {
470471
const value = generate({
471472
type: "Value",
473+
loc: null,
472474
children: new List<CssNode>().fromArray(nodes),
473475
});
474476
const parsed = parseCssValue(property, value, false) as LayerValueItem;
@@ -506,6 +508,7 @@ export const parseCssValue = (
506508
}
507509
return generate({
508510
type: "Value",
511+
loc: null,
509512
children: new List<CssNode>().fromArray(nodes),
510513
});
511514
}),

0 commit comments

Comments
 (0)