@eslint/css-tree 4.1.2 → 4.1.4

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/README.md CHANGED
@@ -201,7 +201,7 @@ The following companies, organizations, and individuals support ESLint's ongoing
201
201
  to get your logo on our READMEs and [website](https://eslint.org/sponsors).
202
202
 
203
203
  <h3>Gold Sponsors</h3>
204
- <p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a> <a href="https://shopify.engineering/"><img src="https://avatars.githubusercontent.com/u/8085" alt="Shopify" height="96"></a> <a href="https://www.coderabbit.ai/?utm_source=cr_org&utm_medium=github"><img src="https://avatars.githubusercontent.com/u/132028505" alt="CodeRabbit" height="96"></a></p><h3>Silver Sponsors</h3>
204
+ <p><a href="#"><img src="https://images.opencollective.com/vite-ecosystem-fund/logo.png" alt="Vite Ecosystem Fund" height="96"></a> <a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a> <a href="https://shopify.engineering/"><img src="https://avatars.githubusercontent.com/u/8085" alt="Shopify" height="96"></a> <a href="https://www.coderabbit.ai/?utm_source=cr_org&utm_medium=github"><img src="https://avatars.githubusercontent.com/u/132028505" alt="CodeRabbit" height="96"></a> <a href="https://automattic.com"><img src="https://avatars.githubusercontent.com/u/887802" alt="Automattic" height="96"></a></p><h3>Silver Sponsors</h3>
205
205
  <p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/d472863/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/2d6c3b6/logo.png" alt="Liftoff" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
206
206
  <p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://opensource.sap.com"><img src="https://avatars.githubusercontent.com/u/2531208" alt="SAP" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://citadel-ai.com"><img src="https://avatars.githubusercontent.com/u/75781367" alt="Citadel AI" height="32"></a> <a href="https://www.testmuai.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="TestMu AI Open Source Office (Formerly LambdaTest)" height="32"></a></p>
207
207
  <h3>Technology Sponsors</h3>
@@ -62,6 +62,10 @@ const config = {
62
62
  },
63
63
  container: {
64
64
  style() {
65
+ if (this.tokenType === types.Ident && this.lookupTypeNonSC(1) !== types.Colon) {
66
+ return this.Identifier();
67
+ }
68
+
65
69
  return this.Declaration();
66
70
  }
67
71
  }
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const names = require('../../utils/names.cjs');
3
4
  const types = require('../../tokenizer/types.cjs');
4
5
 
5
6
  const AMPERSAND = 0x0026; // U+0026 AMPERSAND (&)
@@ -53,43 +54,32 @@ function isElementSelectorStart() {
53
54
  return true;
54
55
  }
55
56
 
56
- // If next token is colon, we need to look further ahead to distinguish
57
- // between property declarations (p: value) and pseudo-class selectors (p:hover)
58
- if (nextTokenType === types.Colon) {
59
- // Look for the token after the colon (skipping whitespace)
60
- const tokenAfterColon = this.lookupTypeNonSC(2);
61
-
62
- // If it's an identifier (like 'hover', 'first-of-type') or function (like 'nth-child()', 'not()'),
63
- // this could be a pseudo-class
64
- if (tokenAfterColon === types.Ident || tokenAfterColon === types.Function) {
65
- // Look further ahead to see if there's a left curly bracket
66
- // which would indicate this is a selector with a block
67
- let offset = 3;
68
- let tokenType;
69
-
70
- // Skip whitespace and look for either a left curly bracket or other tokens
71
- while (offset <= 15) { // Increased limit to handle function pseudo-classes
72
- tokenType = this.lookupType(offset);
73
-
74
- if (tokenType === types.LeftCurlyBracket) {
75
- // Found opening brace, this is definitely a selector
76
- return true;
77
- } else if (tokenType === types.Semicolon || tokenType === types.RightCurlyBracket) {
78
- // Found semicolon or closing brace before opening brace, likely a property
79
- return false;
80
- } else if (tokenType === types.WhiteSpace || tokenType === types.Comment) {
81
- // Skip whitespace and comments
82
- offset++;
83
- continue;
84
- } else {
85
- // Other tokens might indicate more complex selectors, continue looking
86
- offset++;
87
- }
88
- }
57
+ // Custom property values may contain top-level curly blocks.
58
+ if (names.isCustomProperty(this.source, this.tokenStart)) {
59
+ return false;
60
+ }
61
+
62
+ // Only top-level delimiters distinguish declarations from nested rules.
63
+ for (let offset = 1; this.tokenIndex + offset < this.tokenCount; offset++) {
64
+ const tokenType = this.lookupType(offset);
65
+
66
+ if (tokenType === types.LeftCurlyBracket) {
67
+ return true;
89
68
  }
90
69
 
91
- // If we can't determine conclusively, default to property behavior
92
- return false;
70
+ if (tokenType === types.Semicolon || tokenType === types.RightCurlyBracket) {
71
+ return false;
72
+ }
73
+
74
+ if (this.isBlockOpenerTokenType(tokenType)) {
75
+ const pairIndex = this.getBlockTokenPairIndex(this.tokenIndex + offset);
76
+
77
+ if (pairIndex === -1) {
78
+ return false;
79
+ }
80
+
81
+ offset = pairIndex - this.tokenIndex;
82
+ }
93
83
  }
94
84
 
95
85
  return false;
@@ -17,8 +17,29 @@ const structure = {
17
17
  };
18
18
 
19
19
  function featureOrRange(kind) {
20
- if (this.lookupTypeNonSC(1) === types.Ident &&
21
- likelyFeatureToken.has(this.lookupTypeNonSC(2))) {
20
+ const firstToken = this.lookupTypeNonSC(1);
21
+ let secondToken = this.lookupTypeNonSC(2);
22
+
23
+ if (firstToken === types.Function) {
24
+ let index = this.getBlockTokenPairIndex(this.tokenIndex + this.lookupOffsetNonSC(1));
25
+
26
+ if (index !== -1) {
27
+ do {
28
+ secondToken = this.getTokenType(++index);
29
+ } while (secondToken === types.WhiteSpace || secondToken === types.Comment);
30
+
31
+ if (secondToken !== types.Delim) {
32
+ return null;
33
+ }
34
+ }
35
+ }
36
+
37
+ if (firstToken === types.LeftParenthesis ||
38
+ (firstToken === types.Ident && (secondToken === types.LeftParenthesis || secondToken === types.Function))) {
39
+ return null;
40
+ }
41
+
42
+ if (firstToken === types.Ident && likelyFeatureToken.has(secondToken)) {
22
43
  return this.Feature(kind);
23
44
  }
24
45
 
@@ -68,9 +68,13 @@ function parse() {
68
68
  }
69
69
  }
70
70
 
71
+ const loc = this.getLocation(start, this.tokenStart);
72
+
73
+ this.skipSC();
74
+
71
75
  return {
72
76
  type: 'MediaQuery',
73
- loc: this.getLocation(start, this.tokenStart),
77
+ loc,
74
78
  modifier,
75
79
  mediaType,
76
80
  condition
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const lang = require('./lang.cjs');
4
+ const types = require('../../tokenizer/types.cjs');
4
5
 
5
6
  const selectorList = {
6
7
  parse() {
@@ -26,6 +27,19 @@ const identList = {
26
27
  }
27
28
  };
28
29
 
30
+ const identSequence = {
31
+ parse() {
32
+ const children = this.createList();
33
+
34
+ do {
35
+ children.push(this.Identifier());
36
+ this.skipSC();
37
+ } while (this.tokenType === types.Ident);
38
+
39
+ return children;
40
+ }
41
+ };
42
+
29
43
  const langList = {
30
44
  parse: lang.parseLanguageRangeList
31
45
  };
@@ -54,7 +68,8 @@ const pseudo = {
54
68
  'nth-of-type': nth,
55
69
  'slotted': selector,
56
70
  'host': selector,
57
- 'host-context': selector
71
+ 'host-context': selector,
72
+ 'part': identSequence
58
73
  };
59
74
 
60
75
  module.exports = pseudo;
@@ -5,8 +5,8 @@ const utils = require('./utils.cjs');
5
5
  const names = require('./names.cjs');
6
6
  const types = require('./types.cjs');
7
7
 
8
- const OFFSET_MASK = 0x00FFFFFF;
9
- const TYPE_SHIFT = 24;
8
+ const OFFSET_MASK = 0x07FFFFFF;
9
+ const TYPE_SHIFT = 27;
10
10
  const BLOCK_OPEN_TOKEN = 1;
11
11
  const BLOCK_CLOSE_TOKEN = 2;
12
12
  const balancePair = new Uint8Array(32); // 32b of memory ought to be enough for anyone (any number of tokens)
@@ -43,6 +43,10 @@ class TokenStream {
43
43
  source = String(source || '');
44
44
 
45
45
  const sourceLength = source.length;
46
+ if (sourceLength > OFFSET_MASK) {
47
+ throw new RangeError('Source exceeds the maximum length of ' + OFFSET_MASK + ' UTF-16 code units');
48
+ }
49
+
46
50
  const offsetAndType = adoptBuffer.adoptBuffer(this.offsetAndType, source.length + 1); // +1 because of eof-token
47
51
  const balance = adoptBuffer.adoptBuffer(this.balance, source.length + 1);
48
52
  let tokenCount = 0;
@@ -53,7 +57,7 @@ class TokenStream {
53
57
  // capture buffers
54
58
  this.offsetAndType = null;
55
59
  this.balance = null;
56
- balance.fill(0);
60
+ balance.fill(0, 0, sourceLength + 1);
57
61
 
58
62
  tokenize(source, (type, start, end) => {
59
63
  const index = tokenCount++;
@@ -76,7 +80,7 @@ class TokenStream {
76
80
 
77
81
  // pop state
78
82
  balanceStart = prevBalanceStart;
79
- balanceCloseType = balancePair[offsetAndType[prevBalanceStart] >> TYPE_SHIFT];
83
+ balanceCloseType = balancePair[offsetAndType[prevBalanceStart] >>> TYPE_SHIFT];
80
84
  } else if (this.isBlockOpenerTokenType(type)) { // check for FunctionToken, <(-token>, <[-token> and <{-token>
81
85
  // push state
82
86
  balanceStart = index;
@@ -128,14 +132,14 @@ class TokenStream {
128
132
  offset += this.tokenIndex;
129
133
 
130
134
  if (offset < this.tokenCount) {
131
- return this.offsetAndType[offset] >> TYPE_SHIFT;
135
+ return this.offsetAndType[offset] >>> TYPE_SHIFT;
132
136
  }
133
137
 
134
138
  return types.EOF;
135
139
  }
136
140
  lookupTypeNonSC(idx) {
137
141
  for (let offset = this.tokenIndex; offset < this.tokenCount; offset++) {
138
- const tokenType = this.offsetAndType[offset] >> TYPE_SHIFT;
142
+ const tokenType = this.offsetAndType[offset] >>> TYPE_SHIFT;
139
143
 
140
144
  if (tokenType !== types.WhiteSpace && tokenType !== types.Comment) {
141
145
  if (idx-- === 0) {
@@ -157,7 +161,7 @@ class TokenStream {
157
161
  }
158
162
  lookupOffsetNonSC(idx) {
159
163
  for (let offset = this.tokenIndex; offset < this.tokenCount; offset++) {
160
- const tokenType = this.offsetAndType[offset] >> TYPE_SHIFT;
164
+ const tokenType = this.offsetAndType[offset] >>> TYPE_SHIFT;
161
165
 
162
166
  if (tokenType !== types.WhiteSpace && tokenType !== types.Comment) {
163
167
  if (idx-- === 0) {
@@ -207,7 +211,7 @@ class TokenStream {
207
211
  return this.tokenType;
208
212
  }
209
213
 
210
- return this.offsetAndType[boundIndex(tokenIndex, 0, this.tokenCount)] >> TYPE_SHIFT;
214
+ return this.offsetAndType[boundIndex(tokenIndex, 0, this.tokenCount)] >>> TYPE_SHIFT;
211
215
  }
212
216
  substrToCursor(start) {
213
217
  return this.source.substring(start, this.tokenStart);
@@ -263,7 +267,7 @@ class TokenStream {
263
267
  this.tokenIndex = next;
264
268
  this.tokenStart = this.offsetAndType[next - 1] & OFFSET_MASK;
265
269
  next = this.offsetAndType[next];
266
- this.tokenType = next >> TYPE_SHIFT;
270
+ this.tokenType = next >>> TYPE_SHIFT;
267
271
  this.tokenEnd = next & OFFSET_MASK;
268
272
  } else {
269
273
  this.tokenIndex = this.tokenCount;
@@ -277,7 +281,7 @@ class TokenStream {
277
281
  this.tokenIndex = next;
278
282
  this.tokenStart = this.tokenEnd;
279
283
  next = this.offsetAndType[next];
280
- this.tokenType = next >> TYPE_SHIFT;
284
+ this.tokenType = next >>> TYPE_SHIFT;
281
285
  this.tokenEnd = next & OFFSET_MASK;
282
286
  } else {
283
287
  this.eof = true;
@@ -318,7 +322,7 @@ class TokenStream {
318
322
 
319
323
  default:
320
324
  // fast forward to the end of balanced block for an open block tokens
321
- if (this.isBlockOpenerTokenType(this.offsetAndType[cursor] >> TYPE_SHIFT)) {
325
+ if (this.isBlockOpenerTokenType(this.offsetAndType[cursor] >>> TYPE_SHIFT)) {
322
326
  cursor = balanceEnd;
323
327
  }
324
328
  }
@@ -332,7 +336,7 @@ class TokenStream {
332
336
  const start = offset;
333
337
  const item = this.offsetAndType[i];
334
338
  const end = item & OFFSET_MASK;
335
- const type = item >> TYPE_SHIFT;
339
+ const type = item >>> TYPE_SHIFT;
336
340
 
337
341
  offset = end;
338
342
 
@@ -217,7 +217,7 @@ function consumeBadUrlRemnants(source, offset) {
217
217
  // Note: This allows an escaped right parenthesis ("\)") to be encountered
218
218
  // without ending the <bad-url-token>. This is otherwise identical to
219
219
  // the "anything else" clause.
220
- offset = consumeEscaped(source, offset);
220
+ offset = consumeEscaped(source, offset) - 1;
221
221
  }
222
222
  }
223
223
 
package/cjs/utils/url.cjs CHANGED
@@ -24,10 +24,14 @@ function decode(str) {
24
24
  end--;
25
25
  }
26
26
 
27
+ let runStart = start;
28
+
27
29
  for (let i = start; i <= end; i++) {
28
30
  let code = str.charCodeAt(i);
29
31
 
30
32
  if (code === REVERSE_SOLIDUS) {
33
+ decoded += str.slice(runStart, i);
34
+
31
35
  // special case at the ending
32
36
  if (i === end) {
33
37
  // if the next input code point is EOF, do nothing
@@ -35,7 +39,7 @@ function decode(str) {
35
39
  if (i !== len - 1) {
36
40
  decoded = str.substr(i + 1);
37
41
  }
38
- break;
42
+ return decoded;
39
43
  }
40
44
 
41
45
  code = str.charCodeAt(++i);
@@ -47,22 +51,24 @@ function decode(str) {
47
51
 
48
52
  i = escapeEnd - 1;
49
53
  decoded += utils.decodeEscaped(str.substring(escapeStart + 1, escapeEnd));
54
+ runStart = escapeEnd;
50
55
  } else {
51
56
  // \r\n
52
57
  if (code === 0x000d && str.charCodeAt(i + 1) === 0x000a) {
53
58
  i++;
54
59
  }
60
+
61
+ runStart = i + 1;
55
62
  }
56
- } else {
57
- decoded += str[i];
58
63
  }
59
64
  }
60
65
 
61
- return decoded;
66
+ return decoded + str.slice(runStart, end + 1);
62
67
  }
63
68
 
64
69
  function encode(str) {
65
70
  let encoded = '';
71
+ let runStart = 0;
66
72
  let wsBeforeHexIsNeeded = false;
67
73
 
68
74
  for (let i = 0; i < str.length; i++) {
@@ -70,7 +76,8 @@ function encode(str) {
70
76
 
71
77
  // If the character is NULL (U+0000), then the REPLACEMENT CHARACTER (U+FFFD).
72
78
  if (code === 0x0000) {
73
- encoded += '\uFFFD';
79
+ encoded += str.slice(runStart, i) + '\uFFFD';
80
+ runStart = i + 1;
74
81
  continue;
75
82
  }
76
83
 
@@ -78,7 +85,8 @@ function encode(str) {
78
85
  // the character escaped as code point.
79
86
  // Note: Do not compare with 0x0001 since 0x0000 is precessed before
80
87
  if (code <= 0x001f || code === 0x007F) {
81
- encoded += '\\' + code.toString(16);
88
+ encoded += str.slice(runStart, i) + '\\' + code.toString(16);
89
+ runStart = i + 1;
82
90
  wsBeforeHexIsNeeded = true;
83
91
  continue;
84
92
  }
@@ -89,19 +97,20 @@ function encode(str) {
89
97
  code === APOSTROPHE ||
90
98
  code === LEFTPARENTHESIS ||
91
99
  code === RIGHTPARENTHESIS) {
92
- encoded += '\\' + str.charAt(i);
100
+ encoded += str.slice(runStart, i) + '\\' + str.charAt(i);
101
+ runStart = i + 1;
93
102
  wsBeforeHexIsNeeded = false;
94
103
  } else {
95
104
  if (wsBeforeHexIsNeeded && charCodeDefinitions.isHexDigit(code)) {
96
- encoded += ' ';
105
+ encoded += str.slice(runStart, i) + ' ';
106
+ runStart = i;
97
107
  }
98
108
 
99
- encoded += str.charAt(i);
100
109
  wsBeforeHexIsNeeded = false;
101
110
  }
102
111
  }
103
112
 
104
- return 'url(' + encoded + ')';
113
+ return 'url(' + encoded + str.slice(runStart) + ')';
105
114
  }
106
115
 
107
116
  exports.decode = decode;
package/data/patch.json CHANGED
@@ -939,6 +939,9 @@
939
939
  "comment": "missed, https://drafts.csswg.org/css-contain-3/#container-rule",
940
940
  "syntax": "( <style-condition> ) | ( <style-feature> ) | <general-enclosed>"
941
941
  },
942
+ "style-feature": {
943
+ "syntax": "<declaration> | <custom-property-name>"
944
+ },
942
945
  "supports-feature": {
943
946
  "syntax": "<supports-selector-fn> | <supports-font-tech-fn> | <supports-font-format-fn> | <supports-at-rule-fn> | <supports-named-feature-fn> | <supports-env-fn> | <supports-decl>"
944
947
  },