@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,667 @@
1
+ import type {
2
+ AliasDeclaration,
3
+ Declaration,
4
+ MediaTypesBlock,
5
+ RuntimeBlock,
6
+ Setting,
7
+ SetupBlock,
8
+ Stylesheet,
9
+ StylesheetItem,
10
+ TokenDeclaration,
11
+ UseImport,
12
+ VariablesBlock,
13
+ } from "../types/ast.js";
14
+ import type { ParseResult } from "../types/result.js";
15
+ import type { Token } from "../types/token.js";
16
+ import {
17
+ TokenCursor,
18
+ lastContentIndex,
19
+ skipTriviaAt,
20
+ textOf,
21
+ tokenAt,
22
+ trimWhitespace,
23
+ } from "./cursor.js";
24
+ import { type ParseContext, parseDeclaration } from "./declaration.js";
25
+ import { DiagnosticBag, messages } from "./diagnostics.js";
26
+ import { isGroupAtKeyword, parseGroupDefinition } from "./group.js";
27
+ import { readModifier } from "./modifier.js";
28
+ import { recoverStatement, skipAtRule, skipBalancedBlock, skipStatementBlock } from "./recovery.js";
29
+ import {
30
+ atRuleName,
31
+ classifyStatement,
32
+ isNativeAtRuleName,
33
+ parseNativeAtRule,
34
+ parseRule,
35
+ } from "./rule.js";
36
+ import { containsDollarRef } from "./value.js";
37
+
38
+ /** How a scalar `key: value` line ended. */
39
+ type SimpleTerminator = "semicolon" | "rbrace" | "eof" | "lbrace";
40
+
41
+ interface SimpleValue {
42
+ readonly terminator: SimpleTerminator;
43
+ readonly boundaryIndex: number;
44
+ readonly malformed: boolean;
45
+ readonly bounds: { readonly start: number; readonly end: number };
46
+ readonly valueEnd: number;
47
+ }
48
+
49
+ /**
50
+ * Scan a scalar value up to `;`, the closing `}`, or end of input while
51
+ * balancing parentheses and brackets (used by `@setup`, `@variables` and
52
+ * `@media-types`).
53
+ */
54
+ function scanSimpleValue(ctx: ParseContext, startIndex: number): SimpleValue {
55
+ const { cursor } = ctx;
56
+ const tokens = cursor.tokens;
57
+ const closers: Array<"rparen" | "rbracket"> = [];
58
+ let malformed = false;
59
+ let index = startIndex;
60
+ let terminator: SimpleTerminator = "eof";
61
+
62
+ while (true) {
63
+ const token = tokenAt(tokens, index, cursor.endOffset);
64
+ if (token.kind === "eof") {
65
+ terminator = "eof";
66
+ break;
67
+ }
68
+ if (token.kind === "lparen") closers.push("rparen");
69
+ else if (token.kind === "lbracket") closers.push("rbracket");
70
+ else if (token.kind === "rparen" || token.kind === "rbracket") {
71
+ if (closers.pop() !== token.kind) malformed = true;
72
+ } else if (closers.length === 0) {
73
+ if (token.kind === "semicolon") {
74
+ terminator = "semicolon";
75
+ break;
76
+ }
77
+ if (token.kind === "rbrace") {
78
+ terminator = "rbrace";
79
+ break;
80
+ }
81
+ if (token.kind === "lbrace") {
82
+ terminator = "lbrace";
83
+ break;
84
+ }
85
+ }
86
+ index++;
87
+ }
88
+
89
+ const bounds = trimWhitespace(tokens, startIndex, index);
90
+ const last = lastContentIndex(tokens, bounds.start, bounds.end);
91
+ return {
92
+ terminator,
93
+ boundaryIndex: index,
94
+ malformed: malformed || closers.length > 0,
95
+ bounds,
96
+ valueEnd: last >= bounds.start ? (tokens[last]?.end ?? 0) : 0,
97
+ };
98
+ }
99
+
100
+ /** Consume a statement terminator, reporting a missing `;` when one is absent. */
101
+ function finishSimple(
102
+ ctx: ParseContext,
103
+ scan: SimpleValue,
104
+ startTokenStart: number,
105
+ fallbackEnd: number,
106
+ what: string,
107
+ ): number {
108
+ const { cursor, bag } = ctx;
109
+ const tokens = cursor.tokens;
110
+ if (scan.terminator === "semicolon") {
111
+ const semicolon = tokenAt(tokens, scan.boundaryIndex, cursor.endOffset);
112
+ cursor.index = scan.boundaryIndex + 1;
113
+ return semicolon.end;
114
+ }
115
+ const end = scan.valueEnd > 0 ? scan.valueEnd : fallbackEnd;
116
+ bag.add("CHIKX1001", messages.missingSemicolon(what), {
117
+ start: startTokenStart,
118
+ end,
119
+ file: cursor.file,
120
+ });
121
+ cursor.index = Math.min(scan.boundaryIndex, tokens.length);
122
+ return end;
123
+ }
124
+
125
+ function expectBlockOpen(ctx: ParseContext, construct: string): boolean {
126
+ const { cursor, bag } = ctx;
127
+ cursor.skipTrivia();
128
+ const token = cursor.current();
129
+ if (token.kind === "lbrace") {
130
+ cursor.index++;
131
+ return true;
132
+ }
133
+ bag.add("CHIKX1001", messages.missingBrace(construct), cursor.span(token));
134
+ recoverStatement(cursor);
135
+ return false;
136
+ }
137
+
138
+ function reportUnclosed(ctx: ParseContext, startOffset: number, construct: string): void {
139
+ ctx.bag.add("CHIKX1001", messages.unclosedBlock(construct), {
140
+ start: startOffset,
141
+ end: ctx.cursor.endOffset,
142
+ file: ctx.cursor.file,
143
+ });
144
+ }
145
+
146
+ /**
147
+ * Parse `@setup { key: scalar; ... }`.
148
+ *
149
+ * Settings keep authored order and duplicates; the resolver merges blocks and
150
+ * rejects duplicate or unknown keys (AST `SetupBlock` JSDoc). Values stay raw,
151
+ * quotes included.
152
+ */
153
+ export function parseSetupBlock(ctx: ParseContext): SetupBlock | undefined {
154
+ const { cursor, bag } = ctx;
155
+ const file = cursor.file;
156
+ const startToken = cursor.current();
157
+ cursor.index++;
158
+ if (!expectBlockOpen(ctx, "@setup")) return undefined;
159
+
160
+ const settings: Setting[] = [];
161
+ let end = cursor.endOffset;
162
+ let closed = false;
163
+
164
+ while (true) {
165
+ cursor.skipTrivia();
166
+ const guard = cursor.index;
167
+ const token = cursor.current();
168
+
169
+ if (token.kind === "eof") break;
170
+ if (token.kind === "rbrace") {
171
+ end = token.end;
172
+ cursor.index++;
173
+ closed = true;
174
+ break;
175
+ }
176
+ if (token.kind === "semicolon") {
177
+ cursor.index++;
178
+ continue;
179
+ }
180
+ if (token.kind !== "ident") {
181
+ bag.add("CHIKX1001", messages.expectedSettingKey, cursor.span(token));
182
+ recoverStatement(cursor);
183
+ } else {
184
+ const setting = parseSetting(ctx, token);
185
+ if (setting !== undefined) settings.push(setting);
186
+ }
187
+
188
+ if (cursor.index === guard) cursor.index++;
189
+ }
190
+
191
+ if (!closed) reportUnclosed(ctx, startToken.start, "@setup");
192
+ return Object.freeze({
193
+ kind: "setup",
194
+ settings: Object.freeze(settings),
195
+ span: { start: startToken.start, end, file },
196
+ });
197
+ }
198
+
199
+ function parseSetting(ctx: ParseContext, keyToken: Token): Setting | undefined {
200
+ const { cursor, bag } = ctx;
201
+ const file = cursor.file;
202
+ cursor.index++;
203
+ cursor.skipTrivia();
204
+
205
+ const colon = cursor.current();
206
+ if (colon.kind !== "colon") {
207
+ bag.add("CHIKX1001", messages.expectedSettingColon, cursor.span(colon));
208
+ recoverStatement(cursor);
209
+ return undefined;
210
+ }
211
+ cursor.index++;
212
+
213
+ const scan = scanSimpleValue(ctx, cursor.index);
214
+ if (scan.malformed) {
215
+ bag.add("CHIKX1003", messages.malformedValue, {
216
+ start: keyToken.start,
217
+ end: scan.valueEnd > 0 ? scan.valueEnd : keyToken.end,
218
+ file,
219
+ });
220
+ if (scan.terminator === "lbrace") {
221
+ cursor.index = skipBalancedBlock(cursor.tokens, scan.boundaryIndex, cursor.endOffset);
222
+ } else if (scan.terminator === "semicolon") {
223
+ cursor.index = scan.boundaryIndex + 1;
224
+ } else {
225
+ cursor.index = Math.min(scan.boundaryIndex, cursor.tokens.length);
226
+ }
227
+ return undefined;
228
+ }
229
+
230
+ const value = textOf(cursor.tokens, scan.bounds.start, scan.bounds.end);
231
+ const valueSpan =
232
+ scan.bounds.start < scan.bounds.end
233
+ ? {
234
+ start: cursor.tokens[scan.bounds.start]?.start ?? colon.end,
235
+ end: cursor.tokens[scan.bounds.end - 1]?.end ?? colon.end,
236
+ file,
237
+ }
238
+ : { start: colon.end, end: colon.end, file };
239
+ const end = finishSimple(ctx, scan, keyToken.start, keyToken.end, "a setup setting");
240
+ return Object.freeze({
241
+ kind: "setting",
242
+ key: keyToken.value,
243
+ value,
244
+ valueSpan,
245
+ span: { start: keyToken.start, end, file },
246
+ });
247
+ }
248
+
249
+ /**
250
+ * Parse `@use "..." [as alias] [styles];` (SPECIFICATION.md §3.2, ADR-0014).
251
+ *
252
+ * The optional `styles` clause merges the target's rules into the importing
253
+ * build; it is recorded as `styles: true` and is absent for token-only imports.
254
+ */
255
+ export function parseUseImport(ctx: ParseContext): UseImport | undefined {
256
+ const { cursor, bag } = ctx;
257
+ const tokens = cursor.tokens;
258
+ const file = cursor.file;
259
+ const startToken = cursor.current();
260
+ cursor.index++;
261
+ cursor.skipTrivia();
262
+
263
+ const specifier = cursor.current();
264
+ if (specifier.kind !== "string") {
265
+ bag.add("CHIKX1001", messages.expectedModuleSpecifier, cursor.span(specifier));
266
+ recoverStatement(cursor);
267
+ return undefined;
268
+ }
269
+ const path = unquote(specifier.value);
270
+ cursor.index++;
271
+ cursor.skipTrivia();
272
+
273
+ let alias: string | undefined;
274
+ const maybeAs = cursor.current();
275
+ if (maybeAs.kind === "ident" && maybeAs.value.toLowerCase() === "as") {
276
+ cursor.index++;
277
+ cursor.skipTrivia();
278
+ const aliasToken = cursor.current();
279
+ if (aliasToken.kind !== "ident" && aliasToken.kind !== "number") {
280
+ bag.add("CHIKX1001", messages.expectedImportAlias, cursor.span(aliasToken));
281
+ recoverStatement(cursor);
282
+ return undefined;
283
+ }
284
+ alias = aliasToken.value;
285
+ cursor.index++;
286
+ cursor.skipTrivia();
287
+ }
288
+
289
+ let styles: boolean | undefined;
290
+ const maybeStyles = cursor.current();
291
+ if (maybeStyles.kind === "ident" && maybeStyles.value === "styles") {
292
+ styles = true;
293
+ cursor.index++;
294
+ cursor.skipTrivia();
295
+ }
296
+
297
+ const terminator = cursor.current();
298
+ let end: number;
299
+ if (terminator.kind === "semicolon") {
300
+ end = terminator.end;
301
+ cursor.index++;
302
+ } else {
303
+ end = cursor.span(specifier).end;
304
+ bag.add("CHIKX1001", messages.missingSemicolon("an @use import"), {
305
+ start: startToken.start,
306
+ end,
307
+ file,
308
+ });
309
+ cursor.index = Math.min(cursor.index, tokens.length);
310
+ }
311
+
312
+ return Object.freeze({
313
+ kind: "use",
314
+ path,
315
+ ...(alias === undefined ? {} : { alias }),
316
+ ...(styles === undefined ? {} : { styles }),
317
+ span: { start: startToken.start, end, file },
318
+ });
319
+ }
320
+
321
+ /** Strip one matching pair of quotes without decoding escapes. */
322
+ function unquote(value: string): string {
323
+ if (value.length >= 2) {
324
+ const first = value[0];
325
+ const last = value[value.length - 1];
326
+ if ((first === '"' || first === "'") && last === first) return value.slice(1, -1);
327
+ }
328
+ return value;
329
+ }
330
+
331
+ /** Parse `@variables { name: value; ... }` with raw values and optional tokens. */
332
+ export function parseVariablesBlock(ctx: ParseContext): VariablesBlock | undefined {
333
+ const { cursor, bag } = ctx;
334
+ const file = cursor.file;
335
+ const startToken = cursor.current();
336
+ cursor.index++;
337
+ if (!expectBlockOpen(ctx, "@variables")) return undefined;
338
+
339
+ const tokens: TokenDeclaration[] = [];
340
+ let end = cursor.endOffset;
341
+ let closed = false;
342
+
343
+ while (true) {
344
+ cursor.skipTrivia();
345
+ const guard = cursor.index;
346
+ const token = cursor.current();
347
+
348
+ if (token.kind === "eof") break;
349
+ if (token.kind === "rbrace") {
350
+ end = token.end;
351
+ cursor.index++;
352
+ closed = true;
353
+ break;
354
+ }
355
+ if (token.kind === "semicolon") {
356
+ cursor.index++;
357
+ continue;
358
+ }
359
+ if (token.kind !== "ident" && token.kind !== "dollar-ref") {
360
+ bag.add("CHIKX1001", messages.expectedTokenName, cursor.span(token));
361
+ recoverStatement(cursor);
362
+ } else {
363
+ const declaration = parseTokenDeclaration(ctx, token);
364
+ if (declaration !== undefined) tokens.push(declaration);
365
+ }
366
+
367
+ if (cursor.index === guard) cursor.index++;
368
+ }
369
+
370
+ if (!closed) reportUnclosed(ctx, startToken.start, "@variables");
371
+ return Object.freeze({
372
+ kind: "variables",
373
+ tokens: Object.freeze(tokens),
374
+ span: { start: startToken.start, end, file },
375
+ });
376
+ }
377
+
378
+ function parseTokenDeclaration(ctx: ParseContext, nameToken: Token): TokenDeclaration | undefined {
379
+ const { cursor, bag } = ctx;
380
+ const file = cursor.file;
381
+ const name = nameToken.value.startsWith("$") ? nameToken.value.slice(1) : nameToken.value;
382
+ cursor.index++;
383
+ cursor.skipTrivia();
384
+
385
+ const colon = cursor.current();
386
+ if (colon.kind !== "colon") {
387
+ bag.add("CHIKX1001", messages.missingColon(name), cursor.span(colon));
388
+ recoverStatement(cursor);
389
+ return undefined;
390
+ }
391
+ cursor.index++;
392
+
393
+ const scan = scanSimpleValue(ctx, cursor.index);
394
+ if (scan.malformed) {
395
+ bag.add("CHIKX1003", messages.malformedValue, {
396
+ start: nameToken.start,
397
+ end: scan.valueEnd > 0 ? scan.valueEnd : nameToken.end,
398
+ file,
399
+ });
400
+ if (scan.terminator === "lbrace") {
401
+ cursor.index = skipBalancedBlock(cursor.tokens, scan.boundaryIndex, cursor.endOffset);
402
+ } else if (scan.terminator === "semicolon") {
403
+ cursor.index = scan.boundaryIndex + 1;
404
+ } else {
405
+ cursor.index = Math.min(scan.boundaryIndex, cursor.tokens.length);
406
+ }
407
+ return undefined;
408
+ }
409
+
410
+ const value = textOf(cursor.tokens, scan.bounds.start, scan.bounds.end);
411
+ const valueTokens = containsDollarRef(cursor.tokens, scan.bounds.start, scan.bounds.end)
412
+ ? Object.freeze(cursor.tokens.slice(scan.bounds.start, scan.bounds.end))
413
+ : undefined;
414
+ const end = finishSimple(ctx, scan, nameToken.start, nameToken.end, "a token declaration");
415
+
416
+ return Object.freeze({
417
+ kind: "token-declaration",
418
+ name,
419
+ value,
420
+ ...(valueTokens === undefined ? {} : { tokens: valueTokens }),
421
+ span: { start: nameToken.start, end, file },
422
+ });
423
+ }
424
+
425
+ /** Parse `@runtime { declaration ... }`, including inline variant segments. */
426
+ export function parseRuntimeBlock(ctx: ParseContext): RuntimeBlock | undefined {
427
+ const { cursor, bag } = ctx;
428
+ const file = cursor.file;
429
+ const startToken = cursor.current();
430
+ cursor.index++;
431
+ if (!expectBlockOpen(ctx, "@runtime")) return undefined;
432
+
433
+ const declarations: Declaration[] = [];
434
+ let end = cursor.endOffset;
435
+ let closed = false;
436
+
437
+ while (true) {
438
+ cursor.skipTrivia();
439
+ const guard = cursor.index;
440
+ const token = cursor.current();
441
+
442
+ if (token.kind === "eof") break;
443
+ if (token.kind === "rbrace") {
444
+ end = token.end;
445
+ cursor.index++;
446
+ closed = true;
447
+ break;
448
+ }
449
+ if (token.kind === "semicolon") {
450
+ cursor.index++;
451
+ continue;
452
+ }
453
+ if (token.kind === "at-keyword" || token.kind === "modifier") {
454
+ bag.add("CHIKX1001", messages.unexpectedAtRule, cursor.span(token));
455
+ cursor.index = skipAtRule(cursor.tokens, cursor.index, cursor.endOffset);
456
+ } else if (token.kind === "lbrace") {
457
+ bag.add("CHIKX1001", messages.unexpectedToken, cursor.span(token));
458
+ cursor.index = skipBalancedBlock(cursor.tokens, cursor.index, cursor.endOffset);
459
+ } else if (classifyStatement(cursor) === "rule") {
460
+ bag.add("CHIKX1001", messages.unexpectedStatement, cursor.span(token));
461
+ cursor.index = skipStatementBlock(cursor.tokens, cursor.index, cursor.endOffset);
462
+ } else {
463
+ const declaration = parseDeclaration(ctx);
464
+ if (declaration !== undefined) declarations.push(declaration);
465
+ }
466
+
467
+ if (cursor.index === guard) cursor.index++;
468
+ }
469
+
470
+ if (!closed) reportUnclosed(ctx, startToken.start, "@runtime");
471
+ return Object.freeze({
472
+ kind: "runtime",
473
+ declarations: Object.freeze(declarations),
474
+ span: { start: startToken.start, end, file },
475
+ });
476
+ }
477
+
478
+ /** Parse `@media-types { alias: condition; ... }` with raw trimmed conditions. */
479
+ export function parseMediaTypesBlock(ctx: ParseContext): MediaTypesBlock | undefined {
480
+ const { cursor, bag } = ctx;
481
+ const file = cursor.file;
482
+ const startToken = cursor.current();
483
+ cursor.index++;
484
+ if (!expectBlockOpen(ctx, "@media-types")) return undefined;
485
+
486
+ const aliases: AliasDeclaration[] = [];
487
+ let end = cursor.endOffset;
488
+ let closed = false;
489
+
490
+ while (true) {
491
+ cursor.skipTrivia();
492
+ const guard = cursor.index;
493
+ const token = cursor.current();
494
+
495
+ if (token.kind === "eof") break;
496
+ if (token.kind === "rbrace") {
497
+ end = token.end;
498
+ cursor.index++;
499
+ closed = true;
500
+ break;
501
+ }
502
+ if (token.kind === "semicolon") {
503
+ cursor.index++;
504
+ continue;
505
+ }
506
+ if (token.kind !== "ident" && token.kind !== "number") {
507
+ bag.add("CHIKX1001", messages.expectedAliasName, cursor.span(token));
508
+ recoverStatement(cursor);
509
+ } else {
510
+ const alias = parseAliasDeclaration(ctx, token);
511
+ if (alias !== undefined) aliases.push(alias);
512
+ }
513
+
514
+ if (cursor.index === guard) cursor.index++;
515
+ }
516
+
517
+ if (!closed) reportUnclosed(ctx, startToken.start, "@media-types");
518
+ return Object.freeze({
519
+ kind: "media-types",
520
+ aliases: Object.freeze(aliases),
521
+ span: { start: startToken.start, end, file },
522
+ });
523
+ }
524
+
525
+ function parseAliasDeclaration(ctx: ParseContext, nameToken: Token): AliasDeclaration | undefined {
526
+ const { cursor, bag } = ctx;
527
+ const file = cursor.file;
528
+ const name = nameToken.value.startsWith("@") ? nameToken.value.slice(1) : nameToken.value;
529
+ cursor.index++;
530
+ cursor.skipTrivia();
531
+
532
+ const colon = cursor.current();
533
+ if (colon.kind !== "colon") {
534
+ bag.add("CHIKX1001", messages.missingColon(name), cursor.span(colon));
535
+ recoverStatement(cursor);
536
+ return undefined;
537
+ }
538
+ cursor.index++;
539
+
540
+ const scan = scanSimpleValue(ctx, cursor.index);
541
+ if (scan.malformed) {
542
+ bag.add("CHIKX1003", messages.malformedCondition, {
543
+ start: nameToken.start,
544
+ end: scan.valueEnd > 0 ? scan.valueEnd : nameToken.end,
545
+ file,
546
+ });
547
+ if (scan.terminator === "lbrace") {
548
+ cursor.index = skipBalancedBlock(cursor.tokens, scan.boundaryIndex, cursor.endOffset);
549
+ } else if (scan.terminator === "semicolon") {
550
+ cursor.index = scan.boundaryIndex + 1;
551
+ } else {
552
+ cursor.index = Math.min(scan.boundaryIndex, cursor.tokens.length);
553
+ }
554
+ return undefined;
555
+ }
556
+
557
+ const media = textOf(cursor.tokens, scan.bounds.start, scan.bounds.end);
558
+ const end = finishSimple(ctx, scan, nameToken.start, nameToken.end, "an alias declaration");
559
+ return Object.freeze({
560
+ kind: "alias-declaration",
561
+ name,
562
+ media,
563
+ span: { start: nameToken.start, end, file },
564
+ });
565
+ }
566
+
567
+ /**
568
+ * Top-level dispatch: Chikx directives, rules and native at-rules.
569
+ *
570
+ * A top-level conditional block (an unknown `@alias {`) is a CHIKX1001 error and
571
+ * produces no node; recovery skips the balanced block (D3/ADR-0004).
572
+ */
573
+ function parseTopLevelAtRule(ctx: ParseContext): StylesheetItem | undefined {
574
+ const { cursor, bag } = ctx;
575
+ const tokens = cursor.tokens;
576
+ const startToken = cursor.current();
577
+ const name = atRuleName(startToken).toLowerCase();
578
+
579
+ if (isGroupAtKeyword(startToken)) return parseGroupDefinition(ctx);
580
+
581
+ switch (name) {
582
+ case "setup":
583
+ return parseSetupBlock(ctx);
584
+ case "use":
585
+ return parseUseImport(ctx);
586
+ case "variables":
587
+ return parseVariablesBlock(ctx);
588
+ case "runtime":
589
+ return parseRuntimeBlock(ctx);
590
+ case "media-types":
591
+ return parseMediaTypesBlock(ctx);
592
+ default:
593
+ break;
594
+ }
595
+
596
+ if (isNativeAtRuleName(name)) return parseNativeAtRule(ctx);
597
+
598
+ const read = readModifier(tokens, cursor.index, tokens.length, cursor.file);
599
+ const afterModifier = read === undefined ? cursor.index + 1 : read.nextIndex;
600
+ const openIndex = skipTriviaAt(tokens, afterModifier);
601
+ const open = tokenAt(tokens, openIndex, cursor.endOffset);
602
+
603
+ if (open.kind === "lbrace") {
604
+ bag.add("CHIKX1001", messages.topLevelConditional, cursor.span(startToken));
605
+ cursor.index = skipBalancedBlock(tokens, openIndex, cursor.endOffset);
606
+ return undefined;
607
+ }
608
+
609
+ return parseNativeAtRule(ctx);
610
+ }
611
+
612
+ /**
613
+ * Tolerant recursive-descent parse of a top-level stylesheet.
614
+ *
615
+ * Never throws: statement-level recovery keeps prior items, every iteration
616
+ * advances, and a recovered AST is always returned (SPECIFICATION.md §12).
617
+ */
618
+ export function parseStylesheet(tokens: readonly Token[], file: string): ParseResult {
619
+ const cursor = new TokenCursor(tokens, file);
620
+ const bag = new DiagnosticBag();
621
+ const ctx: ParseContext = { cursor, bag };
622
+ const items: StylesheetItem[] = [];
623
+
624
+ while (true) {
625
+ cursor.skipTrivia();
626
+ const guard = cursor.index;
627
+ const token = cursor.current();
628
+
629
+ if (token.kind === "eof") break;
630
+ if (token.kind === "semicolon") {
631
+ cursor.index++;
632
+ continue;
633
+ }
634
+ if (token.kind === "rbrace") {
635
+ bag.add("CHIKX1001", messages.unexpectedToken, cursor.span(token));
636
+ cursor.index++;
637
+ continue;
638
+ }
639
+ if (token.kind === "lbrace") {
640
+ bag.add("CHIKX1001", messages.unexpectedToken, cursor.span(token));
641
+ cursor.index = skipBalancedBlock(tokens, cursor.index, cursor.endOffset);
642
+ } else if (token.kind === "at-keyword" || token.kind === "modifier") {
643
+ const item = parseTopLevelAtRule(ctx);
644
+ if (item !== undefined) items.push(item);
645
+ } else if (classifyStatement(cursor) === "rule") {
646
+ const rule = parseRule(ctx);
647
+ if (rule !== undefined) items.push(rule);
648
+ } else {
649
+ bag.add("CHIKX1001", messages.unexpectedStatement, cursor.span(token));
650
+ recoverStatement(cursor);
651
+ }
652
+
653
+ if (cursor.index === guard) {
654
+ bag.add("CHIKX1001", messages.internalRecovery, cursor.span(token));
655
+ cursor.index++;
656
+ }
657
+ }
658
+
659
+ const ast: Stylesheet = Object.freeze({
660
+ kind: "stylesheet",
661
+ file,
662
+ items: Object.freeze(items),
663
+ span: { start: 0, end: cursor.endOffset, file },
664
+ });
665
+
666
+ return { ast, diagnostics: bag.finish() };
667
+ }