@projectwallace/css-parser 0.15.0 → 0.16.1

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/walk.js CHANGED
@@ -1,4 +1,5 @@
1
- import "./arena-DnV0a_Ne.js";
1
+ import "./arena-CCye9VYE.js";
2
+ import { t as CSSNode } from "./css-node-CuLhABl8.js";
2
3
  import "./constants.js";
3
4
  //#region src/walk.ts
4
5
  const SKIP = Symbol("SKIP");
@@ -16,12 +17,29 @@ function walk(node, callback, depth = 0) {
16
17
  const result = callback(node, depth);
17
18
  if (result === BREAK) return false;
18
19
  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;
20
+ const impl = node;
21
+ const arena = impl.__get_arena();
22
+ const source = impl.__get_source();
23
+ const index = impl.__get_index();
24
+ const type = arena.get_type(index);
25
+ const child_depth = type === 2 || type === 3 ? depth + 1 : depth;
26
+ let child = arena.get_first_child(index);
27
+ while (child !== 0) {
28
+ if (!_walk(arena, source, child, callback, child_depth)) return false;
29
+ child = arena.get_next_sibling(child);
30
+ }
31
+ return true;
32
+ }
33
+ function _walk(arena, source, index, callback, depth) {
34
+ const result = callback(new CSSNode(arena, source, index), depth);
35
+ if (result === BREAK) return false;
36
+ if (result === SKIP) return true;
37
+ const type = arena.get_type(index);
38
+ const child_depth = type === 2 || type === 3 ? depth + 1 : depth;
39
+ let child = arena.get_first_child(index);
40
+ while (child !== 0) {
41
+ if (!_walk(arena, source, child, callback, child_depth)) return false;
42
+ child = arena.get_next_sibling(child);
25
43
  }
26
44
  return true;
27
45
  }
