@eslint/css-tree 3.2.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.
Files changed (279) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +194 -0
  3. package/cjs/convertor/create.cjs +32 -0
  4. package/cjs/convertor/index.cjs +8 -0
  5. package/cjs/data-patch.cjs +7 -0
  6. package/cjs/data.cjs +120 -0
  7. package/cjs/definition-syntax/SyntaxError.cjs +16 -0
  8. package/cjs/definition-syntax/generate.cjs +139 -0
  9. package/cjs/definition-syntax/index.cjs +13 -0
  10. package/cjs/definition-syntax/parse.cjs +556 -0
  11. package/cjs/definition-syntax/scanner.cjs +113 -0
  12. package/cjs/definition-syntax/walk.cjs +57 -0
  13. package/cjs/generator/create.cjs +102 -0
  14. package/cjs/generator/index.cjs +8 -0
  15. package/cjs/generator/sourceMap.cjs +96 -0
  16. package/cjs/generator/token-before.cjs +170 -0
  17. package/cjs/index.cjs +65 -0
  18. package/cjs/lexer/Lexer.cjs +517 -0
  19. package/cjs/lexer/error.cjs +128 -0
  20. package/cjs/lexer/generic-an-plus-b.cjs +235 -0
  21. package/cjs/lexer/generic-const.cjs +12 -0
  22. package/cjs/lexer/generic-urange.cjs +149 -0
  23. package/cjs/lexer/generic.cjs +589 -0
  24. package/cjs/lexer/index.cjs +7 -0
  25. package/cjs/lexer/match-graph.cjs +530 -0
  26. package/cjs/lexer/match.cjs +632 -0
  27. package/cjs/lexer/prepare-tokens.cjs +54 -0
  28. package/cjs/lexer/search.cjs +65 -0
  29. package/cjs/lexer/structure.cjs +173 -0
  30. package/cjs/lexer/trace.cjs +73 -0
  31. package/cjs/lexer/units.cjs +38 -0
  32. package/cjs/parser/SyntaxError.cjs +74 -0
  33. package/cjs/parser/create.cjs +378 -0
  34. package/cjs/parser/index.cjs +8 -0
  35. package/cjs/parser/parse-selector.cjs +8 -0
  36. package/cjs/parser/sequence.cjs +47 -0
  37. package/cjs/syntax/atrule/container.cjs +32 -0
  38. package/cjs/syntax/atrule/font-face.cjs +12 -0
  39. package/cjs/syntax/atrule/import.cjs +101 -0
  40. package/cjs/syntax/atrule/index.cjs +27 -0
  41. package/cjs/syntax/atrule/layer.cjs +16 -0
  42. package/cjs/syntax/atrule/media.cjs +16 -0
  43. package/cjs/syntax/atrule/nest.cjs +16 -0
  44. package/cjs/syntax/atrule/page.cjs +16 -0
  45. package/cjs/syntax/atrule/scope.cjs +16 -0
  46. package/cjs/syntax/atrule/starting-style.cjs +12 -0
  47. package/cjs/syntax/atrule/supports.cjs +16 -0
  48. package/cjs/syntax/config/generator.cjs +9 -0
  49. package/cjs/syntax/config/lexer.cjs +14 -0
  50. package/cjs/syntax/config/mix.cjs +126 -0
  51. package/cjs/syntax/config/parser-selector.cjs +19 -0
  52. package/cjs/syntax/config/parser.cjs +49 -0
  53. package/cjs/syntax/config/walker.cjs +9 -0
  54. package/cjs/syntax/create.cjs +58 -0
  55. package/cjs/syntax/function/expression.cjs +11 -0
  56. package/cjs/syntax/function/var.cjs +43 -0
  57. package/cjs/syntax/index.cjs +14 -0
  58. package/cjs/syntax/node/AnPlusB.cjs +293 -0
  59. package/cjs/syntax/node/Atrule.cjs +103 -0
  60. package/cjs/syntax/node/AtrulePrelude.cjs +52 -0
  61. package/cjs/syntax/node/AttributeSelector.cjs +148 -0
  62. package/cjs/syntax/node/Block.cjs +96 -0
  63. package/cjs/syntax/node/Brackets.cjs +38 -0
  64. package/cjs/syntax/node/CDC.cjs +26 -0
  65. package/cjs/syntax/node/CDO.cjs +26 -0
  66. package/cjs/syntax/node/ClassSelector.cjs +31 -0
  67. package/cjs/syntax/node/Combinator.cjs +61 -0
  68. package/cjs/syntax/node/Comment.cjs +40 -0
  69. package/cjs/syntax/node/Condition.cjs +120 -0
  70. package/cjs/syntax/node/Declaration.cjs +166 -0
  71. package/cjs/syntax/node/DeclarationList.cjs +62 -0
  72. package/cjs/syntax/node/Dimension.cjs +30 -0
  73. package/cjs/syntax/node/Feature.cjs +101 -0
  74. package/cjs/syntax/node/FeatureFunction.cjs +67 -0
  75. package/cjs/syntax/node/FeatureRange.cjs +133 -0
  76. package/cjs/syntax/node/Function.cjs +45 -0
  77. package/cjs/syntax/node/GeneralEnclosed.cjs +68 -0
  78. package/cjs/syntax/node/Hash.cjs +30 -0
  79. package/cjs/syntax/node/IdSelector.cjs +33 -0
  80. package/cjs/syntax/node/Identifier.cjs +25 -0
  81. package/cjs/syntax/node/Layer.cjs +35 -0
  82. package/cjs/syntax/node/LayerList.cjs +43 -0
  83. package/cjs/syntax/node/MediaQuery.cjs +100 -0
  84. package/cjs/syntax/node/MediaQueryList.cjs +41 -0
  85. package/cjs/syntax/node/NestingSelector.cjs +29 -0
  86. package/cjs/syntax/node/Nth.cjs +54 -0
  87. package/cjs/syntax/node/Number.cjs +25 -0
  88. package/cjs/syntax/node/Operator.cjs +28 -0
  89. package/cjs/syntax/node/Parentheses.cjs +38 -0
  90. package/cjs/syntax/node/Percentage.cjs +25 -0
  91. package/cjs/syntax/node/PseudoClassSelector.cjs +67 -0
  92. package/cjs/syntax/node/PseudoElementSelector.cjs +69 -0
  93. package/cjs/syntax/node/Ratio.cjs +71 -0
  94. package/cjs/syntax/node/Raw.cjs +48 -0
  95. package/cjs/syntax/node/Rule.cjs +58 -0
  96. package/cjs/syntax/node/Scope.cjs +69 -0
  97. package/cjs/syntax/node/Selector.cjs +38 -0
  98. package/cjs/syntax/node/SelectorList.cjs +43 -0
  99. package/cjs/syntax/node/String.cjs +26 -0
  100. package/cjs/syntax/node/StyleSheet.cjs +83 -0
  101. package/cjs/syntax/node/SupportsDeclaration.cjs +38 -0
  102. package/cjs/syntax/node/TypeSelector.cjs +59 -0
  103. package/cjs/syntax/node/UnicodeRange.cjs +158 -0
  104. package/cjs/syntax/node/Url.cjs +54 -0
  105. package/cjs/syntax/node/Value.cjs +26 -0
  106. package/cjs/syntax/node/WhiteSpace.cjs +34 -0
  107. package/cjs/syntax/node/index-generate.cjs +103 -0
  108. package/cjs/syntax/node/index-parse-selector.cjs +39 -0
  109. package/cjs/syntax/node/index-parse.cjs +103 -0
  110. package/cjs/syntax/node/index.cjs +103 -0
  111. package/cjs/syntax/pseudo/index.cjs +60 -0
  112. package/cjs/syntax/pseudo/lang.cjs +37 -0
  113. package/cjs/syntax/scope/atrulePrelude.cjs +9 -0
  114. package/cjs/syntax/scope/default.cjs +76 -0
  115. package/cjs/syntax/scope/index.cjs +11 -0
  116. package/cjs/syntax/scope/selector.cjs +88 -0
  117. package/cjs/syntax/scope/value.cjs +29 -0
  118. package/cjs/tokenizer/OffsetToLocation.cjs +91 -0
  119. package/cjs/tokenizer/TokenStream.cjs +358 -0
  120. package/cjs/tokenizer/adopt-buffer.cjs +13 -0
  121. package/cjs/tokenizer/char-code-definitions.cjs +236 -0
  122. package/cjs/tokenizer/index.cjs +554 -0
  123. package/cjs/tokenizer/names.cjs +32 -0
  124. package/cjs/tokenizer/types.cjs +57 -0
  125. package/cjs/tokenizer/utils.cjs +261 -0
  126. package/cjs/utils/List.cjs +473 -0
  127. package/cjs/utils/clone.cjs +25 -0
  128. package/cjs/utils/create-custom-error.cjs +18 -0
  129. package/cjs/utils/ident.cjs +102 -0
  130. package/cjs/utils/index.cjs +20 -0
  131. package/cjs/utils/names.cjs +113 -0
  132. package/cjs/utils/string.cjs +99 -0
  133. package/cjs/utils/url.cjs +108 -0
  134. package/cjs/version.cjs +5 -0
  135. package/cjs/walker/create.cjs +291 -0
  136. package/cjs/walker/index.cjs +8 -0
  137. package/data/patch.json +874 -0
  138. package/dist/csstree.esm.js +12 -0
  139. package/dist/csstree.js +12 -0
  140. package/dist/data.cjs +1341 -0
  141. package/dist/data.js +1341 -0
  142. package/dist/version.cjs +1 -0
  143. package/dist/version.js +1 -0
  144. package/lib/convertor/create.js +28 -0
  145. package/lib/convertor/index.js +4 -0
  146. package/lib/data-patch.js +6 -0
  147. package/lib/data.js +118 -0
  148. package/lib/definition-syntax/SyntaxError.js +12 -0
  149. package/lib/definition-syntax/generate.js +135 -0
  150. package/lib/definition-syntax/index.js +4 -0
  151. package/lib/definition-syntax/parse.js +552 -0
  152. package/lib/definition-syntax/scanner.js +109 -0
  153. package/lib/definition-syntax/walk.js +53 -0
  154. package/lib/generator/create.js +97 -0
  155. package/lib/generator/index.js +4 -0
  156. package/lib/generator/sourceMap.js +92 -0
  157. package/lib/generator/token-before.js +182 -0
  158. package/lib/index.d.ts +3016 -0
  159. package/lib/index.js +30 -0
  160. package/lib/lexer/Lexer.js +511 -0
  161. package/lib/lexer/error.js +123 -0
  162. package/lib/lexer/generic-an-plus-b.js +238 -0
  163. package/lib/lexer/generic-const.js +8 -0
  164. package/lib/lexer/generic-urange.js +151 -0
  165. package/lib/lexer/generic.js +622 -0
  166. package/lib/lexer/index.js +1 -0
  167. package/lib/lexer/match-graph.js +527 -0
  168. package/lib/lexer/match.js +630 -0
  169. package/lib/lexer/prepare-tokens.js +50 -0
  170. package/lib/lexer/search.js +61 -0
  171. package/lib/lexer/structure.js +169 -0
  172. package/lib/lexer/trace.js +66 -0
  173. package/lib/lexer/units.js +27 -0
  174. package/lib/parser/SyntaxError.js +70 -0
  175. package/lib/parser/create.js +388 -0
  176. package/lib/parser/index.js +4 -0
  177. package/lib/parser/parse-selector.js +4 -0
  178. package/lib/parser/sequence.js +43 -0
  179. package/lib/syntax/atrule/container.js +28 -0
  180. package/lib/syntax/atrule/font-face.js +8 -0
  181. package/lib/syntax/atrule/import.js +104 -0
  182. package/lib/syntax/atrule/index.js +23 -0
  183. package/lib/syntax/atrule/layer.js +12 -0
  184. package/lib/syntax/atrule/media.js +12 -0
  185. package/lib/syntax/atrule/nest.js +12 -0
  186. package/lib/syntax/atrule/page.js +12 -0
  187. package/lib/syntax/atrule/scope.js +12 -0
  188. package/lib/syntax/atrule/starting-style.js +8 -0
  189. package/lib/syntax/atrule/supports.js +12 -0
  190. package/lib/syntax/config/generator.js +5 -0
  191. package/lib/syntax/config/lexer.js +10 -0
  192. package/lib/syntax/config/mix.js +122 -0
  193. package/lib/syntax/config/parser-selector.js +15 -0
  194. package/lib/syntax/config/parser.js +45 -0
  195. package/lib/syntax/config/walker.js +5 -0
  196. package/lib/syntax/create.js +55 -0
  197. package/lib/syntax/function/expression.js +7 -0
  198. package/lib/syntax/function/var.js +39 -0
  199. package/lib/syntax/index.js +10 -0
  200. package/lib/syntax/node/AnPlusB.js +292 -0
  201. package/lib/syntax/node/Atrule.js +100 -0
  202. package/lib/syntax/node/AtrulePrelude.js +47 -0
  203. package/lib/syntax/node/AttributeSelector.js +147 -0
  204. package/lib/syntax/node/Block.js +95 -0
  205. package/lib/syntax/node/Brackets.js +35 -0
  206. package/lib/syntax/node/CDC.js +19 -0
  207. package/lib/syntax/node/CDO.js +19 -0
  208. package/lib/syntax/node/ClassSelector.js +24 -0
  209. package/lib/syntax/node/Combinator.js +54 -0
  210. package/lib/syntax/node/Comment.js +33 -0
  211. package/lib/syntax/node/Condition.js +123 -0
  212. package/lib/syntax/node/Declaration.js +165 -0
  213. package/lib/syntax/node/DeclarationList.js +62 -0
  214. package/lib/syntax/node/Dimension.js +23 -0
  215. package/lib/syntax/node/Feature.js +103 -0
  216. package/lib/syntax/node/FeatureFunction.js +63 -0
  217. package/lib/syntax/node/FeatureRange.js +133 -0
  218. package/lib/syntax/node/Function.js +41 -0
  219. package/lib/syntax/node/GeneralEnclosed.js +66 -0
  220. package/lib/syntax/node/Hash.js +23 -0
  221. package/lib/syntax/node/IdSelector.js +26 -0
  222. package/lib/syntax/node/Identifier.js +18 -0
  223. package/lib/syntax/node/Layer.js +28 -0
  224. package/lib/syntax/node/LayerList.js +36 -0
  225. package/lib/syntax/node/MediaQuery.js +102 -0
  226. package/lib/syntax/node/MediaQueryList.js +34 -0
  227. package/lib/syntax/node/NestingSelector.js +22 -0
  228. package/lib/syntax/node/Nth.js +47 -0
  229. package/lib/syntax/node/Number.js +18 -0
  230. package/lib/syntax/node/Operator.js +21 -0
  231. package/lib/syntax/node/Parentheses.js +34 -0
  232. package/lib/syntax/node/Percentage.js +18 -0
  233. package/lib/syntax/node/PseudoClassSelector.js +65 -0
  234. package/lib/syntax/node/PseudoElementSelector.js +66 -0
  235. package/lib/syntax/node/Ratio.js +68 -0
  236. package/lib/syntax/node/Raw.js +41 -0
  237. package/lib/syntax/node/Rule.js +51 -0
  238. package/lib/syntax/node/Scope.js +66 -0
  239. package/lib/syntax/node/Selector.js +31 -0
  240. package/lib/syntax/node/SelectorList.js +35 -0
  241. package/lib/syntax/node/String.js +19 -0
  242. package/lib/syntax/node/StyleSheet.js +82 -0
  243. package/lib/syntax/node/SupportsDeclaration.js +34 -0
  244. package/lib/syntax/node/TypeSelector.js +52 -0
  245. package/lib/syntax/node/UnicodeRange.js +156 -0
  246. package/lib/syntax/node/Url.js +52 -0
  247. package/lib/syntax/node/Value.js +19 -0
  248. package/lib/syntax/node/WhiteSpace.js +27 -0
  249. package/lib/syntax/node/index-generate.js +49 -0
  250. package/lib/syntax/node/index-parse-selector.js +17 -0
  251. package/lib/syntax/node/index-parse.js +49 -0
  252. package/lib/syntax/node/index.js +49 -0
  253. package/lib/syntax/pseudo/index.js +56 -0
  254. package/lib/syntax/pseudo/lang.js +33 -0
  255. package/lib/syntax/scope/atrulePrelude.js +5 -0
  256. package/lib/syntax/scope/default.js +85 -0
  257. package/lib/syntax/scope/index.js +3 -0
  258. package/lib/syntax/scope/selector.js +94 -0
  259. package/lib/syntax/scope/value.js +25 -0
  260. package/lib/tokenizer/OffsetToLocation.js +87 -0
  261. package/lib/tokenizer/TokenStream.js +366 -0
  262. package/lib/tokenizer/adopt-buffer.js +9 -0
  263. package/lib/tokenizer/char-code-definitions.js +212 -0
  264. package/lib/tokenizer/index.js +513 -0
  265. package/lib/tokenizer/names.js +28 -0
  266. package/lib/tokenizer/types.js +28 -0
  267. package/lib/tokenizer/utils.js +254 -0
  268. package/lib/utils/List.js +469 -0
  269. package/lib/utils/clone.js +21 -0
  270. package/lib/utils/create-custom-error.js +14 -0
  271. package/lib/utils/ident.js +101 -0
  272. package/lib/utils/index.js +6 -0
  273. package/lib/utils/names.js +106 -0
  274. package/lib/utils/string.js +99 -0
  275. package/lib/utils/url.js +108 -0
  276. package/lib/version.js +5 -0
  277. package/lib/walker/create.js +287 -0
  278. package/lib/walker/index.js +4 -0
  279. package/package.json +133 -0
