@eslint/css-tree 3.6.8 → 4.0.0
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/LICENSE +1 -1
- package/README.md +4 -4
- package/cjs/definition-syntax/parse.cjs +63 -23
- package/cjs/generator/create.cjs +10 -2
- package/cjs/generator/token-before.cjs +9 -10
- package/cjs/lexer/generic.cjs +44 -1
- package/cjs/parser/create.cjs +37 -13
- package/cjs/syntax/atrule/layer.cjs +2 -2
- package/cjs/syntax/node/Block.cjs +40 -0
- package/data/patch.json +40 -1
- package/dist/csstree.esm.js +9 -9
- package/dist/csstree.js +9 -9
- package/dist/data.cjs +101 -42
- package/dist/data.js +101 -42
- package/dist/version.cjs +1 -1
- package/dist/version.js +1 -1
- package/lib/definition-syntax/parse.js +63 -23
- package/lib/generator/create.js +10 -2
- package/lib/generator/token-before.js +9 -11
- package/lib/lexer/generic.js +32 -1
- package/lib/parser/create.js +37 -13
- package/lib/syntax/atrule/layer.js +2 -2
- package/lib/syntax/node/Block.js +41 -0
- package/package.json +8 -8
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
WhiteSpace,
|
|
3
2
|
Delim,
|
|
4
3
|
Ident,
|
|
5
4
|
Function as FunctionToken,
|
|
@@ -20,17 +19,20 @@ import {
|
|
|
20
19
|
const PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
|
|
21
20
|
const HYPHENMINUS = 0x002D; // U+002D HYPHEN-MINUS (-)
|
|
22
21
|
|
|
22
|
+
// code:
|
|
23
|
+
// 0xxxxxxx x0000000 - char code (0x80 for non-ASCII) or delim value
|
|
24
|
+
// 00000000 0xxxxxx0 - token type (0 for delim, 1 for token)
|
|
25
|
+
// 00000000 0000000x - reserved for carriage emit flag (0 for no space, 1 for space)
|
|
23
26
|
const code = (type, value) => {
|
|
24
27
|
if (type === Delim) {
|
|
25
28
|
type = value;
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
if (typeof type === 'string') {
|
|
29
|
-
|
|
30
|
-
return charCode > 0x7F ? 0x8000 : charCode << 8;
|
|
32
|
+
type = Math.min(type.charCodeAt(0), 0x80) << 6; // replace non-ASCII with 0x80
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
return type;
|
|
35
|
+
return type << 1;
|
|
34
36
|
};
|
|
35
37
|
|
|
36
38
|
// https://www.w3.org/TR/css-syntax-3/#serialization
|
|
@@ -167,14 +169,10 @@ function createMap(pairs) {
|
|
|
167
169
|
type !== FunctionToken &&
|
|
168
170
|
type !== CDC) ||
|
|
169
171
|
(nextCharCode === PLUSSIGN)
|
|
170
|
-
? isWhiteSpaceRequired.has(prevCode << 16 | nextCharCode <<
|
|
171
|
-
: isWhiteSpaceRequired.has(prevCode << 16 | nextCode);
|
|
172
|
+
? isWhiteSpaceRequired.has((prevCode & 0xFFFE) << 16 | nextCharCode << 7)
|
|
173
|
+
: isWhiteSpaceRequired.has((prevCode & 0xFFFE) << 16 | nextCode);
|
|
172
174
|
|
|
173
|
-
|
|
174
|
-
this.emit(' ', WhiteSpace, true);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return nextCode;
|
|
175
|
+
return nextCode | emitWs;
|
|
178
176
|
};
|
|
179
177
|
}
|
|
180
178
|
|
package/lib/lexer/generic.js
CHANGED
|
@@ -698,10 +698,41 @@ export function createDemensionTypes(units) {
|
|
|
698
698
|
};
|
|
699
699
|
}
|
|
700
700
|
|
|
701
|
+
// The <attr-unit> production matches any identifier that is an ASCII case-insensitive
|
|
702
|
+
// match for the name of a CSS dimension unit, such as px, or the <delim-token> %.
|
|
703
|
+
function createAttrUnit(units) {
|
|
704
|
+
const unitSet = new Set();
|
|
705
|
+
|
|
706
|
+
for (const group of unitGroups) {
|
|
707
|
+
if (Array.isArray(units[group])) {
|
|
708
|
+
for (const unit of units[group]) {
|
|
709
|
+
unitSet.add(unit.toLowerCase());
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
return function attrUnit(token) {
|
|
715
|
+
if (token === null) {
|
|
716
|
+
return 0;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if (token.type === Delim && token.value === '%') {
|
|
720
|
+
return 1;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (token.type === Ident && unitSet.has(token.value.toLowerCase())) {
|
|
724
|
+
return 1;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
return 0;
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
|
|
701
731
|
export function createGenericTypes(units) {
|
|
702
732
|
return {
|
|
703
733
|
...tokenTypes,
|
|
704
734
|
...productionTypes,
|
|
705
|
-
...createDemensionTypes(units)
|
|
735
|
+
...createDemensionTypes(units),
|
|
736
|
+
'attr-unit': createAttrUnit(units)
|
|
706
737
|
};
|
|
707
738
|
};
|
package/lib/parser/create.js
CHANGED
|
@@ -29,6 +29,36 @@ const SEMICOLON = 0x003B; // U+003B SEMICOLON (;)
|
|
|
29
29
|
const LEFTCURLYBRACKET = 0x007B; // U+007B LEFT CURLY BRACKET ({)
|
|
30
30
|
const NULL = 0;
|
|
31
31
|
|
|
32
|
+
const arrayMethods = {
|
|
33
|
+
createList() {
|
|
34
|
+
return [];
|
|
35
|
+
},
|
|
36
|
+
createSingleNodeList(node) {
|
|
37
|
+
return [node];
|
|
38
|
+
},
|
|
39
|
+
getFirstListNode(list) {
|
|
40
|
+
return list && list[0] || null;
|
|
41
|
+
},
|
|
42
|
+
getLastListNode(list) {
|
|
43
|
+
return list && list.length > 0 ? list[list.length - 1] : null;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const listMethods = {
|
|
48
|
+
createList() {
|
|
49
|
+
return new List();
|
|
50
|
+
},
|
|
51
|
+
createSingleNodeList(node) {
|
|
52
|
+
return new List().appendData(node);
|
|
53
|
+
},
|
|
54
|
+
getFirstListNode(list) {
|
|
55
|
+
return list && list.first;
|
|
56
|
+
},
|
|
57
|
+
getLastListNode(list) {
|
|
58
|
+
return list && list.last;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
32
62
|
function createParseContext(name) {
|
|
33
63
|
return function() {
|
|
34
64
|
return this[name]();
|
|
@@ -110,18 +140,10 @@ export function createParser(config) {
|
|
|
110
140
|
return code === SEMICOLON ? 2 : 0;
|
|
111
141
|
},
|
|
112
142
|
|
|
113
|
-
createList
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return new List().appendData(node);
|
|
118
|
-
},
|
|
119
|
-
getFirstListNode(list) {
|
|
120
|
-
return list && list.first;
|
|
121
|
-
},
|
|
122
|
-
getLastListNode(list) {
|
|
123
|
-
return list && list.last;
|
|
124
|
-
},
|
|
143
|
+
createList: NOOP,
|
|
144
|
+
createSingleNodeList: NOOP,
|
|
145
|
+
getFirstListNode: NOOP,
|
|
146
|
+
getLastListNode: NOOP,
|
|
125
147
|
|
|
126
148
|
parseWithFallback(consumer, fallback) {
|
|
127
149
|
const startIndex = this.tokenIndex;
|
|
@@ -346,12 +368,14 @@ export function createParser(config) {
|
|
|
346
368
|
parser.parseValue = 'parseValue' in options ? Boolean(options.parseValue) : true;
|
|
347
369
|
parser.parseCustomProperty = 'parseCustomProperty' in options ? Boolean(options.parseCustomProperty) : false;
|
|
348
370
|
|
|
349
|
-
const { context = 'default', onComment, onToken } = options;
|
|
371
|
+
const { context = 'default', list = true, onComment, onToken } = options;
|
|
350
372
|
|
|
351
373
|
if (context in parser.context === false) {
|
|
352
374
|
throw new Error('Unknown context `' + context + '`');
|
|
353
375
|
}
|
|
354
376
|
|
|
377
|
+
Object.assign(parser, list ? listMethods : arrayMethods);
|
|
378
|
+
|
|
355
379
|
if (Array.isArray(onToken)) {
|
|
356
380
|
parser.forEachToken((type, start, end) => {
|
|
357
381
|
onToken.push({ type, start, end });
|
package/lib/syntax/node/Block.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
Hash,
|
|
7
7
|
Colon,
|
|
8
8
|
Ident,
|
|
9
|
+
Function,
|
|
9
10
|
AtKeyword,
|
|
10
11
|
LeftSquareBracket,
|
|
11
12
|
LeftCurlyBracket,
|
|
@@ -58,10 +59,50 @@ function isElementSelectorStart() {
|
|
|
58
59
|
|
|
59
60
|
const nextTokenType = this.lookupTypeNonSC(1);
|
|
60
61
|
|
|
62
|
+
// If next token is not colon, semicolon, or right curly bracket, it's likely a selector
|
|
61
63
|
if (nextTokenType !== Colon && nextTokenType !== Semicolon && nextTokenType !== RightCurlyBracket) {
|
|
62
64
|
return true;
|
|
63
65
|
}
|
|
64
66
|
|
|
67
|
+
// If next token is colon, we need to look further ahead to distinguish
|
|
68
|
+
// between property declarations (p: value) and pseudo-class selectors (p:hover)
|
|
69
|
+
if (nextTokenType === Colon) {
|
|
70
|
+
// Look for the token after the colon (skipping whitespace)
|
|
71
|
+
const tokenAfterColon = this.lookupTypeNonSC(2);
|
|
72
|
+
|
|
73
|
+
// If it's an identifier (like 'hover', 'first-of-type') or function (like 'nth-child()', 'not()'),
|
|
74
|
+
// this could be a pseudo-class
|
|
75
|
+
if (tokenAfterColon === Ident || tokenAfterColon === Function) {
|
|
76
|
+
// Look further ahead to see if there's a left curly bracket
|
|
77
|
+
// which would indicate this is a selector with a block
|
|
78
|
+
let offset = 3;
|
|
79
|
+
let tokenType;
|
|
80
|
+
|
|
81
|
+
// Skip whitespace and look for either a left curly bracket or other tokens
|
|
82
|
+
while (offset <= 15) { // Increased limit to handle function pseudo-classes
|
|
83
|
+
tokenType = this.lookupType(offset);
|
|
84
|
+
|
|
85
|
+
if (tokenType === LeftCurlyBracket) {
|
|
86
|
+
// Found opening brace, this is definitely a selector
|
|
87
|
+
return true;
|
|
88
|
+
} else if (tokenType === Semicolon || tokenType === RightCurlyBracket) {
|
|
89
|
+
// Found semicolon or closing brace before opening brace, likely a property
|
|
90
|
+
return false;
|
|
91
|
+
} else if (tokenType === WhiteSpace || tokenType === Comment) {
|
|
92
|
+
// Skip whitespace and comments
|
|
93
|
+
offset++;
|
|
94
|
+
continue;
|
|
95
|
+
} else {
|
|
96
|
+
// Other tokens might indicate more complex selectors, continue looking
|
|
97
|
+
offset++;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// If we can't determine conclusively, default to property behavior
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
65
106
|
return false;
|
|
66
107
|
}
|
|
67
108
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint/css-tree",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "A tool set for CSS: fast detailed parser (CSS → AST), walker (AST traversal), generator (AST → CSS) and lexer (validation and matching) based on specs and browser implementations",
|
|
5
5
|
"author": "Roman Dvornov <rdvornov@gmail.com> (https://github.com/lahmatiy)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -107,21 +107,21 @@
|
|
|
107
107
|
"test:types": "tsc -p tests/types/tsconfig.json"
|
|
108
108
|
},
|
|
109
109
|
"dependencies": {
|
|
110
|
-
"mdn-data": "2.
|
|
111
|
-
"source-map-js": "^1.
|
|
110
|
+
"mdn-data": "2.27.1",
|
|
111
|
+
"source-map-js": "^1.2.1"
|
|
112
112
|
},
|
|
113
113
|
"devDependencies": {
|
|
114
|
-
"c8": "^
|
|
114
|
+
"c8": "^11.0.0",
|
|
115
115
|
"clap": "^2.0.1",
|
|
116
|
-
"esbuild": "^0.
|
|
117
|
-
"eslint": "^8.
|
|
116
|
+
"esbuild": "^0.27.3",
|
|
117
|
+
"eslint": "^8.50.0",
|
|
118
118
|
"json-to-ast": "^2.1.0",
|
|
119
119
|
"mocha": "^9.2.2",
|
|
120
|
-
"rollup": "^2.
|
|
120
|
+
"rollup": "^2.80.0",
|
|
121
121
|
"typescript": "^5.7.3"
|
|
122
122
|
},
|
|
123
123
|
"engines": {
|
|
124
|
-
"node": "^
|
|
124
|
+
"node": "^20.19.0 || ^22.13.0 || >=24"
|
|
125
125
|
},
|
|
126
126
|
"files": [
|
|
127
127
|
"data",
|