@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,16 @@
1
+ 'use strict';
2
+
3
+ const scope = {
4
+ parse: {
5
+ prelude() {
6
+ return this.createSingleNodeList(
7
+ this.Scope()
8
+ );
9
+ },
10
+ block(nested = false) {
11
+ return this.Block(nested);
12
+ }
13
+ }
14
+ };
15
+
16
+ module.exports = scope;
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ const startingStyle = {
4
+ parse: {
5
+ prelude: null,
6
+ block(nested = false) {
7
+ return this.Block(nested);
8
+ }
9
+ }
10
+ };
11
+
12
+ module.exports = startingStyle;
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ const supports = {
4
+ parse: {
5
+ prelude() {
6
+ return this.createSingleNodeList(
7
+ this.Condition('supports')
8
+ );
9
+ },
10
+ block(nested = false) {
11
+ return this.Block(nested);
12
+ }
13
+ }
14
+ };
15
+
16
+ module.exports = supports;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const indexGenerate = require('../node/index-generate.cjs');
4
+
5
+ const config = {
6
+ node: indexGenerate
7
+ };
8
+
9
+ module.exports = config;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const genericConst = require('../../lexer/generic-const.cjs');
4
+ const data = require('../../data.cjs');
5
+ const index = require('../node/index.cjs');
6
+
7
+ const lexerConfig = {
8
+ generic: true,
9
+ cssWideKeywords: genericConst.cssWideKeywords,
10
+ ...data,
11
+ node: index
12
+ };
13
+
14
+ module.exports = lexerConfig;
@@ -0,0 +1,126 @@
1
+ 'use strict';
2
+
3
+ function appendOrSet(a, b) {
4
+ if (typeof b === 'string' && /^\s*\|/.test(b)) {
5
+ return typeof a === 'string'
6
+ ? a + b
7
+ : b.replace(/^\s*\|\s*/, '');
8
+ }
9
+
10
+ return b || null;
11
+ }
12
+
13
+ function extractProps(obj, props) {
14
+ const result = Object.create(null);
15
+
16
+ for (const prop of Object.keys(obj)) {
17
+ if (props.includes(prop)) {
18
+ result[prop] = obj[prop];
19
+ }
20
+ }
21
+
22
+ return result;
23
+ }
24
+
25
+ function mergeDicts(base, ext, fields) {
26
+ const result = { ...base };
27
+
28
+ for (const [key, props] of Object.entries(ext)) {
29
+ result[key] = {
30
+ ...result[key],
31
+ ...fields ? extractProps(props, fields) : props
32
+ };
33
+ }
34
+
35
+ return result;
36
+ }
37
+
38
+ function mix(dest, src) {
39
+ const result = { ...dest };
40
+
41
+ for (const [prop, value] of Object.entries(src)) {
42
+ switch (prop) {
43
+ case 'generic':
44
+ result[prop] = Boolean(value);
45
+ break;
46
+
47
+ case 'cssWideKeywords':
48
+ result[prop] = dest[prop]
49
+ ? [...dest[prop], ...value]
50
+ : value || [];
51
+ break;
52
+
53
+ case 'units':
54
+ result[prop] = { ...dest[prop] };
55
+ for (const [name, patch] of Object.entries(value)) {
56
+ result[prop][name] = Array.isArray(patch) ? patch : [];
57
+ }
58
+ break;
59
+
60
+ case 'atrules':
61
+ result[prop] = { ...dest[prop] };
62
+
63
+ for (const [name, atrule] of Object.entries(value)) {
64
+ const exists = result[prop][name] || {};
65
+ const current = result[prop][name] = {
66
+ prelude: exists.prelude || null,
67
+ descriptors: {
68
+ ...exists.descriptors
69
+ }
70
+ };
71
+
72
+ if (!atrule) {
73
+ continue;
74
+ }
75
+
76
+ current.prelude = atrule.prelude
77
+ ? appendOrSet(current.prelude, atrule.prelude)
78
+ : current.prelude || null;
79
+
80
+ for (const [descriptorName, descriptorValue] of Object.entries(atrule.descriptors || {})) {
81
+ current.descriptors[descriptorName] = descriptorValue
82
+ ? appendOrSet(current.descriptors[descriptorName], descriptorValue)
83
+ : null;
84
+ }
85
+
86
+ if (!Object.keys(current.descriptors).length) {
87
+ current.descriptors = null;
88
+ }
89
+ }
90
+ break;
91
+
92
+ case 'types':
93
+ case 'properties':
94
+ result[prop] = { ...dest[prop] };
95
+ for (const [name, syntax] of Object.entries(value)) {
96
+ result[prop][name] = appendOrSet(result[prop][name], syntax);
97
+ }
98
+ break;
99
+
100
+ case 'parseContext':
101
+ result[prop] = {
102
+ ...dest[prop],
103
+ ...value
104
+ };
105
+ break;
106
+
107
+ case 'scope':
108
+ case 'features':
109
+ result[prop] = mergeDicts(dest[prop], value);
110
+ break;
111
+
112
+ case 'atrule':
113
+ case 'pseudo':
114
+ result[prop] = mergeDicts(dest[prop], value, ['parse']);
115
+ break;
116
+
117
+ case 'node':
118
+ result[prop] = mergeDicts(dest[prop], value, ['name', 'structure', 'parse', 'generate', 'walkContext']);
119
+ break;
120
+ }
121
+ }
122
+
123
+ return result;
124
+ }
125
+
126
+ module.exports = mix;
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ const index = require('../pseudo/index.cjs');
4
+ const indexParseSelector = require('../node/index-parse-selector.cjs');
5
+ const selector = require('../scope/selector.cjs');
6
+
7
+ const config = {
8
+ parseContext: {
9
+ default: 'SelectorList',
10
+ selectorList: 'SelectorList',
11
+ selector: 'Selector'
12
+ },
13
+ scope: { Selector: selector },
14
+ atrule: {},
15
+ pseudo: index,
16
+ node: indexParseSelector
17
+ };
18
+
19
+ module.exports = config;
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ const index = require('../scope/index.cjs');
4
+ const index$1 = require('../atrule/index.cjs');
5
+ const index$2 = require('../pseudo/index.cjs');
6
+ const indexParse = require('../node/index-parse.cjs');
7
+
8
+ const config = {
9
+ parseContext: {
10
+ default: 'StyleSheet',
11
+ stylesheet: 'StyleSheet',
12
+ atrule: 'Atrule',
13
+ atrulePrelude(options) {
14
+ return this.AtrulePrelude(options.atrule ? String(options.atrule) : null);
15
+ },
16
+ mediaQueryList: 'MediaQueryList',
17
+ mediaQuery: 'MediaQuery',
18
+ condition(options) {
19
+ return this.Condition(options.kind);
20
+ },
21
+ rule: 'Rule',
22
+ selectorList: 'SelectorList',
23
+ selector: 'Selector',
24
+ block() {
25
+ return this.Block(true);
26
+ },
27
+ declarationList: 'DeclarationList',
28
+ declaration: 'Declaration',
29
+ value: 'Value'
30
+ },
31
+ features: {
32
+ supports: {
33
+ selector() {
34
+ return this.Selector();
35
+ }
36
+ },
37
+ container: {
38
+ style() {
39
+ return this.Declaration();
40
+ }
41
+ }
42
+ },
43
+ scope: index,
44
+ atrule: index$1,
45
+ pseudo: index$2,
46
+ node: indexParse
47
+ };
48
+
49
+ module.exports = config;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const index = require('../node/index.cjs');
4
+
5
+ const config = {
6
+ node: index
7
+ };
8
+
9
+ module.exports = config;
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ const index = require('../tokenizer/index.cjs');
4
+ const create = require('../parser/create.cjs');
5
+ const create$2 = require('../generator/create.cjs');
6
+ const create$3 = require('../convertor/create.cjs');
7
+ const create$1 = require('../walker/create.cjs');
8
+ const Lexer = require('../lexer/Lexer.cjs');
9
+ const mix = require('./config/mix.cjs');
10
+
11
+ function createSyntax(config) {
12
+ const parse = create.createParser(config);
13
+ const walk = create$1.createWalker(config);
14
+ const generate = create$2.createGenerator(config);
15
+ const { fromPlainObject, toPlainObject } = create$3.createConvertor(walk);
16
+
17
+ const syntax = {
18
+ lexer: null,
19
+ createLexer: config => new Lexer.Lexer(config, syntax, syntax.lexer.structure),
20
+
21
+ tokenize: index.tokenize,
22
+ parse,
23
+ generate,
24
+
25
+ walk,
26
+ find: walk.find,
27
+ findLast: walk.findLast,
28
+ findAll: walk.findAll,
29
+
30
+ fromPlainObject,
31
+ toPlainObject,
32
+
33
+ fork(extension) {
34
+ const base = mix({}, config); // copy of config
35
+
36
+ return createSyntax(
37
+ typeof extension === 'function'
38
+ ? extension(base) // TODO: remove Object.assign as second parameter
39
+ : mix(base, extension)
40
+ );
41
+ }
42
+ };
43
+
44
+ syntax.lexer = new Lexer.Lexer({
45
+ generic: config.generic,
46
+ cssWideKeywords: config.cssWideKeywords,
47
+ units: config.units,
48
+ types: config.types,
49
+ atrules: config.atrules,
50
+ properties: config.properties,
51
+ node: config.node
52
+ }, syntax);
53
+
54
+ return syntax;
55
+ }
56
+ const createSyntax$1 = config => createSyntax(mix({}, config));
57
+
58
+ module.exports = createSyntax$1;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ // legacy IE function
4
+ // expression( <any-value> )
5
+ function expressionFn() {
6
+ return this.createSingleNodeList(
7
+ this.Raw(null, false)
8
+ );
9
+ }
10
+
11
+ module.exports = expressionFn;
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ const types = require('../../tokenizer/types.cjs');
4
+
5
+ // var( <ident> , <value>? )
6
+ function varFn() {
7
+ const children = this.createList();
8
+
9
+ this.skipSC();
10
+
11
+ // NOTE: Don't check more than a first argument is an ident, rest checks are for lexer
12
+ children.push(this.Identifier());
13
+
14
+ this.skipSC();
15
+
16
+ if (this.tokenType === types.Comma) {
17
+ children.push(this.Operator());
18
+
19
+ const startIndex = this.tokenIndex;
20
+ const value = this.parseCustomProperty
21
+ ? this.Value(null)
22
+ : this.Raw(this.consumeUntilExclamationMarkOrSemicolon, false);
23
+
24
+ if (value.type === 'Value' && value.children.isEmpty) {
25
+ for (let offset = startIndex - this.tokenIndex; offset <= 0; offset++) {
26
+ if (this.lookupType(offset) === types.WhiteSpace) {
27
+ value.children.appendData({
28
+ type: 'WhiteSpace',
29
+ loc: null,
30
+ value: ' '
31
+ });
32
+ break;
33
+ }
34
+ }
35
+ }
36
+
37
+ children.push(value);
38
+ }
39
+
40
+ return children;
41
+ }
42
+
43
+ module.exports = varFn;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const create = require('./create.cjs');
4
+ const lexer = require('./config/lexer.cjs');
5
+ const parser = require('./config/parser.cjs');
6
+ const walker = require('./config/walker.cjs');
7
+
8
+ const syntax = create({
9
+ ...lexer,
10
+ ...parser,
11
+ ...walker
12
+ });
13
+
14
+ module.exports = syntax;
@@ -0,0 +1,293 @@
1
+ 'use strict';
2
+
3
+ const types = require('../../tokenizer/types.cjs');
4
+ const charCodeDefinitions = require('../../tokenizer/char-code-definitions.cjs');
5
+
6
+ const PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
7
+ const HYPHENMINUS = 0x002D; // U+002D HYPHEN-MINUS (-)
8
+ const N = 0x006E; // U+006E LATIN SMALL LETTER N (n)
9
+ const DISALLOW_SIGN = true;
10
+ const ALLOW_SIGN = false;
11
+
12
+ function checkInteger(offset, disallowSign) {
13
+ let pos = this.tokenStart + offset;
14
+ const code = this.charCodeAt(pos);
15
+
16
+ if (code === PLUSSIGN || code === HYPHENMINUS) {
17
+ if (disallowSign) {
18
+ this.error('Number sign is not allowed');
19
+ }
20
+ pos++;
21
+ }
22
+
23
+ for (; pos < this.tokenEnd; pos++) {
24
+ if (!charCodeDefinitions.isDigit(this.charCodeAt(pos))) {
25
+ this.error('Integer is expected', pos);
26
+ }
27
+ }
28
+ }
29
+
30
+ function checkTokenIsInteger(disallowSign) {
31
+ return checkInteger.call(this, 0, disallowSign);
32
+ }
33
+
34
+ function expectCharCode(offset, code) {
35
+ if (!this.cmpChar(this.tokenStart + offset, code)) {
36
+ let msg = '';
37
+
38
+ switch (code) {
39
+ case N:
40
+ msg = 'N is expected';
41
+ break;
42
+ case HYPHENMINUS:
43
+ msg = 'HyphenMinus is expected';
44
+ break;
45
+ }
46
+
47
+ this.error(msg, this.tokenStart + offset);
48
+ }
49
+ }
50
+
51
+ // ... <signed-integer>
52
+ // ... ['+' | '-'] <signless-integer>
53
+ function consumeB() {
54
+ let offset = 0;
55
+ let sign = 0;
56
+ let type = this.tokenType;
57
+
58
+ while (type === types.WhiteSpace || type === types.Comment) {
59
+ type = this.lookupType(++offset);
60
+ }
61
+
62
+ if (type !== types.Number) {
63
+ if (this.isDelim(PLUSSIGN, offset) ||
64
+ this.isDelim(HYPHENMINUS, offset)) {
65
+ sign = this.isDelim(PLUSSIGN, offset) ? PLUSSIGN : HYPHENMINUS;
66
+
67
+ do {
68
+ type = this.lookupType(++offset);
69
+ } while (type === types.WhiteSpace || type === types.Comment);
70
+
71
+ if (type !== types.Number) {
72
+ this.skip(offset);
73
+ checkTokenIsInteger.call(this, DISALLOW_SIGN);
74
+ }
75
+ } else {
76
+ return null;
77
+ }
78
+ }
79
+
80
+ if (offset > 0) {
81
+ this.skip(offset);
82
+ }
83
+
84
+ if (sign === 0) {
85
+ type = this.charCodeAt(this.tokenStart);
86
+ if (type !== PLUSSIGN && type !== HYPHENMINUS) {
87
+ this.error('Number sign is expected');
88
+ }
89
+ }
90
+
91
+ checkTokenIsInteger.call(this, sign !== 0);
92
+ return sign === HYPHENMINUS ? '-' + this.consume(types.Number) : this.consume(types.Number);
93
+ }
94
+
95
+ // An+B microsyntax https://www.w3.org/TR/css-syntax-3/#anb
96
+ const name = 'AnPlusB';
97
+ const structure = {
98
+ a: [String, null],
99
+ b: [String, null]
100
+ };
101
+
102
+ function parse() {
103
+ /* eslint-disable brace-style*/
104
+ const start = this.tokenStart;
105
+ let a = null;
106
+ let b = null;
107
+
108
+ // <integer>
109
+ if (this.tokenType === types.Number) {
110
+ checkTokenIsInteger.call(this, ALLOW_SIGN);
111
+ b = this.consume(types.Number);
112
+ }
113
+
114
+ // -n
115
+ // -n <signed-integer>
116
+ // -n ['+' | '-'] <signless-integer>
117
+ // -n- <signless-integer>
118
+ // <dashndashdigit-ident>
119
+ else if (this.tokenType === types.Ident && this.cmpChar(this.tokenStart, HYPHENMINUS)) {
120
+ a = '-1';
121
+
122
+ expectCharCode.call(this, 1, N);
123
+
124
+ switch (this.tokenEnd - this.tokenStart) {
125
+ // -n
126
+ // -n <signed-integer>
127
+ // -n ['+' | '-'] <signless-integer>
128
+ case 2:
129
+ this.next();
130
+ b = consumeB.call(this);
131
+ break;
132
+
133
+ // -n- <signless-integer>
134
+ case 3:
135
+ expectCharCode.call(this, 2, HYPHENMINUS);
136
+
137
+ this.next();
138
+ this.skipSC();
139
+
140
+ checkTokenIsInteger.call(this, DISALLOW_SIGN);
141
+
142
+ b = '-' + this.consume(types.Number);
143
+ break;
144
+
145
+ // <dashndashdigit-ident>
146
+ default:
147
+ expectCharCode.call(this, 2, HYPHENMINUS);
148
+ checkInteger.call(this, 3, DISALLOW_SIGN);
149
+ this.next();
150
+
151
+ b = this.substrToCursor(start + 2);
152
+ }
153
+ }
154
+
155
+ // '+'? n
156
+ // '+'? n <signed-integer>
157
+ // '+'? n ['+' | '-'] <signless-integer>
158
+ // '+'? n- <signless-integer>
159
+ // '+'? <ndashdigit-ident>
160
+ else if (this.tokenType === types.Ident || (this.isDelim(PLUSSIGN) && this.lookupType(1) === types.Ident)) {
161
+ let sign = 0;
162
+ a = '1';
163
+
164
+ // just ignore a plus
165
+ if (this.isDelim(PLUSSIGN)) {
166
+ sign = 1;
167
+ this.next();
168
+ }
169
+
170
+ expectCharCode.call(this, 0, N);
171
+
172
+ switch (this.tokenEnd - this.tokenStart) {
173
+ // '+'? n
174
+ // '+'? n <signed-integer>
175
+ // '+'? n ['+' | '-'] <signless-integer>
176
+ case 1:
177
+ this.next();
178
+ b = consumeB.call(this);
179
+ break;
180
+
181
+ // '+'? n- <signless-integer>
182
+ case 2:
183
+ expectCharCode.call(this, 1, HYPHENMINUS);
184
+
185
+ this.next();
186
+ this.skipSC();
187
+
188
+ checkTokenIsInteger.call(this, DISALLOW_SIGN);
189
+
190
+ b = '-' + this.consume(types.Number);
191
+ break;
192
+
193
+ // '+'? <ndashdigit-ident>
194
+ default:
195
+ expectCharCode.call(this, 1, HYPHENMINUS);
196
+ checkInteger.call(this, 2, DISALLOW_SIGN);
197
+ this.next();
198
+
199
+ b = this.substrToCursor(start + sign + 1);
200
+ }
201
+ }
202
+
203
+ // <ndashdigit-dimension>
204
+ // <ndash-dimension> <signless-integer>
205
+ // <n-dimension>
206
+ // <n-dimension> <signed-integer>
207
+ // <n-dimension> ['+' | '-'] <signless-integer>
208
+ else if (this.tokenType === types.Dimension) {
209
+ const code = this.charCodeAt(this.tokenStart);
210
+ const sign = code === PLUSSIGN || code === HYPHENMINUS;
211
+ let i = this.tokenStart + sign;
212
+
213
+ for (; i < this.tokenEnd; i++) {
214
+ if (!charCodeDefinitions.isDigit(this.charCodeAt(i))) {
215
+ break;
216
+ }
217
+ }
218
+
219
+ if (i === this.tokenStart + sign) {
220
+ this.error('Integer is expected', this.tokenStart + sign);
221
+ }
222
+
223
+ expectCharCode.call(this, i - this.tokenStart, N);
224
+ a = this.substring(start, i);
225
+
226
+ // <n-dimension>
227
+ // <n-dimension> <signed-integer>
228
+ // <n-dimension> ['+' | '-'] <signless-integer>
229
+ if (i + 1 === this.tokenEnd) {
230
+ this.next();
231
+ b = consumeB.call(this);
232
+ } else {
233
+ expectCharCode.call(this, i - this.tokenStart + 1, HYPHENMINUS);
234
+
235
+ // <ndash-dimension> <signless-integer>
236
+ if (i + 2 === this.tokenEnd) {
237
+ this.next();
238
+ this.skipSC();
239
+ checkTokenIsInteger.call(this, DISALLOW_SIGN);
240
+ b = '-' + this.consume(types.Number);
241
+ }
242
+ // <ndashdigit-dimension>
243
+ else {
244
+ checkInteger.call(this, i - this.tokenStart + 2, DISALLOW_SIGN);
245
+ this.next();
246
+ b = this.substrToCursor(i + 1);
247
+ }
248
+ }
249
+ } else {
250
+ this.error();
251
+ }
252
+
253
+ if (a !== null && a.charCodeAt(0) === PLUSSIGN) {
254
+ a = a.substr(1);
255
+ }
256
+
257
+ if (b !== null && b.charCodeAt(0) === PLUSSIGN) {
258
+ b = b.substr(1);
259
+ }
260
+
261
+ return {
262
+ type: 'AnPlusB',
263
+ loc: this.getLocation(start, this.tokenStart),
264
+ a,
265
+ b
266
+ };
267
+ }
268
+
269
+ function generate(node) {
270
+ if (node.a) {
271
+ const a =
272
+ node.a === '+1' && 'n' ||
273
+ node.a === '1' && 'n' ||
274
+ node.a === '-1' && '-n' ||
275
+ node.a + 'n';
276
+
277
+ if (node.b) {
278
+ const b = node.b[0] === '-' || node.b[0] === '+'
279
+ ? node.b
280
+ : '+' + node.b;
281
+ this.tokenize(a + b);
282
+ } else {
283
+ this.tokenize(a);
284
+ }
285
+ } else {
286
+ this.tokenize(node.b);
287
+ }
288
+ }
289
+
290
+ exports.generate = generate;
291
+ exports.name = name;
292
+ exports.parse = parse;
293
+ exports.structure = structure;