@eslint/css-tree 3.3.3 → 3.4.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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const index = require('../tokenizer/index.cjs');
3
+ const getTokenizer = require('../utils/get-tokenizer.cjs');
4
4
  const sourceMap = require('./sourceMap.cjs');
5
5
  const tokenBefore = require('./token-before.cjs');
6
6
  const types = require('../tokenizer/types.cjs');
@@ -26,12 +26,6 @@ function processChildren(node, delimeter) {
26
26
  node.children.forEach(this.node, this);
27
27
  }
28
28
 
29
- function processChunk(chunk) {
30
- index.tokenize(chunk, (type, start, end) => {
31
- this.token(type, chunk.slice(start, end));
32
- });
33
- }
34
-
35
29
  function createGenerator(config) {
36
30
  const types$1 = new Map();
37
31
 
@@ -90,7 +84,13 @@ function createGenerator(config) {
90
84
  node: (node) => handlers.node(node),
91
85
  children: processChildren,
92
86
  token: (type, value) => handlers.token(type, value),
93
- tokenize: processChunk
87
+ tokenize: function (chunk) {
88
+ const tokenize = getTokenizer.getTokenizer(config);
89
+
90
+ return tokenize(chunk, (type, start, end) => {
91
+ this.token(type, chunk.slice(start, end));
92
+ });
93
+ }
94
94
  };
95
95
 
96
96
  handlers.node(node);
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const index = require('../tokenizer/index.cjs');
3
+ const getTokenizer = require('../utils/get-tokenizer.cjs');
4
4
 
5
5
  const astToTokens = {
6
6
  decorator(handlers) {
@@ -29,10 +29,11 @@ const astToTokens = {
29
29
  }
30
30
  };
31
31
 
32
- function stringToTokens(str) {
32
+ function stringToTokens(str, syntax) {
33
33
  const tokens = [];
34
+ const tokenize = getTokenizer.getTokenizer(syntax);
34
35
 
35
- index.tokenize(str, (type, start, end) =>
36
+ tokenize(str, (type, start, end) =>
36
37
  tokens.push({
37
38
  type,
38
39
  value: str.slice(start, end),
@@ -45,7 +46,7 @@ function stringToTokens(str) {
45
46
 
46
47
  function prepareTokens(value, syntax) {
47
48
  if (typeof value === 'string') {
48
- return stringToTokens(value);
49
+ return stringToTokens(value, syntax);
49
50
  }
50
51
 
51
52
  return syntax.generate(value, astToTokens);
@@ -2,8 +2,8 @@
2
2
 
3
3
  const List = require('../utils/List.cjs');
4
4
  const SyntaxError = require('./SyntaxError.cjs');
5
- const index = require('../tokenizer/index.cjs');
6
5
  const sequence = require('./sequence.cjs');
6
+ const getTokenizer = require('../utils/get-tokenizer.cjs');
7
7
  const OffsetToLocation = require('../tokenizer/OffsetToLocation.cjs');
8
8
  const TokenStream = require('../tokenizer/TokenStream.cjs');
9
9
  const utils = require('../tokenizer/utils.cjs');
@@ -45,7 +45,8 @@ function processConfig(config) {
45
45
  scope: Object.assign(Object.create(null), config.scope),
46
46
  atrule: fetchParseValues(config.atrule),
47
47
  pseudo: fetchParseValues(config.pseudo),
48
- node: fetchParseValues(config.node)
48
+ node: fetchParseValues(config.node),
49
+ tokenize: getTokenizer.getTokenizer(config)
49
50
  };
50
51
 
51
52
  for (const [name, context] of Object.entries(config.parseContext)) {
@@ -315,7 +316,7 @@ function createParser(config) {
315
316
  source = source_;
316
317
  options = options || {};
317
318
 
318
- parser.setSource(source, index.tokenize);
319
+ parser.setSource(source, parser.tokenize);
319
320
  locationMap.setSource(
320
321
  source,
321
322
  options.offset,
@@ -117,6 +117,12 @@ function mix(dest, src) {
117
117
  case 'node':
118
118
  result[prop] = mergeDicts(dest[prop], value, ['name', 'structure', 'parse', 'generate', 'walkContext']);
119
119
  break;
120
+
121
+ case 'tokenize':
122
+ if (typeof value === 'function') {
123
+ result[prop] = value;
124
+ }
125
+ break;
120
126
  }
121
127
  }
122
128
 
@@ -4,6 +4,7 @@ const index = require('../scope/index.cjs');
4
4
  const index$1 = require('../atrule/index.cjs');
5
5
  const index$2 = require('../pseudo/index.cjs');
6
6
  const indexParse = require('../node/index-parse.cjs');
7
+ const index$3 = require('../../tokenizer/index.cjs');
7
8
 
8
9
  const config = {
9
10
  parseContext: {
@@ -43,7 +44,8 @@ const config = {
43
44
  scope: index,
44
45
  atrule: index$1,
45
46
  pseudo: index$2,
46
- node: indexParse
47
+ node: indexParse,
48
+ tokenize: index$3.tokenize
47
49
  };
48
50
 
49
51
  module.exports = config;
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
- const index = require('../tokenizer/index.cjs');
4
3
  const create = require('../parser/create.cjs');
5
4
  const create$2 = require('../generator/create.cjs');
6
5
  const create$3 = require('../convertor/create.cjs');
7
6
  const create$1 = require('../walker/create.cjs');
8
7
  const Lexer = require('../lexer/Lexer.cjs');
9
8
  const mix = require('./config/mix.cjs');
9
+ const getTokenizer = require('../utils/get-tokenizer.cjs');
10
10
 
11
11
  function createSyntax(config) {
12
12
  const parse = create.createParser(config);
@@ -18,7 +18,7 @@ function createSyntax(config) {
18
18
  lexer: null,
19
19
  createLexer: config => new Lexer.Lexer(config, syntax, syntax.lexer.structure),
20
20
 
21
- tokenize: index.tokenize,
21
+ tokenize: getTokenizer.getTokenizer(config),
22
22
  parse,
23
23
  generate,
24
24
 
@@ -3,7 +3,7 @@
3
3
  const types = require('../../tokenizer/types.cjs');
4
4
 
5
5
  const name = 'CDC';
6
- const structure = [];
6
+ const structure = {};
7
7
 
8
8
  function parse() {
9
9
  const start = this.tokenStart;
@@ -3,7 +3,7 @@
3
3
  const types = require('../../tokenizer/types.cjs');
4
4
 
5
5
  const name = 'CDO';
6
- const structure = [];
6
+ const structure = {};
7
7
 
8
8
  function parse() {
9
9
  const start = this.tokenStart;
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const index = require('../tokenizer/index.cjs');
4
+
5
+ const FUNCTION_TYPE = 'function';
6
+
7
+ /**
8
+ * Gets the tokenizer function from the configuration object or returns the default tokenizer
9
+ *
10
+ * @param config Configuration object
11
+ * @returns Corresponding tokenizer function
12
+ */
13
+ function getTokenizer(config) {
14
+ if (config && typeof config.tokenize === FUNCTION_TYPE) {
15
+ return config.tokenize;
16
+ }
17
+
18
+ // Fallback to the default tokenizer
19
+ return index.tokenize;
20
+ }
21
+
22
+ exports.getTokenizer = getTokenizer;
package/data/patch.json CHANGED
@@ -55,6 +55,10 @@
55
55
  }
56
56
  },
57
57
  "properties": {
58
+ "-moz-background-clip": {
59
+ "comment": "deprecated syntax in old Firefox, https://developer.mozilla.org/en/docs/Web/CSS/background-clip",
60
+ "syntax": "padding | border"
61
+ },
58
62
  "-moz-border-radius-bottomleft": {
59
63
  "comment": "https://developer.mozilla.org/en-US/docs/Web/CSS/border-bottom-left-radius",
60
64
  "syntax": "<'border-bottom-left-radius'>"
@@ -138,6 +142,10 @@
138
142
  ],
139
143
  "syntax": "none | button | button-bevel | caps-lock-indicator | caret | checkbox | default-button | inner-spin-button | listbox | listitem | media-controls-background | media-controls-fullscreen-background | media-current-time-display | media-enter-fullscreen-button | media-exit-fullscreen-button | media-fullscreen-button | media-mute-button | media-overlay-play-button | media-play-button | media-seek-back-button | media-seek-forward-button | media-slider | media-sliderthumb | media-time-remaining-display | media-toggle-closed-captions-button | media-volume-slider | media-volume-slider-container | media-volume-sliderthumb | menulist | menulist-button | menulist-text | menulist-textfield | meter | progress-bar | progress-bar-value | push-button | radio | scrollbarbutton-down | scrollbarbutton-left | scrollbarbutton-right | scrollbarbutton-up | scrollbargripper-horizontal | scrollbargripper-vertical | scrollbarthumb-horizontal | scrollbarthumb-vertical | scrollbartrack-horizontal | scrollbartrack-vertical | searchfield | searchfield-cancel-button | searchfield-decoration | searchfield-results-button | searchfield-results-decoration | slider-horizontal | slider-vertical | sliderthumb-horizontal | sliderthumb-vertical | square-button | textarea | textfield | -apple-pay-button"
140
144
  },
145
+ "-webkit-background-clip": {
146
+ "comment": "https://developer.mozilla.org/en/docs/Web/CSS/background-clip",
147
+ "syntax": "[ <visual-box> | border | padding | content | text ]#"
148
+ },
141
149
  "-webkit-column-break-after": {
142
150
  "comment": "added, http://help.dottoro.com/lcrthhhv.php",
143
151
  "syntax": "always | auto | avoid"
@@ -542,14 +550,6 @@
542
550
  "comment": "https://developer.mozilla.org/en-US/docs/Web/CSS/-ms-filter",
543
551
  "syntax": "<ident-token> | <function-token> <any-value>? )"
544
552
  },
545
- "absolute-color-base": {
546
- "comment": "https://www.w3.org/TR/css-color-4/#color-syntax",
547
- "syntax": "<hex-color> | <absolute-color-function> | <named-color> | transparent"
548
- },
549
- "absolute-color-function": {
550
- "comment": "https://www.w3.org/TR/css-color-4/#color-syntax",
551
- "syntax": "<rgb()> | <rgba()> | <hsl()> | <hsla()> | <hwb()> | <lab()> | <lch()> | <oklab()> | <oklch()> | <color()>"
552
- },
553
553
  "age": {
554
554
  "comment": "https://www.w3.org/TR/css3-speech/#voice-family",
555
555
  "syntax": "child | young | old"
@@ -568,10 +568,6 @@
568
568
  "comment": "added attr(), see https://github.com/csstree/csstree/issues/201",
569
569
  "syntax": "[ <string> | contents | <image> | <counter> | <quote> | <target> | <leader()> | <attr()> ]+"
570
570
  },
571
- "container-name": {
572
- "comment": "missed, https://drafts.csswg.org/css-contain-3/#container-rule",
573
- "syntax": "<custom-ident>"
574
- },
575
571
  "container-condition": {
576
572
  "comment": "missed, https://drafts.csswg.org/css-contain-3/#container-rule",
577
573
  "syntax": "not <query-in-parens> | <query-in-parens> [ [ and <query-in-parens> ]* | [ or <query-in-parens> ]* ]"
@@ -606,12 +602,6 @@
606
602
  "generic-script-specific": {
607
603
  "syntax": "generic(kai) | generic(fangsong) | generic(nastaliq)"
608
604
  },
609
- "generic-complete": {
610
- "syntax": "serif | sans-serif | system-ui | cursive | fantasy | math | monospace"
611
- },
612
- "generic-incomplete": {
613
- "syntax": "ui-serif | ui-sans-serif | ui-monospace | ui-rounded"
614
- },
615
605
  "-non-standard-generic-family": {
616
606
  "syntax": "-apple-system | BlinkMacSystemFont",
617
607
  "references": [
@@ -777,9 +767,6 @@
777
767
  "xyz-space": {
778
768
  "syntax": "xyz | xyz-d50 | xyz-d65"
779
769
  },
780
- "basic-shape": {
781
- "syntax": "<inset()> | <xywh()> | <rect()> | <circle()> | <ellipse()> | <polygon()> | <path()>"
782
- },
783
770
  "query-in-parens": {
784
771
  "comment": "missed, https://drafts.csswg.org/css-contain-3/#container-rule",
785
772
  "syntax": "( <container-condition> ) | ( <size-feature> ) | style( <style-query> ) | <general-enclosed>"
@@ -788,10 +775,6 @@
788
775
  "comment": "missed, https://drafts.csswg.org/css-contain-3/#typedef-size-feature",
789
776
  "syntax": "<mf-plain> | <mf-boolean> | <mf-range>"
790
777
  },
791
- "style-feature": {
792
- "comment": "missed, https://drafts.csswg.org/css-contain-3/#typedef-style-feature",
793
- "syntax": "<declaration>"
794
- },
795
778
  "style-query": {
796
779
  "comment": "missed, https://drafts.csswg.org/css-contain-3/#container-rule",
797
780
  "syntax": "<style-condition> | <style-feature>"
@@ -821,24 +804,6 @@
821
804
  "https://drafts.csswg.org/css-anchor-position-1/#typedef-position-area"
822
805
  ]
823
806
  },
824
- "anchor()": {
825
- "syntax": "anchor( <anchor-element>? && <anchor-side>, <length-percentage>? )",
826
- "comment": "missed",
827
- "references": [
828
- "https://drafts.csswg.org/css-anchor-position-1/#anchor-pos"
829
- ]
830
- },
831
- "anchor-size()": {
832
- "syntax": "anchor-size( [ <anchor-element> || <anchor-size> ]? , <length-percentage>? )",
833
- "comment": "missed",
834
- "references": [
835
- "https://drafts.csswg.org/css-anchor-position-1/#funcdef-anchor-size"
836
- ]
837
- },
838
- "anchor-element": {
839
- "syntax": "<dashed-ident>",
840
- "comment": "missed, https://drafts.csswg.org/css-anchor-position-1/#typedef-anchor-element"
841
- },
842
807
  "font-variant-css2": {
843
808
  "syntax": "normal | small-caps",
844
809
  "comment": "new definition on font-4, https://drafts.csswg.org/css-fonts-4/#font-variant-css21-values"