@@ -0,0 +1,378 @@
1
+ 'use strict';
2
+
3
+ const List = require('../utils/List.cjs');
4
+ const SyntaxError = require('./SyntaxError.cjs');
5
+ const index = require('../tokenizer/index.cjs');
6
+ const sequence = require('./sequence.cjs');
7
+ const OffsetToLocation = require('../tokenizer/OffsetToLocation.cjs');
8
+ const TokenStream = require('../tokenizer/TokenStream.cjs');
9
+ const utils = require('../tokenizer/utils.cjs');
10
+ const types = require('../tokenizer/types.cjs');
11
+ const names = require('../tokenizer/names.cjs');
12
+
13
+ const NOOP = () => {};
14
+ const EXCLAMATIONMARK = 0x0021; // U+0021 EXCLAMATION MARK (!)
15
+ const NUMBERSIGN = 0x0023; // U+0023 NUMBER SIGN (#)
16
+ const SEMICOLON = 0x003B; // U+003B SEMICOLON (;)
17
+ const LEFTCURLYBRACKET = 0x007B; // U+007B LEFT CURLY BRACKET ({)
18
+ const NULL = 0;
19
+
20
+ function createParseContext(name) {
21
+ return function() {
22
+ return this[name]();
23
+ };
24
+ }
25
+
26
+ function fetchParseValues(dict) {
27
+ const result = Object.create(null);
28
+
29
+ for (const name of Object.keys(dict)) {
30
+ const item = dict[name];
31
+ const fn = item.parse || item;
32
+
33
+ if (fn) {
34
+ result[name] = fn;
35
+ }
36
+ }
37
+
38
+ return result;
39
+ }
40
+
41
+ function processConfig(config) {
42
+ const parseConfig = {
43
+ context: Object.create(null),
44
+ features: Object.assign(Object.create(null), config.features),
45
+ scope: Object.assign(Object.create(null), config.scope),
46
+ atrule: fetchParseValues(config.atrule),
47
+ pseudo: fetchParseValues(config.pseudo),
48
+ node: fetchParseValues(config.node)
49
+ };
50
+
51
+ for (const [name, context] of Object.entries(config.parseContext)) {
52
+ switch (typeof context) {
53
+ case 'function':
54
+ parseConfig.context[name] = context;
55
+ break;
56
+
57
+ case 'string':
58
+ parseConfig.context[name] = createParseContext(context);
59
+ break;
60
+ }
61
+ }
62
+
63
+ return {
64
+ config: parseConfig,
65
+ ...parseConfig,
66
+ ...parseConfig.node
67
+ };
68
+ }
69
+
70
+ function createParser(config) {
71
+ let source = '';
72
+ let filename = '<unknown>';
73
+ let needPositions = false;
74
+ let onParseError = NOOP;
75
+ let onParseErrorThrow = false;
76
+
77
+ const locationMap = new OffsetToLocation.OffsetToLocation();
78
+ const parser = Object.assign(new TokenStream.TokenStream(), processConfig(config || {}), {
79
+ parseAtrulePrelude: true,
80
+ parseRulePrelude: true,
81
+ parseValue: true,
82
+ parseCustomProperty: false,
83
+
84
+ readSequence: sequence.readSequence,
85
+
86
+ consumeUntilBalanceEnd: () => 0,
87
+ consumeUntilLeftCurlyBracket(code) {
88
+ return code === LEFTCURLYBRACKET ? 1 : 0;
89
+ },
90
+ consumeUntilLeftCurlyBracketOrSemicolon(code) {
91
+ return code === LEFTCURLYBRACKET || code === SEMICOLON ? 1 : 0;
92
+ },
93
+ consumeUntilExclamationMarkOrSemicolon(code) {
94
+ return code === EXCLAMATIONMARK || code === SEMICOLON ? 1 : 0;
95
+ },
96
+ consumeUntilSemicolonIncluded(code) {
97
+ return code === SEMICOLON ? 2 : 0;
98
+ },
99
+
100
+ createList() {
101
+ return new List.List();
102
+ },
103
+ createSingleNodeList(node) {
104
+ return new List.List().appendData(node);
105
+ },
106
+ getFirstListNode(list) {
107
+ return list && list.first;
108
+ },
109
+ getLastListNode(list) {
110
+ return list && list.last;
111
+ },
112
+
113
+ parseWithFallback(consumer, fallback) {
114
+ const startIndex = this.tokenIndex;
115
+
116
+ try {
117
+ return consumer.call(this);
118
+ } catch (e) {
119
+ if (onParseErrorThrow) {
120
+ throw e;
121
+ }
122
+
123
+ this.skip(startIndex - this.tokenIndex);
124
+ const fallbackNode = fallback.call(this);
125
+
126
+ onParseErrorThrow = true;
127
+ onParseError(e, fallbackNode);
128
+ onParseErrorThrow = false;
129
+
130
+ return fallbackNode;
131
+ }
132
+ },
133
+
134
+ lookupNonWSType(offset) {
135
+ let type;
136
+
137
+ do {
138
+ type = this.lookupType(offset++);
139
+ if (type !== types.WhiteSpace && type !== types.Comment) {
140
+ return type;
141
+ }
142
+ } while (type !== NULL);
143
+
144
+ return NULL;
145
+ },
146
+
147
+ charCodeAt(offset) {
148
+ return offset >= 0 && offset < source.length ? source.charCodeAt(offset) : 0;
149
+ },
150
+ substring(offsetStart, offsetEnd) {
151
+ return source.substring(offsetStart, offsetEnd);
152
+ },
153
+ substrToCursor(start) {
154
+ return this.source.substring(start, this.tokenStart);
155
+ },
156
+
157
+ cmpChar(offset, charCode) {
158
+ return utils.cmpChar(source, offset, charCode);
159
+ },
160
+ cmpStr(offsetStart, offsetEnd, str) {
161
+ return utils.cmpStr(source, offsetStart, offsetEnd, str);
162
+ },
163
+
164
+ consume(tokenType) {
165
+ const start = this.tokenStart;
166
+
167
+ this.eat(tokenType);
168
+
169
+ return this.substrToCursor(start);
170
+ },
171
+ consumeFunctionName() {
172
+ const name = source.substring(this.tokenStart, this.tokenEnd - 1);
173
+
174
+ this.eat(types.Function);
175
+
176
+ return name;
177
+ },
178
+ consumeNumber(type) {
179
+ const number = source.substring(this.tokenStart, utils.consumeNumber(source, this.tokenStart));
180
+
181
+ this.eat(type);
182
+
183
+ return number;
184
+ },
185
+
186
+ eat(tokenType) {
187
+ if (this.tokenType !== tokenType) {
188
+ const tokenName = names[tokenType].slice(0, -6).replace(/-/g, ' ').replace(/^./, m => m.toUpperCase());
189
+ let message = `${/[[\](){}]/.test(tokenName) ? `"${tokenName}"` : tokenName} is expected`;
190
+ let offset = this.tokenStart;
191
+
192
+ // tweak message and offset
193
+ switch (tokenType) {
194
+ case types.Ident:
195
+ // when identifier is expected but there is a function or url
196
+ if (this.tokenType === types.Function || this.tokenType === types.Url) {
197
+ offset = this.tokenEnd - 1;
198
+ message = 'Identifier is expected but function found';
199
+ } else {
200
+ message = 'Identifier is expected';
201
+ }
202
+ break;
203
+
204
+ case types.Hash:
205
+ if (this.isDelim(NUMBERSIGN)) {
206
+ this.next();
207
+ offset++;
208
+ message = 'Name is expected';
209
+ }
210
+ break;
211
+
212
+ case types.Percentage:
213
+ if (this.tokenType === types.Number) {
214
+ offset = this.tokenEnd;
215
+ message = 'Percent sign is expected';
216
+ }
217
+ break;
218
+ }
219
+
220
+ this.error(message, offset);
221
+ }
222
+
223
+ this.next();
224
+ },
225
+ eatIdent(name) {
226
+ if (this.tokenType !== types.Ident || this.lookupValue(0, name) === false) {
227
+ this.error(`Identifier "${name}" is expected`);
228
+ }
229
+
230
+ this.next();
231
+ },
232
+ eatDelim(code) {
233
+ if (!this.isDelim(code)) {
234
+ this.error(`Delim "${String.fromCharCode(code)}" is expected`);
235
+ }
236
+
237
+ this.next();
238
+ },
239
+
240
+ getLocation(start, end) {
241
+ if (needPositions) {
242
+ return locationMap.getLocationRange(
243
+ start,
244
+ end,
245
+ filename
246
+ );
247
+ }
248
+
249
+ return null;
250
+ },
251
+ getLocationFromList(list) {
252
+ if (needPositions) {
253
+ const head = this.getFirstListNode(list);
254
+ const tail = this.getLastListNode(list);
255
+ return locationMap.getLocationRange(
256
+ head !== null ? head.loc.start.offset - locationMap.startOffset : this.tokenStart,
257
+ tail !== null ? tail.loc.end.offset - locationMap.startOffset : this.tokenStart,
258
+ filename
259
+ );
260
+ }
261
+
262
+ return null;
263
+ },
264
+
265
+ error(message, offset) {
266
+ const location = typeof offset !== 'undefined' && offset < source.length
267
+ ? locationMap.getLocation(offset)
268
+ : this.eof
269
+ ? locationMap.getLocation(utils.findWhiteSpaceStart(source, source.length - 1))
270
+ : locationMap.getLocation(this.tokenStart);
271
+
272
+ throw new SyntaxError.SyntaxError(
273
+ message || 'Unexpected input',
274
+ source,
275
+ location.offset,
276
+ location.line,
277
+ location.column,
278
+ locationMap.startLine,
279
+ locationMap.startColumn
280
+ );
281
+ }
282
+ });
283
+ const createTokenIterateAPI = () => ({
284
+ filename,
285
+ source,
286
+ tokenCount: parser.tokenCount,
287
+
288
+ getTokenType: (index) =>
289
+ parser.getTokenType(index),
290
+ getTokenTypeName: (index) =>
291
+ names[parser.getTokenType(index)],
292
+ getTokenStart: (index) =>
293
+ parser.getTokenStart(index),
294
+ getTokenEnd: (index) =>
295
+ parser.getTokenEnd(index),
296
+ getTokenValue: (index) =>
297
+ parser.source.substring(parser.getTokenStart(index), parser.getTokenEnd(index)),
298
+
299
+ substring: (start, end) =>
300
+ parser.source.substring(start, end),
301
+
302
+ balance: parser.balance.subarray(0, parser.tokenCount + 1),
303
+ isBlockOpenerTokenType: parser.isBlockOpenerTokenType,
304
+ isBlockCloserTokenType: parser.isBlockCloserTokenType,
305
+ getBlockTokenPairIndex: (index) =>
306
+ parser.getBlockTokenPairIndex(index),
307
+
308
+ getLocation: (offset) =>
309
+ locationMap.getLocation(offset, filename),
310
+ getRangeLocation: (start, end) =>
311
+ locationMap.getLocationRange(start, end, filename)
312
+ });
313
+
314
+ const parse = function(source_, options) {
315
+ source = source_;
316
+ options = options || {};
317
+
318
+ parser.setSource(source, index.tokenize);
319
+ locationMap.setSource(
320
+ source,
321
+ options.offset,
322
+ options.line,
323
+ options.column
324
+ );
325
+
326
+ filename = options.filename || '<unknown>';
327
+ needPositions = Boolean(options.positions);
328
+ onParseError = typeof options.onParseError === 'function' ? options.onParseError : NOOP;
329
+ onParseErrorThrow = false;
330
+
331
+ parser.parseAtrulePrelude = 'parseAtrulePrelude' in options ? Boolean(options.parseAtrulePrelude) : true;
332
+ parser.parseRulePrelude = 'parseRulePrelude' in options ? Boolean(options.parseRulePrelude) : true;
333
+ parser.parseValue = 'parseValue' in options ? Boolean(options.parseValue) : true;
334
+ parser.parseCustomProperty = 'parseCustomProperty' in options ? Boolean(options.parseCustomProperty) : false;
335
+
336
+ const { context = 'default', onComment, onToken } = options;
337
+
338
+ if (context in parser.context === false) {
339
+ throw new Error('Unknown context `' + context + '`');
340
+ }
341
+
342
+ if (Array.isArray(onToken)) {
343
+ parser.forEachToken((type, start, end) => {
344
+ onToken.push({ type, start, end });
345
+ });
346
+ } else if (typeof onToken === 'function') {
347
+ parser.forEachToken(onToken.bind(createTokenIterateAPI()));
348
+ }
349
+
350
+ if (typeof onComment === 'function') {
351
+ parser.forEachToken((type, start, end) => {
352
+ if (type === types.Comment) {
353
+ const loc = parser.getLocation(start, end);
354
+ const value = utils.cmpStr(source, end - 2, end, '*/')
355
+ ? source.slice(start + 2, end - 2)
356
+ : source.slice(start + 2, end);
357
+
358
+ onComment(value, loc);
359
+ }
360
+ });
361
+ }
362
+
363
+ const ast = parser.context[context].call(parser, options);
364
+
365
+ if (!parser.eof) {
366
+ parser.error();
367
+ }
368
+
369
+ return ast;
370
+ };
371
+
372
+ return Object.assign(parse, {
373
+ SyntaxError: SyntaxError.SyntaxError,
374
+ config: parser.config
375
+ });
376
+ }
377
+
378
+ exports.createParser = createParser;
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ const create = require('./create.cjs');
4
+ const parser = require('../syntax/config/parser.cjs');
5
+
6
+ const index = create.createParser(parser);
7
+
8
+ module.exports = index;
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ const create = require('./create.cjs');
4
+ const parserSelector = require('../syntax/config/parser-selector.cjs');
5
+
6
+ const parseSelector = create.createParser(parserSelector);
7
+
8
+ module.exports = parseSelector;
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ const types = require('../tokenizer/types.cjs');
4
+
5
+ function readSequence(recognizer) {
6
+ const children = this.createList();
7
+ let space = false;
8
+ const context = {
9
+ recognizer
10
+ };
11
+
12
+ while (!this.eof) {
13
+ switch (this.tokenType) {
14
+ case types.Comment:
15
+ this.next();
16
+ continue;
17
+
18
+ case types.WhiteSpace:
19
+ space = true;
20
+ this.next();
21
+ continue;
22
+ }
23
+
24
+ let child = recognizer.getNode.call(this, context);
25
+
26
+ if (child === undefined) {
27
+ break;
28
+ }
29
+
30
+ if (space) {
31
+ if (recognizer.onWhiteSpace) {
32
+ recognizer.onWhiteSpace.call(this, child, children, context);
33
+ }
34
+ space = false;
35
+ }
36
+
37
+ children.push(child);
38
+ }
39
+
40
+ if (space && recognizer.onWhiteSpace) {
41
+ recognizer.onWhiteSpace.call(this, null, children, context);
42
+ }
43
+
44
+ return children;
45
+ }
46
+
47
+ exports.readSequence = readSequence;
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ const types = require('../../tokenizer/types.cjs');
4
+
5
+ // https://drafts.csswg.org/css-contain-3/#container-rule
6
+ // The keywords `none`, `and`, `not`, and `or` are excluded from the <custom-ident> above.
7
+ const nonContainerNameKeywords = new Set(['none', 'and', 'not', 'or']);
8
+
9
+ const container = {
10
+ parse: {
11
+ prelude() {
12
+ const children = this.createList();
13
+
14
+ if (this.tokenType === types.Ident) {
15
+ const name = this.substring(this.tokenStart, this.tokenEnd);
16
+
17
+ if (!nonContainerNameKeywords.has(name.toLowerCase())) {
18
+ children.push(this.Identifier());
19
+ }
20
+ }
21
+
22
+ children.push(this.Condition('container'));
23
+
24
+ return children;
25
+ },
26
+ block(nested = false) {
27
+ return this.Block(nested);
28
+ }
29
+ }
30
+ };
31
+
32
+ module.exports = container;
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ const fontFace = {
4
+ parse: {
5
+ prelude: null,
6
+ block() {
7
+ return this.Block(true);
8
+ }
9
+ }
10
+ };
11
+
12
+ module.exports = fontFace;
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ const types = require('../../tokenizer/types.cjs');
4
+
5
+ function parseWithFallback(parse, fallback) {
6
+ return this.parseWithFallback(
7
+ () => {
8
+ try {
9
+ return parse.call(this);
10
+ } finally {
11
+ this.skipSC();
12
+ if (this.lookupNonWSType(0) !== types.RightParenthesis) {
13
+ this.error();
14
+ }
15
+ }
16
+ },
17
+ fallback || (() => this.Raw(null, true))
18
+ );
19
+ }
20
+
21
+ const parseFunctions = {
22
+ layer() {
23
+ this.skipSC();
24
+
25
+ const children = this.createList();
26
+ const node = parseWithFallback.call(this, this.Layer);
27
+
28
+ if (node.type !== 'Raw' || node.value !== '') {
29
+ children.push(node);
30
+ }
31
+
32
+ return children;
33
+ },
34
+ supports() {
35
+ this.skipSC();
36
+
37
+ const children = this.createList();
38
+ const node = parseWithFallback.call(
39
+ this,
40
+ this.Declaration,
41
+ () => parseWithFallback.call(this, () => this.Condition('supports'))
42
+ );
43
+
44
+ if (node.type !== 'Raw' || node.value !== '') {
45
+ children.push(node);
46
+ }
47
+
48
+ return children;
49
+ }
50
+ };
51
+
52
+ const importAtrule = {
53
+ parse: {
54
+ prelude() {
55
+ const children = this.createList();
56
+
57
+ switch (this.tokenType) {
58
+ case types.String:
59
+ children.push(this.String());
60
+ break;
61
+
62
+ case types.Url:
63
+ case types.Function:
64
+ children.push(this.Url());
65
+ break;
66
+
67
+ default:
68
+ this.error('String or url() is expected');
69
+ }
70
+
71
+ this.skipSC();
72
+
73
+ if (this.tokenType === types.Ident &&
74
+ this.cmpStr(this.tokenStart, this.tokenEnd, 'layer')) {
75
+ children.push(this.Identifier());
76
+ } else if (
77
+ this.tokenType === types.Function &&
78
+ this.cmpStr(this.tokenStart, this.tokenEnd, 'layer(')
79
+ ) {
80
+ children.push(this.Function(null, parseFunctions));
81
+ }
82
+
83
+ this.skipSC();
84
+
85
+ if (this.tokenType === types.Function &&
86
+ this.cmpStr(this.tokenStart, this.tokenEnd, 'supports(')) {
87
+ children.push(this.Function(null, parseFunctions));
88
+ }
89
+
90
+ if (this.lookupNonWSType(0) === types.Ident ||
91
+ this.lookupNonWSType(0) === types.LeftParenthesis) {
92
+ children.push(this.MediaQueryList());
93
+ }
94
+
95
+ return children;
96
+ },
97
+ block: null
98
+ }
99
+ };
100
+
101
+ module.exports = importAtrule;
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ const container = require('./container.cjs');
4
+ const fontFace = require('./font-face.cjs');
5
+ const _import = require('./import.cjs');
6
+ const layer = require('./layer.cjs');
7
+ const media = require('./media.cjs');
8
+ const nest = require('./nest.cjs');
9
+ const page = require('./page.cjs');
10
+ const scope = require('./scope.cjs');
11
+ const startingStyle = require('./starting-style.cjs');
12
+ const supports = require('./supports.cjs');
13
+
14
+ const atrule = {
15
+ container,
16
+ 'font-face': fontFace,
17
+ import: _import,
18
+ layer,
19
+ media,
20
+ nest,
21
+ page,
22
+ scope,
23
+ 'starting-style': startingStyle,
24
+ supports
25
+ };
26
+
27
+ module.exports = atrule;
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ const layer = {
4
+ parse: {
5
+ prelude() {
6
+ return this.createSingleNodeList(
7
+ this.LayerList()
8
+ );
9
+ },
10
+ block() {
11
+ return this.Block(false);
12
+ }
13
+ }
14
+ };
15
+
16
+ module.exports = layer;
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ const media = {
4
+ parse: {
5
+ prelude() {
6
+ return this.createSingleNodeList(
7
+ this.MediaQueryList()
8
+ );
9
+ },
10
+ block(nested = false) {
11
+ return this.Block(nested);
12
+ }
13
+ }
14
+ };
15
+
16
+ module.exports = media;
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ const nest = {
4
+ parse: {
5
+ prelude() {
6
+ return this.createSingleNodeList(
7
+ this.SelectorList()
8
+ );
9
+ },
10
+ block() {
11
+ return this.Block(true);
12
+ }
13
+ }
14
+ };
15
+
16
+ module.exports = nest;
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ const page = {
4
+ parse: {
5
+ prelude() {
6
+ return this.createSingleNodeList(
7
+ this.SelectorList()
8
+ );
9
+ },
10
+ block() {
11
+ return this.Block(true);
12
+ }
13
+ }
14
+ };
15
+
16
+ module.exports = page;