@projectwallace/css-parser 0.13.8 → 0.13.10
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/arena-BtlVZlkG.d.ts +105 -0
- package/dist/arena-CDAx4eAB.js +220 -0
- package/dist/constants.d.ts +47 -0
- package/dist/constants.js +46 -0
- package/dist/{css-node-DqyvMXBN.d.ts → css-node-B9tSb6YD.d.ts} +3 -105
- package/dist/{css-node-Uj4oBgaw.js → css-node-CZf-PvCf.js} +2 -220
- package/dist/index.d.ts +5 -77
- package/dist/index.js +5 -96
- package/dist/parse-anplusb.d.ts +2 -1
- package/dist/parse-anplusb.js +3 -2
- package/dist/parse-atrule-prelude.d.ts +2 -1
- package/dist/parse-atrule-prelude.js +4 -3
- package/dist/parse-declaration.d.ts +3 -2
- package/dist/parse-declaration.js +11 -6
- package/dist/parse-selector.d.ts +2 -1
- package/dist/parse-selector.js +5 -3
- package/dist/parse-value.d.ts +2 -1
- package/dist/parse-value.js +3 -2
- package/dist/parse.d.ts +3 -2
- package/dist/parse.js +4 -3
- package/dist/{tokenize-BQFB1jXg.js → tokenize-BSycRGm0.js} +11 -8
- package/dist/tokenize.d.ts +1 -1
- package/dist/tokenize.js +1 -1
- package/dist/walk.d.ts +34 -0
- package/dist/walk.js +53 -0
- package/package.json +13 -3
- /package/dist/{parse-utils-DnsZRpfd.js → parse-utils-BxrmqJxI.js} +0 -0
- /package/dist/{tokenize-odLrcjj2.d.ts → tokenize-CyiJelQC.d.ts} +0 -0
package/dist/tokenize.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as tokenize, t as Lexer } from "./tokenize-
|
|
1
|
+
import { n as tokenize, t as Lexer } from "./tokenize-BSycRGm0.js";
|
|
2
2
|
export { Lexer, tokenize };
|
package/dist/walk.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { r as CSSNode } from "./css-node-B9tSb6YD.js";
|
|
2
|
+
|
|
3
|
+
//#region src/walk.d.ts
|
|
4
|
+
declare const SKIP: unique symbol;
|
|
5
|
+
declare const BREAK: unique symbol;
|
|
6
|
+
type WalkCallback = (node: CSSNode, depth: number) => void | typeof SKIP | typeof BREAK;
|
|
7
|
+
/**
|
|
8
|
+
* Walk the AST in depth-first order, calling the callback for each node.
|
|
9
|
+
* Return SKIP to skip children, BREAK to stop traversal. See API.md for examples.
|
|
10
|
+
*
|
|
11
|
+
* @param node - The root node to start walking from
|
|
12
|
+
* @param callback - Function called for each node. Receives the node and its nesting depth.
|
|
13
|
+
* Depth increments only for STYLE_RULE and AT_RULE nodes (tracks rule nesting, not tree depth).
|
|
14
|
+
* @param depth - Starting depth (default: 0)
|
|
15
|
+
*/
|
|
16
|
+
declare function walk(node: CSSNode, callback: WalkCallback, depth?: number): boolean;
|
|
17
|
+
type WalkEnterLeaveCallback = (node: CSSNode) => void | typeof SKIP | typeof BREAK;
|
|
18
|
+
interface WalkEnterLeaveOptions {
|
|
19
|
+
enter?: WalkEnterLeaveCallback;
|
|
20
|
+
leave?: WalkEnterLeaveCallback;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Walk the AST in depth-first order, calling enter before visiting children and leave after.
|
|
24
|
+
* Return SKIP in enter to skip children (leave still called), BREAK to stop (leave NOT called). See API.md for examples.
|
|
25
|
+
*
|
|
26
|
+
* @param node - The root node to start walking from
|
|
27
|
+
* @param options - Object with optional enter and leave callback functions
|
|
28
|
+
*/
|
|
29
|
+
declare function traverse(node: CSSNode, {
|
|
30
|
+
enter,
|
|
31
|
+
leave
|
|
32
|
+
}?: WalkEnterLeaveOptions): boolean;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { BREAK, SKIP, traverse, walk };
|
package/dist/walk.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import "./arena-CDAx4eAB.js";
|
|
2
|
+
import "./constants.js";
|
|
3
|
+
//#region src/walk.ts
|
|
4
|
+
const SKIP = Symbol("SKIP");
|
|
5
|
+
const BREAK = Symbol("BREAK");
|
|
6
|
+
/**
|
|
7
|
+
* Walk the AST in depth-first order, calling the callback for each node.
|
|
8
|
+
* Return SKIP to skip children, BREAK to stop traversal. See API.md for examples.
|
|
9
|
+
*
|
|
10
|
+
* @param node - The root node to start walking from
|
|
11
|
+
* @param callback - Function called for each node. Receives the node and its nesting depth.
|
|
12
|
+
* Depth increments only for STYLE_RULE and AT_RULE nodes (tracks rule nesting, not tree depth).
|
|
13
|
+
* @param depth - Starting depth (default: 0)
|
|
14
|
+
*/
|
|
15
|
+
function walk(node, callback, depth = 0) {
|
|
16
|
+
const result = callback(node, depth);
|
|
17
|
+
if (result === BREAK) return false;
|
|
18
|
+
if (result === SKIP) return true;
|
|
19
|
+
let child_depth = depth;
|
|
20
|
+
if (node.type === 2 || node.type === 3) child_depth = depth + 1;
|
|
21
|
+
let child = node.first_child;
|
|
22
|
+
while (child) {
|
|
23
|
+
if (!walk(child, callback, child_depth)) return false;
|
|
24
|
+
child = child.next_sibling;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
const NOOP = function() {};
|
|
29
|
+
/**
|
|
30
|
+
* Walk the AST in depth-first order, calling enter before visiting children and leave after.
|
|
31
|
+
* Return SKIP in enter to skip children (leave still called), BREAK to stop (leave NOT called). See API.md for examples.
|
|
32
|
+
*
|
|
33
|
+
* @param node - The root node to start walking from
|
|
34
|
+
* @param options - Object with optional enter and leave callback functions
|
|
35
|
+
*/
|
|
36
|
+
function traverse(node, { enter = NOOP, leave = NOOP } = {}) {
|
|
37
|
+
const enter_result = enter(node);
|
|
38
|
+
if (enter_result === BREAK) return false;
|
|
39
|
+
if (enter_result !== SKIP) {
|
|
40
|
+
let child = node.first_child;
|
|
41
|
+
while (child) {
|
|
42
|
+
if (!traverse(child, {
|
|
43
|
+
enter,
|
|
44
|
+
leave
|
|
45
|
+
})) return false;
|
|
46
|
+
child = child.next_sibling;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (leave(node) === BREAK) return false;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { BREAK, SKIP, traverse, walk };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@projectwallace/css-parser",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.10",
|
|
4
4
|
"description": "High-performance CSS lexer and parser, optimized for CSS inspection and analysis",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast",
|
|
@@ -60,6 +60,14 @@
|
|
|
60
60
|
"./parse-dimension": {
|
|
61
61
|
"types": "./dist/parse-dimension.d.ts",
|
|
62
62
|
"import": "./dist/parse-dimension.js"
|
|
63
|
+
},
|
|
64
|
+
"./walker": {
|
|
65
|
+
"types": "./dist/walk.d.ts",
|
|
66
|
+
"import": "./dist/walk.js"
|
|
67
|
+
},
|
|
68
|
+
"./nodes": {
|
|
69
|
+
"types": "./dist/constants.d.ts",
|
|
70
|
+
"import": "./dist/constants.js"
|
|
63
71
|
}
|
|
64
72
|
},
|
|
65
73
|
"scripts": {
|
|
@@ -71,6 +79,7 @@
|
|
|
71
79
|
"benchmark:memory": "npm run build && node --expose-gc benchmark/memory.ts",
|
|
72
80
|
"lint": "oxlint --config .oxlintrc.json && oxfmt --check",
|
|
73
81
|
"check": "tsc --noEmit",
|
|
82
|
+
"knip": "knip",
|
|
74
83
|
"precommit": "npm run test -- --run; npm run lint; npm run check"
|
|
75
84
|
},
|
|
76
85
|
"devDependencies": {
|
|
@@ -80,12 +89,13 @@
|
|
|
80
89
|
"@vitest/coverage-v8": "^4.0.8",
|
|
81
90
|
"bootstrap": "^5.3.8",
|
|
82
91
|
"css-tree": "^3.1.0",
|
|
83
|
-
"
|
|
92
|
+
"knip": "^6.0.1",
|
|
93
|
+
"oxfmt": "^0.41.0",
|
|
84
94
|
"oxlint": "^1.28.0",
|
|
85
95
|
"postcss": "^8.5.6",
|
|
86
96
|
"publint": "^0.3.18",
|
|
87
97
|
"tailwindcss": "^2.2.8",
|
|
88
|
-
"tinybench": "^
|
|
98
|
+
"tinybench": "^6.0.0",
|
|
89
99
|
"tsdown": "^0.21.0",
|
|
90
100
|
"typescript": "^5.9.3",
|
|
91
101
|
"vitest": "^4.0.8"
|
|
File without changes
|
|
File without changes
|