@@ -37,13 +55,28 @@ function traverse(node, { enter = NOOP, leave = NOOP } = {}) {
37
55
  const enter_result = enter(node);
38
56
  if (enter_result === BREAK) return false;
39
57
  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;
58
+ const impl = node;
59
+ const arena = impl.__get_arena();
60
+ const source = impl.__get_source();
61
+ const index = impl.__get_index();
62
+ let child = arena.get_first_child(index);
63
+ while (child !== 0) {
64
+ if (!_traverse(arena, source, child, enter, leave)) return false;
65
+ child = arena.get_next_sibling(child);
66
+ }
67
+ }
68
+ if (leave(node) === BREAK) return false;
69
+ return true;
70
+ }
71
+ function _traverse(arena, source, index, enter, leave) {
72
+ const node = new CSSNode(arena, source, index);
73
+ const enter_result = enter(node);
74
+ if (enter_result === BREAK) return false;
75
+ if (enter_result !== SKIP) {
76
+ let child = arena.get_first_child(index);
77
+ while (child !== 0) {
78
+ if (!_traverse(arena, source, child, enter, leave)) return false;
79
+ child = arena.get_next_sibling(child);
47
80
  }
48
81
  }
49
82
  if (leave(node) === BREAK) return false;
package/package.json CHANGED
@@ -1,104 +1,110 @@
1
1
  {
2
- "name": "@projectwallace/css-parser",
3
- "version": "0.15.0",
4
- "description": "High-performance CSS lexer and parser, optimized for CSS inspection and analysis",
5
- "keywords": [
6
- "ast",
7
- "css",
8
- "lexer",
9
- "parser",
10
- "tokenizer"
11
- ],
12
- "homepage": "https://github.com/projectwallace/css-parser",
13
- "license": "MIT",
14
- "author": "Bart Veneman <bart@projectwallace.com>",
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/projectwallace/css-parser.git"
18
- },
19
- "files": [
20
- "dist"
21
- ],
22
- "type": "module",
23
- "main": "./dist/index.js",
24
- "module": "./dist/index.js",
25
- "types": "./dist/index.d.ts",
26
- "exports": {
27
- ".": {
28
- "types": "./dist/index.d.ts",
29
- "import": "./dist/index.js"
30
- },
31
- "./package.json": "./package.json",
32
- "./tokenizer": {
33
- "types": "./dist/tokenize.d.ts",
34
- "import": "./dist/tokenize.js"
35
- },
36
- "./parse": {
37
- "types": "./dist/parse.d.ts",
38
- "import": "./dist/parse.js"
39
- },
40
- "./parse-selector": {
41
- "types": "./dist/parse-selector.d.ts",
42
- "import": "./dist/parse-selector.js"
43
- },
44
- "./parse-atrule-prelude": {
45
- "types": "./dist/parse-atrule-prelude.d.ts",
46
- "import": "./dist/parse-atrule-prelude.js"
47
- },
48
- "./parse-declaration": {
49
- "types": "./dist/parse-declaration.d.ts",
50
- "import": "./dist/parse-declaration.js"
51
- },
52
- "./parse-value": {
53
- "types": "./dist/parse-value.d.ts",
54
- "import": "./dist/parse-value.js"
55
- },
56
- "./parse-anplusb": {
57
- "types": "./dist/parse-anplusb.d.ts",
58
- "import": "./dist/parse-anplusb.js"
59
- },
60
- "./parse-dimension": {
61
- "types": "./dist/parse-dimension.d.ts",
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"
71
- }
72
- },
73
- "scripts": {
74
- "test": "vitest",
75
- "test-coverage": "vitest --coverage",
76
- "test-build": "npm run build && vitest run --config vitest.config.build.ts",
77
- "build": "tsdown",
78
- "benchmark": "npm run build && node benchmark/index.ts",
79
- "benchmark:memory": "npm run build && node --expose-gc benchmark/memory.ts",
80
- "lint": "oxlint --config .oxlintrc.json && oxfmt --check",
81
- "check": "tsc --noEmit",
82
- "knip": "knip",
83
- "precommit": "npm run test -- --run; npm run lint; npm run check"
84
- },
85
- "devDependencies": {
86
- "@codecov/rollup-plugin": "^2.0.1",
87
- "@projectwallace/preset-oxlint": "^0.0.10",
88
- "@types/node": "^24.10.1",
89
- "@vitest/coverage-v8": "^4.1.5",
90
- "bootstrap": "^5.3.8",
91
- "css-tree": "^3.1.0",
92
- "knip": "^6.11.0",
93
- "oxfmt": "^0.47.0",
94
- "oxlint": "^1.62.0",
95
- "postcss": "^8.5.6",
96
- "publint": "^0.3.18",
97
- "tailwindcss": "^2.2.8",
98
- "tinybench": "^6.0.1",
99
- "tsdown": "^0.21.0",
100
- "typescript": "^6.0.3",
101
- "vitest": "^4.1.5"
102
- },
103
- "issues": "https://github.com/projectwallace/css-parser/issues"
104
- }
2
+ "name": "@projectwallace/css-parser",
3
+ "version": "0.16.1",
4
+ "description": "High-performance CSS lexer and parser, optimized for CSS inspection and analysis",
5
+ "keywords": [
6
+ "ast",
7
+ "css",
8
+ "lexer",
9
+ "parser",
10
+ "tokenizer"
11
+ ],
12
+ "homepage": "https://github.com/projectwallace/css-parser",
13
+ "license": "MIT",
14
+ "author": "Bart Veneman <bart@projectwallace.com>",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/projectwallace/css-parser.git"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "type": "module",
23
+ "main": "./dist/index.js",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
30
+ },
31
+ "./package.json": "./package.json",
32
+ "./tokenizer": {
33
+ "types": "./dist/tokenize.d.ts",
34
+ "import": "./dist/tokenize.js"
35
+ },
36
+ "./parse": {
37
+ "types": "./dist/parse.d.ts",
38
+ "import": "./dist/parse.js"
39
+ },
40
+ "./parse-selector": {
41
+ "types": "./dist/parse-selector.d.ts",
42
+ "import": "./dist/parse-selector.js"
43
+ },
44
+ "./parse-atrule-prelude": {
45
+ "types": "./dist/parse-atrule-prelude.d.ts",
46
+ "import": "./dist/parse-atrule-prelude.js"
47
+ },
48
+ "./parse-declaration": {
49
+ "types": "./dist/parse-declaration.d.ts",
50
+ "import": "./dist/parse-declaration.js"
51
+ },
52
+ "./parse-value": {
53
+ "types": "./dist/parse-value.d.ts",
54
+ "import": "./dist/parse-value.js"
55
+ },
56
+ "./parse-anplusb": {
57
+ "types": "./dist/parse-anplusb.d.ts",
58
+ "import": "./dist/parse-anplusb.js"
59
+ },
60
+ "./parse-dimension": {
61
+ "types": "./dist/parse-dimension.d.ts",
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"
71
+ }
72
+ },
73
+ "publishConfig": {
74
+ "access": "public",
75
+ "provenance": true
76
+ },
77
+ "devDependencies": {
78
+ "@projectwallace/preset-oxlint": "^0.0.10",
79
+ "@types/node": "^24.10.1",
80
+ "@vitest/coverage-v8": "^4.1.9",
81
+ "bootstrap": "^5.3.8",
82
+ "css-tree": "^3.1.0",
83
+ "knip": "^6.18.0",
84
+ "oxfmt": "^0.56.0",
85
+ "oxlint": "^1.71.0",
86
+ "postcss": "^8.5.15",
87
+ "publint": "^0.3.21",
88
+ "tailwindcss": "^2.2.8",
89
+ "tinybench": "^6.0.2",
90
+ "tsdown": "^0.22.3",
91
+ "typescript": "^6.0.3",
92
+ "vite": "^8.0.16",
93
+ "vitest": "^4.1.9"
94
+ },
95
+ "engines": {
96
+ "pnpm": ">=11.0.0"
97
+ },
98
+ "issues": "https://github.com/projectwallace/css-parser/issues",
99
+ "scripts": {
100
+ "test": "vitest",
101
+ "test-coverage": "vitest --coverage",
102
+ "test-build": "pnpm run build && vitest run --config vitest.config.build.ts",
103
+ "build": "tsdown",
104
+ "benchmark": "pnpm run build && node --expose-gc benchmark/index.ts",
105
+ "lint": "oxlint --config .oxlintrc.json && oxfmt --check",
106
+ "check": "tsc --noEmit",
107
+ "knip": "knip",
108
+ "precommit": "pnpm run test -- --run; pnpm run lint; pnpm run check"
109
+ }
110
+ }