@eslint/css-tree 4.1.3 → 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
@@ -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
@@ -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.3";
1
+ module.exports = "4.1.4";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "4.1.3";
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
 
@@ -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
@@ -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.3",
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": {