@md-code/follow-architecture 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +202 -0
  3. package/README.md +597 -126
  4. package/dist/aliases.d.ts +3 -0
  5. package/dist/aliases.js +12 -0
  6. package/dist/args.d.ts +14 -0
  7. package/dist/args.js +77 -0
  8. package/dist/bin/follow-architecture.d.ts +2 -0
  9. package/dist/bin/follow-architecture.js +23 -0
  10. package/dist/code-roles/classify.d.ts +11 -0
  11. package/dist/code-roles/classify.js +43 -0
  12. package/dist/code-roles/connector.d.ts +5 -0
  13. package/dist/code-roles/connector.js +114 -0
  14. package/dist/code-roles/project.d.ts +12 -0
  15. package/dist/code-roles/project.js +122 -0
  16. package/dist/code-roles/roles.d.ts +8 -0
  17. package/dist/code-roles/roles.js +190 -0
  18. package/dist/config-options.d.ts +53 -0
  19. package/dist/config-options.js +35 -0
  20. package/dist/config-project.d.ts +4 -0
  21. package/dist/config-project.js +74 -0
  22. package/dist/config-report.d.ts +19 -0
  23. package/dist/config-report.js +134 -0
  24. package/dist/config-rule.d.ts +70 -0
  25. package/dist/config-rule.js +118 -0
  26. package/dist/config-state.d.ts +14 -0
  27. package/dist/config-state.js +96 -0
  28. package/dist/config.d.ts +82 -0
  29. package/dist/config.js +38 -0
  30. package/dist/css/index.d.ts +27 -0
  31. package/dist/css/index.js +140 -0
  32. package/dist/css/syntax/css/gate.d.ts +2 -0
  33. package/dist/css/syntax/css/gate.js +69 -0
  34. package/dist/css/syntax/css/index.d.ts +7 -0
  35. package/dist/css/syntax/css/index.js +41 -0
  36. package/dist/css/syntax/css/reference.d.ts +3 -0
  37. package/dist/css/syntax/css/reference.js +24 -0
  38. package/dist/css/syntax/language.d.ts +25 -0
  39. package/dist/css/syntax/language.js +69 -0
  40. package/dist/css/syntax/scss/index.d.ts +25 -0
  41. package/dist/css/syntax/scss/index.js +85 -0
  42. package/dist/css/syntax/scss/reference.d.ts +3 -0
  43. package/dist/css/syntax/scss/reference.js +11 -0
  44. package/dist/css/syntax/styled/document.d.ts +68 -0
  45. package/dist/css/syntax/styled/document.js +241 -0
  46. package/dist/css/syntax/styled/markup.d.ts +6 -0
  47. package/dist/css/syntax/styled/markup.js +76 -0
  48. package/dist/css/syntax/styled/template.d.ts +23 -0
  49. package/dist/css/syntax/styled/template.js +61 -0
  50. package/dist/css/syntax/tailwind/tailwind-engine.d.ts +23 -0
  51. package/dist/css/syntax/tailwind/tailwind-engine.js +37 -0
  52. package/dist/css/syntax/tailwind/tailwind.d.ts +26 -0
  53. package/dist/css/syntax/tailwind/tailwind.js +118 -0
  54. package/dist/css/value/check.d.ts +86 -0
  55. package/dist/css/value/check.js +122 -0
  56. package/dist/css/value/expression/arithmetic.d.ts +7 -0
  57. package/dist/css/value/expression/arithmetic.js +69 -0
  58. package/dist/css/value/expression/block.d.ts +9 -0
  59. package/dist/css/value/expression/block.js +91 -0
  60. package/dist/css/value/expression/conditional.d.ts +8 -0
  61. package/dist/css/value/expression/conditional.js +53 -0
  62. package/dist/css/value/expression/index.d.ts +5 -0
  63. package/dist/css/value/expression/index.js +69 -0
  64. package/dist/css/value/expression/map.d.ts +7 -0
  65. package/dist/css/value/expression/map.js +113 -0
  66. package/dist/css/value/object/index.d.ts +5 -0
  67. package/dist/css/value/object/index.js +103 -0
  68. package/dist/css/value/object/members.d.ts +7 -0
  69. package/dist/css/value/object/members.js +103 -0
  70. package/dist/css/value/object/node.d.ts +8 -0
  71. package/dist/css/value/object/node.js +129 -0
  72. package/dist/css/value/object/path.d.ts +10 -0
  73. package/dist/css/value/object/path.js +146 -0
  74. package/dist/css/value/pieces.d.ts +61 -0
  75. package/dist/css/value/pieces.js +55 -0
  76. package/dist/css/value/resolve.d.ts +33 -0
  77. package/dist/css/value/resolve.js +94 -0
  78. package/dist/css/value/scope.d.ts +27 -0
  79. package/dist/css/value/scope.js +187 -0
  80. package/dist/css/value/substitute.d.ts +10 -0
  81. package/dist/css/value/substitute.js +113 -0
  82. package/dist/css/value/values.d.ts +23 -0
  83. package/dist/css/value/values.js +131 -0
  84. package/dist/entities/architecture.d.ts +162 -0
  85. package/dist/entities/architecture.js +2 -0
  86. package/dist/entities/ast/assignments-nodes.d.ts +10 -0
  87. package/dist/entities/ast/assignments-nodes.js +64 -0
  88. package/dist/entities/ast/assignments-raw.d.ts +6 -0
  89. package/dist/entities/ast/assignments-raw.js +86 -0
  90. package/dist/entities/ast/assignments-tagged.d.ts +5 -0
  91. package/dist/entities/ast/assignments-tagged.js +180 -0
  92. package/dist/entities/ast/assignments.d.ts +9 -0
  93. package/dist/entities/ast/assignments.js +78 -0
  94. package/dist/entities/ast/branches.d.ts +4 -0
  95. package/dist/entities/ast/branches.js +32 -0
  96. package/dist/entities/ast/calls.d.ts +6 -0
  97. package/dist/entities/ast/calls.js +134 -0
  98. package/dist/entities/ast/classes.d.ts +5 -0
  99. package/dist/entities/ast/classes.js +57 -0
  100. package/dist/entities/ast/climb.d.ts +12 -0
  101. package/dist/entities/ast/climb.js +17 -0
  102. package/dist/entities/ast/comments.d.ts +4 -0
  103. package/dist/entities/ast/comments.js +100 -0
  104. package/dist/entities/ast/declaration.d.ts +4 -0
  105. package/dist/entities/ast/declaration.js +26 -0
  106. package/dist/entities/ast/depth.d.ts +17 -0
  107. package/dist/entities/ast/depth.js +149 -0
  108. package/dist/entities/ast/enums.d.ts +6 -0
  109. package/dist/entities/ast/enums.js +17 -0
  110. package/dist/entities/ast/file-exports.d.ts +7 -0
  111. package/dist/entities/ast/file-exports.js +78 -0
  112. package/dist/entities/ast/file-facts.d.ts +13 -0
  113. package/dist/entities/ast/file-facts.js +35 -0
  114. package/dist/entities/ast/file-imports.d.ts +5 -0
  115. package/dist/entities/ast/file-imports.js +77 -0
  116. package/dist/entities/ast/file.d.ts +5 -0
  117. package/dist/entities/ast/file.js +22 -0
  118. package/dist/entities/ast/functions.d.ts +8 -0
  119. package/dist/entities/ast/functions.js +102 -0
  120. package/dist/entities/ast/heritage.d.ts +4 -0
  121. package/dist/entities/ast/heritage.js +36 -0
  122. package/dist/entities/ast/index.d.ts +6 -0
  123. package/dist/entities/ast/index.js +125 -0
  124. package/dist/entities/ast/kind.d.ts +5 -0
  125. package/dist/entities/ast/kind.js +28 -0
  126. package/dist/entities/ast/loose.d.ts +37 -0
  127. package/dist/entities/ast/loose.js +2 -0
  128. package/dist/entities/ast/modifiers.d.ts +5 -0
  129. package/dist/entities/ast/modifiers.js +32 -0
  130. package/dist/entities/ast/project.d.ts +9 -0
  131. package/dist/entities/ast/project.js +75 -0
  132. package/dist/entities/ast/properties.d.ts +11 -0
  133. package/dist/entities/ast/properties.js +171 -0
  134. package/dist/entities/ast/resolve.d.ts +16 -0
  135. package/dist/entities/ast/resolve.js +307 -0
  136. package/dist/entities/ast/tree.d.ts +29 -0
  137. package/dist/entities/ast/tree.js +351 -0
  138. package/dist/entities/ast/types.d.ts +6 -0
  139. package/dist/entities/ast/types.js +45 -0
  140. package/dist/entities/ast/usage.d.ts +11 -0
  141. package/dist/entities/ast/usage.js +81 -0
  142. package/dist/entities/ast/variables.d.ts +8 -0
  143. package/dist/entities/ast/variables.js +91 -0
  144. package/dist/entities/context.d.ts +29 -0
  145. package/dist/entities/context.js +2 -0
  146. package/dist/entities/facts.d.ts +261 -0
  147. package/dist/entities/facts.js +2 -0
  148. package/dist/entities/findings.d.ts +19 -0
  149. package/dist/entities/findings.js +2 -0
  150. package/dist/entities/kinds.d.ts +40 -0
  151. package/dist/entities/kinds.js +221 -0
  152. package/dist/entities/location/homes.d.ts +28 -0
  153. package/dist/entities/location/homes.js +169 -0
  154. package/dist/entities/location/place.d.ts +10 -0
  155. package/dist/entities/location/place.js +56 -0
  156. package/dist/entities/location/where.d.ts +17 -0
  157. package/dist/entities/location/where.js +218 -0
  158. package/dist/entities/location.d.ts +16 -0
  159. package/dist/entities/location.js +140 -0
  160. package/dist/entities/operators.d.ts +14 -0
  161. package/dist/entities/operators.js +30 -0
  162. package/dist/entities/overview/data.d.ts +43 -0
  163. package/dist/entities/overview/data.js +2 -0
  164. package/dist/entities/overview/decision.d.ts +60 -0
  165. package/dist/entities/overview/decision.js +2 -0
  166. package/dist/entities/overview/file-tree.d.ts +10 -0
  167. package/dist/entities/overview/file-tree.js +2 -0
  168. package/dist/entities/overview/finding.d.ts +58 -0
  169. package/dist/entities/overview/finding.js +2 -0
  170. package/dist/entities/overview/graph.d.ts +65 -0
  171. package/dist/entities/overview/graph.js +2 -0
  172. package/dist/entities/overview/input.d.ts +15 -0
  173. package/dist/entities/overview/input.js +2 -0
  174. package/dist/entities/overview/summaries.d.ts +79 -0
  175. package/dist/entities/overview/summaries.js +2 -0
  176. package/dist/entities/place.d.ts +5 -0
  177. package/dist/entities/place.js +2 -0
  178. package/dist/entities/queries.d.ts +9 -0
  179. package/dist/entities/queries.js +305 -0
  180. package/dist/entities/repair.d.ts +16 -0
  181. package/dist/entities/repair.js +23 -0
  182. package/dist/entities/schema.d.ts +8 -0
  183. package/dist/entities/schema.js +23 -0
  184. package/dist/entities/story.d.ts +47 -0
  185. package/dist/entities/story.js +2 -0
  186. package/dist/entities/structure-facts.d.ts +11 -0
  187. package/dist/entities/structure-facts.js +2 -0
  188. package/dist/entities/token.d.ts +23 -0
  189. package/dist/entities/token.js +2 -0
  190. package/dist/entities/tree/build.d.ts +5 -0
  191. package/dist/entities/tree/build.js +252 -0
  192. package/dist/entities/tree/entries.d.ts +7 -0
  193. package/dist/entities/tree/entries.js +120 -0
  194. package/dist/entities/tree/index.d.ts +6 -0
  195. package/dist/entities/tree/index.js +21 -0
  196. package/dist/entities/tree/match.d.ts +17 -0
  197. package/dist/entities/tree/match.js +176 -0
  198. package/dist/frameworks/angular/index.d.ts +7 -0
  199. package/dist/frameworks/angular/index.js +17 -0
  200. package/dist/frameworks/facet.d.ts +16 -0
  201. package/dist/frameworks/facet.js +2 -0
  202. package/dist/frameworks/index.d.ts +9 -0
  203. package/dist/frameworks/index.js +120 -0
  204. package/dist/frameworks/react/index.d.ts +7 -0
  205. package/dist/frameworks/react/index.js +214 -0
  206. package/dist/frameworks/vue/index.d.ts +7 -0
  207. package/dist/frameworks/vue/index.js +17 -0
  208. package/dist/invariants/index.d.ts +6 -0
  209. package/dist/invariants/index.js +299 -0
  210. package/dist/invariants/list-vars.d.ts +5 -0
  211. package/dist/invariants/list-vars.js +143 -0
  212. package/dist/invariants/name.d.ts +16 -0
  213. package/dist/invariants/name.js +18 -0
  214. package/dist/invariants/normalize.d.ts +4 -0
  215. package/dist/invariants/normalize.js +95 -0
  216. package/dist/invariants/vars.d.ts +20 -0
  217. package/dist/invariants/vars.js +117 -0
  218. package/dist/main.d.ts +7 -0
  219. package/dist/main.js +229 -0
  220. package/dist/nodes/child-roles.d.ts +3 -0
  221. package/dist/nodes/child-roles.js +12 -0
  222. package/dist/nodes/children.d.ts +25 -0
  223. package/dist/nodes/children.js +112 -0
  224. package/dist/nodes/finally/emit.d.ts +6 -0
  225. package/dist/nodes/finally/emit.js +55 -0
  226. package/dist/nodes/finally/index.d.ts +8 -0
  227. package/dist/nodes/finally/index.js +35 -0
  228. package/dist/nodes/finally/queries.d.ts +5 -0
  229. package/dist/nodes/finally/queries.js +22 -0
  230. package/dist/nodes/finally/relations-access.d.ts +5 -0
  231. package/dist/nodes/finally/relations-access.js +46 -0
  232. package/dist/nodes/finally/relations-edge.d.ts +29 -0
  233. package/dist/nodes/finally/relations-edge.js +125 -0
  234. package/dist/nodes/finally/relations-group.d.ts +31 -0
  235. package/dist/nodes/finally/relations-group.js +103 -0
  236. package/dist/nodes/finally/relations.d.ts +5 -0
  237. package/dist/nodes/finally/relations.js +81 -0
  238. package/dist/nodes/finally/required.d.ts +5 -0
  239. package/dist/nodes/finally/required.js +90 -0
  240. package/dist/nodes/finally/roles.d.ts +13 -0
  241. package/dist/nodes/finally/roles.js +41 -0
  242. package/dist/nodes/finally/violation.d.ts +17 -0
  243. package/dist/nodes/finally/violation.js +2 -0
  244. package/dist/nodes/similar.d.ts +21 -0
  245. package/dist/nodes/similar.js +156 -0
  246. package/dist/pipeline-facts.d.ts +11 -0
  247. package/dist/pipeline-facts.js +112 -0
  248. package/dist/pipeline-roles.d.ts +6 -0
  249. package/dist/pipeline-roles.js +75 -0
  250. package/dist/pipeline-unroled.d.ts +14 -0
  251. package/dist/pipeline-unroled.js +193 -0
  252. package/dist/pipeline.d.ts +7 -0
  253. package/dist/pipeline.js +73 -0
  254. package/dist/plugin.d.ts +2 -0
  255. package/dist/plugin.js +3 -0
  256. package/dist/report/asks.d.ts +55 -0
  257. package/dist/report/asks.js +50 -0
  258. package/dist/report/cli-report.d.ts +2 -0
  259. package/dist/report/cli-report.js +13 -0
  260. package/dist/report/config-error-guard.d.ts +8 -0
  261. package/dist/report/config-error-guard.js +5 -0
  262. package/dist/report/configErrors.d.ts +98 -0
  263. package/dist/report/configErrors.js +75 -0
  264. package/dist/report/errorTypes/codes/structure.d.ts +15 -0
  265. package/dist/report/errorTypes/codes/structure.js +76 -0
  266. package/dist/report/errorTypes/decision-maker.d.ts +23 -0
  267. package/dist/report/errorTypes/decision-maker.js +99 -0
  268. package/dist/report/errorTypes/destinations.d.ts +38 -0
  269. package/dist/report/errorTypes/destinations.js +147 -0
  270. package/dist/report/errorTypes/finding-type.d.ts +11 -0
  271. package/dist/report/errorTypes/finding-type.js +2 -0
  272. package/dist/report/errorTypes/index.d.ts +15 -0
  273. package/dist/report/errorTypes/index.js +45 -0
  274. package/dist/report/errorTypes/types/fileContents.d.ts +9 -0
  275. package/dist/report/errorTypes/types/fileContents.js +34 -0
  276. package/dist/report/errorTypes/types/unknownRole.d.ts +9 -0
  277. package/dist/report/errorTypes/types/unknownRole.js +22 -0
  278. package/dist/report/errorTypes/types/wrongAction.d.ts +22 -0
  279. package/dist/report/errorTypes/types/wrongAction.js +135 -0
  280. package/dist/report/errorTypes/types/wrongPlacement.d.ts +9 -0
  281. package/dist/report/errorTypes/types/wrongPlacement.js +57 -0
  282. package/dist/report/errorTypes/vocabulary/ids.d.ts +5 -0
  283. package/dist/report/errorTypes/vocabulary/ids.js +16 -0
  284. package/dist/report/errorTypes/vocabulary/phrases.d.ts +10 -0
  285. package/dist/report/errorTypes/vocabulary/phrases.js +174 -0
  286. package/dist/report/errorTypes/vocabulary/places.d.ts +8 -0
  287. package/dist/report/errorTypes/vocabulary/places.js +36 -0
  288. package/dist/report/errorTypes/vocabulary/verbs.d.ts +7 -0
  289. package/dist/report/errorTypes/vocabulary/verbs.js +30 -0
  290. package/dist/report/finding-from.d.ts +9 -0
  291. package/dist/report/finding-from.js +103 -0
  292. package/dist/report/notices.d.ts +4 -0
  293. package/dist/report/notices.js +31 -0
  294. package/dist/report/render-report.d.ts +12 -0
  295. package/dist/report/render-report.js +142 -0
  296. package/dist/report/user-report/build/bundle.d.ts +3 -0
  297. package/dist/report/user-report/build/bundle.js +169 -0
  298. package/dist/report/user-report/build/bundle.prebuilt.js +760 -0
  299. package/dist/report/user-report/data/collect.d.ts +4 -0
  300. package/dist/report/user-report/data/collect.js +80 -0
  301. package/dist/report/user-report/data/file-tree.d.ts +9 -0
  302. package/dist/report/user-report/data/file-tree.js +72 -0
  303. package/dist/report/user-report/data/finding-boundary.d.ts +9 -0
  304. package/dist/report/user-report/data/finding-boundary.js +21 -0
  305. package/dist/report/user-report/data/finding-plan.d.ts +16 -0
  306. package/dist/report/user-report/data/finding-plan.js +45 -0
  307. package/dist/report/user-report/data/finding-title.d.ts +12 -0
  308. package/dist/report/user-report/data/finding-title.js +36 -0
  309. package/dist/report/user-report/data/findings.d.ts +10 -0
  310. package/dist/report/user-report/data/findings.js +171 -0
  311. package/dist/report/user-report/data/graph-edges.d.ts +19 -0
  312. package/dist/report/user-report/data/graph-edges.js +109 -0
  313. package/dist/report/user-report/data/graph-helpers.d.ts +7 -0
  314. package/dist/report/user-report/data/graph-helpers.js +67 -0
  315. package/dist/report/user-report/data/graph-roles.d.ts +5 -0
  316. package/dist/report/user-report/data/graph-roles.js +71 -0
  317. package/dist/report/user-report/data/graph.d.ts +11 -0
  318. package/dist/report/user-report/data/graph.js +90 -0
  319. package/dist/report/user-report/data/invariants.d.ts +7 -0
  320. package/dist/report/user-report/data/invariants.js +62 -0
  321. package/dist/report/user-report/data/nodes.d.ts +11 -0
  322. package/dist/report/user-report/data/nodes.js +106 -0
  323. package/dist/report/user-report/data/role-examples.d.ts +16 -0
  324. package/dist/report/user-report/data/role-examples.js +94 -0
  325. package/dist/report/user-report/data/role-filters.d.ts +15 -0
  326. package/dist/report/user-report/data/role-filters.js +79 -0
  327. package/dist/report/user-report/data/role-marks.d.ts +5 -0
  328. package/dist/report/user-report/data/role-marks.js +79 -0
  329. package/dist/report/user-report/data/roles.d.ts +7 -0
  330. package/dist/report/user-report/data/roles.js +83 -0
  331. package/dist/report/user-report/data/scan.d.ts +8 -0
  332. package/dist/report/user-report/data/scan.js +59 -0
  333. package/dist/report/user-report/html/shell.d.ts +3 -0
  334. package/dist/report/user-report/html/shell.js +27 -0
  335. package/dist/report/user-report/index.d.ts +8 -0
  336. package/dist/report/user-report/index.js +48 -0
  337. package/dist/report/user-report/shared/describe.d.ts +7 -0
  338. package/dist/report/user-report/shared/describe.js +86 -0
  339. package/dist/scripts/audit-report.d.ts +2 -0
  340. package/dist/scripts/audit-report.js +147 -0
  341. package/dist/utils/accumulate.d.ts +6 -0
  342. package/dist/utils/accumulate.js +18 -0
  343. package/dist/utils/article.d.ts +2 -0
  344. package/dist/utils/article.js +12 -0
  345. package/dist/utils/classify.d.ts +12 -0
  346. package/dist/utils/classify.js +25 -0
  347. package/dist/utils/configs.d.ts +25 -0
  348. package/dist/utils/configs.js +87 -0
  349. package/dist/utils/count.d.ts +7 -0
  350. package/dist/utils/count.js +13 -0
  351. package/dist/utils/dispatch.d.ts +2 -0
  352. package/dist/utils/dispatch.js +27 -0
  353. package/dist/utils/distinct.d.ts +2 -0
  354. package/dist/utils/distinct.js +12 -0
  355. package/dist/utils/field.d.ts +14 -0
  356. package/dist/utils/field.js +60 -0
  357. package/dist/utils/file-name.d.ts +2 -0
  358. package/dist/utils/file-name.js +11 -0
  359. package/dist/utils/files.d.ts +7 -0
  360. package/dist/utils/files.js +73 -0
  361. package/dist/utils/fixpoint.d.ts +2 -0
  362. package/dist/utils/fixpoint.js +19 -0
  363. package/dist/utils/gate.d.ts +2 -0
  364. package/dist/utils/gate.js +12 -0
  365. package/dist/utils/group.d.ts +3 -0
  366. package/dist/utils/group.js +33 -0
  367. package/dist/utils/host.d.ts +3 -0
  368. package/dist/utils/host.js +13 -0
  369. package/dist/utils/imports.d.ts +12 -0
  370. package/dist/utils/imports.js +121 -0
  371. package/dist/utils/judged.d.ts +5 -0
  372. package/dist/utils/judged.js +19 -0
  373. package/dist/utils/keyed.d.ts +2 -0
  374. package/dist/utils/keyed.js +23 -0
  375. package/dist/utils/map-record.d.ts +2 -0
  376. package/dist/utils/map-record.js +11 -0
  377. package/dist/utils/path-label.d.ts +6 -0
  378. package/dist/utils/path-label.js +35 -0
  379. package/dist/utils/pattern.d.ts +18 -0
  380. package/dist/utils/pattern.js +191 -0
  381. package/dist/utils/permission.d.ts +16 -0
  382. package/dist/utils/permission.js +16 -0
  383. package/dist/utils/plural.d.ts +2 -0
  384. package/dist/utils/plural.js +9 -0
  385. package/dist/utils/qualified.d.ts +2 -0
  386. package/dist/utils/qualified.js +21 -0
  387. package/dist/utils/rank.d.ts +2 -0
  388. package/dist/utils/rank.js +24 -0
  389. package/dist/utils/read-field.d.ts +12 -0
  390. package/dist/utils/read-field.js +50 -0
  391. package/dist/utils/read-when.d.ts +2 -0
  392. package/dist/utils/read-when.js +17 -0
  393. package/dist/utils/reason.d.ts +4 -0
  394. package/dist/utils/reason.js +9 -0
  395. package/dist/utils/record.d.ts +3 -0
  396. package/dist/utils/record.js +21 -0
  397. package/dist/utils/resolve.d.ts +2 -0
  398. package/dist/utils/resolve.js +24 -0
  399. package/dist/utils/search.d.ts +2 -0
  400. package/dist/utils/search.js +16 -0
  401. package/dist/utils/seen.d.ts +6 -0
  402. package/dist/utils/seen.js +27 -0
  403. package/dist/utils/span.d.ts +5 -0
  404. package/dist/utils/span.js +2 -0
  405. package/dist/utils/speak.d.ts +2 -0
  406. package/dist/utils/speak.js +18 -0
  407. package/dist/utils/split.d.ts +8 -0
  408. package/dist/utils/split.js +8 -0
  409. package/dist/utils/template.d.ts +5 -0
  410. package/dist/utils/template.js +5 -0
  411. package/dist/utils/text.d.ts +4 -0
  412. package/dist/utils/text.js +42 -0
  413. package/dist/utils/tokenize.d.ts +2 -0
  414. package/dist/utils/tokenize.js +13 -0
  415. package/dist/utils/try-read.d.ts +4 -0
  416. package/dist/utils/try-read.js +24 -0
  417. package/dist/utils/typed-field.d.ts +3 -0
  418. package/dist/utils/typed-field.js +16 -0
  419. package/dist/utils/verdicts.d.ts +4 -0
  420. package/dist/utils/verdicts.js +20 -0
  421. package/entities/operators.ts +31 -0
  422. package/package.json +62 -19
  423. package/report/errorTypes/vocabulary/ids.ts +12 -0
  424. package/report/errorTypes/vocabulary/phrases.ts +161 -0
  425. package/report/errorTypes/vocabulary/places.ts +46 -0
  426. package/report/errorTypes/vocabulary/verbs.ts +31 -0
  427. package/report/user-report/shared/describe.ts +107 -0
  428. package/ast.js +0 -107
  429. package/bin/follow-architecture.js +0 -6
  430. package/config.js +0 -82
  431. package/entities/aliases.js +0 -10
  432. package/entities/invariants.js +0 -134
  433. package/entities/nodes.js +0 -112
  434. package/main.js +0 -95
  435. package/report.js +0 -73
  436. package/utils.js +0 -104
