@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,473 @@
1
+ 'use strict';
2
+
3
+ //
4
+ // list
5
+ // ┌──────┐
6
+ // ┌──────────────┼─head │
7
+ // │ │ tail─┼──────────────┐
8
+ // │ └──────┘ │
9
+ // ▼ ▼
10
+ // item item item item
11
+ // ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐
12
+ // null ◀──┼─prev │◀───┼─prev │◀───┼─prev │◀───┼─prev │
13
+ // │ next─┼───▶│ next─┼───▶│ next─┼───▶│ next─┼──▶ null
14
+ // ├──────┤ ├──────┤ ├──────┤ ├──────┤
15
+ // │ data │ │ data │ │ data │ │ data │
16
+ // └──────┘ └──────┘ └──────┘ └──────┘
17
+ //
18
+
19
+ let releasedCursors = null;
20
+
21
+ class List {
22
+ static createItem(data) {
23
+ return {
24
+ prev: null,
25
+ next: null,
26
+ data
27
+ };
28
+ }
29
+
30
+ constructor() {
31
+ this.head = null;
32
+ this.tail = null;
33
+ this.cursor = null;
34
+ }
35
+ createItem(data) {
36
+ return List.createItem(data);
37
+ }
38
+
39
+ // cursor helpers
40
+ allocateCursor(prev, next) {
41
+ let cursor;
42
+
43
+ if (releasedCursors !== null) {
44
+ cursor = releasedCursors;
45
+ releasedCursors = releasedCursors.cursor;
46
+ cursor.prev = prev;
47
+ cursor.next = next;
48
+ cursor.cursor = this.cursor;
49
+ } else {
50
+ cursor = {
51
+ prev,
52
+ next,
53
+ cursor: this.cursor
54
+ };
55
+ }
56
+
57
+ this.cursor = cursor;
58
+
59
+ return cursor;
60
+ }
61
+ releaseCursor() {
62
+ const { cursor } = this;
63
+
64
+ this.cursor = cursor.cursor;
65
+ cursor.prev = null;
66
+ cursor.next = null;
67
+ cursor.cursor = releasedCursors;
68
+ releasedCursors = cursor;
69
+ }
70
+ updateCursors(prevOld, prevNew, nextOld, nextNew) {
71
+ let { cursor } = this;
72
+
73
+ while (cursor !== null) {
74
+ if (cursor.prev === prevOld) {
75
+ cursor.prev = prevNew;
76
+ }
77
+
78
+ if (cursor.next === nextOld) {
79
+ cursor.next = nextNew;
80
+ }
81
+
82
+ cursor = cursor.cursor;
83
+ }
84
+ }
85
+ *[Symbol.iterator]() {
86
+ for (let cursor = this.head; cursor !== null; cursor = cursor.next) {
87
+ yield cursor.data;
88
+ }
89
+ }
90
+
91
+ // getters
92
+ get size() {
93
+ let size = 0;
94
+
95
+ for (let cursor = this.head; cursor !== null; cursor = cursor.next) {
96
+ size++;
97
+ }
98
+
99
+ return size;
100
+ }
101
+ get isEmpty() {
102
+ return this.head === null;
103
+ }
104
+ get first() {
105
+ return this.head && this.head.data;
106
+ }
107
+ get last() {
108
+ return this.tail && this.tail.data;
109
+ }
110
+
111
+ // convertors
112
+ fromArray(array) {
113
+ let cursor = null;
114
+ this.head = null;
115
+
116
+ for (let data of array) {
117
+ const item = List.createItem(data);
118
+
119
+ if (cursor !== null) {
120
+ cursor.next = item;
121
+ } else {
122
+ this.head = item;
123
+ }
124
+
125
+ item.prev = cursor;
126
+ cursor = item;
127
+ }
128
+
129
+ this.tail = cursor;
130
+ return this;
131
+ }
132
+ toArray() {
133
+ return [...this];
134
+ }
135
+ toJSON() {
136
+ return [...this];
137
+ }
138
+
139
+ // array-like methods
140
+ forEach(fn, thisArg = this) {
141
+ // push cursor
142
+ const cursor = this.allocateCursor(null, this.head);
143
+
144
+ while (cursor.next !== null) {
145
+ const item = cursor.next;
146
+ cursor.next = item.next;
147
+ fn.call(thisArg, item.data, item, this);
148
+ }
149
+
150
+ // pop cursor
151
+ this.releaseCursor();
152
+ }
153
+ forEachRight(fn, thisArg = this) {
154
+ // push cursor
155
+ const cursor = this.allocateCursor(this.tail, null);
156
+
157
+ while (cursor.prev !== null) {
158
+ const item = cursor.prev;
159
+ cursor.prev = item.prev;
160
+ fn.call(thisArg, item.data, item, this);
161
+ }
162
+
163
+ // pop cursor
164
+ this.releaseCursor();
165
+ }
166
+ reduce(fn, initialValue, thisArg = this) {
167
+ // push cursor
168
+ let cursor = this.allocateCursor(null, this.head);
169
+ let acc = initialValue;
170
+ let item;
171
+
172
+ while (cursor.next !== null) {
173
+ item = cursor.next;
174
+ cursor.next = item.next;
175
+
176
+ acc = fn.call(thisArg, acc, item.data, item, this);
177
+ }
178
+
179
+ // pop cursor
180
+ this.releaseCursor();
181
+
182
+ return acc;
183
+ }
184
+ reduceRight(fn, initialValue, thisArg = this) {
185
+ // push cursor
186
+ let cursor = this.allocateCursor(this.tail, null);
187
+ let acc = initialValue;
188
+ let item;
189
+
190
+ while (cursor.prev !== null) {
191
+ item = cursor.prev;
192
+ cursor.prev = item.prev;
193
+
194
+ acc = fn.call(thisArg, acc, item.data, item, this);
195
+ }
196
+
197
+ // pop cursor
198
+ this.releaseCursor();
199
+
200
+ return acc;
201
+ }
202
+ some(fn, thisArg = this) {
203
+ for (let cursor = this.head; cursor !== null; cursor = cursor.next) {
204
+ if (fn.call(thisArg, cursor.data, cursor, this)) {
205
+ return true;
206
+ }
207
+ }
208
+
209
+ return false;
210
+ }
211
+ map(fn, thisArg = this) {
212
+ const result = new List();
213
+
214
+ for (let cursor = this.head; cursor !== null; cursor = cursor.next) {
215
+ result.appendData(fn.call(thisArg, cursor.data, cursor, this));
216
+ }
217
+
218
+ return result;
219
+ }
220
+ filter(fn, thisArg = this) {
221
+ const result = new List();
222
+
223
+ for (let cursor = this.head; cursor !== null; cursor = cursor.next) {
224
+ if (fn.call(thisArg, cursor.data, cursor, this)) {
225
+ result.appendData(cursor.data);
226
+ }
227
+ }
228
+
229
+ return result;
230
+ }
231
+
232
+ nextUntil(start, fn, thisArg = this) {
233
+ if (start === null) {
234
+ return;
235
+ }
236
+
237
+ // push cursor
238
+ const cursor = this.allocateCursor(null, start);
239
+
240
+ while (cursor.next !== null) {
241
+ const item = cursor.next;
242
+ cursor.next = item.next;
243
+ if (fn.call(thisArg, item.data, item, this)) {
244
+ break;
245
+ }
246
+ }
247
+
248
+ // pop cursor
249
+ this.releaseCursor();
250
+ }
251
+ prevUntil(start, fn, thisArg = this) {
252
+ if (start === null) {
253
+ return;
254
+ }
255
+
256
+ // push cursor
257
+ const cursor = this.allocateCursor(start, null);
258
+
259
+ while (cursor.prev !== null) {
260
+ const item = cursor.prev;
261
+ cursor.prev = item.prev;
262
+ if (fn.call(thisArg, item.data, item, this)) {
263
+ break;
264
+ }
265
+ }
266
+
267
+ // pop cursor
268
+ this.releaseCursor();
269
+ }
270
+
271
+ // mutation
272
+ clear() {
273
+ this.head = null;
274
+ this.tail = null;
275
+ }
276
+ copy() {
277
+ const result = new List();
278
+
279
+ for (let data of this) {
280
+ result.appendData(data);
281
+ }
282
+
283
+ return result;
284
+ }
285
+ prepend(item) {
286
+ // head
287
+ // ^
288
+ // item
289
+ this.updateCursors(null, item, this.head, item);
290
+
291
+ // insert to the beginning of the list
292
+ if (this.head !== null) {
293
+ // new item <- first item
294
+ this.head.prev = item;
295
+ // new item -> first item
296
+ item.next = this.head;
297
+ } else {
298
+ // if list has no head, then it also has no tail
299
+ // in this case tail points to the new item
300
+ this.tail = item;
301
+ }
302
+
303
+ // head always points to new item
304
+ this.head = item;
305
+ return this;
306
+ }
307
+ prependData(data) {
308
+ return this.prepend(List.createItem(data));
309
+ }
310
+ append(item) {
311
+ return this.insert(item);
312
+ }
313
+ appendData(data) {
314
+ return this.insert(List.createItem(data));
315
+ }
316
+ insert(item, before = null) {
317
+ if (before !== null) {
318
+ // prev before
319
+ // ^
320
+ // item
321
+ this.updateCursors(before.prev, item, before, item);
322
+
323
+ if (before.prev === null) {
324
+ // insert to the beginning of list
325
+ if (this.head !== before) {
326
+ throw new Error('before doesn\'t belong to list');
327
+ }
328
+ // since head points to before therefore list doesn't empty
329
+ // no need to check tail
330
+ this.head = item;
331
+ before.prev = item;
332
+ item.next = before;
333
+ this.updateCursors(null, item);
334
+ } else {
335
+ // insert between two items
336
+ before.prev.next = item;
337
+ item.prev = before.prev;
338
+ before.prev = item;
339
+ item.next = before;
340
+ }
341
+ } else {
342
+ // tail
343
+ // ^
344
+ // item
345
+ this.updateCursors(this.tail, item, null, item);
346
+
347
+ // insert to the ending of the list
348
+ if (this.tail !== null) {
349
+ // last item -> new item
350
+ this.tail.next = item;
351
+ // last item <- new item
352
+ item.prev = this.tail;
353
+ } else {
354
+ // if list has no tail, then it also has no head
355
+ // in this case head points to new item
356
+ this.head = item;
357
+ }
358
+
359
+ // tail always points to new item
360
+ this.tail = item;
361
+ }
362
+
363
+ return this;
364
+ }
365
+ insertData(data, before) {
366
+ return this.insert(List.createItem(data), before);
367
+ }
368
+ remove(item) {
369
+ // item
370
+ // ^
371
+ // prev next
372
+ this.updateCursors(item, item.prev, item, item.next);
373
+
374
+ if (item.prev !== null) {
375
+ item.prev.next = item.next;
376
+ } else {
377
+ if (this.head !== item) {
378
+ throw new Error('item doesn\'t belong to list');
379
+ }
380
+
381
+ this.head = item.next;
382
+ }
383
+
384
+ if (item.next !== null) {
385
+ item.next.prev = item.prev;
386
+ } else {
387
+ if (this.tail !== item) {
388
+ throw new Error('item doesn\'t belong to list');
389
+ }
390
+
391
+ this.tail = item.prev;
392
+ }
393
+
394
+ item.prev = null;
395
+ item.next = null;
396
+
397
+ return item;
398
+ }
399
+ push(data) {
400
+ this.insert(List.createItem(data));
401
+ }
402
+ pop() {
403
+ return this.tail !== null ? this.remove(this.tail) : null;
404
+ }
405
+ unshift(data) {
406
+ this.prepend(List.createItem(data));
407
+ }
408
+ shift() {
409
+ return this.head !== null ? this.remove(this.head) : null;
410
+ }
411
+ prependList(list) {
412
+ return this.insertList(list, this.head);
413
+ }
414
+ appendList(list) {
415
+ return this.insertList(list);
416
+ }
417
+ insertList(list, before) {
418
+ // ignore empty lists
419
+ if (list.head === null) {
420
+ return this;
421
+ }
422
+
423
+ if (before !== undefined && before !== null) {
424
+ this.updateCursors(before.prev, list.tail, before, list.head);
425
+
426
+ // insert in the middle of dist list
427
+ if (before.prev !== null) {
428
+ // before.prev <-> list.head
429
+ before.prev.next = list.head;
430
+ list.head.prev = before.prev;
431
+ } else {
432
+ this.head = list.head;
433
+ }
434
+
435
+ before.prev = list.tail;
436
+ list.tail.next = before;
437
+ } else {
438
+ this.updateCursors(this.tail, list.tail, null, list.head);
439
+
440
+ // insert to end of the list
441
+ if (this.tail !== null) {
442
+ // if destination list has a tail, then it also has a head,
443
+ // but head doesn't change
444
+ // dest tail -> source head
445
+ this.tail.next = list.head;
446
+ // dest tail <- source head
447
+ list.head.prev = this.tail;
448
+ } else {
449
+ // if list has no a tail, then it also has no a head
450
+ // in this case points head to new item
451
+ this.head = list.head;
452
+ }
453
+
454
+ // tail always start point to new item
455
+ this.tail = list.tail;
456
+ }
457
+
458
+ list.head = null;
459
+ list.tail = null;
460
+ return this;
461
+ }
462
+ replace(oldItem, newItemOrList) {
463
+ if ('head' in newItemOrList) {
464
+ this.insertList(newItemOrList, oldItem);
465
+ } else {
466
+ this.insert(newItemOrList, oldItem);
467
+ }
468
+
469
+ this.remove(oldItem);
470
+ }
471
+ }
472
+
473
+ exports.List = List;
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ const List = require('./List.cjs');
4
+
5
+ function clone(node) {
6
+ const result = {};
7
+
8
+ for (const key of Object.keys(node)) {
9
+ let value = node[key];
10
+
11
+ if (value) {
12
+ if (Array.isArray(value) || value instanceof List.List) {
13
+ value = value.map(clone);
14
+ } else if (value.constructor === Object) {
15
+ value = clone(value);
16
+ }
17
+ }
18
+
19
+ result[key] = value;
20
+ }
21
+
22
+ return result;
23
+ }
24
+
25
+ exports.clone = clone;
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ function createCustomError(name, message) {
4
+ // use Object.create(), because some VMs prevent setting line/column otherwise
5
+ // (iOS Safari 10 even throws an exception)
6
+ const error = Object.create(SyntaxError.prototype);
7
+ const errorStack = new Error();
8
+
9
+ return Object.assign(error, {
10
+ name,
11
+ message,
12
+ get stack() {
13
+ return (errorStack.stack || '').replace(/^(.+\n){1,3}/, `${name}: ${message}\n`);
14
+ }
15
+ });
16
+ }
17
+
18
+ exports.createCustomError = createCustomError;
@@ -0,0 +1,102 @@
1
+ 'use strict';
2
+
3
+ const charCodeDefinitions = require('../tokenizer/char-code-definitions.cjs');
4
+ const utils = require('../tokenizer/utils.cjs');
5
+
6
+ const REVERSE_SOLIDUS = 0x005c; // U+005C REVERSE SOLIDUS (\)
7
+
8
+ function decode(str) {
9
+ const end = str.length - 1;
10
+ let decoded = '';
11
+
12
+ for (let i = 0; i < str.length; i++) {
13
+ let code = str.charCodeAt(i);
14
+
15
+ if (code === REVERSE_SOLIDUS) {
16
+ // special case at the ending
17
+ if (i === end) {
18
+ // if the next input code point is EOF, do nothing
19
+ break;
20
+ }
21
+
22
+ code = str.charCodeAt(++i);
23
+
24
+ // consume escaped
25
+ if (charCodeDefinitions.isValidEscape(REVERSE_SOLIDUS, code)) {
26
+ const escapeStart = i - 1;
27
+ const escapeEnd = utils.consumeEscaped(str, escapeStart);
28
+
29
+ i = escapeEnd - 1;
30
+ decoded += utils.decodeEscaped(str.substring(escapeStart + 1, escapeEnd));
31
+ } else {
32
+ // \r\n
33
+ if (code === 0x000d && str.charCodeAt(i + 1) === 0x000a) {
34
+ i++;
35
+ }
36
+ }
37
+ } else {
38
+ decoded += str[i];
39
+ }
40
+ }
41
+
42
+ return decoded;
43
+ }
44
+
45
+ // https://drafts.csswg.org/cssom/#serialize-an-identifier
46
+ // § 2.1. Common Serializing Idioms
47
+ function encode(str) {
48
+ let encoded = '';
49
+
50
+ // If the character is the first character and is a "-" (U+002D),
51
+ // and there is no second character, then the escaped character.
52
+ // Note: That's means a single dash string "-" return as escaped dash,
53
+ // so move the condition out of the main loop
54
+ if (str.length === 1 && str.charCodeAt(0) === 0x002D) {
55
+ return '\\-';
56
+ }
57
+
58
+ // To serialize an identifier means to create a string represented
59
+ // by the concatenation of, for each character of the identifier:
60
+ for (let i = 0; i < str.length; i++) {
61
+ const code = str.charCodeAt(i);
62
+
63
+ // If the character is NULL (U+0000), then the REPLACEMENT CHARACTER (U+FFFD).
64
+ if (code === 0x0000) {
65
+ encoded += '\uFFFD';
66
+ continue;
67
+ }
68
+
69
+ if (
70
+ // If the character is in the range [\1-\1f] (U+0001 to U+001F) or is U+007F ...
71
+ // Note: Do not compare with 0x0001 since 0x0000 is precessed before
72
+ code <= 0x001F || code === 0x007F ||
73
+ // [or] ... is in the range [0-9] (U+0030 to U+0039),
74
+ (code >= 0x0030 && code <= 0x0039 && (
75
+ // If the character is the first character ...
76
+ i === 0 ||
77
+ // If the character is the second character ... and the first character is a "-" (U+002D)
78
+ i === 1 && str.charCodeAt(0) === 0x002D
79
+ ))
80
+ ) {
81
+ // ... then the character escaped as code point.
82
+ encoded += '\\' + code.toString(16) + ' ';
83
+ continue;
84
+ }
85
+
86
+ // If the character is not handled by one of the above rules and is greater
87
+ // than or equal to U+0080, is "-" (U+002D) or "_" (U+005F), or is in one
88
+ // of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to U+005A),
89
+ // or \[a-z] (U+0061 to U+007A), then the character itself.
90
+ if (charCodeDefinitions.isName(code)) {
91
+ encoded += str.charAt(i);
92
+ } else {
93
+ // Otherwise, the escaped character.
94
+ encoded += '\\' + str.charAt(i);
95
+ }
96
+ }
97
+
98
+ return encoded;
99
+ }
100
+
101
+ exports.decode = decode;
102
+ exports.encode = encode;
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ const clone = require('./clone.cjs');
4
+ const ident = require('./ident.cjs');
5
+ const List = require('./List.cjs');
6
+ const names = require('./names.cjs');
7
+ const string = require('./string.cjs');
8
+ const url = require('./url.cjs');
9
+
10
+
11
+
12
+ exports.clone = clone.clone;
13
+ exports.ident = ident;
14
+ exports.List = List.List;
15
+ exports.isCustomProperty = names.isCustomProperty;
16
+ exports.keyword = names.keyword;
17
+ exports.property = names.property;
18
+ exports.vendorPrefix = names.vendorPrefix;
19
+ exports.string = string;
20
+ exports.url = url;