@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,544 @@
1
+ /**
2
+ * Canonical Chikx source formatter.
3
+ *
4
+ * The formatter is a pure `parse → print` pass with zero dependencies: it never
5
+ * reads the filesystem, never mutates input and never throws. Values, aliases,
6
+ * selectors and `!important` flags are printed from the AST's raw slices, so
7
+ * formatting cannot change compilation semantics.
8
+ *
9
+ * Canonical style (documented for the CLI and the language service):
10
+ *
11
+ * - two-space indentation, one declaration per line, every declaration ends
12
+ * with `;`, and the file ends with a single `\n`;
13
+ * - one blank line between top-level constructs, and inside a rule or at-rule
14
+ * block a blank line whenever either side is a nested rule/conditional block;
15
+ * - inline variants stay on the declaration line (`padding: 12px @md 20px;`),
16
+ * and adjacent authored markers stay adjacent (`x: 1 @a@b 2;`) because
17
+ * `@a@b` and `@a @b` split into different variants;
18
+ * - a directive entry keeps its authored `$` sigil (`$layout.margin: 4px;`), so
19
+ * a namespaced token declaration still reparses as the same declaration;
20
+ * - a statement at-rule whose prelude leaves a `[` or `(` open prints without a
21
+ * terminator, because that `;` would be read back as prelude text and grow on
22
+ * every pass;
23
+ * - directive blocks (`@setup`, `@variables`, `@runtime`, `@media-types`) hold
24
+ * one entry per line, and `@group.<name>` definitions and use sites print
25
+ * like other at-rule blocks with one declaration per line (ADR-0017);
26
+ * - block comments are kept on their own lines, attached to the statement that
27
+ * follows them; comments embedded in values or selectors stay in the raw
28
+ * slice and are never duplicated;
29
+ * - `@use` specifiers are re-emitted with double quotes (paths are opaque raw
30
+ * text; the AST does not retain the original quote character).
31
+ *
32
+ * Unparseable input is returned unchanged together with the parse diagnostics,
33
+ * so a formatter run never destroys code. `format(format(x)) === format(x)` for
34
+ * every accepted input.
35
+ */
36
+
37
+ import { tokenize } from "../lexer/index.js";
38
+ import { parseTokens } from "../parser/index.js";
39
+ import type {
40
+ AliasDeclaration,
41
+ BlockItem,
42
+ ConditionalBlock,
43
+ ConditionalBlockItem,
44
+ Declaration,
45
+ GroupDefinition,
46
+ GroupUseSite,
47
+ MediaTypesBlock,
48
+ NativeAtRule,
49
+ Rule,
50
+ RuntimeBlock,
51
+ Setting,
52
+ SetupBlock,
53
+ Stylesheet,
54
+ StylesheetItem,
55
+ TokenDeclaration,
56
+ UseImport,
57
+ VariablesBlock,
58
+ } from "../types/ast.js";
59
+ import type { Diagnostic } from "../types/diagnostics.js";
60
+ import type { Token } from "../types/token.js";
61
+
62
+ /** Result of formatting one source string. */
63
+ export interface FormatResult {
64
+ /** Canonical source, or the original text when parsing reported an error. */
65
+ readonly formatted: string;
66
+ /** Parse diagnostics; errors leave `formatted` byte-identical to the input. */
67
+ readonly diagnostics: readonly Diagnostic[];
68
+ }
69
+
70
+ /** A comment treated as free-standing rather than embedded in a raw slice. */
71
+ interface EmbeddedRange {
72
+ readonly start: number;
73
+ readonly end: number;
74
+ }
75
+
76
+ /** One printed statement chunk and whether it opens a nested block. */
77
+ interface Chunk {
78
+ readonly lines: readonly string[];
79
+ readonly block: boolean;
80
+ }
81
+
82
+ const INDENT = " ";
83
+
84
+ function pad(level: number): string {
85
+ return INDENT.repeat(level);
86
+ }
87
+
88
+ function itemStart(item: StylesheetItem): number {
89
+ return item.kind === "rule" ? item.selectorSpan.start : item.span.start;
90
+ }
91
+
92
+ function blockItemStart(item: BlockItem | ConditionalBlockItem): number {
93
+ if (item.kind === "rule") return item.selectorSpan.start;
94
+ if (item.kind === "conditional-block") return item.variant.span.start;
95
+ return item.span.start;
96
+ }
97
+
98
+ /** Range of a native at-rule header, whose prelude is printed verbatim. */
99
+ function nativeHeaderRange(item: NativeAtRule, tokens: readonly Token[]): EmbeddedRange {
100
+ if (item.block === undefined) return { start: item.span.start, end: item.span.end };
101
+ const first = item.block[0];
102
+ const limit = first === undefined ? item.span.end : blockItemStart(first);
103
+ // The header ends at the block's `{`, so comments after it stay free-standing.
104
+ const open = tokens.find(
105
+ (token) => token.kind === "lbrace" && token.start >= item.span.start && token.start < limit,
106
+ );
107
+ return { start: item.span.start, end: open?.start ?? limit };
108
+ }
109
+
110
+ /**
111
+ * Collect comments that are already part of a printed raw slice.
112
+ *
113
+ * Declarations keep their authored value text (including an inline comment),
114
+ * selectors keep their authored text, and directive entries keep raw values.
115
+ * Those comments must not be printed a second time by the comment attachment
116
+ * pass.
117
+ */
118
+ function embeddedCommentRanges(
119
+ ast: Stylesheet,
120
+ tokens: readonly Token[],
121
+ ): readonly EmbeddedRange[] {
122
+ const ranges: EmbeddedRange[] = [];
123
+
124
+ const visitDeclaration = (declaration: Declaration): void => {
125
+ ranges.push({ start: declaration.span.start, end: declaration.span.end });
126
+ };
127
+ const visitItems = (items: readonly BlockItem[]): void => {
128
+ for (const item of items) {
129
+ switch (item.kind) {
130
+ case "declaration":
131
+ visitDeclaration(item);
132
+ break;
133
+ case "rule":
134
+ ranges.push({ start: item.selectorSpan.start, end: item.selectorSpan.end });
135
+ visitItems(item.body);
136
+ break;
137
+ case "conditional-block":
138
+ visitConditional(item);
139
+ break;
140
+ case "native-at-rule":
141
+ visitNative(item);
142
+ break;
143
+ case "group-use-site":
144
+ for (const declaration of item.declarations) visitDeclaration(declaration);
145
+ break;
146
+ }
147
+ }
148
+ };
149
+ const visitConditional = (block: ConditionalBlock): void => {
150
+ for (const item of block.body) {
151
+ if (item.kind === "declaration") visitDeclaration(item);
152
+ else if (item.kind === "rule") {
153
+ ranges.push({ start: item.selectorSpan.start, end: item.selectorSpan.end });
154
+ visitItems(item.body);
155
+ } else visitConditional(item);
156
+ }
157
+ };
158
+ const visitNative = (item: NativeAtRule): void => {
159
+ ranges.push(nativeHeaderRange(item, tokens));
160
+ if (item.block !== undefined) visitItems(item.block);
161
+ };
162
+
163
+ for (const item of ast.items) {
164
+ switch (item.kind) {
165
+ case "setup":
166
+ for (const setting of item.settings) ranges.push(setting.span);
167
+ break;
168
+ case "use":
169
+ ranges.push(item.span);
170
+ break;
171
+ case "variables":
172
+ for (const token of item.tokens) ranges.push(token.span);
173
+ break;
174
+ case "runtime":
175
+ for (const declaration of item.declarations) visitDeclaration(declaration);
176
+ break;
177
+ case "media-types":
178
+ for (const alias of item.aliases) ranges.push(alias.span);
179
+ break;
180
+ case "group-definition":
181
+ for (const declaration of item.declarations) visitDeclaration(declaration);
182
+ break;
183
+ case "rule":
184
+ ranges.push({ start: item.selectorSpan.start, end: item.selectorSpan.end });
185
+ visitItems(item.body);
186
+ break;
187
+ case "native-at-rule":
188
+ visitNative(item);
189
+ break;
190
+ }
191
+ }
192
+
193
+ return ranges.sort((left, right) => left.start - right.start);
194
+ }
195
+
196
+ /** Stateful printer that consumes free-standing comments in source order. */
197
+ class Printer {
198
+ private readonly comments: readonly Token[];
199
+ private readonly embedded: readonly EmbeddedRange[];
200
+ private readonly source: string;
201
+ private readonly file: string;
202
+ private commentIndex = 0;
203
+
204
+ constructor(
205
+ comments: readonly Token[],
206
+ embedded: readonly EmbeddedRange[],
207
+ source: string,
208
+ file: string,
209
+ ) {
210
+ this.comments = comments;
211
+ this.embedded = embedded;
212
+ this.source = source;
213
+ this.file = file;
214
+ }
215
+
216
+ /** Comments to print before `offset`, skipping any embedded in raw slices. */
217
+ takeComments(offset: number, level: number): string[] {
218
+ const lines: string[] = [];
219
+ while (this.commentIndex < this.comments.length) {
220
+ const token = this.comments[this.commentIndex];
221
+ if (token === undefined || token.start >= offset) break;
222
+ this.commentIndex += 1;
223
+ if (this.isEmbedded(token)) continue;
224
+ lines.push(...commentLines(token.value, level));
225
+ }
226
+ return lines;
227
+ }
228
+
229
+ /** Any comments left after the last statement, printed at the given level. */
230
+ takeRest(level: number): string[] {
231
+ return this.takeComments(Number.POSITIVE_INFINITY, level);
232
+ }
233
+
234
+ private isEmbedded(token: Token): boolean {
235
+ for (const range of this.embedded) {
236
+ if (range.start > token.start) return false;
237
+ if (token.start >= range.start && token.end <= range.end) return true;
238
+ }
239
+ return false;
240
+ }
241
+
242
+ printStylesheet(ast: Stylesheet): string[] {
243
+ const chunks: Chunk[] = [];
244
+ for (const item of ast.items) {
245
+ const comments = this.takeComments(itemStart(item), 0);
246
+ const printed = this.printItem(item, 0);
247
+ const lines = [...comments, ...(printed?.lines ?? [])];
248
+ if (lines.length > 0) chunks.push({ lines, block: printed?.block ?? false });
249
+ }
250
+ const rest = this.takeRest(0);
251
+ if (rest.length > 0) chunks.push({ lines: rest, block: false });
252
+
253
+ const output: string[] = [];
254
+ for (let index = 0; index < chunks.length; index += 1) {
255
+ const chunk = chunks[index];
256
+ if (chunk === undefined) continue;
257
+ if (index > 0) output.push("");
258
+ output.push(...chunk.lines);
259
+ }
260
+ return output;
261
+ }
262
+
263
+ private printItem(item: StylesheetItem, level: number): Chunk | undefined {
264
+ switch (item.kind) {
265
+ case "setup":
266
+ return this.printSetup(item, level);
267
+ case "use":
268
+ return this.printUse(item, level);
269
+ case "variables":
270
+ return this.printVariables(item, level);
271
+ case "runtime":
272
+ return this.printRuntime(item, level);
273
+ case "media-types":
274
+ return this.printMediaTypes(item, level);
275
+ case "group-definition":
276
+ return this.printGroupDefinition(item, level);
277
+ case "rule":
278
+ return this.printRule(item, level);
279
+ case "native-at-rule":
280
+ return this.printNative(item, level);
281
+ }
282
+ }
283
+
284
+ private printSetup(block: SetupBlock, level: number): Chunk {
285
+ const lines = [`${pad(level)}@setup {`];
286
+ for (const setting of block.settings) {
287
+ lines.push(...this.takeComments(setting.span.start, level + 1));
288
+ lines.push(`${pad(level + 1)}${printSetting(setting)}`);
289
+ }
290
+ lines.push(...this.takeComments(block.span.end, level + 1));
291
+ lines.push(`${pad(level)}}`);
292
+ return { lines, block: true };
293
+ }
294
+
295
+ private printUse(item: UseImport, level: number): Chunk {
296
+ const alias = item.alias === undefined ? "" : ` as ${item.alias}`;
297
+ // `styles` is semantic, not cosmetic: dropping it would downgrade a
298
+ // rule-merge import to a token-only one (ADR-0014, SPECIFICATION.md §6.3).
299
+ const styles = item.styles === true ? " styles" : "";
300
+ return { lines: [`${pad(level)}@use "${item.path}"${alias}${styles};`], block: false };
301
+ }
302
+
303
+ private printVariables(block: VariablesBlock, level: number): Chunk {
304
+ const lines = [`${pad(level)}@variables {`];
305
+ for (const token of block.tokens) {
306
+ lines.push(...this.takeComments(token.span.start, level + 1));
307
+ lines.push(`${pad(level + 1)}${printTokenDeclaration(token, this.source)}`);
308
+ }
309
+ lines.push(...this.takeComments(block.span.end, level + 1));
310
+ lines.push(`${pad(level)}}`);
311
+ return { lines, block: true };
312
+ }
313
+
314
+ private printRuntime(block: RuntimeBlock, level: number): Chunk {
315
+ const lines = [`${pad(level)}@runtime {`];
316
+ const body = this.printBlockItems(block.declarations, level + 1, block.span.end);
317
+ lines.push(...body);
318
+ lines.push(`${pad(level)}}`);
319
+ return { lines, block: true };
320
+ }
321
+
322
+ private printMediaTypes(block: MediaTypesBlock, level: number): Chunk {
323
+ const lines = [`${pad(level)}@media-types {`];
324
+ for (const alias of block.aliases) {
325
+ lines.push(...this.takeComments(alias.span.start, level + 1));
326
+ lines.push(`${pad(level + 1)}${printAlias(alias)}`);
327
+ }
328
+ lines.push(...this.takeComments(block.span.end, level + 1));
329
+ lines.push(`${pad(level)}}`);
330
+ return { lines, block: true };
331
+ }
332
+
333
+ /**
334
+ * Print a `@group.<name>` definition or use site (ADR-0017).
335
+ *
336
+ * Both node kinds are the same authored construct at different positions, so
337
+ * they share one layout: the `@group` header, then one declaration per line at
338
+ * the next depth. Declarations are ordinary {@link Declaration} nodes, so
339
+ * inline variants and per-segment `!important` print exactly as they do in a
340
+ * rule body; only the block's own comments and trailing comments are printed
341
+ * here. Omitting either node would delete an authored group on format-on-save
342
+ * (ADR-0017 item 8), which is why the printer handles both kinds explicitly.
343
+ */
344
+ private printGroup(
345
+ name: string,
346
+ declarations: readonly Declaration[],
347
+ endOffset: number,
348
+ level: number,
349
+ ): Chunk {
350
+ const lines = [`${pad(level)}@group.${name} {`];
351
+ lines.push(...this.printBlockItems(declarations, level + 1, endOffset));
352
+ lines.push(`${pad(level)}}`);
353
+ return { lines, block: true };
354
+ }
355
+
356
+ private printGroupDefinition(block: GroupDefinition, level: number): Chunk {
357
+ return this.printGroup(block.name, block.declarations, block.span.end, level);
358
+ }
359
+
360
+ private printGroupUseSite(block: GroupUseSite, level: number): Chunk {
361
+ return this.printGroup(block.name, block.declarations, block.span.end, level);
362
+ }
363
+
364
+ private printRule(rule: Rule, level: number): Chunk {
365
+ const lines = [`${pad(level)}${rule.selector} {`];
366
+ lines.push(...this.printBlockItems(rule.body, level + 1, rule.span.end));
367
+ lines.push(`${pad(level)}}`);
368
+ return { lines, block: true };
369
+ }
370
+
371
+ private printConditional(block: ConditionalBlock, level: number): Chunk {
372
+ const header = `@${block.variant.aliases.join("+")}`;
373
+ const lines = [`${pad(level)}${header} {`];
374
+ const body: ConditionalBlockItem[] = [...block.body];
375
+ lines.push(...this.printBlockItems(body, level + 1, block.span.end));
376
+ lines.push(`${pad(level)}}`);
377
+ return { lines, block: true };
378
+ }
379
+
380
+ private printNative(item: NativeAtRule, level: number): Chunk {
381
+ const header = item.prelude.length === 0 ? `@${item.name}` : `@${item.name} ${item.prelude}`;
382
+ if (item.block === undefined) {
383
+ const terminator = preludeSwallowsTerminator(item.prelude, this.file) ? "" : ";";
384
+ return { lines: [`${pad(level)}${header}${terminator}`], block: false };
385
+ }
386
+ const lines = [`${pad(level)}${header} {`];
387
+ lines.push(...this.printBlockItems(item.block, level + 1, item.span.end));
388
+ lines.push(`${pad(level)}}`);
389
+ return { lines, block: true };
390
+ }
391
+
392
+ private printBlockItems(
393
+ items: readonly (BlockItem | ConditionalBlockItem | Declaration)[],
394
+ level: number,
395
+ endOffset: number,
396
+ ): string[] {
397
+ const chunks: Chunk[] = [];
398
+ for (const item of items) {
399
+ const start = blockItemStart(item);
400
+ const comments = this.takeComments(start, level);
401
+ const printed = this.printBlockItem(item, level);
402
+ const lines = [...comments, ...(printed?.lines ?? [])];
403
+ if (lines.length > 0) chunks.push({ lines, block: printed?.block ?? false });
404
+ }
405
+ const trailing = this.takeComments(endOffset, level);
406
+ if (trailing.length > 0) chunks.push({ lines: trailing, block: false });
407
+
408
+ const output: string[] = [];
409
+ let previousBlock = false;
410
+ for (let index = 0; index < chunks.length; index += 1) {
411
+ const chunk = chunks[index];
412
+ if (chunk === undefined) continue;
413
+ if (index > 0 && (previousBlock || chunk.block)) output.push("");
414
+ output.push(...chunk.lines);
415
+ previousBlock = chunk.block;
416
+ }
417
+ return output;
418
+ }
419
+
420
+ private printBlockItem(
421
+ item: BlockItem | ConditionalBlockItem | Declaration,
422
+ level: number,
423
+ ): Chunk | undefined {
424
+ switch (item.kind) {
425
+ case "declaration":
426
+ return { lines: [`${pad(level)}${printDeclaration(item)}`], block: false };
427
+ case "rule":
428
+ return this.printRule(item, level);
429
+ case "conditional-block":
430
+ return this.printConditional(item, level);
431
+ case "native-at-rule":
432
+ return this.printNative(item, level);
433
+ case "group-use-site":
434
+ return this.printGroupUseSite(item, level);
435
+ }
436
+ }
437
+ }
438
+
439
+ function commentLines(value: string, level: number): string[] {
440
+ return value.split("\n").map((line, index) => {
441
+ const text = index === 0 ? line : line.replace(/^[ \t]*/, "");
442
+ return `${pad(level)}${text}`;
443
+ });
444
+ }
445
+
446
+ function printSetting(setting: Setting): string {
447
+ return `${setting.key}: ${setting.value};`;
448
+ }
449
+
450
+ /**
451
+ * Whether a `;` printed after this prelude would be read back as part of it.
452
+ *
453
+ * The parser ends a statement at-rule's prelude only at a top-level `{`, `;` or
454
+ * `}`; while a `[` or `(` is still open, those tokens are prelude text. A
455
+ * prelude with a dangling opener therefore swallows the formatter's terminator,
456
+ * and re-formatting would add one `;` per pass. In that case the authored form
457
+ * has no terminator to restore, so printing none is both stable and lossless.
458
+ * The token stack mirrors `parseNativeAtRule`, so strings and comments (which
459
+ * the lexer already collapsed) cannot be miscounted.
460
+ */
461
+ function preludeSwallowsTerminator(prelude: string, file: string): boolean {
462
+ if (prelude.length === 0) return false;
463
+ let tokens: readonly Token[];
464
+ try {
465
+ tokens = tokenize(prelude, file).tokens;
466
+ } catch {
467
+ return false;
468
+ }
469
+ const closers: Array<"rparen" | "rbracket"> = [];
470
+ for (const token of tokens) {
471
+ if (token.kind === "lparen") closers.push("rparen");
472
+ else if (token.kind === "lbracket") closers.push("rbracket");
473
+ else if (token.kind === "rparen" || token.kind === "rbracket") {
474
+ // A mismatched closer ends the prelude rather than nesting it.
475
+ if (closers.pop() !== token.kind) return false;
476
+ } else if (
477
+ closers.length === 0 &&
478
+ (token.kind === "lbrace" || token.kind === "semicolon" || token.kind === "rbrace")
479
+ ) {
480
+ return false;
481
+ }
482
+ }
483
+ return closers.length > 0;
484
+ }
485
+
486
+ function printTokenDeclaration(token: TokenDeclaration, source: string): string {
487
+ // The parser strips the authored `$` from `name`; keep it so a namespaced
488
+ // declaration (`$layout.margin: 4px`) still reparses as a token declaration.
489
+ const sigil = source[token.span.start] === "$" ? "$" : "";
490
+ return `${sigil}${token.name}: ${token.value};`;
491
+ }
492
+
493
+ function printAlias(alias: AliasDeclaration): string {
494
+ return `${alias.name}: ${alias.media};`;
495
+ }
496
+
497
+ /** Print one declaration with its inline variants on the same line. */
498
+ function printDeclaration(declaration: Declaration): string {
499
+ let text = `${declaration.property}: ${declaration.value}`;
500
+ for (const variant of declaration.variants) {
501
+ const modifier = `@${variant.aliases.join("+")}`;
502
+ if (variant.value.length === 0) {
503
+ text += ` ${modifier}`;
504
+ continue;
505
+ }
506
+ // The parser treats a marker directly after another marker as part of the
507
+ // same variant's value; inserting a space would split one variant into two
508
+ // and change which conditional block the value lands in.
509
+ const separator = variant.value.startsWith("@") ? "" : " ";
510
+ text += ` ${modifier}${separator}${variant.value}`;
511
+ }
512
+ return `${text};`;
513
+ }
514
+
515
+ /**
516
+ * Format one Chikx source string canonically.
517
+ *
518
+ * @param source Authored source text; never mutated.
519
+ * @param file Workspace-relative POSIX path used for diagnostics and spans.
520
+ * @returns The canonical text plus parse diagnostics. Any error diagnostic
521
+ * returns the original `source` unchanged so no data is lost.
522
+ */
523
+ export function format(source: string, file: string): FormatResult {
524
+ const lexed = tokenize(source, file);
525
+ const parsed = parseTokens(lexed.tokens, file);
526
+ const diagnostics = Object.freeze([...lexed.diagnostics, ...parsed.diagnostics]);
527
+
528
+ if (diagnostics.some((diagnostic) => diagnostic.severity === "error")) {
529
+ return Object.freeze({ formatted: source, diagnostics });
530
+ }
531
+
532
+ const comments = lexed.tokens.filter((token) => token.kind === "comment");
533
+ const printer = new Printer(
534
+ comments,
535
+ embeddedCommentRanges(parsed.ast, lexed.tokens),
536
+ source,
537
+ file,
538
+ );
539
+ const lines = printer.printStylesheet(parsed.ast);
540
+ return Object.freeze({
541
+ formatted: lines.length === 0 ? "" : `${lines.join("\n")}\n`,
542
+ diagnostics,
543
+ });
544
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Default Node/Bun filesystem host for `compile`.
3
+ *
4
+ * The compiler core stays filesystem-free; this host is the batteries-included
5
+ * adapter used by `compile` so callers do not have to build one. It is built on
6
+ * Node-compatible modules only (`node:fs/promises`, `node:fs` for the
7
+ * synchronous realpath required by {@link ModuleHost.canonicalize}, and
8
+ * `node:path`), with no Bun-only APIs.
9
+ *
10
+ * Workspace policy: the root is the explicit `root` argument when provided,
11
+ * otherwise `process.cwd()` resolved **at the moment `createNodeHost` is
12
+ * called**. The caller should pass `CompileOptions.workspaceRoot` for stable
13
+ * behaviour across process directory changes. Paths crossing the host boundary
14
+ * are absolute POSIX-style paths with forward slashes; `node:path` handles the
15
+ * platform separator and Windows drive letters internally.
16
+ *
17
+ * Canonicalization note: the frozen {@link ModuleHost.canonicalize} signature is
18
+ * synchronous, so `fs/promises.realpath` (async) cannot back it directly. The
19
+ * host uses `realpathSync` in a guarded try/catch, falling back to the resolved
20
+ * lexical path when the target does not exist or the platform refuses to
21
+ * resolve it. This is the only `node:fs` use; reads and existence checks use
22
+ * `node:fs/promises` as requested.
23
+ */
24
+
25
+ import { realpathSync } from "node:fs";
26
+ import { readFile, stat } from "node:fs/promises";
27
+ import { dirname, resolve } from "node:path";
28
+ import type { ModuleHost } from "../types/options.js";
29
+
30
+ /** Convert a platform path to a POSIX-style path with forward slashes. */
31
+ function toPosix(path: string): string {
32
+ return path.replace(/\\/g, "/");
33
+ }
34
+
35
+ /** Remove a trailing separator except for a filesystem root. */
36
+ function trimTrailingSlash(path: string): string {
37
+ if (path === "/" || /^[A-Za-z]:\/$/.test(path)) return path;
38
+ return path.endsWith("/") ? path.slice(0, -1) : path;
39
+ }
40
+
41
+ /**
42
+ * Create the default Node/Bun {@link ModuleHost}.
43
+ *
44
+ * @param root Absolute workspace root; defaults to `process.cwd()` at call
45
+ * time. Relative roots are resolved against the current directory.
46
+ * @returns A host whose `canonicalize` resolves symlinks when the real path is
47
+ * available and falls back to a lexical absolute path otherwise.
48
+ */
49
+ export function createNodeHost(root?: string): ModuleHost {
50
+ const lexicalRoot = trimTrailingSlash(toPosix(resolve(root ?? process.cwd())));
51
+ const workspaceRoot = realOrLexical(lexicalRoot);
52
+
53
+ const absolute = (path: string): string =>
54
+ trimTrailingSlash(toPosix(resolve(workspaceRoot, path)));
55
+
56
+ return {
57
+ async readFile(path: string): Promise<string> {
58
+ return readFile(path, "utf8");
59
+ },
60
+ async fileExists(path: string): Promise<boolean> {
61
+ try {
62
+ return (await stat(path)).isFile();
63
+ } catch {
64
+ return false;
65
+ }
66
+ },
67
+ canonicalize(path: string): string {
68
+ return realOrLexical(absolute(path));
69
+ },
70
+ resolvePath(from: string, to: string): string {
71
+ return trimTrailingSlash(toPosix(resolve(dirname(from), to)));
72
+ },
73
+ workspaceRoot(): string {
74
+ return workspaceRoot;
75
+ },
76
+ };
77
+ }
78
+
79
+ function realOrLexical(path: string): string {
80
+ try {
81
+ return trimTrailingSlash(toPosix(realpathSync(path)));
82
+ } catch {
83
+ return path;
84
+ }
85
+ }