@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/dist/data.cjs CHANGED
@@ -420,7 +420,7 @@ module.exports = {
420
420
  "step-position": "jump-start|jump-end|jump-none|jump-both|start|end",
421
421
  "step-easing-function": "step-start|step-end|<steps()>",
422
422
  "steps()": "steps( <integer> , <step-position>? )",
423
- "style-feature": "<declaration>",
423
+ "style-feature": "<declaration>|<custom-property-name>",
424
424
  "style-in-parens": "( <style-condition> )|( <style-feature> )|<general-enclosed>",
425
425
  "style-query": "<style-condition>|<style-feature>",
426
426
  "subclass-selector": "<id-selector>|<class-selector>|<attribute-selector>|<pseudo-class-selector>",
@@ -819,6 +819,7 @@ module.exports = {
819
819
  "clip-path": "<clip-source>|[<basic-shape>||<geometry-box>]|none",
820
820
  "clip-rule": "nonzero|evenodd",
821
821
  "color": "<color>",
822
+ "color-interpolation": "auto|sRGB|linearRGB|<color-interpolation-method>",
822
823
  "color-interpolation-filters": "auto|sRGB|linearRGB",
823
824
  "color-scheme": "normal|[light|dark|<custom-ident>]+&&only?",
824
825
  "column-count": "<integer>|auto",
@@ -990,7 +991,7 @@ module.exports = {
990
991
  "margin-left": "<length-percentage>|auto|<anchor-size()>",
991
992
  "margin-right": "<length-percentage>|auto|<anchor-size()>",
992
993
  "margin-top": "<length-percentage>|auto|<anchor-size()>",
993
- "margin-trim": "none|in-flow|all",
994
+ "margin-trim": "none|block|[block-start||block-end]",
994
995
  "marker": "none|<url>",
995
996
  "marker-end": "none|<url>",
996
997
  "marker-mid": "none|<url>",
package/dist/data.js CHANGED
@@ -420,7 +420,7 @@ export default {
420
420
  "step-position": "jump-start|jump-end|jump-none|jump-both|start|end",
421
421
  "step-easing-function": "step-start|step-end|<steps()>",
422
422
  "steps()": "steps( <integer> , <step-position>? )",
423
- "style-feature": "<declaration>",
423
+ "style-feature": "<declaration>|<custom-property-name>",
424
424
  "style-in-parens": "( <style-condition> )|( <style-feature> )|<general-enclosed>",
425
425
  "style-query": "<style-condition>|<style-feature>",
426
426
  "subclass-selector": "<id-selector>|<class-selector>|<attribute-selector>|<pseudo-class-selector>",
@@ -819,6 +819,7 @@ export default {
819
819
  "clip-path": "<clip-source>|[<basic-shape>||<geometry-box>]|none",
820
820
  "clip-rule": "nonzero|evenodd",
821
821
  "color": "<color>",
822
+ "color-interpolation": "auto|sRGB|linearRGB|<color-interpolation-method>",
822
823
  "color-interpolation-filters": "auto|sRGB|linearRGB",
823
824
  "color-scheme": "normal|[light|dark|<custom-ident>]+&&only?",
824
825
  "column-count": "<integer>|auto",
@@ -990,7 +991,7 @@ export default {
990
991
  "margin-left": "<length-percentage>|auto|<anchor-size()>",
991
992
  "margin-right": "<length-percentage>|auto|<anchor-size()>",
992
993
  "margin-top": "<length-percentage>|auto|<anchor-size()>",
993
- "margin-trim": "none|in-flow|all",
994
+ "margin-trim": "none|block|[block-start||block-end]",
994
995
  "marker": "none|<url>",
995
996
  "marker-end": "none|<url>",
996
997
  "marker-mid": "none|<url>",
package/dist/version.cjs CHANGED
@@ -1 +1 @@
1
- module.exports = "4.1.2";
1
+ module.exports = "4.1.4";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "4.1.2";
1
+ export const version = "4.1.4";
package/lib/index.d.ts CHANGED
@@ -1224,8 +1224,8 @@ export class TokenStream {
1224
1224
  /**
1225
1225
  * An internal buffer used for storing token information, including type and offset.
1226
1226
  * The 32-bit integer at each index contains two pieces of information:
1227
- * - The starting index (inclusive) of the token within the source string is stored in the lower 24 bits of the 32-bit integer.
1228
- * - The numeric type of the token is stored in the upper 8 bits of the 32-bit integer.
1227
+ * - The ending index (exclusive) of the token within the source string is stored in the lower 27 bits of the 32-bit integer.
1228
+ * - The numeric type of the token is stored in the upper 5 bits of the 32-bit integer.
1229
1229
  */
1230
1230
  readonly offsetAndType: Uint32Array;
1231
1231
 
@@ -5,6 +5,7 @@ import * as node from '../node/index-parse.js';
5
5
  import {
6
6
  Ident,
7
7
  String as StringToken,
8
+ Colon,
8
9
  tokenize
9
10
  } from '../../tokenizer/index.js';
10
11
 
@@ -63,6 +64,10 @@ export default {
63
64
  },
64
65
  container: {
65
66
  style() {
67
+ if (this.tokenType === Ident && this.lookupTypeNonSC(1) !== Colon) {
68
+ return this.Identifier();
69
+ }
70
+
66
71
  return this.Declaration();
67
72
  }
68
73
  }
@@ -6,12 +6,12 @@ import {
6
6
  Hash,
7
7
  Colon,
8
8
  Ident,
9
- Function,
10
9
  AtKeyword,
11
10
  LeftSquareBracket,
12
11
  LeftCurlyBracket,
13
12
  RightCurlyBracket
14
13
  } from '../../tokenizer/index.js';
14
+ import { isCustomProperty } from '../../utils/names.js';
15
15
 
16
16
  const AMPERSAND = 0x0026; // U+0026 AMPERSAND (&)
17
17
  const DOT = 0x002E; // U+002E FULL STOP (.)
@@ -64,43 +64,32 @@ function isElementSelectorStart() {
64
64
  return true;
65
65
  }
66
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
- }
67
+ // Custom property values may contain top-level curly blocks.
68
+ if (isCustomProperty(this.source, this.tokenStart)) {
69
+ return false;
70
+ }
71
+
72
+ // Only top-level delimiters distinguish declarations from nested rules.
73
+ for (let offset = 1; this.tokenIndex + offset < this.tokenCount; offset++) {
74
+ const tokenType = this.lookupType(offset);
75
+
76
+ if (tokenType === LeftCurlyBracket) {
77
+ return true;
100
78
  }
101
79
 
102
- // If we can't determine conclusively, default to property behavior
103
- return false;
80
+ if (tokenType === Semicolon || tokenType === RightCurlyBracket) {
81
+ return false;
82
+ }
83
+
84
+ if (this.isBlockOpenerTokenType(tokenType)) {
85
+ const pairIndex = this.getBlockTokenPairIndex(this.tokenIndex + offset);
86
+
87
+ if (pairIndex === -1) {
88
+ return false;
89
+ }
90
+
91
+ offset = pairIndex - this.tokenIndex;
92
+ }
104
93
  }
105
94
 
106
95
  return false;
@@ -6,6 +6,7 @@ import {
6
6
  RightParenthesis,
7
7
  Function as FunctionToken,
8
8
  Colon,
9
+ Delim,
9
10
  EOF
10
11
  } from '../../tokenizer/index.js';
11
12
 
@@ -24,8 +25,29 @@ export const structure = {
24
25
  };
25
26
 
26
27
  function featureOrRange(kind) {
27
- if (this.lookupTypeNonSC(1) === Ident &&
28
- likelyFeatureToken.has(this.lookupTypeNonSC(2))) {
28
+ const firstToken = this.lookupTypeNonSC(1);
29
+ let secondToken = this.lookupTypeNonSC(2);
30
+
31
+ if (firstToken === FunctionToken) {
32
+ let index = this.getBlockTokenPairIndex(this.tokenIndex + this.lookupOffsetNonSC(1));
33
+
34
+ if (index !== -1) {
35
+ do {
36
+ secondToken = this.getTokenType(++index);
37
+ } while (secondToken === WhiteSpace || secondToken === Comment);
38
+
39
+ if (secondToken !== Delim) {
40
+ return null;
41
+ }
42
+ }
43
+ }
44
+
45
+ if (firstToken === LeftParenthesis ||
46
+ (firstToken === Ident && (secondToken === LeftParenthesis || secondToken === FunctionToken))) {
47
+ return null;
48
+ }
49
+
50
+ if (firstToken === Ident && likelyFeatureToken.has(secondToken)) {
29
51
  return this.Feature(kind);
30
52
  }
31
53
 
@@ -125,4 +147,3 @@ export function generate(node) {
125
147
  }
126
148
  });
127
149
  }
128
-
@@ -74,9 +74,13 @@ export function parse() {
74
74
  }
75
75
  }
76
76
 
77
+ const loc = this.getLocation(start, this.tokenStart);
78
+
79
+ this.skipSC();
80
+
77
81
  return {
78
82
  type: 'MediaQuery',
79
- loc: this.getLocation(start, this.tokenStart),
83
+ loc,
80
84
  modifier,
81
85
  mediaType,
82
86
  condition
@@ -1,3 +1,4 @@
1
+ import { Ident } from '../../tokenizer/index.js';
1
2
  import { parseLanguageRangeList } from './lang.js';
2
3
 
3
4
  const selectorList = {
@@ -24,6 +25,19 @@ const identList = {
24
25
  }
25
26
  };
26
27
 
28
+ const identSequence = {
29
+ parse() {
30
+ const children = this.createList();
31
+
32
+ do {
33
+ children.push(this.Identifier());
34
+ this.skipSC();
35
+ } while (this.tokenType === Ident);
36
+
37
+ return children;
38
+ }
39
+ };
40
+
27
41
  const langList = {
28
42
  parse: parseLanguageRangeList
29
43
  };
@@ -52,5 +66,6 @@ export default {
52
66
  'nth-of-type': nth,
53
67
  'slotted': selector,
54
68
  'host': selector,
55
- 'host-context': selector
69
+ 'host-context': selector,
70
+ 'part': identSequence
56
71
  };
@@ -15,8 +15,8 @@ import {
15
15
  RightCurlyBracket
16
16
  } from './types.js';
17
17
 
18
- const OFFSET_MASK = 0x00FFFFFF;
19
- const TYPE_SHIFT = 24;
18
+ const OFFSET_MASK = 0x07FFFFFF;
19
+ const TYPE_SHIFT = 27;
20
20
  const BLOCK_OPEN_TOKEN = 1;
21
21
  const BLOCK_CLOSE_TOKEN = 2;
22
22
  const balancePair = new Uint8Array(32); // 32b of memory ought to be enough for anyone (any number of tokens)
@@ -53,6 +53,10 @@ export class TokenStream {
53
53
  source = String(source || '');
54
54
 
55
55
  const sourceLength = source.length;
56
+ if (sourceLength > OFFSET_MASK) {
57
+ throw new RangeError('Source exceeds the maximum length of ' + OFFSET_MASK + ' UTF-16 code units');
58
+ }
59
+
56
60
  const offsetAndType = adoptBuffer(this.offsetAndType, source.length + 1); // +1 because of eof-token
57
61
  const balance = adoptBuffer(this.balance, source.length + 1);
58
62
  let tokenCount = 0;
@@ -63,7 +67,7 @@ export class TokenStream {
63
67
  // capture buffers
64
68
  this.offsetAndType = null;
65
69
  this.balance = null;
66
- balance.fill(0);
70
+ balance.fill(0, 0, sourceLength + 1);
67
71
 
68
72
  tokenize(source, (type, start, end) => {
69
73
  const index = tokenCount++;
@@ -86,7 +90,7 @@ export class TokenStream {
86
90
 
87
91
  // pop state
88
92
  balanceStart = prevBalanceStart;
89
- balanceCloseType = balancePair[offsetAndType[prevBalanceStart] >> TYPE_SHIFT];
93
+ balanceCloseType = balancePair[offsetAndType[prevBalanceStart] >>> TYPE_SHIFT];
90
94
  } else if (this.isBlockOpenerTokenType(type)) { // check for FunctionToken, <(-token>, <[-token> and <{-token>
91
95
  // push state
92
96
  balanceStart = index;
@@ -138,14 +142,14 @@ export class TokenStream {
138
142
  offset += this.tokenIndex;
139
143
 
140
144
  if (offset < this.tokenCount) {
141
- return this.offsetAndType[offset] >> TYPE_SHIFT;
145
+ return this.offsetAndType[offset] >>> TYPE_SHIFT;
142
146
  }
143
147
 
144
148
  return EOF;
145
149
  }
146
150
  lookupTypeNonSC(idx) {
147
151
  for (let offset = this.tokenIndex; offset < this.tokenCount; offset++) {
148
- const tokenType = this.offsetAndType[offset] >> TYPE_SHIFT;
152
+ const tokenType = this.offsetAndType[offset] >>> TYPE_SHIFT;
149
153
 
150
154
  if (tokenType !== WhiteSpace && tokenType !== Comment) {
151
155
  if (idx-- === 0) {
@@ -167,7 +171,7 @@ export class TokenStream {
167
171
  }
168
172
  lookupOffsetNonSC(idx) {
169
173
  for (let offset = this.tokenIndex; offset < this.tokenCount; offset++) {
170
- const tokenType = this.offsetAndType[offset] >> TYPE_SHIFT;
174
+ const tokenType = this.offsetAndType[offset] >>> TYPE_SHIFT;
171
175
 
172
176
  if (tokenType !== WhiteSpace && tokenType !== Comment) {
173
177
  if (idx-- === 0) {
@@ -217,7 +221,7 @@ export class TokenStream {
217
221
  return this.tokenType;
218
222
  }
219
223
 
220
- return this.offsetAndType[boundIndex(tokenIndex, 0, this.tokenCount)] >> TYPE_SHIFT;
224
+ return this.offsetAndType[boundIndex(tokenIndex, 0, this.tokenCount)] >>> TYPE_SHIFT;
221
225
  }
222
226
  substrToCursor(start) {
223
227
  return this.source.substring(start, this.tokenStart);
@@ -273,7 +277,7 @@ export class TokenStream {
273
277
  this.tokenIndex = next;
274
278
  this.tokenStart = this.offsetAndType[next - 1] & OFFSET_MASK;
275
279
  next = this.offsetAndType[next];
276
- this.tokenType = next >> TYPE_SHIFT;
280
+ this.tokenType = next >>> TYPE_SHIFT;
277
281
  this.tokenEnd = next & OFFSET_MASK;
278
282
  } else {
279
283
  this.tokenIndex = this.tokenCount;
@@ -287,7 +291,7 @@ export class TokenStream {
287
291
  this.tokenIndex = next;
288
292
  this.tokenStart = this.tokenEnd;
289
293
  next = this.offsetAndType[next];
290
- this.tokenType = next >> TYPE_SHIFT;
294
+ this.tokenType = next >>> TYPE_SHIFT;
291
295
  this.tokenEnd = next & OFFSET_MASK;
292
296
  } else {
293
297
  this.eof = true;
@@ -328,7 +332,7 @@ export class TokenStream {
328
332
 
329
333
  default:
330
334
  // fast forward to the end of balanced block for an open block tokens
331
- if (this.isBlockOpenerTokenType(this.offsetAndType[cursor] >> TYPE_SHIFT)) {
335
+ if (this.isBlockOpenerTokenType(this.offsetAndType[cursor] >>> TYPE_SHIFT)) {
332
336
  cursor = balanceEnd;
333
337
  }
334
338
  }
@@ -342,7 +346,7 @@ export class TokenStream {
342
346
  const start = offset;
343
347
  const item = this.offsetAndType[i];
344
348
  const end = item & OFFSET_MASK;
345
- const type = item >> TYPE_SHIFT;
349
+ const type = item >>> TYPE_SHIFT;
346
350
 
347
351
  offset = end;
348
352
 
@@ -222,7 +222,7 @@ export function consumeBadUrlRemnants(source, offset) {
222
222
  // Note: This allows an escaped right parenthesis ("\)") to be encountered
223
223
  // without ending the <bad-url-token>. This is otherwise identical to
224
224
  // the "anything else" clause.
225
- offset = consumeEscaped(source, offset);
225
+ offset = consumeEscaped(source, offset) - 1;
226
226
  }
227
227
  }
228
228
 
package/lib/utils/url.js CHANGED
@@ -27,10 +27,14 @@ export function decode(str) {
27
27
  end--;
28
28
  }
29
29
 
30
+ let runStart = start;
31
+
30
32
  for (let i = start; i <= end; i++) {
31
33
  let code = str.charCodeAt(i);
32
34
 
33
35
  if (code === REVERSE_SOLIDUS) {
36
+ decoded += str.slice(runStart, i);
37
+
34
38
  // special case at the ending
35
39
  if (i === end) {
36
40
  // if the next input code point is EOF, do nothing
@@ -38,7 +42,7 @@ export function decode(str) {
38
42
  if (i !== len - 1) {
39
43
  decoded = str.substr(i + 1);
40
44
  }
41
- break;
45
+ return decoded;
42
46
  }
43
47
 
44
48
  code = str.charCodeAt(++i);
@@ -50,22 +54,24 @@ export function decode(str) {
50
54
 
51
55
  i = escapeEnd - 1;
52
56
  decoded += decodeEscaped(str.substring(escapeStart + 1, escapeEnd));
57
+ runStart = escapeEnd;
53
58
  } else {
54
59
  // \r\n
55
60
  if (code === 0x000d && str.charCodeAt(i + 1) === 0x000a) {
56
61
  i++;
57
62
  }
63
+
64
+ runStart = i + 1;
58
65
  }
59
- } else {
60
- decoded += str[i];
61
66
  }
62
67
  }
63
68
 
64
- return decoded;
69
+ return decoded + str.slice(runStart, end + 1);
65
70
  }
66
71
 
67
72
  export function encode(str) {
68
73
  let encoded = '';
74
+ let runStart = 0;
69
75
  let wsBeforeHexIsNeeded = false;
70
76
 
71
77
  for (let i = 0; i < str.length; i++) {
@@ -73,7 +79,8 @@ export function encode(str) {
73
79
 
74
80
  // If the character is NULL (U+0000), then the REPLACEMENT CHARACTER (U+FFFD).
75
81
  if (code === 0x0000) {
76
- encoded += '\uFFFD';
82
+ encoded += str.slice(runStart, i) + '\uFFFD';
83
+ runStart = i + 1;
77
84
  continue;
78
85
  }
79
86
 
@@ -81,7 +88,8 @@ export function encode(str) {
81
88
  // the character escaped as code point.
82
89
  // Note: Do not compare with 0x0001 since 0x0000 is precessed before
83
90
  if (code <= 0x001f || code === 0x007F) {
84
- encoded += '\\' + code.toString(16);
91
+ encoded += str.slice(runStart, i) + '\\' + code.toString(16);
92
+ runStart = i + 1;
85
93
  wsBeforeHexIsNeeded = true;
86
94
  continue;
87
95
  }
@@ -92,17 +100,18 @@ export function encode(str) {
92
100
  code === APOSTROPHE ||
93
101
  code === LEFTPARENTHESIS ||
94
102
  code === RIGHTPARENTHESIS) {
95
- encoded += '\\' + str.charAt(i);
103
+ encoded += str.slice(runStart, i) + '\\' + str.charAt(i);
104
+ runStart = i + 1;
96
105
  wsBeforeHexIsNeeded = false;
97
106
  } else {
98
107
  if (wsBeforeHexIsNeeded && isHexDigit(code)) {
99
- encoded += ' ';
108
+ encoded += str.slice(runStart, i) + ' ';
109
+ runStart = i;
100
110
  }
101
111
 
102
- encoded += str.charAt(i);
103
112
  wsBeforeHexIsNeeded = false;
104
113
  }
105
114
  }
106
115
 
107
- return 'url(' + encoded + ')';
116
+ return 'url(' + encoded + str.slice(runStart) + ')';
108
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint/css-tree",
3
- "version": "4.1.2",
3
+ "version": "4.1.4",
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",
@@ -111,7 +111,7 @@
111
111
  "fsevents": false
112
112
  },
113
113
  "dependencies": {
114
- "mdn-data": "2.37.2",
114
+ "mdn-data": "2.38.1",
115
115
  "source-map-js": "^1.2.1"
116
116
  },
117
117
  "devDependencies": {