@chikx/compiler 0.0.0-stage → 0.1.1

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 (398) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -2
  3. package/dist/emitter/index.d.ts +96 -0
  4. package/dist/emitter/index.d.ts.map +1 -0
  5. package/dist/emitter/index.js +415 -0
  6. package/dist/emitter/index.js.map +1 -0
  7. package/dist/formatter/index.d.ts +53 -0
  8. package/dist/formatter/index.d.ts.map +1 -0
  9. package/dist/formatter/index.js +464 -0
  10. package/dist/formatter/index.js.map +1 -0
  11. package/dist/host/node.d.ts +34 -0
  12. package/dist/host/node.d.ts.map +1 -0
  13. package/dist/host/node.js +80 -0
  14. package/dist/host/node.js.map +1 -0
  15. package/dist/index.d.ts +93 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +792 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/ir/factories.d.ts +35 -0
  20. package/dist/ir/factories.d.ts.map +1 -0
  21. package/dist/ir/factories.js +47 -0
  22. package/dist/ir/factories.js.map +1 -0
  23. package/dist/ir/index.d.ts +13 -0
  24. package/dist/ir/index.d.ts.map +1 -0
  25. package/dist/ir/index.js +2 -0
  26. package/dist/ir/index.js.map +1 -0
  27. package/dist/ir/types.d.ts +139 -0
  28. package/dist/ir/types.d.ts.map +1 -0
  29. package/dist/ir/types.js +2 -0
  30. package/dist/ir/types.js.map +1 -0
  31. package/dist/lexer/at-keywords.d.ts +27 -0
  32. package/dist/lexer/at-keywords.d.ts.map +1 -0
  33. package/dist/lexer/at-keywords.js +35 -0
  34. package/dist/lexer/at-keywords.js.map +1 -0
  35. package/dist/lexer/characters.d.ts +38 -0
  36. package/dist/lexer/characters.d.ts.map +1 -0
  37. package/dist/lexer/characters.js +74 -0
  38. package/dist/lexer/characters.js.map +1 -0
  39. package/dist/lexer/comments.d.ts +22 -0
  40. package/dist/lexer/comments.d.ts.map +1 -0
  41. package/dist/lexer/comments.js +20 -0
  42. package/dist/lexer/comments.js.map +1 -0
  43. package/dist/lexer/diagnostics.d.ts +24 -0
  44. package/dist/lexer/diagnostics.d.ts.map +1 -0
  45. package/dist/lexer/diagnostics.js +29 -0
  46. package/dist/lexer/diagnostics.js.map +1 -0
  47. package/dist/lexer/dollar-refs.d.ts +13 -0
  48. package/dist/lexer/dollar-refs.d.ts.map +1 -0
  49. package/dist/lexer/dollar-refs.js +22 -0
  50. package/dist/lexer/dollar-refs.js.map +1 -0
  51. package/dist/lexer/index.d.ts +32 -0
  52. package/dist/lexer/index.d.ts.map +1 -0
  53. package/dist/lexer/index.js +26 -0
  54. package/dist/lexer/index.js.map +1 -0
  55. package/dist/lexer/names.d.ts +23 -0
  56. package/dist/lexer/names.d.ts.map +1 -0
  57. package/dist/lexer/names.js +48 -0
  58. package/dist/lexer/names.js.map +1 -0
  59. package/dist/lexer/numbers.d.ts +22 -0
  60. package/dist/lexer/numbers.d.ts.map +1 -0
  61. package/dist/lexer/numbers.js +60 -0
  62. package/dist/lexer/numbers.js.map +1 -0
  63. package/dist/lexer/scanner.d.ts +30 -0
  64. package/dist/lexer/scanner.d.ts.map +1 -0
  65. package/dist/lexer/scanner.js +158 -0
  66. package/dist/lexer/scanner.js.map +1 -0
  67. package/dist/lexer/strings.d.ts +25 -0
  68. package/dist/lexer/strings.d.ts.map +1 -0
  69. package/dist/lexer/strings.js +41 -0
  70. package/dist/lexer/strings.js.map +1 -0
  71. package/dist/lexer/urls.d.ts +28 -0
  72. package/dist/lexer/urls.d.ts.map +1 -0
  73. package/dist/lexer/urls.js +54 -0
  74. package/dist/lexer/urls.js.map +1 -0
  75. package/dist/lowering/expand-groups.d.ts +61 -0
  76. package/dist/lowering/expand-groups.d.ts.map +1 -0
  77. package/dist/lowering/expand-groups.js +117 -0
  78. package/dist/lowering/expand-groups.js.map +1 -0
  79. package/dist/lowering/group.d.ts +30 -0
  80. package/dist/lowering/group.d.ts.map +1 -0
  81. package/dist/lowering/group.js +109 -0
  82. package/dist/lowering/group.js.map +1 -0
  83. package/dist/lowering/index.d.ts +26 -0
  84. package/dist/lowering/index.d.ts.map +1 -0
  85. package/dist/lowering/index.js +23 -0
  86. package/dist/lowering/index.js.map +1 -0
  87. package/dist/lowering/lower.d.ts +21 -0
  88. package/dist/lowering/lower.d.ts.map +1 -0
  89. package/dist/lowering/lower.js +296 -0
  90. package/dist/lowering/lower.js.map +1 -0
  91. package/dist/lowering/media.d.ts +63 -0
  92. package/dist/lowering/media.d.ts.map +1 -0
  93. package/dist/lowering/media.js +237 -0
  94. package/dist/lowering/media.js.map +1 -0
  95. package/dist/lowering/merge.d.ts +35 -0
  96. package/dist/lowering/merge.d.ts.map +1 -0
  97. package/dist/lowering/merge.js +146 -0
  98. package/dist/lowering/merge.js.map +1 -0
  99. package/dist/lowering/property-families.d.ts +50 -0
  100. package/dist/lowering/property-families.d.ts.map +1 -0
  101. package/dist/lowering/property-families.js +175 -0
  102. package/dist/lowering/property-families.js.map +1 -0
  103. package/dist/lowering/spans.d.ts +36 -0
  104. package/dist/lowering/spans.d.ts.map +1 -0
  105. package/dist/lowering/spans.js +100 -0
  106. package/dist/lowering/spans.js.map +1 -0
  107. package/dist/naming/index.d.ts +37 -0
  108. package/dist/naming/index.d.ts.map +1 -0
  109. package/dist/naming/index.js +34 -0
  110. package/dist/naming/index.js.map +1 -0
  111. package/dist/naming/mapgen.d.ts +70 -0
  112. package/dist/naming/mapgen.d.ts.map +1 -0
  113. package/dist/naming/mapgen.js +153 -0
  114. package/dist/naming/mapgen.js.map +1 -0
  115. package/dist/naming/merge.d.ts +62 -0
  116. package/dist/naming/merge.d.ts.map +1 -0
  117. package/dist/naming/merge.js +77 -0
  118. package/dist/naming/merge.js.map +1 -0
  119. package/dist/naming/rewrite.d.ts +14 -0
  120. package/dist/naming/rewrite.d.ts.map +1 -0
  121. package/dist/naming/rewrite.js +191 -0
  122. package/dist/naming/rewrite.js.map +1 -0
  123. package/dist/naming/scan.d.ts +80 -0
  124. package/dist/naming/scan.d.ts.map +1 -0
  125. package/dist/naming/scan.js +193 -0
  126. package/dist/naming/scan.js.map +1 -0
  127. package/dist/naming/table.d.ts +68 -0
  128. package/dist/naming/table.d.ts.map +1 -0
  129. package/dist/naming/table.js +132 -0
  130. package/dist/naming/table.js.map +1 -0
  131. package/dist/naming/types.d.ts +94 -0
  132. package/dist/naming/types.d.ts.map +1 -0
  133. package/dist/naming/types.js +2 -0
  134. package/dist/naming/types.js.map +1 -0
  135. package/dist/output/import-path.d.ts +24 -0
  136. package/dist/output/import-path.d.ts.map +1 -0
  137. package/dist/output/import-path.js +30 -0
  138. package/dist/output/import-path.js.map +1 -0
  139. package/dist/output/index.d.ts +40 -0
  140. package/dist/output/index.d.ts.map +1 -0
  141. package/dist/output/index.js +138 -0
  142. package/dist/output/index.js.map +1 -0
  143. package/dist/output/manifest.d.ts +17 -0
  144. package/dist/output/manifest.d.ts.map +1 -0
  145. package/dist/output/manifest.js +22 -0
  146. package/dist/output/manifest.js.map +1 -0
  147. package/dist/output/paths.d.ts +54 -0
  148. package/dist/output/paths.d.ts.map +1 -0
  149. package/dist/output/paths.js +183 -0
  150. package/dist/output/paths.js.map +1 -0
  151. package/dist/output/resolve.d.ts +100 -0
  152. package/dist/output/resolve.d.ts.map +1 -0
  153. package/dist/output/resolve.js +313 -0
  154. package/dist/output/resolve.js.map +1 -0
  155. package/dist/output/validate.d.ts +82 -0
  156. package/dist/output/validate.d.ts.map +1 -0
  157. package/dist/output/validate.js +128 -0
  158. package/dist/output/validate.js.map +1 -0
  159. package/dist/parser/cursor.d.ts +55 -0
  160. package/dist/parser/cursor.d.ts.map +1 -0
  161. package/dist/parser/cursor.js +120 -0
  162. package/dist/parser/cursor.js.map +1 -0
  163. package/dist/parser/declaration.d.ts +21 -0
  164. package/dist/parser/declaration.d.ts.map +1 -0
  165. package/dist/parser/declaration.js +201 -0
  166. package/dist/parser/declaration.js.map +1 -0
  167. package/dist/parser/diagnostics.d.ts +52 -0
  168. package/dist/parser/diagnostics.d.ts.map +1 -0
  169. package/dist/parser/diagnostics.js +55 -0
  170. package/dist/parser/diagnostics.js.map +1 -0
  171. package/dist/parser/group.d.ts +26 -0
  172. package/dist/parser/group.d.ts.map +1 -0
  173. package/dist/parser/group.js +219 -0
  174. package/dist/parser/group.js.map +1 -0
  175. package/dist/parser/index.d.ts +30 -0
  176. package/dist/parser/index.d.ts.map +1 -0
  177. package/dist/parser/index.js +48 -0
  178. package/dist/parser/index.js.map +1 -0
  179. package/dist/parser/modifier.d.ts +25 -0
  180. package/dist/parser/modifier.d.ts.map +1 -0
  181. package/dist/parser/modifier.js +41 -0
  182. package/dist/parser/modifier.js.map +1 -0
  183. package/dist/parser/recovery.d.ts +23 -0
  184. package/dist/parser/recovery.d.ts.map +1 -0
  185. package/dist/parser/recovery.js +80 -0
  186. package/dist/parser/recovery.js.map +1 -0
  187. package/dist/parser/rule.d.ts +39 -0
  188. package/dist/parser/rule.d.ts.map +1 -0
  189. package/dist/parser/rule.js +337 -0
  190. package/dist/parser/rule.js.map +1 -0
  191. package/dist/parser/statement.d.ts +21 -0
  192. package/dist/parser/statement.d.ts.map +1 -0
  193. package/dist/parser/statement.js +48 -0
  194. package/dist/parser/statement.js.map +1 -0
  195. package/dist/parser/statements.d.ts +33 -0
  196. package/dist/parser/statements.d.ts.map +1 -0
  197. package/dist/parser/statements.js +605 -0
  198. package/dist/parser/statements.js.map +1 -0
  199. package/dist/parser/value.d.ts +57 -0
  200. package/dist/parser/value.d.ts.map +1 -0
  201. package/dist/parser/value.js +226 -0
  202. package/dist/parser/value.js.map +1 -0
  203. package/dist/resolver/graph.d.ts +20 -0
  204. package/dist/resolver/graph.d.ts.map +1 -0
  205. package/dist/resolver/graph.js +382 -0
  206. package/dist/resolver/graph.js.map +1 -0
  207. package/dist/resolver/groups.d.ts +70 -0
  208. package/dist/resolver/groups.d.ts.map +1 -0
  209. package/dist/resolver/groups.js +143 -0
  210. package/dist/resolver/groups.js.map +1 -0
  211. package/dist/resolver/index.d.ts +46 -0
  212. package/dist/resolver/index.d.ts.map +1 -0
  213. package/dist/resolver/index.js +46 -0
  214. package/dist/resolver/index.js.map +1 -0
  215. package/dist/resolver/keyframes.d.ts +56 -0
  216. package/dist/resolver/keyframes.d.ts.map +1 -0
  217. package/dist/resolver/keyframes.js +102 -0
  218. package/dist/resolver/keyframes.js.map +1 -0
  219. package/dist/resolver/paths.d.ts +37 -0
  220. package/dist/resolver/paths.d.ts.map +1 -0
  221. package/dist/resolver/paths.js +135 -0
  222. package/dist/resolver/paths.js.map +1 -0
  223. package/dist/resolver/rules.d.ts +34 -0
  224. package/dist/resolver/rules.d.ts.map +1 -0
  225. package/dist/resolver/rules.js +52 -0
  226. package/dist/resolver/rules.js.map +1 -0
  227. package/dist/resolver/scopes.d.ts +44 -0
  228. package/dist/resolver/scopes.d.ts.map +1 -0
  229. package/dist/resolver/scopes.js +213 -0
  230. package/dist/resolver/scopes.js.map +1 -0
  231. package/dist/resolver/types.d.ts +238 -0
  232. package/dist/resolver/types.d.ts.map +1 -0
  233. package/dist/resolver/types.js +11 -0
  234. package/dist/resolver/types.js.map +1 -0
  235. package/dist/selectors/flatten.d.ts +95 -0
  236. package/dist/selectors/flatten.d.ts.map +1 -0
  237. package/dist/selectors/flatten.js +384 -0
  238. package/dist/selectors/flatten.js.map +1 -0
  239. package/dist/selectors/index.d.ts +15 -0
  240. package/dist/selectors/index.d.ts.map +1 -0
  241. package/dist/selectors/index.js +14 -0
  242. package/dist/selectors/index.js.map +1 -0
  243. package/dist/selectors/scan.d.ts +54 -0
  244. package/dist/selectors/scan.d.ts.map +1 -0
  245. package/dist/selectors/scan.js +191 -0
  246. package/dist/selectors/scan.js.map +1 -0
  247. package/dist/selectors/specificity.d.ts +28 -0
  248. package/dist/selectors/specificity.d.ts.map +1 -0
  249. package/dist/selectors/specificity.js +297 -0
  250. package/dist/selectors/specificity.js.map +1 -0
  251. package/dist/setup-list.d.ts +41 -0
  252. package/dist/setup-list.d.ts.map +1 -0
  253. package/dist/setup-list.js +122 -0
  254. package/dist/setup-list.js.map +1 -0
  255. package/dist/sourcemaps/index.d.ts +14 -0
  256. package/dist/sourcemaps/index.d.ts.map +1 -0
  257. package/dist/sourcemaps/index.js +13 -0
  258. package/dist/sourcemaps/index.js.map +1 -0
  259. package/dist/sourcemaps/mappings.d.ts +77 -0
  260. package/dist/sourcemaps/mappings.d.ts.map +1 -0
  261. package/dist/sourcemaps/mappings.js +124 -0
  262. package/dist/sourcemaps/mappings.js.map +1 -0
  263. package/dist/sourcemaps/vlq.d.ts +12 -0
  264. package/dist/sourcemaps/vlq.d.ts.map +1 -0
  265. package/dist/sourcemaps/vlq.js +29 -0
  266. package/dist/sourcemaps/vlq.js.map +1 -0
  267. package/dist/types/ast.d.ts +291 -0
  268. package/dist/types/ast.d.ts.map +1 -0
  269. package/dist/types/ast.js +2 -0
  270. package/dist/types/ast.js.map +1 -0
  271. package/dist/types/diagnostics.d.ts +55 -0
  272. package/dist/types/diagnostics.d.ts.map +1 -0
  273. package/dist/types/diagnostics.js +61 -0
  274. package/dist/types/diagnostics.js.map +1 -0
  275. package/dist/types/options.d.ts +274 -0
  276. package/dist/types/options.d.ts.map +1 -0
  277. package/dist/types/options.js +11 -0
  278. package/dist/types/options.js.map +1 -0
  279. package/dist/types/result.d.ts +112 -0
  280. package/dist/types/result.d.ts.map +1 -0
  281. package/dist/types/result.js +2 -0
  282. package/dist/types/result.js.map +1 -0
  283. package/dist/types/span.d.ts +19 -0
  284. package/dist/types/span.d.ts.map +1 -0
  285. package/dist/types/span.js +2 -0
  286. package/dist/types/span.js.map +1 -0
  287. package/dist/types/token.d.ts +68 -0
  288. package/dist/types/token.d.ts.map +1 -0
  289. package/dist/types/token.js +2 -0
  290. package/dist/types/token.js.map +1 -0
  291. package/dist/variables/ast.d.ts +56 -0
  292. package/dist/variables/ast.d.ts.map +1 -0
  293. package/dist/variables/ast.js +167 -0
  294. package/dist/variables/ast.js.map +1 -0
  295. package/dist/variables/expand.d.ts +109 -0
  296. package/dist/variables/expand.d.ts.map +1 -0
  297. package/dist/variables/expand.js +213 -0
  298. package/dist/variables/expand.js.map +1 -0
  299. package/dist/variables/index.d.ts +36 -0
  300. package/dist/variables/index.d.ts.map +1 -0
  301. package/dist/variables/index.js +33 -0
  302. package/dist/variables/index.js.map +1 -0
  303. package/dist/variables/naming.d.ts +39 -0
  304. package/dist/variables/naming.d.ts.map +1 -0
  305. package/dist/variables/naming.js +14 -0
  306. package/dist/variables/naming.js.map +1 -0
  307. package/dist/variables/runtime.d.ts +81 -0
  308. package/dist/variables/runtime.d.ts.map +1 -0
  309. package/dist/variables/runtime.js +228 -0
  310. package/dist/variables/runtime.js.map +1 -0
  311. package/dist/variables/substitute.d.ts +65 -0
  312. package/dist/variables/substitute.d.ts.map +1 -0
  313. package/dist/variables/substitute.js +73 -0
  314. package/dist/variables/substitute.js.map +1 -0
  315. package/dist/variables/walk.d.ts +37 -0
  316. package/dist/variables/walk.d.ts.map +1 -0
  317. package/dist/variables/walk.js +113 -0
  318. package/dist/variables/walk.js.map +1 -0
  319. package/package.json +35 -4
  320. package/src/emitter/index.ts +658 -0
  321. package/src/formatter/index.ts +544 -0
  322. package/src/host/node.ts +85 -0
  323. package/src/index.ts +1021 -0
  324. package/src/ir/factories.ts +85 -0
  325. package/src/ir/index.ts +28 -0
  326. package/src/ir/types.ts +145 -0
  327. package/src/lexer/at-keywords.ts +35 -0
  328. package/src/lexer/characters.ts +82 -0
  329. package/src/lexer/comments.ts +27 -0
  330. package/src/lexer/diagnostics.ts +42 -0
  331. package/src/lexer/dollar-refs.ts +23 -0
  332. package/src/lexer/index.ts +37 -0
  333. package/src/lexer/names.ts +49 -0
  334. package/src/lexer/numbers.ts +59 -0
  335. package/src/lexer/scanner.ts +199 -0
  336. package/src/lexer/strings.ts +52 -0
  337. package/src/lexer/urls.ts +63 -0
  338. package/src/lowering/expand-groups.ts +206 -0
  339. package/src/lowering/group.ts +119 -0
  340. package/src/lowering/index.ts +43 -0
  341. package/src/lowering/lower.ts +441 -0
  342. package/src/lowering/media.ts +314 -0
  343. package/src/lowering/merge.ts +163 -0
  344. package/src/lowering/property-families.ts +194 -0
  345. package/src/lowering/spans.ts +118 -0
  346. package/src/naming/index.ts +44 -0
  347. package/src/naming/mapgen.ts +252 -0
  348. package/src/naming/merge.ts +114 -0
  349. package/src/naming/rewrite.ts +333 -0
  350. package/src/naming/scan.ts +267 -0
  351. package/src/naming/table.ts +153 -0
  352. package/src/naming/types.ts +100 -0
  353. package/src/output/import-path.ts +30 -0
  354. package/src/output/index.ts +213 -0
  355. package/src/output/manifest.ts +28 -0
  356. package/src/output/paths.ts +200 -0
  357. package/src/output/resolve.ts +401 -0
  358. package/src/output/validate.ts +251 -0
  359. package/src/parser/cursor.ts +138 -0
  360. package/src/parser/declaration.ts +247 -0
  361. package/src/parser/diagnostics.ts +75 -0
  362. package/src/parser/group.ts +303 -0
  363. package/src/parser/index.ts +50 -0
  364. package/src/parser/modifier.ts +60 -0
  365. package/src/parser/recovery.ts +88 -0
  366. package/src/parser/rule.ts +370 -0
  367. package/src/parser/statement.ts +47 -0
  368. package/src/parser/statements.ts +667 -0
  369. package/src/parser/value.ts +265 -0
  370. package/src/resolver/graph.ts +467 -0
  371. package/src/resolver/groups.ts +177 -0
  372. package/src/resolver/index.ts +68 -0
  373. package/src/resolver/keyframes.ts +131 -0
  374. package/src/resolver/paths.ts +142 -0
  375. package/src/resolver/rules.ts +54 -0
  376. package/src/resolver/scopes.ts +342 -0
  377. package/src/resolver/types.ts +259 -0
  378. package/src/selectors/flatten.ts +448 -0
  379. package/src/selectors/index.ts +14 -0
  380. package/src/selectors/scan.ts +227 -0
  381. package/src/selectors/specificity.ts +319 -0
  382. package/src/setup-list.ts +172 -0
  383. package/src/sourcemaps/index.ts +25 -0
  384. package/src/sourcemaps/mappings.ts +190 -0
  385. package/src/sourcemaps/vlq.ts +29 -0
  386. package/src/types/ast.ts +318 -0
  387. package/src/types/diagnostics.ts +124 -0
  388. package/src/types/options.ts +286 -0
  389. package/src/types/result.ts +121 -0
  390. package/src/types/span.ts +18 -0
  391. package/src/types/token.ts +77 -0
  392. package/src/variables/ast.ts +182 -0
  393. package/src/variables/expand.ts +319 -0
  394. package/src/variables/index.ts +38 -0
  395. package/src/variables/naming.ts +46 -0
  396. package/src/variables/runtime.ts +336 -0
  397. package/src/variables/substitute.ts +148 -0
  398. package/src/variables/walk.ts +147 -0
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Base64 VLQ encoding for source-map v3 `mappings` (zero dependencies).
3
+ *
4
+ * Source maps encode every number as a signed variable-length quantity in
5
+ * base64 digits: the low bit of the first digit is the sign, the remaining bits
6
+ * are the magnitude in five-bit groups, and the continuation bit (`0x20`) marks
7
+ * every group but the last. All values here are integers within JavaScript's
8
+ * safe range, which is far beyond the line/column deltas a stylesheet produces.
9
+ */
10
+
11
+ /** Standard source-map base64 alphabet (`A`=0 … `9`=61, `+`=62, `/`=63). */
12
+ const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
13
+
14
+ /** Encode one signed integer as a base64 VLQ segment value. */
15
+ export function encodeVlq(value: number): string {
16
+ if (!Number.isFinite(value) || !Number.isInteger(value)) {
17
+ throw new RangeError(`VLQ values must be finite integers, received ${String(value)}.`);
18
+ }
19
+ // Negative numbers use the low bit as the sign and the magnitude shifted left.
20
+ let remaining = value < 0 ? (-value << 1) | 1 : value << 1;
21
+ let encoded = "";
22
+ do {
23
+ let digit = remaining & 0x1f;
24
+ remaining >>>= 5;
25
+ if (remaining > 0) digit |= 0x20;
26
+ encoded += BASE64.charAt(digit);
27
+ } while (remaining > 0);
28
+ return encoded;
29
+ }
@@ -0,0 +1,318 @@
1
+ import type { Span } from "./span.js";
2
+ import type { Token } from "./token.js";
3
+
4
+ /**
5
+ * Abstract syntax tree produced by `parse`.
6
+ *
7
+ * Node shapes mirror SPECIFICATION.md §3.2, refined by
8
+ * ADR-0003 (per-segment `!important`), ADR-0004 (rule-scoped conditional
9
+ * blocks), ADR-0005 (raw value slices plus optional token sequences) and
10
+ * ADR-0017 (inert `@group.<name>` definitions and use sites).
11
+ *
12
+ * Every node is immutable and carries a {@link Span} into the original source,
13
+ * so diagnostics, lowering and source maps keep exact origins. Value-bearing
14
+ * strings are raw source slices exactly as authored: no whitespace trimming,
15
+ * escape decoding or normalization happens here. Lowering produces new IR
16
+ * nodes instead of editing the AST in place.
17
+ *
18
+ * Two structural notes:
19
+ *
20
+ * - A top-level conditional block is invalid (ADR-0004). It is never
21
+ * represented as a node: the parser reports a CHIKX1001-family diagnostic and
22
+ * resumes at the next statement boundary, so {@link Stylesheet.items} only
23
+ * holds valid top-level constructs.
24
+ * - Multiple `@setup` blocks are allowed at the top level and are parsed into
25
+ * multiple {@link SetupBlock} nodes so recovery and diagnostics stay local;
26
+ * the resolver merges them in document order. A duplicate setting key within
27
+ * or across blocks is a CHIKX1001-family diagnostic.
28
+ */
29
+ export interface Stylesheet {
30
+ readonly kind: "stylesheet";
31
+ /** Workspace-relative POSIX path of the parsed source, equal to `span.file`. */
32
+ readonly file: string;
33
+ /** Top-level constructs in authored order. */
34
+ readonly items: readonly StylesheetItem[];
35
+ /** Covers the whole source file, from offset 0 through the final character. */
36
+ readonly span: Span;
37
+ }
38
+
39
+ /** Any construct that may appear at the top level of a file. */
40
+ export type StylesheetItem =
41
+ | SetupBlock
42
+ | UseImport
43
+ | VariablesBlock
44
+ | RuntimeBlock
45
+ | MediaTypesBlock
46
+ | GroupDefinition
47
+ | Rule
48
+ | NativeAtRule;
49
+
50
+ /** A `@setup { ... }` block; one node per authored block. */
51
+ export interface SetupBlock {
52
+ readonly kind: "setup";
53
+ /** Settings in authored order, duplicates preserved for diagnostics. */
54
+ readonly settings: readonly Setting[];
55
+ /** Covers `@setup` through the closing `}`. */
56
+ readonly span: Span;
57
+ }
58
+
59
+ /**
60
+ * One `key: value;` line inside `@setup`.
61
+ *
62
+ * Keys are the kebab-case setup keys of SPECIFICATION.md §9 (`css-dir`,
63
+ * `emit-css`, ...). Values stay raw so the configuration layer owns decoding
64
+ * and validation.
65
+ */
66
+ export interface Setting {
67
+ readonly kind: "setting";
68
+ /** Kebab-case setup key exactly as authored (for example `css-dir`). */
69
+ readonly key: string;
70
+ /**
71
+ * Raw scalar slice exactly as authored, including quotes for strings
72
+ * (`"ui"`, `true`, `12`). Decoders remove quotes and resolve escapes.
73
+ */
74
+ readonly value: string;
75
+ /**
76
+ * Covers the raw {@link value} slice only, excluding the key, colon and
77
+ * terminator. List decoders use it to report per-item spans; it is zero-width
78
+ * when the authored value is empty.
79
+ */
80
+ readonly valueSpan: Span;
81
+ /** Covers the key through the terminating `;`. */
82
+ readonly span: Span;
83
+ }
84
+
85
+ /**
86
+ * A top-level `@use "..." [as alias] [styles];` import.
87
+ *
88
+ * Without the `styles` clause the import brings in tokens only
89
+ * (SPECIFICATION.md §6.1). With it, the target's stylesheet rules are merged
90
+ * into the importing build as well (ADR-0014); merged rules keep the imported
91
+ * module's own `@setup` prefix and are emitted before the importing file's own
92
+ * rules.
93
+ */
94
+ export interface UseImport {
95
+ readonly kind: "use";
96
+ /**
97
+ * Raw text between the quotes of the specifier, exactly as authored. CSS
98
+ * string escapes are not decoded here; the resolver decodes them and resolves
99
+ * relative to the importing file.
100
+ */
101
+ readonly path: string;
102
+ /** Explicit namespace from an `as` clause, exactly as authored; `undefined` when absent. */
103
+ readonly alias?: string;
104
+ /**
105
+ * `true` when the authored statement carries the `styles` clause, merging the
106
+ * target's rules into this build (ADR-0014). Absent means a token-only import,
107
+ * which emits no rules of its own (SPECIFICATION.md §6.1).
108
+ */
109
+ readonly styles?: boolean;
110
+ /** Covers `@use` through the terminating `;`. */
111
+ readonly span: Span;
112
+ }
113
+
114
+ /** A `@variables { ... }` block holding compile-time token definitions. */
115
+ export interface VariablesBlock {
116
+ readonly kind: "variables";
117
+ /** Token declarations in authored order; duplicates are preserved for diagnostics. */
118
+ readonly tokens: readonly TokenDeclaration[];
119
+ /** Covers `@variables` through the closing `}`. */
120
+ readonly span: Span;
121
+ }
122
+
123
+ /** One compile-time variable definition inside `@variables`. */
124
+ export interface TokenDeclaration {
125
+ readonly kind: "token-declaration";
126
+ /** Local variable name without the `$` sigil, exactly as authored. */
127
+ readonly name: string;
128
+ /**
129
+ * Raw value slice exactly as authored; compile-time variables substitute
130
+ * token sequences, not expressions.
131
+ */
132
+ readonly value: string;
133
+ /**
134
+ * Parsed value tokens, present only when {@link value} contains a `$`
135
+ * reference (ADR-0005). Literal content stays in `value` as well.
136
+ */
137
+ readonly tokens?: readonly Token[];
138
+ /** Covers the name through the terminating `;`. */
139
+ readonly span: Span;
140
+ }
141
+
142
+ /** A `@runtime { ... }` block whose declarations emit native custom properties. */
143
+ export interface RuntimeBlock {
144
+ readonly kind: "runtime";
145
+ /** Declarations in authored order, including inline variant segments. */
146
+ readonly declarations: readonly Declaration[];
147
+ /** Covers `@runtime` through the closing `}`. */
148
+ readonly span: Span;
149
+ }
150
+
151
+ /** A `@media-types { ... }` block of file-local media alias definitions. */
152
+ export interface MediaTypesBlock {
153
+ readonly kind: "media-types";
154
+ /** Alias definitions in authored order; later keys win at merge time. */
155
+ readonly aliases: readonly AliasDeclaration[];
156
+ /** Covers `@media-types` through the closing `}`. */
157
+ readonly span: Span;
158
+ }
159
+
160
+ /** One `alias: condition;` definition inside `@media-types`. */
161
+ export interface AliasDeclaration {
162
+ readonly kind: "alias-declaration";
163
+ /** Alias name without the `@` sigil; may begin with a digit (`2xl`). */
164
+ readonly name: string;
165
+ /** Raw media condition text as authored, trimmed of surrounding whitespace. */
166
+ readonly media: string;
167
+ /** Covers the name through the terminating `;`. */
168
+ readonly span: Span;
169
+ }
170
+
171
+ /**
172
+ * A top-level `@group.<name> { ... }` reusable declaration group (ADR-0017).
173
+ *
174
+ * A definition is inert: it emits no CSS and only a matching
175
+ * {@link GroupUseSite} splices its declarations into a rule. The block accepts
176
+ * declarations and nothing else; a nested rule, conditional block, native
177
+ * at-rule or further `@group.` statement inside it is a CHIKX1001-family
178
+ * diagnostic and that statement is omitted while the rest of the definition
179
+ * survives. Names are plain CSS identifiers matched exactly and
180
+ * case-sensitively, and the dotted form is contiguous only.
181
+ *
182
+ * An empty or unused definition is legal and produces no diagnostic. Duplicate
183
+ * definitions in one module stay in the AST as separate nodes; the resolver
184
+ * reports the later one as CHIKX2001 (plan G2).
185
+ */
186
+ export interface GroupDefinition {
187
+ readonly kind: "group-definition";
188
+ /** Group name without the `@group.` prefix, exactly as authored (`card`, `keyframes`). */
189
+ readonly name: string;
190
+ /** Declarations in authored order, including inline variant segments. */
191
+ readonly declarations: readonly Declaration[];
192
+ /** Covers `@group` through the closing `}`. */
193
+ readonly span: Span;
194
+ }
195
+
196
+ /** A selector block: the only place declarations, nested rules and conditional blocks live. */
197
+ export interface Rule {
198
+ readonly kind: "rule";
199
+ /** Raw selector list exactly as authored, including functional pseudos and escapes. */
200
+ readonly selector: string;
201
+ /** Covers only the selector text, so diagnostics can point at selectors precisely. */
202
+ readonly selectorSpan: Span;
203
+ /** Declarations, nested rules, conditional blocks and native at-rules in authored order. */
204
+ readonly body: readonly BlockItem[];
205
+ /** Covers the selector through the closing `}`, including the block. */
206
+ readonly span: Span;
207
+ }
208
+
209
+ /** Any construct that may appear inside a rule block or a native at-rule block. */
210
+ export type BlockItem = Declaration | Rule | ConditionalBlock | NativeAtRule | GroupUseSite;
211
+
212
+ /**
213
+ * A `@group.<name> { ... }` use site inside a rule body (ADR-0017).
214
+ *
215
+ * The block is required in v0.1 and holds per-use-site overrides only;
216
+ * expansion splices the group's defaults before these declarations at the
217
+ * authored position (plan G3). A definition is the same syntax at the top level
218
+ * of a file. Inside this block declarations are the only valid statement: a
219
+ * nested rule, conditional block or native at-rule is a CHIKX1001-family
220
+ * diagnostic and only that statement is omitted. Conditional use sites such as
221
+ * `@group.x @md { ... }` are out of v1.
222
+ */
223
+ export interface GroupUseSite {
224
+ readonly kind: "group-use-site";
225
+ /** Group name without the `@group.` prefix, exactly as authored and case-sensitive. */
226
+ readonly name: string;
227
+ /** Override declarations in authored order, including inline variant segments. */
228
+ readonly declarations: readonly Declaration[];
229
+ /** Covers `@group` through the closing `}`. */
230
+ readonly span: Span;
231
+ }
232
+
233
+ /**
234
+ * A rule-scoped `@md { ... }` conditional block (ADR-0004).
235
+ *
236
+ * A native at-rule inside a conditional block is invalid per the §3.2 grammar
237
+ * and is reported as a CHIKX1001-family diagnostic with statement-boundary
238
+ * recovery.
239
+ */
240
+ export interface ConditionalBlock {
241
+ readonly kind: "conditional-block";
242
+ /** Parsed modifier combination applied to every member of the block. */
243
+ readonly variant: Modifier;
244
+ /** Conditional blocks contain declarations, nested rules and further conditional blocks only. */
245
+ readonly body: readonly ConditionalBlockItem[];
246
+ /** Covers the modifier through the closing `}`. */
247
+ readonly span: Span;
248
+ }
249
+
250
+ /** Members allowed inside a conditional block by the §3.2 grammar. */
251
+ export type ConditionalBlockItem = Declaration | Rule | ConditionalBlock;
252
+
253
+ /**
254
+ * A property declaration with an optional inline-variant chain.
255
+ *
256
+ * `!important` binds per value segment (ADR-0003): it stays ordinary CSS token
257
+ * content of the segment it terminates and is never propagated to other
258
+ * segments.
259
+ */
260
+ export interface Declaration {
261
+ readonly kind: "declaration";
262
+ /** Property name exactly as authored, including custom properties (`--brand`). */
263
+ readonly property: string;
264
+ /** Raw base-value slice, including a trailing `!important` when present. */
265
+ readonly value: string;
266
+ /**
267
+ * Parsed base-value tokens, present only when {@link value} contains a `$`
268
+ * reference (ADR-0005).
269
+ */
270
+ readonly tokens?: readonly Token[];
271
+ /** Inline variants in authored order; empty when the declaration has none. */
272
+ readonly variants: readonly Variant[];
273
+ /**
274
+ * Whether the base value segment carries `!important`. Never implies that any
275
+ * variant is important.
276
+ */
277
+ readonly important?: boolean;
278
+ /** Covers the property through the last value character; the terminating `;` is excluded. */
279
+ readonly span: Span;
280
+ }
281
+
282
+ /** A parsed Chikx condition: one or more aliases joined by `+` (logical AND). */
283
+ export interface Modifier {
284
+ /** Alias names in authored order, without `@`; duplicates are preserved until lowering normalizes them. */
285
+ readonly aliases: readonly string[];
286
+ /** Covers the modifier text including `@` and `+` joins. */
287
+ readonly span: Span;
288
+ }
289
+
290
+ /** One inline variant segment: its condition, value and per-segment importance. */
291
+ export interface Variant extends Modifier {
292
+ /** Raw value slice for this segment, including a trailing `!important` when present. */
293
+ readonly value: string;
294
+ /**
295
+ * Parsed value tokens, present only when {@link value} contains a `$`
296
+ * reference (ADR-0005).
297
+ */
298
+ readonly tokens?: readonly Token[];
299
+ /** Whether this segment alone carries `!important` (ADR-0003). */
300
+ readonly important?: boolean;
301
+ }
302
+
303
+ /** A native CSS at-rule preserved with its authored meaning. */
304
+ export interface NativeAtRule {
305
+ readonly kind: "native-at-rule";
306
+ /** At-rule name without the `@` sigil (for example `media`, `keyframes`, `font-face`). */
307
+ readonly name: string;
308
+ /** Raw prelude text as authored, trimmed of surrounding whitespace; empty when absent. */
309
+ readonly prelude: string;
310
+ /**
311
+ * Parsed block members for block at-rules, or `undefined` for statement
312
+ * at-rules such as `@import` and `@charset`. Contexts that cannot accept
313
+ * Chikx transformations are rejected semantically rather than rewritten.
314
+ */
315
+ readonly block?: readonly BlockItem[];
316
+ /** Covers the `@` name through the block or terminating `;`. */
317
+ readonly span: Span;
318
+ }
@@ -0,0 +1,124 @@
1
+ import type { Span } from "./span.js";
2
+
3
+ type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
4
+
5
+ /**
6
+ * Stable diagnostic identifier of the form `CHIKX####`.
7
+ *
8
+ * Families are CHIKX1xxx (syntax and lexical), CHIKX2xxx (symbols and
9
+ * modules), CHIKX3xxx (media and conditions), CHIKX4xxx (naming and exports)
10
+ * and CHIKX5xxx (output planning). Subcodes may be added inside a family
11
+ * without changing the shape of {@link DIAGNOSTIC_CODES}; every code is stable
12
+ * once released.
13
+ */
14
+ export type DiagnosticCode = `CHIKX${Digit}${Digit}${Digit}${Digit}`;
15
+
16
+ /** A diagnostic is either fatal for the affected construct or advisory. */
17
+ export type DiagnosticSeverity = "error" | "warning";
18
+
19
+ /** The five stable diagnostic families. */
20
+ export type DiagnosticFamily = "syntax" | "variables" | "media" | "naming" | "output";
21
+
22
+ /** Registry metadata for one reserved diagnostic code. */
23
+ export interface DiagnosticCodeInfo {
24
+ /** The code itself, identical to its key in {@link DIAGNOSTIC_CODES}. */
25
+ readonly code: DiagnosticCode;
26
+ /** Family the code belongs to. */
27
+ readonly family: DiagnosticFamily;
28
+ /** Severity producers should use unless a documented case narrows it. */
29
+ readonly defaultSeverity: DiagnosticSeverity;
30
+ /** Short, user-facing description of when the code is reported. */
31
+ readonly summary: string;
32
+ }
33
+
34
+ /** Codes reserved for v0.1; additional subcodes may join a family later. */
35
+ export type ReservedDiagnosticCode =
36
+ | "CHIKX1001"
37
+ | "CHIKX1002"
38
+ | "CHIKX1003"
39
+ | "CHIKX2001"
40
+ | "CHIKX3001"
41
+ | "CHIKX4001"
42
+ | "CHIKX5001";
43
+
44
+ /**
45
+ * Every reserved Chikx diagnostic with a short description.
46
+ *
47
+ * Family anchors double as the canonical code for the whole family, so early
48
+ * implementations may report the anchor while finer subcodes are introduced
49
+ * later. Statement-scoped syntax diagnostics span the affected statement so
50
+ * editors and fixtures can point at its start.
51
+ */
52
+ export const DIAGNOSTIC_CODES: Readonly<Record<ReservedDiagnosticCode, DiagnosticCodeInfo>> = {
53
+ CHIKX1001: {
54
+ code: "CHIKX1001",
55
+ family: "syntax",
56
+ defaultSeverity: "error",
57
+ summary:
58
+ "General syntax or lexical error, including a conditional block outside a rule, an unknown setup key, a duplicate setting, a duplicate @setup block and a lexer-level recovery.",
59
+ },
60
+ CHIKX1002: {
61
+ code: "CHIKX1002",
62
+ family: "syntax",
63
+ defaultSeverity: "error",
64
+ summary:
65
+ "Missing semicolon after a Chikx declaration. v0.1 requires semicolons for Chikx declarations, while an ordinary CSS final declaration without a trailing semicolon before `}` MAY be accepted (SPECIFICATION §3.1).",
66
+ },
67
+ CHIKX1003: {
68
+ code: "CHIKX1003",
69
+ family: "syntax",
70
+ defaultSeverity: "error",
71
+ summary:
72
+ "Malformed declaration or block: unbalanced parentheses or braces in values, or an unrecoverable statement.",
73
+ },
74
+ CHIKX2001: {
75
+ code: "CHIKX2001",
76
+ family: "variables",
77
+ defaultSeverity: "error",
78
+ summary:
79
+ "Symbol or module error: undefined token, import cycle, duplicate or ambiguous definition, or a compile-time/runtime name collision.",
80
+ },
81
+ CHIKX3001: {
82
+ code: "CHIKX3001",
83
+ family: "media",
84
+ defaultSeverity: "error",
85
+ summary:
86
+ "Media or condition error: unknown alias, unsupported alias combination or a combination that cannot form valid CSS.",
87
+ },
88
+ CHIKX4001: {
89
+ code: "CHIKX4001",
90
+ family: "naming",
91
+ defaultSeverity: "error",
92
+ summary:
93
+ "Naming or export error: camelCase alias collision, invalid CSS identifier, or an omitted named export that is reserved or not a valid JavaScript identifier (a warning in that case).",
94
+ },
95
+ CHIKX5001: {
96
+ code: "CHIKX5001",
97
+ family: "output",
98
+ defaultSeverity: "error",
99
+ summary:
100
+ "Output planning error: duplicate target, input/output overlap, workspace or symlink escape, or another unsafe output plan.",
101
+ },
102
+ };
103
+
104
+ /** One reported problem tied to an exact source range. */
105
+ export interface Diagnostic {
106
+ /** Stable Chikx code, always a member of the CHIKX#### family. */
107
+ readonly code: DiagnosticCode;
108
+ /** Whether the affected construct is rejected or merely flagged. */
109
+ readonly severity: DiagnosticSeverity;
110
+ /** Complete, user-facing explanation with actionable context. */
111
+ readonly message: string;
112
+ /** Exact source range; line and column are derived from its offsets. */
113
+ readonly span: Span;
114
+ }
115
+
116
+ /** Create an error diagnostic; the affected construct is rejected. */
117
+ export function error(code: DiagnosticCode, message: string, span: Span): Diagnostic {
118
+ return { code, severity: "error", message, span };
119
+ }
120
+
121
+ /** Create a warning diagnostic; output is still produced. */
122
+ export function warning(code: DiagnosticCode, message: string, span: Span): Diagnostic {
123
+ return { code, severity: "warning", message, span };
124
+ }