@eslint/css-tree 3.6.6 → 3.6.7

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/version.cjs CHANGED
@@ -1 +1 @@
1
- module.exports = "3.6.6";
1
+ module.exports = "3.6.7";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "3.6.6";
1
+ export const version = "3.6.7";
@@ -66,8 +66,31 @@ function isElementSelectorStart() {
66
66
  }
67
67
 
68
68
  function isSelectorStart() {
69
- return this.tokenType === Delim && selectorStarts.has(this.source.charCodeAt(this.tokenStart)) ||
70
- this.tokenType === Hash || this.tokenType === LeftSquareBracket ||
69
+ // Check for Delim tokens that might be selector starts
70
+ if (this.tokenType === Delim && selectorStarts.has(this.source.charCodeAt(this.tokenStart))) {
71
+ const code = this.source.charCodeAt(this.tokenStart);
72
+
73
+ // Special case: browser hack prefixes (*, +, &) followed immediately by an ident
74
+ // (no whitespace) are declarations, not selectors. Examples: *zoom: 1; +width: 100px; &prop: value;
75
+ if (code === STAR || code === PLUSSIGN || code === AMPERSAND) {
76
+ const nextToken = this.lookupType(1);
77
+ const nextTokenNonSC = this.lookupTypeNonSC(1);
78
+
79
+ // If next token is Ident and there's no whitespace between, it's a declaration
80
+ if (nextToken === Ident && nextTokenNonSC === Ident) {
81
+ return false;
82
+ }
83
+ }
84
+ return true;
85
+ }
86
+
87
+ // Hash can be either a Hash token (#id selector) or Delim(#) + Ident (browser hack)
88
+ // When it's a Hash token, it's a selector. When it's Delim, check if followed by Ident without whitespace
89
+ if (this.tokenType === Hash) {
90
+ return true;
91
+ }
92
+
93
+ return this.tokenType === LeftSquareBracket ||
71
94
  this.tokenType === Colon || isElementSelectorStart.call(this);
72
95
  }
73
96
 
@@ -2,15 +2,71 @@ import {
2
2
  WhiteSpace,
3
3
  Comment,
4
4
  Semicolon,
5
- AtKeyword
5
+ AtKeyword,
6
+ Delim,
7
+ Hash,
8
+ LeftSquareBracket,
9
+ Colon,
10
+ Ident,
11
+ RightCurlyBracket
6
12
  } from '../../tokenizer/index.js';
7
13
 
8
14
  const AMPERSAND = 0x0026; // U+0026 AMPERSAND (&)
15
+ const DOT = 0x002E; // U+002E FULL STOP (.)
16
+ const STAR = 0x002A; // U+002A ASTERISK (*);
17
+ const PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
18
+ const GREATERTHANSIGN = 0x003E; // U+003E GREATER-THAN SIGN (>)
19
+ const TILDE = 0x007E; // U+007E TILDE (~)
20
+
21
+ const selectorStarts = new Set([
22
+ AMPERSAND,
23
+ DOT,
24
+ STAR,
25
+ PLUSSIGN,
26
+ GREATERTHANSIGN,
27
+ TILDE
28
+ ]);
9
29
 
10
30
  function consumeRaw() {
11
31
  return this.Raw(this.consumeUntilSemicolonIncluded, true);
12
32
  }
13
33
 
34
+ function isElementSelectorStart() {
35
+ if (this.tokenType !== Ident) {
36
+ return false;
37
+ }
38
+
39
+ const nextTokenType = this.lookupTypeNonSC(1);
40
+
41
+ // Simple case: if next token is not colon, semicolon, or closing brace, it's likely a selector
42
+ if (nextTokenType !== Colon && nextTokenType !== Semicolon && nextTokenType !== RightCurlyBracket) {
43
+ return true;
44
+ }
45
+
46
+ // Special handling for colon case - could be pseudo-class/pseudo-element
47
+ if (nextTokenType === Colon) {
48
+ // Look ahead further to see what follows the colon
49
+ const afterColonType = this.lookupTypeNonSC(2);
50
+
51
+ // If after colon there's an identifier (pseudo-class/pseudo-element name),
52
+ // check what comes after that
53
+ if (afterColonType === Ident) {
54
+ const afterPseudoType = this.lookupTypeNonSC(3);
55
+ // If it's followed by { or other selector tokens, it's a selector
56
+ // If it's followed by ; or } or EOF, it's not a selector (property)
57
+ return afterPseudoType !== Semicolon && afterPseudoType !== RightCurlyBracket && afterPseudoType !== 0; // 0 is EOF
58
+ }
59
+ }
60
+
61
+ return false;
62
+ }
63
+
64
+ function isSelectorStart() {
65
+ return this.tokenType === Delim && selectorStarts.has(this.source.charCodeAt(this.tokenStart)) ||
66
+ this.tokenType === Hash || this.tokenType === LeftSquareBracket ||
67
+ this.tokenType === Colon || isElementSelectorStart.call(this);
68
+ }
69
+
14
70
  export const name = 'DeclarationList';
15
71
  export const structure = {
16
72
  children: [[
@@ -37,7 +93,7 @@ export function parse() {
37
93
  break;
38
94
 
39
95
  default:
40
- if (this.isDelim(AMPERSAND)) {
96
+ if (isSelectorStart.call(this)) {
41
97
  children.push(this.parseWithFallback(this.Rule, consumeRaw));
42
98
  } else {
43
99
  children.push(this.parseWithFallback(this.Declaration, consumeRaw));
@@ -9,6 +9,20 @@ function eatIdentifierOrAsterisk() {
9
9
  this.error('Identifier or asterisk is expected');
10
10
  }
11
11
 
12
+ // Check if asterisk is followed immediately by an ident (no whitespace)
13
+ // This is invalid in selectors (e.g., "*foo" should error, "* foo" or "*:hover" is ok)
14
+ if (this.isDelim(ASTERISK)) {
15
+ const currentTokenEnd = this.tokenStart + 1; // asterisk is 1 char
16
+ this.next();
17
+
18
+ // If next token is an ident and starts immediately after asterisk, it's an error
19
+ if (this.tokenType === Ident && this.tokenStart === currentTokenEnd) {
20
+ this.error('Whitespace is required between universal selector and type selector');
21
+ }
22
+
23
+ return;
24
+ }
25
+
12
26
  this.next();
13
27
  }
14
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint/css-tree",
3
- "version": "3.6.6",
3
+ "version": "3.6.7",
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",