@projectwallace/css-parser 0.18.4 → 0.18.6
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-C-uRgG5-.d.ts → arena-BGvFdbj5.d.ts} +3 -1
- package/dist/{arena-C-ZXJe7F.js → arena-e9O_g2AN.js} +3 -1
- package/dist/constants.d.ts +4 -2
- package/dist/constants.js +4 -2
- package/dist/{css-node-Briho45Z.js → css-node-BmD2JJLr.js} +21 -4
- package/dist/index.d.ts +3 -3
- package/dist/index.js +10 -4
- package/dist/{node-types-Dh1wEDRK.d.ts → node-types-YnOKcNfU.d.ts} +49 -6
- package/dist/parse-anplusb.d.ts +2 -2
- package/dist/parse-anplusb.js +2 -2
- package/dist/parse-atrule-prelude.d.ts +3 -10
- package/dist/parse-atrule-prelude.js +20 -220
- package/dist/parse-declaration.d.ts +2 -2
- package/dist/parse-declaration.js +3 -3
- package/dist/parse-selector-DMduLN4o.js +534 -0
- package/dist/parse-selector.d.ts +2 -2
- package/dist/parse-selector.js +1 -460
- package/dist/parse-value.d.ts +2 -2
- package/dist/parse-value.js +3 -3
- package/dist/parse.d.ts +2 -2
- package/dist/parse.js +3 -4
- package/dist/value-node-parser-3ET5Z4Rf.js +737 -0
- package/dist/walk.d.ts +1 -1
- package/dist/walk.js +2 -2
- package/package.json +3 -2
- package/dist/parse-utils-D7srNG13.js +0 -65
- package/dist/value-node-parser-B0WfJCvC.js +0 -173
package/dist/walk.d.ts
CHANGED
package/dist/walk.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@projectwallace/css-parser",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.6",
|
|
4
4
|
"description": "High-performance CSS lexer and parser, optimized for CSS inspection and analysis",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast",
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"knip": "^6.18.0",
|
|
85
85
|
"oxfmt": "^0.60.0",
|
|
86
86
|
"oxlint": "^1.71.0",
|
|
87
|
+
"pkg-pr-new": "^0.0.88",
|
|
87
88
|
"postcss": "^8.5.15",
|
|
88
89
|
"publint": "^0.3.21",
|
|
89
90
|
"tailwindcss": "^2.2.8",
|
|
@@ -103,7 +104,7 @@
|
|
|
103
104
|
"test-build": "pnpm run build && vitest run --config vitest.config.build.ts",
|
|
104
105
|
"build": "tsdown",
|
|
105
106
|
"benchmark": "pnpm run build && node --expose-gc benchmark/index.ts",
|
|
106
|
-
"lint": "oxlint --config .oxlintrc.json
|
|
107
|
+
"lint": "oxlint --config .oxlintrc.json && oxfmt --check",
|
|
107
108
|
"check": "tsc --noEmit",
|
|
108
109
|
"knip": "knip",
|
|
109
110
|
"precommit": "pnpm run test --run; pnpm run lint; pnpm run check"
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { a as is_whitespace } from "./parse-dimension-ouWXNHdx.js";
|
|
2
|
-
//#region src/parse-utils.ts
|
|
3
|
-
/** @internal */
|
|
4
|
-
function skip_whitespace_forward(source, pos, end) {
|
|
5
|
-
while (pos < end && is_whitespace(source.charCodeAt(pos))) pos++;
|
|
6
|
-
return pos;
|
|
7
|
-
}
|
|
8
|
-
/** @internal */
|
|
9
|
-
function skip_whitespace_and_comments_forward(source, pos, end) {
|
|
10
|
-
while (pos < end) {
|
|
11
|
-
let ch = source.charCodeAt(pos);
|
|
12
|
-
if (is_whitespace(ch)) {
|
|
13
|
-
pos++;
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
if (ch === 47 && pos + 1 < end && source.charCodeAt(pos + 1) === 42) {
|
|
17
|
-
pos += 2;
|
|
18
|
-
while (pos < end) {
|
|
19
|
-
if (source.charCodeAt(pos) === 42 && pos + 1 < end && source.charCodeAt(pos + 1) === 47) {
|
|
20
|
-
pos += 2;
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
pos++;
|
|
24
|
-
}
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
return pos;
|
|
30
|
-
}
|
|
31
|
-
/** @internal */
|
|
32
|
-
function skip_whitespace_and_comments_backward(source, pos, start) {
|
|
33
|
-
while (pos > start) {
|
|
34
|
-
let ch = source.charCodeAt(pos - 1);
|
|
35
|
-
if (is_whitespace(ch)) {
|
|
36
|
-
pos--;
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (pos >= 2 && ch === 47 && source.charCodeAt(pos - 2) === 42) {
|
|
40
|
-
pos -= 2;
|
|
41
|
-
while (pos > start) {
|
|
42
|
-
if (pos >= 2 && source.charCodeAt(pos - 2) === 47 && source.charCodeAt(pos - 1) === 42) {
|
|
43
|
-
pos -= 2;
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
pos--;
|
|
47
|
-
}
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
return pos;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Trims whitespace and CSS comments from both ends; returns null if the range is only whitespace/comments.
|
|
56
|
-
* @internal
|
|
57
|
-
*/
|
|
58
|
-
function trim_boundaries(source, start, end) {
|
|
59
|
-
start = skip_whitespace_and_comments_forward(source, start, end);
|
|
60
|
-
end = skip_whitespace_and_comments_backward(source, end, start);
|
|
61
|
-
if (start >= end) return null;
|
|
62
|
-
return [start, end];
|
|
63
|
-
}
|
|
64
|
-
//#endregion
|
|
65
|
-
export { trim_boundaries as i, skip_whitespace_and_comments_forward as n, skip_whitespace_forward as r, skip_whitespace_and_comments_backward as t };
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { t as Lexer } from "./tokenize-DK24ACbY.js";
|
|
2
|
-
import "./arena-C-ZXJe7F.js";
|
|
3
|
-
import { a as is_whitespace, o as str_equals } from "./parse-dimension-ouWXNHdx.js";
|
|
4
|
-
//#region src/value-node-parser.ts
|
|
5
|
-
/** @internal */
|
|
6
|
-
var ValueNodeParser = class {
|
|
7
|
-
lexer;
|
|
8
|
-
arena;
|
|
9
|
-
source;
|
|
10
|
-
end = 0;
|
|
11
|
-
last_chain_node = 0;
|
|
12
|
-
constructor(arena, source) {
|
|
13
|
-
this.arena = arena;
|
|
14
|
-
this.source = source;
|
|
15
|
-
this.lexer = new Lexer(source);
|
|
16
|
-
}
|
|
17
|
-
parse_chain(start, end, start_line, start_column) {
|
|
18
|
-
this.end = end;
|
|
19
|
-
this.lexer.seek(start, start_line, start_column);
|
|
20
|
-
let first_node = 0;
|
|
21
|
-
let last_node = 0;
|
|
22
|
-
while (this.lexer.pos < this.end) {
|
|
23
|
-
this.lexer.next_token_fast(false);
|
|
24
|
-
if (this.lexer.token_start >= this.end) break;
|
|
25
|
-
if (this.lexer.token_type === 26) break;
|
|
26
|
-
if (this.is_whitespace_inline()) continue;
|
|
27
|
-
let node = this.parse_value_node();
|
|
28
|
-
if (node !== null) {
|
|
29
|
-
if (first_node === 0) first_node = node;
|
|
30
|
-
else this.arena.set_next_sibling(last_node, node);
|
|
31
|
-
last_node = node;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
this.last_chain_node = last_node;
|
|
35
|
-
return first_node;
|
|
36
|
-
}
|
|
37
|
-
is_whitespace_inline() {
|
|
38
|
-
if (this.lexer.token_start >= this.lexer.token_end) return false;
|
|
39
|
-
for (let i = this.lexer.token_start; i < this.lexer.token_end; i++) if (!is_whitespace(this.source.charCodeAt(i))) return false;
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
parse_value_node() {
|
|
43
|
-
let token_type = this.lexer.token_type;
|
|
44
|
-
let start = this.lexer.token_start;
|
|
45
|
-
let end = this.lexer.token_end;
|
|
46
|
-
switch (token_type) {
|
|
47
|
-
case 1: return this.create_node(10, start, end);
|
|
48
|
-
case 10: return this.create_node(11, start, end);
|
|
49
|
-
case 11:
|
|
50
|
-
case 12: return this.create_node(12, start, end);
|
|
51
|
-
case 5: return this.create_node(13, start, end);
|
|
52
|
-
case 4: return this.create_node(14, start, end);
|
|
53
|
-
case 27: return this.create_node(19, start, end);
|
|
54
|
-
case 2: return this.parse_function_node(start, end);
|
|
55
|
-
case 9: return this.parse_operator_node(start, end);
|
|
56
|
-
case 18: return this.create_node(16, start, end);
|
|
57
|
-
case 21: return this.parse_parenthesis_node(start, end);
|
|
58
|
-
default: return null;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
create_node(node_type, start, end) {
|
|
62
|
-
let node = this.arena.create_node(node_type, start, end - start, this.lexer.token_line, this.lexer.token_column);
|
|
63
|
-
this.arena.set_content_length(node, end - start);
|
|
64
|
-
return node;
|
|
65
|
-
}
|
|
66
|
-
parse_operator_node(start, end) {
|
|
67
|
-
let ch = this.source.charCodeAt(start);
|
|
68
|
-
if (ch === 43 || ch === 45 || ch === 42 || ch === 47) return this.create_node(16, start, end);
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
parse_function_node(start, end) {
|
|
72
|
-
let name_end = end - 1;
|
|
73
|
-
let func_name_substr = this.source.substring(start, name_end);
|
|
74
|
-
let node = this.arena.create_node(str_equals("url", func_name_substr) ? 18 : 15, start, 0, this.lexer.token_line, this.lexer.token_column);
|
|
75
|
-
this.arena.set_content_start_delta(node, 0);
|
|
76
|
-
this.arena.set_content_length(node, name_end - start);
|
|
77
|
-
if (str_equals("url", func_name_substr) || str_equals("src", func_name_substr)) {
|
|
78
|
-
let save_pos = this.lexer.save_position();
|
|
79
|
-
this.lexer.next_token_fast(false);
|
|
80
|
-
while (this.is_whitespace_inline() && this.lexer.pos < this.end) this.lexer.next_token_fast(false);
|
|
81
|
-
let first_token_type = this.lexer.token_type;
|
|
82
|
-
this.lexer.restore_position(save_pos);
|
|
83
|
-
if (first_token_type === 5) {} else {
|
|
84
|
-
let paren_depth = 1;
|
|
85
|
-
let func_end = end;
|
|
86
|
-
let content_start = end;
|
|
87
|
-
let content_end = end;
|
|
88
|
-
while (paren_depth > 0) {
|
|
89
|
-
this.lexer.next_token_fast(false);
|
|
90
|
-
let token_type = this.lexer.token_type;
|
|
91
|
-
if (token_type === 26) break;
|
|
92
|
-
if (token_type === 21 || token_type === 2) paren_depth++;
|
|
93
|
-
else if (token_type === 22) {
|
|
94
|
-
paren_depth--;
|
|
95
|
-
if (paren_depth === 0) {
|
|
96
|
-
content_end = this.lexer.token_start;
|
|
97
|
-
func_end = this.lexer.token_end;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
this.arena.set_length(node, func_end - start);
|
|
103
|
-
this.arena.set_value_start_delta(node, content_start - start);
|
|
104
|
-
this.arena.set_value_length(node, content_end - content_start);
|
|
105
|
-
return node;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
let first_arg = 0;
|
|
109
|
-
let last_arg = 0;
|
|
110
|
-
let paren_depth = 1;
|
|
111
|
-
let func_end = end;
|
|
112
|
-
let content_start = end;
|
|
113
|
-
let content_end = end;
|
|
114
|
-
while (this.lexer.pos < this.end && paren_depth > 0) {
|
|
115
|
-
this.lexer.next_token_fast(false);
|
|
116
|
-
let token_type = this.lexer.token_type;
|
|
117
|
-
if (token_type === 26) break;
|
|
118
|
-
if (this.lexer.token_start >= this.end) break;
|
|
119
|
-
if (token_type === 22) {
|
|
120
|
-
paren_depth--;
|
|
121
|
-
if (paren_depth === 0) {
|
|
122
|
-
content_end = this.lexer.token_start;
|
|
123
|
-
func_end = this.lexer.token_end;
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (this.is_whitespace_inline()) continue;
|
|
128
|
-
let arg_node = this.parse_value_node();
|
|
129
|
-
if (arg_node !== null) {
|
|
130
|
-
if (first_arg === 0) first_arg = arg_node;
|
|
131
|
-
else this.arena.set_next_sibling(last_arg, arg_node);
|
|
132
|
-
last_arg = arg_node;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
this.arena.set_length(node, func_end - start);
|
|
136
|
-
this.arena.set_value_start_delta(node, content_start - start);
|
|
137
|
-
this.arena.set_value_length(node, content_end - content_start);
|
|
138
|
-
if (first_arg !== 0) this.arena.set_first_child(node, first_arg);
|
|
139
|
-
return node;
|
|
140
|
-
}
|
|
141
|
-
parse_parenthesis_node(start, end) {
|
|
142
|
-
let node = this.arena.create_node(17, start, 0, this.lexer.token_line, this.lexer.token_column);
|
|
143
|
-
let first_child = 0;
|
|
144
|
-
let last_child = 0;
|
|
145
|
-
let paren_depth = 1;
|
|
146
|
-
let paren_end = end;
|
|
147
|
-
while (this.lexer.pos < this.end && paren_depth > 0) {
|
|
148
|
-
this.lexer.next_token_fast(false);
|
|
149
|
-
let token_type = this.lexer.token_type;
|
|
150
|
-
if (token_type === 26) break;
|
|
151
|
-
if (this.lexer.token_start >= this.end) break;
|
|
152
|
-
if (token_type === 22) {
|
|
153
|
-
paren_depth--;
|
|
154
|
-
if (paren_depth === 0) {
|
|
155
|
-
paren_end = this.lexer.token_end;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (this.is_whitespace_inline()) continue;
|
|
160
|
-
let child_node = this.parse_value_node();
|
|
161
|
-
if (child_node !== null) {
|
|
162
|
-
if (first_child === 0) first_child = child_node;
|
|
163
|
-
else this.arena.set_next_sibling(last_child, child_node);
|
|
164
|
-
last_child = child_node;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
this.arena.set_length(node, paren_end - start);
|
|
168
|
-
if (first_child !== 0) this.arena.set_first_child(node, first_child);
|
|
169
|
-
return node;
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
//#endregion
|
|
173
|
-
export { ValueNodeParser as t };
|