@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,37 @@
1
+ 'use strict';
2
+
3
+ const types = require('../../tokenizer/types.cjs');
4
+
5
+ function parseLanguageRangeList() {
6
+ const children = this.createList();
7
+
8
+ this.skipSC();
9
+
10
+ loop: while (!this.eof) {
11
+ switch (this.tokenType) {
12
+ case types.Ident:
13
+ children.push(this.Identifier());
14
+ break;
15
+
16
+ case types.String:
17
+ children.push(this.String());
18
+ break;
19
+
20
+ case types.Comma:
21
+ children.push(this.Operator());
22
+ break;
23
+
24
+ case types.RightParenthesis:
25
+ break loop;
26
+
27
+ default:
28
+ this.error('Identifier, string or comma is expected');
29
+ }
30
+
31
+ this.skipSC();
32
+ }
33
+
34
+ return children;
35
+ }
36
+
37
+ exports.parseLanguageRangeList = parseLanguageRangeList;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const _default = require('./default.cjs');
4
+
5
+ const atrulePrelude = {
6
+ getNode: _default
7
+ };
8
+
9
+ module.exports = atrulePrelude;
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ const types = require('../../tokenizer/types.cjs');
4
+
5
+ const NUMBERSIGN = 0x0023; // U+0023 NUMBER SIGN (#)
6
+ const ASTERISK = 0x002A; // U+002A ASTERISK (*)
7
+ const PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
8
+ const HYPHENMINUS = 0x002D; // U+002D HYPHEN-MINUS (-)
9
+ const SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
10
+ const U = 0x0075; // U+0075 LATIN SMALL LETTER U (u)
11
+
12
+ function defaultRecognizer(context) {
13
+ switch (this.tokenType) {
14
+ case types.Hash:
15
+ return this.Hash();
16
+
17
+ case types.Comma:
18
+ return this.Operator();
19
+
20
+ case types.LeftParenthesis:
21
+ return this.Parentheses(this.readSequence, context.recognizer);
22
+
23
+ case types.LeftSquareBracket:
24
+ return this.Brackets(this.readSequence, context.recognizer);
25
+
26
+ case types.String:
27
+ return this.String();
28
+
29
+ case types.Dimension:
30
+ return this.Dimension();
31
+
32
+ case types.Percentage:
33
+ return this.Percentage();
34
+
35
+ case types.Number:
36
+ return this.Number();
37
+
38
+ case types.Function:
39
+ return this.cmpStr(this.tokenStart, this.tokenEnd, 'url(')
40
+ ? this.Url()
41
+ : this.Function(this.readSequence, context.recognizer);
42
+
43
+ case types.Url:
44
+ return this.Url();
45
+
46
+ case types.Ident:
47
+ // check for unicode range, it should start with u+ or U+
48
+ if (this.cmpChar(this.tokenStart, U) &&
49
+ this.cmpChar(this.tokenStart + 1, PLUSSIGN)) {
50
+ return this.UnicodeRange();
51
+ } else {
52
+ return this.Identifier();
53
+ }
54
+
55
+ case types.Delim: {
56
+ const code = this.charCodeAt(this.tokenStart);
57
+
58
+ if (code === SOLIDUS ||
59
+ code === ASTERISK ||
60
+ code === PLUSSIGN ||
61
+ code === HYPHENMINUS) {
62
+ return this.Operator(); // TODO: replace with Delim
63
+ }
64
+
65
+ // TODO: produce a node with Delim node type
66
+
67
+ if (code === NUMBERSIGN) {
68
+ this.error('Hex or identifier is expected', this.tokenStart + 1);
69
+ }
70
+
71
+ break;
72
+ }
73
+ }
74
+ }
75
+
76
+ module.exports = defaultRecognizer;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const atrulePrelude = require('./atrulePrelude.cjs');
4
+ const selector = require('./selector.cjs');
5
+ const value = require('./value.cjs');
6
+
7
+
8
+
9
+ exports.AtrulePrelude = atrulePrelude;
10
+ exports.Selector = selector;
11
+ exports.Value = value;
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ const types = require('../../tokenizer/types.cjs');
4
+
5
+ const NUMBERSIGN = 0x0023; // U+0023 NUMBER SIGN (#)
6
+ const AMPERSAND = 0x0026; // U+0026 AMPERSAND (&)
7
+ const ASTERISK = 0x002A; // U+002A ASTERISK (*)
8
+ const PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
9
+ const SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
10
+ const FULLSTOP = 0x002E; // U+002E FULL STOP (.)
11
+ const GREATERTHANSIGN = 0x003E; // U+003E GREATER-THAN SIGN (>)
12
+ const VERTICALLINE = 0x007C; // U+007C VERTICAL LINE (|)
13
+ const TILDE = 0x007E; // U+007E TILDE (~)
14
+
15
+ function onWhiteSpace(next, children) {
16
+ if (children.last !== null && children.last.type !== 'Combinator' &&
17
+ next !== null && next.type !== 'Combinator') {
18
+ children.push({ // FIXME: this.Combinator() should be used instead
19
+ type: 'Combinator',
20
+ loc: null,
21
+ name: ' '
22
+ });
23
+ }
24
+ }
25
+
26
+ function getNode() {
27
+ switch (this.tokenType) {
28
+ case types.LeftSquareBracket:
29
+ return this.AttributeSelector();
30
+
31
+ case types.Hash:
32
+ return this.IdSelector();
33
+
34
+ case types.Colon:
35
+ if (this.lookupType(1) === types.Colon) {
36
+ return this.PseudoElementSelector();
37
+ } else {
38
+ return this.PseudoClassSelector();
39
+ }
40
+
41
+ case types.Ident:
42
+ return this.TypeSelector();
43
+
44
+ case types.Number:
45
+ case types.Percentage:
46
+ return this.Percentage();
47
+
48
+ case types.Dimension:
49
+ // throws when .123ident
50
+ if (this.charCodeAt(this.tokenStart) === FULLSTOP) {
51
+ this.error('Identifier is expected', this.tokenStart + 1);
52
+ }
53
+ break;
54
+
55
+ case types.Delim: {
56
+ const code = this.charCodeAt(this.tokenStart);
57
+
58
+ switch (code) {
59
+ case PLUSSIGN:
60
+ case GREATERTHANSIGN:
61
+ case TILDE:
62
+ case SOLIDUS: // /deep/
63
+ return this.Combinator();
64
+
65
+ case FULLSTOP:
66
+ return this.ClassSelector();
67
+
68
+ case ASTERISK:
69
+ case VERTICALLINE:
70
+ return this.TypeSelector();
71
+
72
+ case NUMBERSIGN:
73
+ return this.IdSelector();
74
+
75
+ case AMPERSAND:
76
+ return this.NestingSelector();
77
+ }
78
+
79
+ break;
80
+ }
81
+ }
82
+ }
83
+ const Selector = {
84
+ onWhiteSpace,
85
+ getNode
86
+ };
87
+
88
+ module.exports = Selector;
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const _default = require('./default.cjs');
4
+ const expression = require('../function/expression.cjs');
5
+ const _var = require('../function/var.cjs');
6
+
7
+ function isPlusMinusOperator(node) {
8
+ return (
9
+ node !== null &&
10
+ node.type === 'Operator' &&
11
+ (node.value[node.value.length - 1] === '-' || node.value[node.value.length - 1] === '+')
12
+ );
13
+ }
14
+
15
+ const value = {
16
+ getNode: _default,
17
+ onWhiteSpace(next, children) {
18
+ if (isPlusMinusOperator(next)) {
19
+ next.value = ' ' + next.value;
20
+ }
21
+ if (isPlusMinusOperator(children.last)) {
22
+ children.last.value += ' ';
23
+ }
24
+ },
25
+ 'expression': expression,
26
+ 'var': _var
27
+ };
28
+
29
+ module.exports = value;
@@ -0,0 +1,91 @@
1
+ 'use strict';
2
+
3
+ const adoptBuffer = require('./adopt-buffer.cjs');
4
+ const charCodeDefinitions = require('./char-code-definitions.cjs');
5
+
6
+ const N = 10;
7
+ const F = 12;
8
+ const R = 13;
9
+
10
+ function computeLinesAndColumns(host) {
11
+ const source = host.source;
12
+ const sourceLength = source.length;
13
+ const startOffset = source.length > 0 ? charCodeDefinitions.isBOM(source.charCodeAt(0)) : 0;
14
+ const lines = adoptBuffer.adoptBuffer(host.lines, sourceLength);
15
+ const columns = adoptBuffer.adoptBuffer(host.columns, sourceLength);
16
+ let line = host.startLine;
17
+ let column = host.startColumn;
18
+
19
+ for (let i = startOffset; i < sourceLength; i++) {
20
+ const code = source.charCodeAt(i);
21
+
22
+ lines[i] = line;
23
+ columns[i] = column++;
24
+
25
+ if (code === N || code === R || code === F) {
26
+ if (code === R && i + 1 < sourceLength && source.charCodeAt(i + 1) === N) {
27
+ i++;
28
+ lines[i] = line;
29
+ columns[i] = column;
30
+ }
31
+
32
+ line++;
33
+ column = 1;
34
+ }
35
+ }
36
+
37
+ lines[sourceLength] = line;
38
+ columns[sourceLength] = column;
39
+
40
+ host.lines = lines;
41
+ host.columns = columns;
42
+ host.computed = true;
43
+ }
44
+
45
+ class OffsetToLocation {
46
+ constructor(source, startOffset, startLine, startColumn) {
47
+ this.setSource(source, startOffset, startLine, startColumn);
48
+ this.lines = null;
49
+ this.columns = null;
50
+ }
51
+ setSource(source = '', startOffset = 0, startLine = 1, startColumn = 1) {
52
+ this.source = source;
53
+ this.startOffset = startOffset;
54
+ this.startLine = startLine;
55
+ this.startColumn = startColumn;
56
+ this.computed = false;
57
+ }
58
+ getLocation(offset, filename) {
59
+ if (!this.computed) {
60
+ computeLinesAndColumns(this);
61
+ }
62
+
63
+ return {
64
+ source: filename,
65
+ offset: this.startOffset + offset,
66
+ line: this.lines[offset],
67
+ column: this.columns[offset]
68
+ };
69
+ }
70
+ getLocationRange(start, end, filename) {
71
+ if (!this.computed) {
72
+ computeLinesAndColumns(this);
73
+ }
74
+
75
+ return {
76
+ source: filename,
77
+ start: {
78
+ offset: this.startOffset + start,
79
+ line: this.lines[start],
80
+ column: this.columns[start]
81
+ },
82
+ end: {
83
+ offset: this.startOffset + end,
84
+ line: this.lines[end],
85
+ column: this.columns[end]
86
+ }
87
+ };
88
+ }
89
+ }
90
+
91
+ exports.OffsetToLocation = OffsetToLocation;
@@ -0,0 +1,358 @@
1
+ 'use strict';
2
+
3
+ const adoptBuffer = require('./adopt-buffer.cjs');
4
+ const utils = require('./utils.cjs');
5
+ const names = require('./names.cjs');
6
+ const types = require('./types.cjs');
7
+
8
+ const OFFSET_MASK = 0x00FFFFFF;
9
+ const TYPE_SHIFT = 24;
10
+ const BLOCK_OPEN_TOKEN = 1;
11
+ const BLOCK_CLOSE_TOKEN = 2;
12
+ const balancePair = new Uint8Array(32); // 32b of memory ought to be enough for anyone (any number of tokens)
13
+ balancePair[types.Function] = types.RightParenthesis;
14
+ balancePair[types.LeftParenthesis] = types.RightParenthesis;
15
+ balancePair[types.LeftSquareBracket] = types.RightSquareBracket;
16
+ balancePair[types.LeftCurlyBracket] = types.RightCurlyBracket;
17
+
18
+ const blockTokens = new Uint8Array(32);
19
+ blockTokens[types.Function] = BLOCK_OPEN_TOKEN;
20
+ blockTokens[types.LeftParenthesis] = BLOCK_OPEN_TOKEN;
21
+ blockTokens[types.LeftSquareBracket] = BLOCK_OPEN_TOKEN;
22
+ blockTokens[types.LeftCurlyBracket] = BLOCK_OPEN_TOKEN;
23
+ blockTokens[types.RightParenthesis] = BLOCK_CLOSE_TOKEN;
24
+ blockTokens[types.RightSquareBracket] = BLOCK_CLOSE_TOKEN;
25
+ blockTokens[types.RightCurlyBracket] = BLOCK_CLOSE_TOKEN;
26
+
27
+ function boundIndex(index, min, max) {
28
+ return index < min ? min : index > max ? max : index;
29
+ }
30
+
31
+ class TokenStream {
32
+ constructor(source, tokenize) {
33
+ this.setSource(source, tokenize);
34
+ }
35
+ reset() {
36
+ this.eof = false;
37
+ this.tokenIndex = -1;
38
+ this.tokenType = 0;
39
+ this.tokenStart = this.firstCharOffset;
40
+ this.tokenEnd = this.firstCharOffset;
41
+ }
42
+ setSource(source = '', tokenize = () => {}) {
43
+ source = String(source || '');
44
+
45
+ const sourceLength = source.length;
46
+ const offsetAndType = adoptBuffer.adoptBuffer(this.offsetAndType, source.length + 1); // +1 because of eof-token
47
+ const balance = adoptBuffer.adoptBuffer(this.balance, source.length + 1);
48
+ let tokenCount = 0;
49
+ let firstCharOffset = -1;
50
+ let balanceCloseType = 0;
51
+ let balanceStart = source.length;
52
+
53
+ // capture buffers
54
+ this.offsetAndType = null;
55
+ this.balance = null;
56
+ balance.fill(0);
57
+
58
+ tokenize(source, (type, start, end) => {
59
+ const index = tokenCount++;
60
+
61
+ // type & offset
62
+ offsetAndType[index] = (type << TYPE_SHIFT) | end;
63
+
64
+ if (firstCharOffset === -1) {
65
+ firstCharOffset = start;
66
+ }
67
+
68
+ // balance
69
+ balance[index] = balanceStart;
70
+
71
+ if (type === balanceCloseType) {
72
+ const prevBalanceStart = balance[balanceStart];
73
+
74
+ // set reference to balance end for a block opener
75
+ balance[balanceStart] = index;
76
+
77
+ // pop state
78
+ balanceStart = prevBalanceStart;
79
+ balanceCloseType = balancePair[offsetAndType[prevBalanceStart] >> TYPE_SHIFT];
80
+ } else if (this.isBlockOpenerTokenType(type)) { // check for FunctionToken, <(-token>, <[-token> and <{-token>
81
+ // push state
82
+ balanceStart = index;
83
+ balanceCloseType = balancePair[type];
84
+ }
85
+ });
86
+
87
+ // finalize buffers
88
+ offsetAndType[tokenCount] = (types.EOF << TYPE_SHIFT) | sourceLength; // <EOF-token>
89
+ balance[tokenCount] = tokenCount; // prevents false positive balance match with any token
90
+
91
+ // reverse references from balance start to end
92
+ // tokens
93
+ // token: a ( [ b c ] d e ) {
94
+ // index: 0 1 2 3 4 5 6 7 8 9
95
+ // before
96
+ // balance: 0 8 5 2 2 2 1 1 1 0
97
+ // - > > < < < < < < -
98
+ // after
99
+ // balance: 9 8 5 5 5 2 8 8 1 9
100
+ // > > > > > < > > < >
101
+ for (let i = 0; i < tokenCount; i++) {
102
+ const balanceStart = balance[i];
103
+
104
+ if (balanceStart <= i) {
105
+ const balanceEnd = balance[balanceStart];
106
+
107
+ if (balanceEnd !== i) {
108
+ balance[i] = balanceEnd;
109
+ }
110
+ } else if (balanceStart > tokenCount) {
111
+ balance[i] = tokenCount;
112
+ }
113
+ }
114
+
115
+ // balance[0] = tokenCount;
116
+
117
+ this.source = source;
118
+ this.firstCharOffset = firstCharOffset === -1 ? 0 : firstCharOffset;
119
+ this.tokenCount = tokenCount;
120
+ this.offsetAndType = offsetAndType;
121
+ this.balance = balance;
122
+
123
+ this.reset();
124
+ this.next();
125
+ }
126
+
127
+ lookupType(offset) {
128
+ offset += this.tokenIndex;
129
+
130
+ if (offset < this.tokenCount) {
131
+ return this.offsetAndType[offset] >> TYPE_SHIFT;
132
+ }
133
+
134
+ return types.EOF;
135
+ }
136
+ lookupTypeNonSC(idx) {
137
+ for (let offset = this.tokenIndex; offset < this.tokenCount; offset++) {
138
+ const tokenType = this.offsetAndType[offset] >> TYPE_SHIFT;
139
+
140
+ if (tokenType !== types.WhiteSpace && tokenType !== types.Comment) {
141
+ if (idx-- === 0) {
142
+ return tokenType;
143
+ }
144
+ }
145
+ }
146
+
147
+ return types.EOF;
148
+ }
149
+ lookupOffset(offset) {
150
+ offset += this.tokenIndex;
151
+
152
+ if (offset < this.tokenCount) {
153
+ return this.offsetAndType[offset - 1] & OFFSET_MASK;
154
+ }
155
+
156
+ return this.source.length;
157
+ }
158
+ lookupOffsetNonSC(idx) {
159
+ for (let offset = this.tokenIndex; offset < this.tokenCount; offset++) {
160
+ const tokenType = this.offsetAndType[offset] >> TYPE_SHIFT;
161
+
162
+ if (tokenType !== types.WhiteSpace && tokenType !== types.Comment) {
163
+ if (idx-- === 0) {
164
+ return offset - this.tokenIndex;
165
+ }
166
+ }
167
+ }
168
+
169
+ return types.EOF;
170
+ }
171
+ lookupValue(offset, referenceStr) {
172
+ offset += this.tokenIndex;
173
+
174
+ if (offset < this.tokenCount) {
175
+ return utils.cmpStr(
176
+ this.source,
177
+ this.offsetAndType[offset - 1] & OFFSET_MASK,
178
+ this.offsetAndType[offset] & OFFSET_MASK,
179
+ referenceStr
180
+ );
181
+ }
182
+
183
+ return false;
184
+ }
185
+ getTokenStart(tokenIndex) {
186
+ if (tokenIndex === this.tokenIndex) {
187
+ return this.tokenStart;
188
+ }
189
+
190
+ if (tokenIndex > 0) {
191
+ return tokenIndex < this.tokenCount
192
+ ? this.offsetAndType[tokenIndex - 1] & OFFSET_MASK
193
+ : this.offsetAndType[this.tokenCount] & OFFSET_MASK;
194
+ }
195
+
196
+ return this.firstCharOffset;
197
+ }
198
+ getTokenEnd(tokenIndex) {
199
+ if (tokenIndex === this.tokenIndex) {
200
+ return this.tokenEnd;
201
+ }
202
+
203
+ return this.offsetAndType[boundIndex(tokenIndex, 0, this.tokenCount)] & OFFSET_MASK;
204
+ }
205
+ getTokenType(tokenIndex) {
206
+ if (tokenIndex === this.tokenIndex) {
207
+ return this.tokenType;
208
+ }
209
+
210
+ return this.offsetAndType[boundIndex(tokenIndex, 0, this.tokenCount)] >> TYPE_SHIFT;
211
+ }
212
+ substrToCursor(start) {
213
+ return this.source.substring(start, this.tokenStart);
214
+ }
215
+
216
+ isBlockOpenerTokenType(tokenType) {
217
+ return blockTokens[tokenType] === BLOCK_OPEN_TOKEN;
218
+ }
219
+ isBlockCloserTokenType(tokenType) {
220
+ return blockTokens[tokenType] === BLOCK_CLOSE_TOKEN;
221
+ }
222
+ getBlockTokenPairIndex(tokenIndex) {
223
+ const type = this.getTokenType(tokenIndex);
224
+
225
+ if (blockTokens[type] === 1) {
226
+ // block open token
227
+ const pairIndex = this.balance[tokenIndex];
228
+ const closeType = this.getTokenType(pairIndex);
229
+
230
+ return balancePair[type] === closeType ? pairIndex : -1;
231
+ } else if (blockTokens[type] === 2) {
232
+ // block close token
233
+ const pairIndex = this.balance[tokenIndex];
234
+ const openType = this.getTokenType(pairIndex);
235
+
236
+ return balancePair[openType] === type ? pairIndex : -1;
237
+ }
238
+
239
+ return -1;
240
+ }
241
+ isBalanceEdge(tokenIndex) {
242
+ return this.balance[this.tokenIndex] < tokenIndex;
243
+ }
244
+
245
+ isDelim(code, offset) {
246
+ if (offset) {
247
+ return (
248
+ this.lookupType(offset) === types.Delim &&
249
+ this.source.charCodeAt(this.lookupOffset(offset)) === code
250
+ );
251
+ }
252
+
253
+ return (
254
+ this.tokenType === types.Delim &&
255
+ this.source.charCodeAt(this.tokenStart) === code
256
+ );
257
+ }
258
+
259
+ skip(tokenCount) {
260
+ let next = this.tokenIndex + tokenCount;
261
+
262
+ if (next < this.tokenCount) {
263
+ this.tokenIndex = next;
264
+ this.tokenStart = this.offsetAndType[next - 1] & OFFSET_MASK;
265
+ next = this.offsetAndType[next];
266
+ this.tokenType = next >> TYPE_SHIFT;
267
+ this.tokenEnd = next & OFFSET_MASK;
268
+ } else {
269
+ this.tokenIndex = this.tokenCount;
270
+ this.next();
271
+ }
272
+ }
273
+ next() {
274
+ let next = this.tokenIndex + 1;
275
+
276
+ if (next < this.tokenCount) {
277
+ this.tokenIndex = next;
278
+ this.tokenStart = this.tokenEnd;
279
+ next = this.offsetAndType[next];
280
+ this.tokenType = next >> TYPE_SHIFT;
281
+ this.tokenEnd = next & OFFSET_MASK;
282
+ } else {
283
+ this.eof = true;
284
+ this.tokenIndex = this.tokenCount;
285
+ this.tokenType = types.EOF;
286
+ this.tokenStart = this.tokenEnd = this.source.length;
287
+ }
288
+ }
289
+ skipSC() {
290
+ while (this.tokenType === types.WhiteSpace || this.tokenType === types.Comment) {
291
+ this.next();
292
+ }
293
+ }
294
+ skipUntilBalanced(startToken, stopConsume) {
295
+ let cursor = startToken;
296
+ let balanceEnd = 0;
297
+ let offset = 0;
298
+
299
+ loop:
300
+ for (; cursor < this.tokenCount; cursor++) {
301
+ balanceEnd = this.balance[cursor];
302
+
303
+ // stop scanning on balance edge that points to offset before start token
304
+ if (balanceEnd < startToken) {
305
+ break loop;
306
+ }
307
+
308
+ offset = cursor > 0 ? this.offsetAndType[cursor - 1] & OFFSET_MASK : this.firstCharOffset;
309
+
310
+ // check stop condition
311
+ switch (stopConsume(this.source.charCodeAt(offset))) {
312
+ case 1: // just stop
313
+ break loop;
314
+
315
+ case 2: // stop & included
316
+ cursor++;
317
+ break loop;
318
+
319
+ default:
320
+ // fast forward to the end of balanced block for an open block tokens
321
+ if (this.isBlockOpenerTokenType(this.offsetAndType[cursor] >> TYPE_SHIFT)) {
322
+ cursor = balanceEnd;
323
+ }
324
+ }
325
+ }
326
+
327
+ this.skip(cursor - this.tokenIndex);
328
+ }
329
+
330
+ forEachToken(fn) {
331
+ for (let i = 0, offset = this.firstCharOffset; i < this.tokenCount; i++) {
332
+ const start = offset;
333
+ const item = this.offsetAndType[i];
334
+ const end = item & OFFSET_MASK;
335
+ const type = item >> TYPE_SHIFT;
336
+
337
+ offset = end;
338
+
339
+ fn(type, start, end, i);
340
+ }
341
+ }
342
+ dump() {
343
+ const tokens = new Array(this.tokenCount);
344
+
345
+ this.forEachToken((type, start, end, index) => {
346
+ tokens[index] = {
347
+ idx: index,
348
+ type: names[type],
349
+ chunk: this.source.substring(start, end),
350
+ balance: this.balance[index]
351
+ };
352
+ });
353
+
354
+ return tokens;
355
+ }
356
+ }
357
+
358
+ exports.TokenStream = TokenStream;