@@ -0,0 +1,61 @@
1
+ import type { TemplateExpr } from "../syntax/styled/template";
2
+ import type { Span } from "../../utils/span";
3
+ type Piece = {
4
+ kind: "text";
5
+ text: string;
6
+ } | {
7
+ kind: "expr";
8
+ index: number;
9
+ text: string;
10
+ };
11
+ type BranchProblem = {
12
+ kind: string;
13
+ name?: string;
14
+ text?: string;
15
+ };
16
+ type Branch = {
17
+ text: string;
18
+ object: string | null;
19
+ media: string | null;
20
+ problems: BranchProblem[];
21
+ directive?: boolean;
22
+ dynamic?: boolean;
23
+ absent?: {
24
+ object: string;
25
+ text: string;
26
+ }[];
27
+ };
28
+ type ObjectReading = {
29
+ text: string;
30
+ origin: string | null;
31
+ dynamic?: boolean;
32
+ };
33
+ type ObjectRead = {
34
+ readings: ObjectReading[];
35
+ absent: string[];
36
+ };
37
+ type ValueResult = {
38
+ values: ObjectReading[];
39
+ problems: BranchProblem[];
40
+ directive?: boolean;
41
+ absent?: string[];
42
+ dynamic?: boolean;
43
+ };
44
+ type Bindings = ReadonlyMap<string, string>;
45
+ declare const NO_BINDINGS: Bindings;
46
+ declare const DYNAMIC_PLACEHOLDER = "1";
47
+ declare const oneValue: (value: string) => ValueResult;
48
+ declare const noValue: (problem: BranchProblem) => ValueResult;
49
+ declare const blockResult: () => ValueResult;
50
+ declare const dynamicValue: () => ValueResult;
51
+ declare const absentResult: (read: ObjectRead) => ValueResult;
52
+ declare const combine: (...results: ValueResult[]) => ValueResult;
53
+ declare const piecesOfRange: (text: string, exprs: readonly TemplateExpr[], span: {
54
+ from: number;
55
+ to: number;
56
+ base: number;
57
+ }) => Piece[];
58
+ declare const rawValueOf: (pieces: Piece[]) => string;
59
+ declare const collapseSpaces: (text: string) => string;
60
+ export { NO_BINDINGS, DYNAMIC_PLACEHOLDER, oneValue, noValue, blockResult, dynamicValue, absentResult, combine, piecesOfRange, rawValueOf, collapseSpaces };
61
+ export type { Piece, Branch, BranchProblem, ObjectReading, ObjectRead, ValueResult, Bindings, Span };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collapseSpaces = exports.rawValueOf = exports.piecesOfRange = exports.combine = exports.absentResult = exports.dynamicValue = exports.blockResult = exports.noValue = exports.oneValue = exports.DYNAMIC_PLACEHOLDER = exports.NO_BINDINGS = void 0;
4
+ const NO_BINDINGS = new Map();
5
+ exports.NO_BINDINGS = NO_BINDINGS;
6
+ // The placeholder a dynamic value contributes while a template is folded: `1`
7
+ // completes `1fr`, `1%`, `url(1)` — the SHAPE around it is what gets checked.
8
+ const DYNAMIC_PLACEHOLDER = "1";
9
+ exports.DYNAMIC_PLACEHOLDER = DYNAMIC_PLACEHOLDER;
10
+ const oneValue = (value) => ({ values: [{ text: value, origin: null }], problems: [] });
11
+ exports.oneValue = oneValue;
12
+ const noValue = (problem) => ({ values: [], problems: [problem] });
13
+ exports.noValue = noValue;
14
+ const blockResult = () => ({ values: [], problems: [], directive: true });
15
+ exports.blockResult = blockResult;
16
+ const dynamicValue = () => ({ values: [{ text: DYNAMIC_PLACEHOLDER, origin: null, dynamic: true }], problems: [], dynamic: true });
17
+ exports.dynamicValue = dynamicValue;
18
+ const absentResult = (read) => ({ values: read.readings, problems: [], absent: read.absent.length ? read.absent : undefined });
19
+ exports.absentResult = absentResult;
20
+ // Every reading and every problem of the given results, in order: the branches of
21
+ // a conditional or a logical chain are the union of what each arm reaches.
22
+ const combine = (...results) => {
23
+ const absent = [...new Set(results.flatMap((result) => result.absent ?? []))];
24
+ return {
25
+ values: results.flatMap((result) => result.values),
26
+ problems: results.flatMap((result) => result.problems),
27
+ absent: absent.length ? absent : undefined,
28
+ directive: results.some((result) => result.directive) ? true : undefined,
29
+ dynamic: results.some((result) => result.dynamic) ? true : undefined,
30
+ };
31
+ };
32
+ exports.combine = combine;
33
+ // The pieces of a range in `text`, using the ABSOLUTE offsets the expressions
34
+ // were recorded at. Both readings (a whole template, or one value string) use
35
+ // this one walk; `base` is the offset `text` starts at.
36
+ const literalPiece = (text, from, to, base) => (from < to ? [{ kind: "text", text: text.slice(from - base, to - base) }] : []);
37
+ const piecesOfRange = (text, exprs, span) => {
38
+ const next = [...exprs].filter((expr) => expr.offset >= span.from && expr.offset < span.to).sort((a, b) => a.offset - b.offset)[0];
39
+ if (!next)
40
+ return literalPiece(text, span.from, span.to, span.base);
41
+ return [
42
+ ...literalPiece(text, span.from, next.offset, span.base),
43
+ { kind: "expr", index: next.index, text: next.text },
44
+ ...piecesOfRange(text, exprs, { from: next.offset + next.text.length, to: span.to, base: span.base }),
45
+ ];
46
+ };
47
+ exports.piecesOfRange = piecesOfRange;
48
+ // What the declaration wrote, with each expression spelled back as `${…}` so a
49
+ // report can quote it. This is a FACT, not a template: the blanks are gone.
50
+ const rawValueOf = (pieces) => pieces.map((piece) => (piece.kind === "text" ? piece.text : `\${${piece.text}}`)).join("");
51
+ exports.rawValueOf = rawValueOf;
52
+ // Whitespace in a substituted value is layout, not content: blanks and the
53
+ // spacing around them collapse to one space.
54
+ const collapseSpaces = (text) => text.replace(/\s+/g, " ").trim();
55
+ exports.collapseSpaces = collapseSpaces;
@@ -0,0 +1,33 @@
1
+ import { type BranchProblem, type Piece, type Span } from "./pieces";
2
+ import { type ResolveContext } from "./substitute";
3
+ import { type Verdict } from "./check";
4
+ type ResolvedValue = Verdict & {
5
+ value: string;
6
+ object: string | null;
7
+ mediaVariant: string | null;
8
+ };
9
+ type UnresolvedValue = BranchProblem & {
10
+ text: string;
11
+ object?: string;
12
+ span?: Span;
13
+ };
14
+ type ValueResolution = {
15
+ property: string;
16
+ rawValue: string;
17
+ resolvedValues: ResolvedValue[];
18
+ unresolved: UnresolvedValue[];
19
+ };
20
+ declare const resolveDeclaration: (declaration: {
21
+ prop: string;
22
+ pieces: Piece[];
23
+ }, context: ResolveContext) => ValueResolution;
24
+ export { resolveDeclaration };
25
+ export { resolvePieces } from "./substitute";
26
+ export { emptyScope, mergeScopes, normalizeScope, withObjects } from "./scope";
27
+ export { piecesOfRange } from "./pieces";
28
+ export { checkValue } from "./check";
29
+ export type { Piece, Span } from "./pieces";
30
+ export type { Scope, ScopeEntry, ObjectLiteral } from "./scope";
31
+ export type { ResolveContext } from "./substitute";
32
+ export type { ValueProblem, ProblemKind } from "./check";
33
+ export type { ResolvedValue, UnresolvedValue, ValueResolution };
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkValue = exports.piecesOfRange = exports.withObjects = exports.normalizeScope = exports.mergeScopes = exports.emptyScope = exports.resolvePieces = exports.resolveDeclaration = void 0;
4
+ // THE FACT a declaration carries: what was written, every concrete reading the
5
+ // resolver reached, and what it could not reach. This module is the surface —
6
+ // the pieces, the expression folding and the variable substitution are modules
7
+ // of their own; a consumer asks for one resolution, not for the machinery.
8
+ //
9
+ // Every problem is STRUCTURED: a reading carries the grammar's `problems`
10
+ // (kind + span), and an unreached part carries a `kind` the report layer matches
11
+ // on. No sentence is composed here.
12
+ const pieces_1 = require("./pieces");
13
+ const substitute_1 = require("./substitute");
14
+ const check_1 = require("./check");
15
+ const readingKey = (item) => `${item.value}|${item.object ?? ""}|${item.mediaVariant ?? ""}`;
16
+ const problemKey = (item) => `${item.kind}|${item.text}|${item.name ?? ""}|${item.object ?? ""}`;
17
+ // Record a problem once; the same reason reached through several branches is one
18
+ // fact, not several.
19
+ const recordProblem = (item, list, seen) => {
20
+ const key = problemKey(item);
21
+ if (seen.has(key))
22
+ return;
23
+ seen.add(key);
24
+ list.push(item);
25
+ };
26
+ // A read that needs an object literal but the invariant named no object role: say
27
+ // that as its own kind, rather than silently resolving against nothing.
28
+ const objectlessKind = (problem, noObjectRole) => (noObjectRole && problem.kind === "unresolved-expr" ? "no-object-role" : problem.kind);
29
+ // Every problem ONE branch carries: the resolver's own kinds, the objects a
30
+ // fixed path was absent in (an object literal is incomplete, not the component),
31
+ // and an empty branch that is neither a nested block nor a value.
32
+ const collectProblems = (branch, raw, sink) => {
33
+ const text = (0, pieces_1.collapseSpaces)(branch.text);
34
+ for (const problem of branch.problems)
35
+ recordProblem({ kind: objectlessKind(problem, raw.noObjectRole), text: problem.text ?? (text || raw.rawValue), name: problem.name }, sink.unresolved, sink.seen);
36
+ if (branch.problems.length)
37
+ return;
38
+ for (const missing of branch.absent ?? [])
39
+ recordProblem({ kind: "absent", text: raw.rawValue, object: missing.object }, sink.unresolved, sink.seen);
40
+ // A branch that was ONLY a nested block (`${aCssFragment}`) is not an empty
41
+ // value: the block's own declarations are checked where it was written. A
42
+ // dynamic branch is runtime data, not an empty value either.
43
+ if (!text && !branch.directive && !branch.dynamic)
44
+ recordProblem({ kind: "empty", text: raw.rawValue }, sink.unresolved, sink.seen);
45
+ };
46
+ // One branch that reached the bottom, as a reading (empty/directive branches
47
+ // have nothing to judge — they are handled by `collectProblems`). A DYNAMIC
48
+ // branch carries a placeholder SHAPE: when that shape is rejected, the real
49
+ // value is still the runtime's and the component is not blamed — the reading is
50
+ // dropped instead of reported.
51
+ const collectReading = (branch, prop, resolvedValues, seen) => {
52
+ const text = (0, pieces_1.collapseSpaces)(branch.text);
53
+ if (!text)
54
+ return;
55
+ const verdict = (0, check_1.checkValue)(prop, text);
56
+ if (branch.dynamic && verdict.valid === false)
57
+ return;
58
+ const item = { value: text, object: branch.object, mediaVariant: branch.media, valid: verdict.valid, problems: verdict.problems };
59
+ const key = readingKey(item);
60
+ if (seen.has(key))
61
+ return;
62
+ seen.add(key);
63
+ resolvedValues.push(item);
64
+ };
65
+ // Resolve ONE declaration. Every branch that reaches the bottom becomes a
66
+ // `resolvedValue` (with its object/media label and the grammar's verdict);
67
+ // every branch that does not becomes an `unresolved` entry with its kind.
68
+ const resolveDeclaration = (declaration, context) => {
69
+ const rawValue = (0, pieces_1.rawValueOf)(declaration.pieces);
70
+ const resolvedValues = [];
71
+ const unresolved = [];
72
+ const seenReadings = new Set();
73
+ const seenProblems = new Set();
74
+ const problemSink = { unresolved, seen: seenProblems };
75
+ const raw = { rawValue, noObjectRole: context.scope.objects.length === 0 };
76
+ for (const branch of (0, substitute_1.resolvePieces)(declaration.pieces, context)) {
77
+ collectProblems(branch, raw, problemSink);
78
+ if (!branch.problems.length)
79
+ collectReading(branch, declaration.prop, resolvedValues, seenReadings);
80
+ }
81
+ return { property: declaration.prop, rawValue, resolvedValues, unresolved };
82
+ };
83
+ exports.resolveDeclaration = resolveDeclaration;
84
+ var substitute_2 = require("./substitute");
85
+ Object.defineProperty(exports, "resolvePieces", { enumerable: true, get: function () { return substitute_2.resolvePieces; } });
86
+ var scope_1 = require("./scope");
87
+ Object.defineProperty(exports, "emptyScope", { enumerable: true, get: function () { return scope_1.emptyScope; } });
88
+ Object.defineProperty(exports, "mergeScopes", { enumerable: true, get: function () { return scope_1.mergeScopes; } });
89
+ Object.defineProperty(exports, "normalizeScope", { enumerable: true, get: function () { return scope_1.normalizeScope; } });
90
+ Object.defineProperty(exports, "withObjects", { enumerable: true, get: function () { return scope_1.withObjects; } });
91
+ var pieces_2 = require("./pieces");
92
+ Object.defineProperty(exports, "piecesOfRange", { enumerable: true, get: function () { return pieces_2.piecesOfRange; } });
93
+ var check_2 = require("./check");
94
+ Object.defineProperty(exports, "checkValue", { enumerable: true, get: function () { return check_2.checkValue; } });
@@ -0,0 +1,27 @@
1
+ import type { Expression, ObjectLiteralExpression, SourceFile } from "ts-morph";
2
+ import { type Piece } from "./pieces";
3
+ import type { DocumentFacts } from "../syntax/styled/document";
4
+ type ObjectLiteral = {
5
+ name: string;
6
+ node: ObjectLiteralExpression;
7
+ };
8
+ type ScopeEntry = {
9
+ name: string;
10
+ pieces: Piece[];
11
+ media: string | null;
12
+ declaredLine: number | null;
13
+ expression: (index: number) => Expression | null;
14
+ };
15
+ type Scope = {
16
+ variables: Map<string, ScopeEntry[]>;
17
+ objects: ObjectLiteral[];
18
+ };
19
+ declare const emptyScope: () => Scope;
20
+ declare const normalizeScope: (scope: Scope) => Scope;
21
+ declare const mergeScopes: (...scopes: Scope[]) => Scope;
22
+ declare const withObjects: (scope: Scope, objects: readonly ObjectLiteral[]) => Scope;
23
+ declare const scopeFromSourceFile: (sourceFile: SourceFile) => Scope;
24
+ declare const scopeFromProject: (sourceFile: SourceFile) => Scope;
25
+ declare const scopeFromFacts: (facts: DocumentFacts) => Scope;
26
+ export { emptyScope, mergeScopes, normalizeScope, withObjects, scopeFromSourceFile, scopeFromProject, scopeFromFacts };
27
+ export type { Scope, ScopeEntry, ObjectLiteral };
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scopeFromFacts = exports.scopeFromProject = exports.scopeFromSourceFile = exports.withObjects = exports.normalizeScope = exports.mergeScopes = exports.emptyScope = void 0;
4
+ const remeda_1 = require("remeda");
5
+ const tree_1 = require("../../entities/ast/tree");
6
+ const group_1 = require("../../utils/group");
7
+ const template_1 = require("../syntax/styled/template");
8
+ const pieces_1 = require("./pieces");
9
+ const emptyScope = () => ({ variables: new Map(), objects: [] });
10
+ exports.emptyScope = emptyScope;
11
+ // Two entries are the same only when name, media query AND value agree; two
12
+ // object literals only when the same literal was collected twice.
13
+ const entryKey = (entry) => `${entry.name}|${entry.media ?? ""}|${entry.pieces.map((piece) => (piece.kind === "text" ? piece.text : `\u0000${piece.text}`)).join("")}`;
14
+ const objectKey = (object) => `${object.name}|${object.node.getSourceFile().getFilePath()}|${object.node.getStart()}`;
15
+ // Drop the duplicates a scope may have collected twice (the same template read
16
+ // by two walks, the same document merged twice).
17
+ const normalizeScope = (scope) => {
18
+ for (const [name, entries] of scope.variables)
19
+ scope.variables.set(name, (0, remeda_1.uniqueBy)(entries, entryKey));
20
+ scope.objects = (0, remeda_1.uniqueBy)(scope.objects, objectKey);
21
+ return scope;
22
+ };
23
+ exports.normalizeScope = normalizeScope;
24
+ // One scope out of several: a component's own templates plus a shared
25
+ // stylesheet a caller merges in. Duplicates collapse, the rest unions.
26
+ const mergeScopes = (...scopes) => {
27
+ const merged = emptyScope();
28
+ for (const scope of scopes) {
29
+ for (const [name, entries] of scope.variables)
30
+ merged.variables.set(name, [...(merged.variables.get(name) ?? []), ...entries]);
31
+ merged.objects.push(...scope.objects);
32
+ }
33
+ return normalizeScope(merged);
34
+ };
35
+ exports.mergeScopes = mergeScopes;
36
+ // The same scope with a different object set: resolution is asked of the object
37
+ // literals ONE invariant named, not of any project-wide list.
38
+ const withObjects = (scope, objects) => ({ ...scope, objects: [...objects] });
39
+ exports.withObjects = withObjects;
40
+ // A custom property declaration as written inside template text. The name is
41
+ // CSS's own (`--x`), so no selector or property list is involved.
42
+ const CUSTOM_PROPERTY_RE = /(--[\w-]+)\s*:/g;
43
+ // The value of a declaration starts just after its `:` — but an expression is
44
+ // written as BLANKS, so whitespace skipping must stop at a blank's start or it
45
+ // would eat the expression itself.
46
+ const valueStartAt = (text, after, exprs) => {
47
+ const starts = new Set(exprs.map((expr) => expr.offset));
48
+ let index = after;
49
+ while (index < text.length && /\s/.test(text[index]) && !starts.has(index))
50
+ index += 1;
51
+ return index;
52
+ };
53
+ // Parentheses pair up inside a value (`calc((100% - 8px) / 2)`), so a `;` only
54
+ // ends a value at depth zero. A `}` at depth zero ends the BLOCK the declaration
55
+ // sits in.
56
+ const depthAfter = (char, depth) => {
57
+ if (char === "(")
58
+ return depth + 1;
59
+ if (char === ")")
60
+ return Math.max(0, depth - 1);
61
+ return depth;
62
+ };
63
+ const endsValue = (char, depth) => depth === 0 && (char === ";" || char === "}");
64
+ const closesQuote = (char, previous, quote) => char === quote && previous !== "\\";
65
+ const valueEndAt = (text, start) => {
66
+ let depth = 0;
67
+ let quote = null;
68
+ for (let index = start; index < text.length; index += 1) {
69
+ const char = text[index];
70
+ if (quote) {
71
+ if (closesQuote(char, text[index - 1], quote))
72
+ quote = null;
73
+ continue;
74
+ }
75
+ if (char === '"' || char === "'") {
76
+ quote = char;
77
+ continue;
78
+ }
79
+ depth = depthAfter(char, depth);
80
+ if (endsValue(char, depth))
81
+ return index;
82
+ }
83
+ return text.length;
84
+ };
85
+ const closingBrace = (text, open) => {
86
+ let depth = 0;
87
+ for (let index = open; index < text.length; index += 1) {
88
+ if (text[index] === "{")
89
+ depth += 1;
90
+ else if (text[index] === "}") {
91
+ depth -= 1;
92
+ if (depth === 0)
93
+ return index;
94
+ }
95
+ }
96
+ return -1;
97
+ };
98
+ // The nearest `@media` block around an offset. Several media blocks may sit side
99
+ // by side; the one whose braces contain the offset is the variant.
100
+ const MEDIA_BLOCK_RE = /@media\b([^{]*)\{/g;
101
+ const mediaAt = (text, position) => {
102
+ let found = null;
103
+ for (const match of text.matchAll(MEDIA_BLOCK_RE)) {
104
+ const open = text.indexOf("{", match.index);
105
+ const close = closingBrace(text, open);
106
+ if (position > open && (close < 0 || position < close))
107
+ found = `@media ${match[1].trim()}`;
108
+ }
109
+ return found;
110
+ };
111
+ const lineAt = (template, text, offset) => {
112
+ const before = text.slice(0, offset);
113
+ const newlines = (before.match(/\n/g) ?? []).length;
114
+ return template.getStartLineNumber() + newlines;
115
+ };
116
+ // Every custom property declaration in one template literal (tagged or nested),
117
+ // with its value as pieces and its media variant.
118
+ const collectFromLiteral = (template, add) => {
119
+ const { text, exprs } = (0, template_1.templateLiteralSource)(template);
120
+ if (!text.includes("--"))
121
+ return;
122
+ const nodes = (0, template_1.expressionNodesOf)(template);
123
+ for (const match of text.matchAll(CUSTOM_PROPERTY_RE)) {
124
+ const name = match[1];
125
+ const from = valueStartAt(text, match.index + match[0].length, exprs);
126
+ const to = valueEndAt(text, from);
127
+ add({ name, pieces: (0, pieces_1.piecesOfRange)(text, exprs, { from, to, base: 0 }), media: mediaAt(text, match.index), declaredLine: lineAt(template, text, match.index), expression: (index) => nodes[index] ?? null });
128
+ }
129
+ };
130
+ // The scope a whole source file offers: its templates' custom properties.
131
+ // Cached on the file — a component's styled blocks all read the same names.
132
+ // Nothing project-wide is scanned: the object literals are the caller's, not
133
+ // this file's.
134
+ const SOURCE_SCOPE = new WeakMap();
135
+ const buildSourceScope = (sourceFile) => {
136
+ const scope = emptyScope();
137
+ const add = (entry) => {
138
+ (0, group_1.pushGroup)(scope.variables, entry.name, entry);
139
+ };
140
+ for (const node of sourceFile.getDescendantsOfKind(tree_1.SK.TemplateExpression))
141
+ collectFromLiteral(node, add);
142
+ for (const node of sourceFile.getDescendantsOfKind(tree_1.SK.NoSubstitutionTemplateLiteral))
143
+ collectFromLiteral(node, add);
144
+ return normalizeScope(scope);
145
+ };
146
+ // A per-key cache write that also hands the value back, so a reader is one
147
+ // expression: the known scope, or the built one remembered for next time.
148
+ const remember = (cache, key, build) => {
149
+ const value = build();
150
+ cache.set(key, value);
151
+ return value;
152
+ };
153
+ const scopeFromSourceFile = (sourceFile) => SOURCE_SCOPE.get(sourceFile) ?? remember(SOURCE_SCOPE, sourceFile, () => buildSourceScope(sourceFile));
154
+ exports.scopeFromSourceFile = scopeFromSourceFile;
155
+ // THE REPO-WIDE SCOPE: every source file's custom properties merged into one.
156
+ // A component's styles do not declare the variables they read — a shared global
157
+ // style does, in another file — so a value can only be walked to the bottom when
158
+ // the whole project is in scope. The merge is the shared `mergeScopes`; cached
159
+ // per project and rebuilt when the project grows (the same policy the project
160
+ // scope cache uses).
161
+ const PROJECT_SCOPE = new WeakMap();
162
+ const scopeFromProject = (sourceFile) => {
163
+ const project = sourceFile.getProject();
164
+ const files = project.getSourceFiles();
165
+ const cached = PROJECT_SCOPE.get(project);
166
+ if (cached && cached.count === files.length)
167
+ return cached.scope;
168
+ const scope = normalizeScope(mergeScopes(...files.map(scopeFromSourceFile)));
169
+ PROJECT_SCOPE.set(project, { count: files.length, scope });
170
+ return scope;
171
+ };
172
+ exports.scopeFromProject = scopeFromProject;
173
+ // The scope one parsed document offers. The LANGUAGE has already marked which
174
+ // declarations are variables and under what name (`variableName`); the same walk
175
+ // covers every syntax because the knowledge of "what a variable looks like here"
176
+ // lives with the language, not here.
177
+ const scopeFromFacts = (facts) => {
178
+ const scope = emptyScope();
179
+ for (const declaration of facts.declarations) {
180
+ if (!declaration.variableName)
181
+ continue;
182
+ const entry = { name: declaration.variableName, pieces: declaration.pieces, media: declaration.media, declaredLine: declaration.line, expression: () => null };
183
+ (0, group_1.pushGroup)(scope.variables, entry.name, entry);
184
+ }
185
+ return normalizeScope(scope);
186
+ };
187
+ exports.scopeFromFacts = scopeFromFacts;
@@ -0,0 +1,10 @@
1
+ import type { Expression } from "ts-morph";
2
+ import type { Scope } from "./scope";
3
+ import type { Branch, Piece } from "./pieces";
4
+ type ResolveContext = {
5
+ scope: Scope;
6
+ expression: (index: number) => Expression | null;
7
+ };
8
+ declare const resolvePieces: (pieces: Piece[], context: ResolveContext, stack?: readonly string[]) => Branch[];
9
+ export { resolvePieces };
10
+ export type { ResolveContext };
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolvePieces = void 0;
4
+ const expression_1 = require("./expression");
5
+ const language_1 = require("../syntax/language");
6
+ const text_1 = require("../../utils/text");
7
+ const BRANCH_LIMIT = 64;
8
+ const problemKey = (problem) => `${problem.kind}|${problem.name ?? ""}|${problem.text ?? ""}`;
9
+ const uniqueProblems = (problems) => [...new Map(problems.map((problem) => [problemKey(problem), problem])).values()];
10
+ // The variable a text refers to next, whichever language names it: every
11
+ // registered tokenizer is asked, and the EARLIEST match is the next to
12
+ // substitute. Ties keep the first registered language's token.
13
+ const nextVariable = (text) => {
14
+ let best = null;
15
+ for (const tokenize of (0, language_1.referenceTokenizers)()) {
16
+ const token = tokenize(text);
17
+ if (token && (!best || token.start < best.start))
18
+ best = token;
19
+ }
20
+ return best;
21
+ };
22
+ // A variable is looked up by NAME in ONE map: the language that declared it chose
23
+ // the spelling (`--gap`, `$gap`), and the resolver never asks which language.
24
+ const entriesOf = (token, scope) => scope.variables.get(token.name);
25
+ const failed = (branch, problems) => [{ ...branch, problems: uniqueProblems([...branch.problems, ...problems]) }];
26
+ // A variable declared in several places (media variants) becomes one branch per
27
+ // declaration; each branch keeps the media query it read.
28
+ const expandEntries = (input, context, stack) => {
29
+ const { branch, token, entries } = input;
30
+ const before = branch.text.slice(0, token.start);
31
+ const after = branch.text.slice(token.end);
32
+ const out = [];
33
+ for (const entry of entries) {
34
+ const resolved = resolvePieces(entry.pieces, { scope: context.scope, expression: entry.expression }, [...stack, token.name]);
35
+ for (const inner of resolved) {
36
+ if (inner.problems.length) {
37
+ out.push({ ...branch, problems: uniqueProblems([...branch.problems, ...inner.problems]) });
38
+ continue;
39
+ }
40
+ const text = before + inner.text + after;
41
+ // The substituted branch is dynamic (or a directive) if EITHER side was: a
42
+ // runtime placeholder survives the substitution, so its shape is still only
43
+ // a SHAPE and must never be grammar-blamed as a concrete value.
44
+ const dynamic = branch.dynamic || inner.dynamic ? true : undefined;
45
+ const directive = branch.directive || inner.directive;
46
+ out.push(...substituteText({ text, object: branch.object ?? inner.object, media: branch.media ?? entry.media ?? inner.media, problems: branch.problems, dynamic, directive }, context, stack));
47
+ }
48
+ }
49
+ return out.slice(0, BRANCH_LIMIT);
50
+ };
51
+ const substituteText = (branch, context, stack) => {
52
+ if (branch.problems.length)
53
+ return [branch];
54
+ const token = nextVariable(branch.text);
55
+ if (!token)
56
+ return [branch];
57
+ if (token.broken)
58
+ return failed(branch, [token.broken]);
59
+ if (stack.includes(token.name))
60
+ return failed(branch, [{ kind: "cyclic-var", name: token.name }]);
61
+ const entries = entriesOf(token, context.scope);
62
+ if (entries?.length)
63
+ return expandEntries({ branch, token, entries }, context, stack);
64
+ if (token.fallback === null)
65
+ return failed(branch, [{ kind: "undeclared-var", name: token.name }]);
66
+ return substituteText({ ...branch, text: branch.text.slice(0, token.start) + token.fallback + branch.text.slice(token.end) }, context, stack);
67
+ };
68
+ // Fold two branch lists, keeping the object label they carry, the object
69
+ // literals a fixed path was absent in, and whether the value is runtime-dynamic.
70
+ const crossValues = (branches, values, absent = []) => {
71
+ const out = [];
72
+ for (const branch of branches) {
73
+ for (const value of values) {
74
+ if (out.length >= BRANCH_LIMIT)
75
+ return out.map((item) => ({ ...item, problems: uniqueProblems([...item.problems, { kind: "too-many-variants" }]) }));
76
+ const merged = [...(branch.absent ?? []), ...absent];
77
+ const dynamic = branch.dynamic || value.dynamic ? true : undefined;
78
+ out.push({ text: branch.text + value.text, object: branch.object ?? value.origin, media: branch.media, problems: branch.problems, directive: branch.directive, dynamic, ...(merged.length ? { absent: merged } : {}) });
79
+ }
80
+ }
81
+ return out;
82
+ };
83
+ // Fold a declaration's pieces: expressions first, then the references in the
84
+ // text they produced. The order matters — a reference can be the VALUE an
85
+ // expression returns, so it is only visible after the expression is folded.
86
+ const resolvePieces = (pieces, context, stack = []) => {
87
+ let branches = [{ text: "", object: null, media: null, problems: [] }];
88
+ for (const piece of pieces) {
89
+ if (piece.kind === "text") {
90
+ branches = branches.map((branch) => ({ ...branch, text: branch.text + piece.text }));
91
+ continue;
92
+ }
93
+ const node = context.expression(piece.index);
94
+ const value = node ? (0, expression_1.expressionValue)(node, context.scope) : { values: [], problems: [{ kind: "missing-node", text: (0, text_1.firstLine)(piece.text) }], directive: false };
95
+ if (value.directive) {
96
+ // A nested block, not a value: it contributes no text to THIS value.
97
+ branches = branches.map((branch) => ({ ...branch, directive: true }));
98
+ continue;
99
+ }
100
+ // A branch that resolves nothing is a REPORTED problem, but it does not
101
+ // erase the branches that DID resolve: a nested ternary may reach two arms
102
+ // and leave a runtime call unresolved, so both are kept side by side.
103
+ const failedBranches = value.problems.length ? branches.map((branch) => ({ ...branch, problems: uniqueProblems([...branch.problems, ...value.problems]) })) : [];
104
+ if (!value.values.length) {
105
+ branches = failedBranches;
106
+ continue;
107
+ }
108
+ const absent = (value.absent ?? []).map((object) => ({ object, text: piece.text }));
109
+ branches = [...crossValues(branches, value.values, absent), ...failedBranches];
110
+ }
111
+ return branches.flatMap((branch) => substituteText(branch, context, stack));
112
+ };
113
+ exports.resolvePieces = resolvePieces;
@@ -0,0 +1,23 @@
1
+ type ValueParts = {
2
+ literals: {
3
+ kind: string;
4
+ text: string;
5
+ line: number | null;
6
+ unit: string | null;
7
+ }[];
8
+ vars: string[];
9
+ functions: {
10
+ name: string;
11
+ text: string;
12
+ line: number | null;
13
+ }[];
14
+ interpolations: {
15
+ text: string;
16
+ line: number | null;
17
+ }[];
18
+ };
19
+ declare const classifyValue: (value: string, line: number | null) => ValueParts & {
20
+ parsed: boolean;
21
+ };
22
+ export { classifyValue };
23
+ export type { ValueParts };