@vigla/svelte 0.0.0-stage → 5.57.3

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 (373) hide show
  1. package/action.d.ts +2 -0
  2. package/animate.d.ts +2 -0
  3. package/compiler/index.js +43266 -0
  4. package/compiler/index.js.map +1 -0
  5. package/compiler/package.json +3 -0
  6. package/compiler.d.ts +2 -0
  7. package/dist/compiler/diagnostics.d.ts +70 -0
  8. package/dist/compiler/diagnostics.d.ts.map +1 -0
  9. package/dist/compiler/diagnostics.js +166 -0
  10. package/dist/compiler/diagnostics.js.map +1 -0
  11. package/dist/compiler/index.d.ts +72 -0
  12. package/dist/compiler/index.d.ts.map +1 -0
  13. package/dist/compiler/index.js +178 -0
  14. package/dist/compiler/index.js.map +1 -0
  15. package/dist/compiler/options.d.ts +7 -0
  16. package/dist/compiler/options.d.ts.map +1 -0
  17. package/dist/compiler/options.js +126 -0
  18. package/dist/compiler/options.js.map +1 -0
  19. package/dist/compiler/preprocess/decode.d.ts +3 -0
  20. package/dist/compiler/preprocess/decode.d.ts.map +1 -0
  21. package/dist/compiler/preprocess/decode.js +60 -0
  22. package/dist/compiler/preprocess/decode.js.map +1 -0
  23. package/dist/compiler/preprocess/index.d.ts +27 -0
  24. package/dist/compiler/preprocess/index.d.ts.map +1 -0
  25. package/dist/compiler/preprocess/index.js +208 -0
  26. package/dist/compiler/preprocess/index.js.map +1 -0
  27. package/dist/compiler/preprocess/mapped.d.ts +25 -0
  28. package/dist/compiler/preprocess/mapped.d.ts.map +1 -0
  29. package/dist/compiler/preprocess/mapped.js +129 -0
  30. package/dist/compiler/preprocess/mapped.js.map +1 -0
  31. package/dist/compiler/proxy.d.ts +3 -0
  32. package/dist/compiler/proxy.d.ts.map +1 -0
  33. package/dist/compiler/proxy.js +133 -0
  34. package/dist/compiler/proxy.js.map +1 -0
  35. package/dist/entries/action.d.ts +2 -0
  36. package/dist/entries/action.d.ts.map +1 -0
  37. package/dist/entries/action.js +1 -0
  38. package/dist/entries/action.js.map +1 -0
  39. package/dist/entries/animate.d.ts +2 -0
  40. package/dist/entries/animate.d.ts.map +1 -0
  41. package/dist/entries/animate.js +2 -0
  42. package/dist/entries/animate.js.map +1 -0
  43. package/dist/entries/attachments.d.ts +2 -0
  44. package/dist/entries/attachments.d.ts.map +1 -0
  45. package/dist/entries/attachments.js +2 -0
  46. package/dist/entries/attachments.js.map +1 -0
  47. package/dist/entries/context.d.ts +15 -0
  48. package/dist/entries/context.d.ts.map +1 -0
  49. package/dist/entries/context.js +32 -0
  50. package/dist/entries/context.js.map +1 -0
  51. package/dist/entries/easing.d.ts +2 -0
  52. package/dist/entries/easing.d.ts.map +1 -0
  53. package/dist/entries/easing.js +2 -0
  54. package/dist/entries/easing.js.map +1 -0
  55. package/dist/entries/events.d.ts +2 -0
  56. package/dist/entries/events.d.ts.map +1 -0
  57. package/dist/entries/events.js +2 -0
  58. package/dist/entries/events.js.map +1 -0
  59. package/dist/entries/index-server.d.ts +4 -0
  60. package/dist/entries/index-server.d.ts.map +1 -0
  61. package/dist/entries/index-server.js +11 -0
  62. package/dist/entries/index-server.js.map +1 -0
  63. package/dist/entries/index.d.ts +10 -0
  64. package/dist/entries/index.d.ts.map +1 -0
  65. package/dist/entries/index.js +24 -0
  66. package/dist/entries/index.js.map +1 -0
  67. package/dist/entries/internal/client.d.ts +4 -0
  68. package/dist/entries/internal/client.d.ts.map +1 -0
  69. package/dist/entries/internal/client.js +9 -0
  70. package/dist/entries/internal/client.js.map +1 -0
  71. package/dist/entries/internal/disclose-version.d.ts +2 -0
  72. package/dist/entries/internal/disclose-version.d.ts.map +1 -0
  73. package/dist/entries/internal/disclose-version.js +4 -0
  74. package/dist/entries/internal/disclose-version.js.map +1 -0
  75. package/dist/entries/internal/index.d.ts +2 -0
  76. package/dist/entries/internal/index.d.ts.map +1 -0
  77. package/dist/entries/internal/index.js +2 -0
  78. package/dist/entries/internal/index.js.map +1 -0
  79. package/dist/entries/internal/server.d.ts +2 -0
  80. package/dist/entries/internal/server.d.ts.map +1 -0
  81. package/dist/entries/internal/server.js +7 -0
  82. package/dist/entries/internal/server.js.map +1 -0
  83. package/dist/entries/internal/tracing.d.ts +2 -0
  84. package/dist/entries/internal/tracing.d.ts.map +1 -0
  85. package/dist/entries/internal/tracing.js +2 -0
  86. package/dist/entries/internal/tracing.js.map +1 -0
  87. package/dist/entries/motion-server.d.ts +2 -0
  88. package/dist/entries/motion-server.d.ts.map +1 -0
  89. package/dist/entries/motion-server.js +2 -0
  90. package/dist/entries/motion-server.js.map +1 -0
  91. package/dist/entries/motion.d.ts +2 -0
  92. package/dist/entries/motion.d.ts.map +1 -0
  93. package/dist/entries/motion.js +2 -0
  94. package/dist/entries/motion.js.map +1 -0
  95. package/dist/entries/proxy.d.ts +6 -0
  96. package/dist/entries/proxy.d.ts.map +1 -0
  97. package/dist/entries/proxy.js +77 -0
  98. package/dist/entries/proxy.js.map +1 -0
  99. package/dist/entries/reactivity-server.d.ts +2 -0
  100. package/dist/entries/reactivity-server.d.ts.map +1 -0
  101. package/dist/entries/reactivity-server.js +2 -0
  102. package/dist/entries/reactivity-server.js.map +1 -0
  103. package/dist/entries/reactivity.d.ts +2 -0
  104. package/dist/entries/reactivity.d.ts.map +1 -0
  105. package/dist/entries/reactivity.js +2 -0
  106. package/dist/entries/reactivity.js.map +1 -0
  107. package/dist/entries/report.d.ts +3 -0
  108. package/dist/entries/report.d.ts.map +1 -0
  109. package/dist/entries/report.js +66 -0
  110. package/dist/entries/report.js.map +1 -0
  111. package/dist/entries/server.d.ts +8 -0
  112. package/dist/entries/server.d.ts.map +1 -0
  113. package/dist/entries/server.js +48 -0
  114. package/dist/entries/server.js.map +1 -0
  115. package/dist/entries/store-client.d.ts +12 -0
  116. package/dist/entries/store-client.d.ts.map +1 -0
  117. package/dist/entries/store-client.js +63 -0
  118. package/dist/entries/store-client.js.map +1 -0
  119. package/dist/entries/store-server.d.ts +12 -0
  120. package/dist/entries/store-server.d.ts.map +1 -0
  121. package/dist/entries/store-server.js +30 -0
  122. package/dist/entries/store-server.js.map +1 -0
  123. package/dist/entries/store.d.ts +25 -0
  124. package/dist/entries/store.d.ts.map +1 -0
  125. package/dist/entries/store.js +139 -0
  126. package/dist/entries/store.js.map +1 -0
  127. package/dist/entries/transition.d.ts +2 -0
  128. package/dist/entries/transition.d.ts.map +1 -0
  129. package/dist/entries/transition.js +2 -0
  130. package/dist/entries/transition.js.map +1 -0
  131. package/dist/entries/window-server.d.ts +2 -0
  132. package/dist/entries/window-server.d.ts.map +1 -0
  133. package/dist/entries/window-server.js +2 -0
  134. package/dist/entries/window-server.js.map +1 -0
  135. package/dist/entries/window.d.ts +2 -0
  136. package/dist/entries/window.d.ts.map +1 -0
  137. package/dist/entries/window.js +2 -0
  138. package/dist/entries/window.js.map +1 -0
  139. package/dist/front/ast.d.ts +290 -0
  140. package/dist/front/ast.d.ts.map +1 -0
  141. package/dist/front/ast.js +1 -0
  142. package/dist/front/ast.js.map +1 -0
  143. package/dist/front/diagnostics.d.ts +13 -0
  144. package/dist/front/diagnostics.d.ts.map +1 -0
  145. package/dist/front/diagnostics.js +38 -0
  146. package/dist/front/diagnostics.js.map +1 -0
  147. package/dist/front/ignores.d.ts +12 -0
  148. package/dist/front/ignores.d.ts.map +1 -0
  149. package/dist/front/ignores.js +75 -0
  150. package/dist/front/ignores.js.map +1 -0
  151. package/dist/front/index.d.ts +17 -0
  152. package/dist/front/index.d.ts.map +1 -0
  153. package/dist/front/index.js +65 -0
  154. package/dist/front/index.js.map +1 -0
  155. package/dist/front/legacy.d.ts +5 -0
  156. package/dist/front/legacy.d.ts.map +1 -0
  157. package/dist/front/legacy.js +408 -0
  158. package/dist/front/legacy.js.map +1 -0
  159. package/dist/front/locate.d.ts +4 -0
  160. package/dist/front/locate.d.ts.map +1 -0
  161. package/dist/front/locate.js +19 -0
  162. package/dist/front/locate.js.map +1 -0
  163. package/dist/front/lower.d.ts +39 -0
  164. package/dist/front/lower.d.ts.map +1 -0
  165. package/dist/front/lower.js +470 -0
  166. package/dist/front/lower.js.map +1 -0
  167. package/dist/front/parse/attribute.d.ts +12 -0
  168. package/dist/front/parse/attribute.d.ts.map +1 -0
  169. package/dist/front/parse/attribute.js +288 -0
  170. package/dist/front/parse/attribute.js.map +1 -0
  171. package/dist/front/parse/bracket.d.ts +3 -0
  172. package/dist/front/parse/bracket.d.ts.map +1 -0
  173. package/dist/front/parse/bracket.js +102 -0
  174. package/dist/front/parse/bracket.js.map +1 -0
  175. package/dist/front/parse/characters.d.ts +4 -0
  176. package/dist/front/parse/characters.d.ts.map +1 -0
  177. package/dist/front/parse/characters.js +6 -0
  178. package/dist/front/parse/characters.js.map +1 -0
  179. package/dist/front/parse/decode.d.ts +2 -0
  180. package/dist/front/parse/decode.d.ts.map +1 -0
  181. package/dist/front/parse/decode.js +89 -0
  182. package/dist/front/parse/decode.js.map +1 -0
  183. package/dist/front/parse/element.d.ts +3 -0
  184. package/dist/front/parse/element.d.ts.map +1 -0
  185. package/dist/front/parse/element.js +311 -0
  186. package/dist/front/parse/element.js.map +1 -0
  187. package/dist/front/parse/entities.d.ts +2 -0
  188. package/dist/front/parse/entities.d.ts.map +1 -0
  189. package/dist/front/parse/entities.js +2234 -0
  190. package/dist/front/parse/entities.js.map +1 -0
  191. package/dist/front/parse/expression.d.ts +5 -0
  192. package/dist/front/parse/expression.d.ts.map +1 -0
  193. package/dist/front/parse/expression.js +86 -0
  194. package/dist/front/parse/expression.js.map +1 -0
  195. package/dist/front/parse/html.d.ts +8 -0
  196. package/dist/front/parse/html.d.ts.map +1 -0
  197. package/dist/front/parse/html.js +146 -0
  198. package/dist/front/parse/html.js.map +1 -0
  199. package/dist/front/parse/identifier.d.ts +4 -0
  200. package/dist/front/parse/identifier.d.ts.map +1 -0
  201. package/dist/front/parse/identifier.js +24 -0
  202. package/dist/front/parse/identifier.js.map +1 -0
  203. package/dist/front/parse/index.d.ts +13 -0
  204. package/dist/front/parse/index.d.ts.map +1 -0
  205. package/dist/front/parse/index.js +74 -0
  206. package/dist/front/parse/index.js.map +1 -0
  207. package/dist/front/parse/js.d.ts +27 -0
  208. package/dist/front/parse/js.d.ts.map +1 -0
  209. package/dist/front/parse/js.js +241 -0
  210. package/dist/front/parse/js.js.map +1 -0
  211. package/dist/front/parse/options.d.ts +3 -0
  212. package/dist/front/parse/options.d.ts.map +1 -0
  213. package/dist/front/parse/options.js +198 -0
  214. package/dist/front/parse/options.js.map +1 -0
  215. package/dist/front/parse/parser.d.ts +50 -0
  216. package/dist/front/parse/parser.d.ts.map +1 -0
  217. package/dist/front/parse/parser.js +157 -0
  218. package/dist/front/parse/parser.js.map +1 -0
  219. package/dist/front/parse/pattern.d.ts +4 -0
  220. package/dist/front/parse/pattern.d.ts.map +1 -0
  221. package/dist/front/parse/pattern.js +53 -0
  222. package/dist/front/parse/pattern.js.map +1 -0
  223. package/dist/front/parse/script.d.ts +4 -0
  224. package/dist/front/parse/script.d.ts.map +1 -0
  225. package/dist/front/parse/script.js +60 -0
  226. package/dist/front/parse/script.js.map +1 -0
  227. package/dist/front/parse/style.d.ts +7 -0
  228. package/dist/front/parse/style.d.ts.map +1 -0
  229. package/dist/front/parse/style.js +397 -0
  230. package/dist/front/parse/style.js.map +1 -0
  231. package/dist/front/parse/tag.d.ts +3 -0
  232. package/dist/front/parse/tag.d.ts.map +1 -0
  233. package/dist/front/parse/tag.js +591 -0
  234. package/dist/front/parse/tag.js.map +1 -0
  235. package/dist/front/print/css.d.ts +5 -0
  236. package/dist/front/print/css.d.ts.map +1 -0
  237. package/dist/front/print/css.js +234 -0
  238. package/dist/front/print/css.js.map +1 -0
  239. package/dist/front/print/index.d.ts +18 -0
  240. package/dist/front/print/index.d.ts.map +1 -0
  241. package/dist/front/print/index.js +24 -0
  242. package/dist/front/print/index.js.map +1 -0
  243. package/dist/front/print/layout.d.ts +11 -0
  244. package/dist/front/print/layout.d.ts.map +1 -0
  245. package/dist/front/print/layout.js +73 -0
  246. package/dist/front/print/layout.js.map +1 -0
  247. package/dist/front/print/template.d.ts +5 -0
  248. package/dist/front/print/template.d.ts.map +1 -0
  249. package/dist/front/print/template.js +455 -0
  250. package/dist/front/print/template.js.map +1 -0
  251. package/dist/front/runes.d.ts +13 -0
  252. package/dist/front/runes.d.ts.map +1 -0
  253. package/dist/front/runes.js +253 -0
  254. package/dist/front/runes.js.map +1 -0
  255. package/dist/front/stores.d.ts +5 -0
  256. package/dist/front/stores.d.ts.map +1 -0
  257. package/dist/front/stores.js +84 -0
  258. package/dist/front/stores.js.map +1 -0
  259. package/dist/front/typescript.d.ts +2 -0
  260. package/dist/front/typescript.d.ts.map +1 -0
  261. package/dist/front/typescript.js +182 -0
  262. package/dist/front/typescript.js.map +1 -0
  263. package/dist/front/validate/anchors.d.ts +15 -0
  264. package/dist/front/validate/anchors.d.ts.map +1 -0
  265. package/dist/front/validate/anchors.js +43 -0
  266. package/dist/front/validate/anchors.js.map +1 -0
  267. package/dist/front/validate/index.d.ts +16 -0
  268. package/dist/front/validate/index.d.ts.map +1 -0
  269. package/dist/front/validate/index.js +139 -0
  270. package/dist/front/validate/index.js.map +1 -0
  271. package/dist/front/validate/legacy.d.ts +9 -0
  272. package/dist/front/validate/legacy.d.ts.map +1 -0
  273. package/dist/front/validate/legacy.js +102 -0
  274. package/dist/front/validate/legacy.js.map +1 -0
  275. package/dist/front/validate/report.d.ts +14 -0
  276. package/dist/front/validate/report.d.ts.map +1 -0
  277. package/dist/front/validate/report.js +29 -0
  278. package/dist/front/validate/report.js.map +1 -0
  279. package/dist/front/validate/template.d.ts +31 -0
  280. package/dist/front/validate/template.d.ts.map +1 -0
  281. package/dist/front/validate/template.js +507 -0
  282. package/dist/front/validate/template.js.map +1 -0
  283. package/dist/front/wording.d.ts +4 -0
  284. package/dist/front/wording.d.ts.map +1 -0
  285. package/dist/front/wording.js +110 -0
  286. package/dist/front/wording.js.map +1 -0
  287. package/dist/shared/format.d.ts +3 -0
  288. package/dist/shared/format.d.ts.map +1 -0
  289. package/dist/shared/format.js +7 -0
  290. package/dist/shared/format.js.map +1 -0
  291. package/easing.d.ts +2 -0
  292. package/elements.d.ts +1220 -0
  293. package/index.d.ts +2 -0
  294. package/motion.d.ts +2 -0
  295. package/package.json +123 -5
  296. package/src/compiler/diagnostics.ts +233 -0
  297. package/src/compiler/index.ts +292 -0
  298. package/src/compiler/options.ts +140 -0
  299. package/src/compiler/preprocess/decode.ts +85 -0
  300. package/src/compiler/preprocess/index.ts +299 -0
  301. package/src/compiler/preprocess/mapped.ts +146 -0
  302. package/src/compiler/proxy.ts +154 -0
  303. package/src/entries/action.ts +1 -0
  304. package/src/entries/animate.ts +1 -0
  305. package/src/entries/attachments.ts +1 -0
  306. package/src/entries/context.ts +50 -0
  307. package/src/entries/easing.ts +1 -0
  308. package/src/entries/events.ts +1 -0
  309. package/src/entries/index-server.ts +17 -0
  310. package/src/entries/index.ts +41 -0
  311. package/src/entries/internal/client.ts +15 -0
  312. package/src/entries/internal/disclose-version.ts +4 -0
  313. package/src/entries/internal/index.ts +3 -0
  314. package/src/entries/internal/server.ts +8 -0
  315. package/src/entries/internal/tracing.ts +1 -0
  316. package/src/entries/motion-server.ts +1 -0
  317. package/src/entries/motion.ts +1 -0
  318. package/src/entries/proxy.ts +86 -0
  319. package/src/entries/reactivity-server.ts +9 -0
  320. package/src/entries/reactivity.ts +9 -0
  321. package/src/entries/report.ts +81 -0
  322. package/src/entries/server.ts +76 -0
  323. package/src/entries/store-client.ts +80 -0
  324. package/src/entries/store-server.ts +44 -0
  325. package/src/entries/store.ts +201 -0
  326. package/src/entries/transition.ts +1 -0
  327. package/src/entries/window-server.ts +1 -0
  328. package/src/entries/window.ts +1 -0
  329. package/src/front/ast.ts +369 -0
  330. package/src/front/diagnostics.ts +53 -0
  331. package/src/front/ignores.ts +84 -0
  332. package/src/front/index.ts +86 -0
  333. package/src/front/legacy.ts +414 -0
  334. package/src/front/locate.ts +20 -0
  335. package/src/front/lower.ts +509 -0
  336. package/src/front/parse/attribute.ts +319 -0
  337. package/src/front/parse/bracket.ts +99 -0
  338. package/src/front/parse/characters.ts +19 -0
  339. package/src/front/parse/decode.ts +87 -0
  340. package/src/front/parse/element.ts +354 -0
  341. package/src/front/parse/entities.ts +2233 -0
  342. package/src/front/parse/expression.ts +85 -0
  343. package/src/front/parse/html.ts +158 -0
  344. package/src/front/parse/identifier.ts +29 -0
  345. package/src/front/parse/index.ts +88 -0
  346. package/src/front/parse/js.ts +284 -0
  347. package/src/front/parse/options.ts +194 -0
  348. package/src/front/parse/parser.ts +189 -0
  349. package/src/front/parse/pattern.ts +57 -0
  350. package/src/front/parse/script.ts +74 -0
  351. package/src/front/parse/style.ts +399 -0
  352. package/src/front/parse/tag.ts +601 -0
  353. package/src/front/print/css.ts +239 -0
  354. package/src/front/print/index.ts +40 -0
  355. package/src/front/print/layout.ts +87 -0
  356. package/src/front/print/template.ts +448 -0
  357. package/src/front/runes.ts +267 -0
  358. package/src/front/stores.ts +98 -0
  359. package/src/front/typescript.ts +178 -0
  360. package/src/front/validate/anchors.ts +54 -0
  361. package/src/front/validate/index.ts +174 -0
  362. package/src/front/validate/legacy.ts +119 -0
  363. package/src/front/validate/report.ts +38 -0
  364. package/src/front/validate/template.ts +549 -0
  365. package/src/front/wording.ts +112 -0
  366. package/src/shared/format.ts +8 -0
  367. package/store.d.ts +2 -0
  368. package/svelte-html.d.ts +53 -0
  369. package/transition.d.ts +2 -0
  370. package/types/compiler/interfaces.d.ts +2 -0
  371. package/types/compiler/preprocess.d.ts +2 -0
  372. package/types/index.d.ts +1453 -0
  373. package/README.md +0 -3
@@ -0,0 +1,84 @@
1
+ import type { Diagnostic } from 'vigla/compiler';
2
+ import { warning, warningCodes } from './diagnostics.ts';
3
+ import { closest } from 'vigla/compiler';
4
+
5
+ const runtimeCodes = [
6
+ 'await_waterfall',
7
+ 'await_reactivity_loss',
8
+ 'state_snapshot_uncloneable',
9
+ 'binding_property_non_reactive',
10
+ 'hydration_attribute_changed',
11
+ 'hydration_html_changed',
12
+ 'ownership_invalid_binding',
13
+ 'ownership_invalid_mutation'
14
+ ];
15
+
16
+ export const ignorableCodes: ReadonlySet<string> = new Set([...warningCodes, ...runtimeCodes]);
17
+
18
+ export const legacyCodes: Readonly<Record<string, string>> = {
19
+ 'non-top-level-reactive-declaration': 'reactive_declaration_invalid_placement',
20
+ 'module-script-reactive-declaration': 'reactive_declaration_module_script',
21
+ 'empty-block': 'block_empty',
22
+ 'avoid-is': 'attribute_avoid_is',
23
+ 'invalid-html-attribute': 'attribute_invalid_property_name',
24
+ 'a11y-structure': 'a11y_figcaption_parent',
25
+ 'illegal-attribute-character': 'attribute_illegal_colon',
26
+ 'invalid-rest-eachblock-binding': 'bind_invalid_each_rest',
27
+ 'unused-export-let': 'export_let_unused'
28
+ };
29
+
30
+ export const ignorePrefix = /^\s*svelte-ignore\s/;
31
+
32
+ export function replacement(code: string): string {
33
+ return legacyCodes[code] ?? code.replace(/-/g, '_');
34
+ }
35
+
36
+ export interface Extracted {
37
+ readonly codes: string[];
38
+ readonly warnings: Diagnostic[];
39
+ }
40
+
41
+ const runesCodes = /([\w$-]+)(,)?/gm;
42
+
43
+ export function extractIgnores(offset: number, text: string): Extracted {
44
+ const match = ignorePrefix.exec(text);
45
+ const codes: string[] = [];
46
+ const warnings: Diagnostic[] = [];
47
+ if (match === null) return { codes, warnings };
48
+ const length = match[0].length;
49
+ const from = offset + length;
50
+ for (const found of text.slice(length).matchAll(runesCodes)) {
51
+ const code = found[1] as string;
52
+ if (ignorableCodes.has(code)) {
53
+ codes.push(code);
54
+ } else {
55
+ const start = from + found.index;
56
+ const at = { start, end: start + code.length };
57
+ const replaced = replacement(code);
58
+ if (ignorableCodes.has(replaced)) {
59
+ warnings.push(warning('legacy_code', at, { code, suggestion: replaced }));
60
+ } else {
61
+ warnings.push(
62
+ warning('unknown_code', at, { code, suggestion: closest(code, [...ignorableCodes]) })
63
+ );
64
+ }
65
+ }
66
+ if (!found[2]) break;
67
+ }
68
+ return { codes, warnings };
69
+ }
70
+
71
+ export function ignoredCodes(text: string): string[] {
72
+ const match = ignorePrefix.exec(text);
73
+ if (match === null) return [];
74
+ const codes: string[] = [];
75
+ for (const found of text.slice(match[0].length).matchAll(/[\w$-]+/gm)) {
76
+ const code = found[0];
77
+ codes.push(code);
78
+ if (!ignorableCodes.has(code)) {
79
+ const replaced = replacement(code);
80
+ if (ignorableCodes.has(replaced)) codes.push(replaced);
81
+ }
82
+ }
83
+ return codes;
84
+ }
@@ -0,0 +1,86 @@
1
+ import {
2
+ parseProgram,
3
+ type ComponentUnit,
4
+ type Diagnostic,
5
+ type FrontEnd,
6
+ type Reading
7
+ } from 'vigla/compiler';
8
+ import { Lowering } from './lower.ts';
9
+ import { parseComponent, type Parsed } from './parse/index.ts';
10
+ import { Resolution } from './runes.ts';
11
+ import { stores } from './stores.ts';
12
+
13
+ export type * as AST from './ast.ts';
14
+ export { legacy } from './legacy.ts';
15
+ export { locator, type Locator } from './locate.ts';
16
+ export { parseComponent, parseStylesheet, type Parsed } from './parse/index.ts';
17
+ export { print, type PrintOptions, type Printed } from './print/index.ts';
18
+ export {
19
+ validateComponent,
20
+ validateModuleSyntax,
21
+ type ValidateOptions,
22
+ type Validated
23
+ } from './validate/index.ts';
24
+ export type { Anchor, Anchors } from './validate/anchors.ts';
25
+ export { wording } from './wording.ts';
26
+
27
+ export interface Lowered extends Reading<ComponentUnit> {
28
+ readonly anchored: ReadonlyMap<object, readonly Diagnostic[]>;
29
+ readonly lowered: ReadonlyMap<object, object>;
30
+ }
31
+
32
+ export function lowerComponent(parsed: Parsed, source: string, filename: string | null): Lowered {
33
+ const ast = parsed.root;
34
+ const lowering = new Lowering(parsed.ts);
35
+ const module = ast.module === undefined ? null : lowering.program(ast.module.content);
36
+ const moduleReferences = new Set(lowering.resolution.references.keys());
37
+ const instance = ast.instance === undefined ? null : lowering.program(ast.instance.content);
38
+ const template = lowering.fragment(ast.fragment);
39
+ const comment = ast.css?.content.comment;
40
+ if (ast.css && comment) lowering.templateIgnores(ast.css, [comment]);
41
+ return {
42
+ unit: {
43
+ kind: 'component',
44
+ source,
45
+ filename,
46
+ module,
47
+ instance,
48
+ template,
49
+ externals: stores(lowering.resolution, module, instance),
50
+ slotReferences: new Set(
51
+ [...lowering.resolution.references]
52
+ .filter(([reference, name]) => name === '$$slots' && !moduleReferences.has(reference))
53
+ .map(([reference]) => reference)
54
+ ),
55
+ style: ast.css ?? null,
56
+ options: lowering.options(ast.options),
57
+ runes: lowering.resolution.runes,
58
+ ignores: lowering.ignores
59
+ },
60
+ warnings: [],
61
+ anchored: lowering.anchored,
62
+ lowered: lowering.lowered
63
+ };
64
+ }
65
+
66
+ export const front: FrontEnd = {
67
+ component({ source, filename }) {
68
+ return lowerComponent(parseComponent(source), source, filename);
69
+ },
70
+ module({ source, filename }) {
71
+ const program = parseProgram(source, 0, source.length);
72
+ const resolution = new Resolution();
73
+ resolution.program(program);
74
+ return {
75
+ unit: {
76
+ kind: 'module',
77
+ source,
78
+ filename,
79
+ program,
80
+ runes: resolution.runes,
81
+ ignores: new Map()
82
+ },
83
+ warnings: []
84
+ };
85
+ }
86
+ };
@@ -0,0 +1,414 @@
1
+ import type * as AST from './ast.ts';
2
+ import { ignoredCodes } from './ignores.ts';
3
+
4
+ type Json = Record<string, unknown>;
5
+ type Any = { type: string; start: number; end: number; [key: string]: unknown };
6
+
7
+ const notWhitespace = /[^ \t\r\n]/;
8
+ const leadingWhitespace = /^[ \t\r\n]+/;
9
+ const trailingWhitespace = /[ \t\r\n]+$/;
10
+ const space = /\s/;
11
+
12
+ const renamed: Readonly<Record<string, string>> = {
13
+ AnimateDirective: 'Animation',
14
+ BindDirective: 'Binding',
15
+ ClassDirective: 'Class',
16
+ HtmlTag: 'RawMustacheTag',
17
+ OnDirective: 'EventHandler',
18
+ SpreadAttribute: 'Spread',
19
+ TransitionDirective: 'Transition',
20
+ UseDirective: 'Action',
21
+ LetDirective: 'Let'
22
+ };
23
+
24
+ const specials: Readonly<Record<string, [string, string]>> = {
25
+ SvelteBody: ['Body', 'svelte:body'],
26
+ SvelteDocument: ['Document', 'svelte:document'],
27
+ SvelteFragment: ['SlotTemplate', 'svelte:fragment'],
28
+ SvelteHead: ['Head', 'svelte:head'],
29
+ SvelteSelf: ['InlineComponent', 'svelte:self'],
30
+ SvelteWindow: ['Window', 'svelte:window']
31
+ };
32
+
33
+ function trimmed(nodes: readonly AST.TemplateNode[]): AST.TemplateNode[] {
34
+ const list = [...nodes];
35
+ const first = list[0];
36
+ if (first?.type === 'Text') {
37
+ if (!notWhitespace.test(first.data)) list.shift();
38
+ else list[0] = { ...first, data: first.data.replace(leadingWhitespace, '') };
39
+ }
40
+ const last = list.at(-1);
41
+ if (last?.type === 'Text') {
42
+ if (!notWhitespace.test(last.data)) list.pop();
43
+ else list[list.length - 1] = { ...last, data: last.data.replace(trailingWhitespace, '') };
44
+ }
45
+ return list;
46
+ }
47
+
48
+ class Converter {
49
+ readonly source: string;
50
+
51
+ constructor(source: string) {
52
+ this.source = source;
53
+ }
54
+
55
+ nodes(nodes: readonly unknown[], parent: Any): unknown[] {
56
+ return nodes.map((node) => this.node(node as Any, parent));
57
+ }
58
+
59
+ attributes(node: AST.ElementLike | AST.Css.StyleSheet): unknown[] {
60
+ return this.nodes(node.attributes, node as unknown as Any);
61
+ }
62
+
63
+ element(node: AST.ElementLike, type: string, name: string): Json {
64
+ return {
65
+ type,
66
+ name,
67
+ start: node.start,
68
+ end: node.end,
69
+ attributes: this.attributes(node),
70
+ children: this.nodes(node.fragment.nodes, node as unknown as Any)
71
+ };
72
+ }
73
+
74
+ node(node: Any, parent: Any | null): unknown {
75
+ const rename = renamed[node.type];
76
+ if (rename !== undefined) return { ...node, type: rename };
77
+ const special = specials[node.type];
78
+ if (special !== undefined) return this.element(node as unknown as AST.ElementLike, ...special);
79
+ switch (node.type) {
80
+ case 'Text':
81
+ if (parent?.type === 'RegularElement' && parent.name === 'style') {
82
+ return { type: 'Text', start: node.start, end: node.end, data: node.data };
83
+ }
84
+ return node;
85
+ case 'Comment':
86
+ return { ...node, ignores: ignoredCodes(node.data as string) };
87
+ case 'ExpressionTag':
88
+ if (parent?.type === 'Attribute' && this.source[parent.start] === '{') {
89
+ return {
90
+ type: 'AttributeShorthand',
91
+ start: node.start,
92
+ end: node.end,
93
+ expression: node.expression
94
+ };
95
+ }
96
+ return {
97
+ type: 'MustacheTag',
98
+ start: node.start,
99
+ end: node.end,
100
+ expression: node.expression
101
+ };
102
+ case 'Attribute':
103
+ case 'StyleDirective': {
104
+ const value = node.value as AST.AttributeValue;
105
+ if (value === true) return node;
106
+ if (!Array.isArray(value))
107
+ return { ...node, value: [this.node(value as unknown as Any, node)] };
108
+ return { ...node, value: this.nodes(value, node) };
109
+ }
110
+ case 'ConstTag':
111
+ return this.constTag(node as unknown as AST.ConstTag);
112
+ case 'KeyBlock': {
113
+ const block = node as unknown as AST.KeyBlock;
114
+ return {
115
+ type: 'KeyBlock',
116
+ start: block.start,
117
+ end: block.end,
118
+ expression: block.expression,
119
+ children: this.nodes(trimmed(block.fragment.nodes), node)
120
+ };
121
+ }
122
+ case 'EachBlock':
123
+ return this.each(node as unknown as AST.EachBlock);
124
+ case 'IfBlock':
125
+ return this.ifBlock(node as unknown as AST.IfBlock);
126
+ case 'AwaitBlock':
127
+ return this.awaitBlock(node as unknown as AST.AwaitBlock);
128
+ case 'SnippetBlock': {
129
+ const block = node as unknown as AST.SnippetBlock;
130
+ return {
131
+ type: 'SnippetBlock',
132
+ start: block.start,
133
+ end: block.end,
134
+ expression: block.expression,
135
+ parameters: block.parameters,
136
+ children: this.nodes(trimmed(block.body.nodes), node),
137
+ typeParams: block.typeParams
138
+ };
139
+ }
140
+ case 'SvelteBoundary': {
141
+ const element = node as unknown as AST.ElementLike;
142
+ return {
143
+ type: 'SvelteBoundary',
144
+ name: 'svelte:boundary',
145
+ start: element.start,
146
+ end: element.end,
147
+ attributes: this.attributes(element),
148
+ children: this.nodes(trimmed(element.fragment.nodes), node)
149
+ };
150
+ }
151
+ case 'RegularElement': {
152
+ const element = node as unknown as AST.ElementLike;
153
+ return {
154
+ type: 'Element',
155
+ start: element.start,
156
+ end: element.end,
157
+ name: element.name,
158
+ attributes: this.attributes(element),
159
+ children: this.nodes(element.fragment.nodes, node)
160
+ };
161
+ }
162
+ case 'Component': {
163
+ const element = node as unknown as AST.ElementLike;
164
+ return {
165
+ type: 'InlineComponent',
166
+ start: element.start,
167
+ end: element.end,
168
+ name: element.name,
169
+ attributes: this.attributes(element),
170
+ children: this.nodes(element.fragment.nodes, node)
171
+ };
172
+ }
173
+ case 'SvelteComponent': {
174
+ const element = node as unknown as AST.ElementLike;
175
+ return {
176
+ type: 'InlineComponent',
177
+ name: 'svelte:component',
178
+ start: element.start,
179
+ end: element.end,
180
+ expression: element.expression,
181
+ attributes: this.attributes(element),
182
+ children: this.nodes(element.fragment.nodes, node)
183
+ };
184
+ }
185
+ case 'SvelteElement': {
186
+ const element = node as unknown as AST.ElementLike;
187
+ let tag: unknown = element.tag;
188
+ const literal = element.tag as { type: string; value: unknown; start: number };
189
+ if (
190
+ literal.type === 'Literal' &&
191
+ typeof literal.value === 'string' &&
192
+ this.source[literal.start - 1] !== '{'
193
+ ) {
194
+ tag = literal.value;
195
+ }
196
+ return {
197
+ type: 'Element',
198
+ name: 'svelte:element',
199
+ start: element.start,
200
+ end: element.end,
201
+ tag,
202
+ attributes: this.attributes(element),
203
+ children: this.nodes(element.fragment.nodes, node)
204
+ };
205
+ }
206
+ case 'SlotElement': {
207
+ const element = node as unknown as AST.ElementLike;
208
+ return {
209
+ type: 'Slot',
210
+ start: element.start,
211
+ end: element.end,
212
+ name: element.name,
213
+ attributes: this.attributes(element),
214
+ children: this.nodes(element.fragment.nodes, node)
215
+ };
216
+ }
217
+ case 'TitleElement':
218
+ return this.element(node as unknown as AST.ElementLike, 'Title', 'title');
219
+ case 'SvelteOptions': {
220
+ const element = node as unknown as AST.ElementLike;
221
+ return {
222
+ type: 'Options',
223
+ name: 'svelte:options',
224
+ start: element.start,
225
+ end: element.end,
226
+ attributes: this.attributes(element)
227
+ };
228
+ }
229
+ default:
230
+ return node;
231
+ }
232
+ }
233
+
234
+ constTag(node: AST.ConstTag): Json {
235
+ const declarator = node.declaration.declarations[0];
236
+ const { typeAnnotation: _, ...left } = declarator.id as unknown as Json;
237
+ return {
238
+ type: 'ConstTag',
239
+ start: node.start,
240
+ end: node.end,
241
+ expression: {
242
+ type: 'AssignmentExpression',
243
+ start: node.declaration.start + 'const '.length,
244
+ end: node.declaration.end,
245
+ operator: '=',
246
+ left,
247
+ right: declarator.init
248
+ }
249
+ };
250
+ }
251
+
252
+ each(node: AST.EachBlock): Json {
253
+ let otherwise: Json | undefined;
254
+ if (node.fallback !== undefined) {
255
+ const end = this.source.lastIndexOf('{', node.end - 1);
256
+ const start = node.fallback.nodes[0]?.start ?? end;
257
+ otherwise = {
258
+ type: 'ElseBlock',
259
+ start,
260
+ end,
261
+ children: this.nodes(trimmed(node.fallback.nodes), node as unknown as Any)
262
+ };
263
+ }
264
+ return {
265
+ type: 'EachBlock',
266
+ start: node.start,
267
+ end: node.end,
268
+ children: this.nodes(trimmed(node.body.nodes), node as unknown as Any),
269
+ context: node.context,
270
+ expression: node.expression,
271
+ index: node.index,
272
+ key: node.key,
273
+ else: otherwise
274
+ };
275
+ }
276
+
277
+ ifBlock(node: AST.IfBlock): Json {
278
+ let otherwise: Json | undefined;
279
+ if (node.alternate !== null) {
280
+ let nodes = node.alternate.nodes;
281
+ const only = nodes[0];
282
+ if (nodes.length === 1 && only?.type === 'IfBlock' && only.elseif)
283
+ nodes = only.consequent.nodes;
284
+ const end = this.source.lastIndexOf('{', node.end - 1);
285
+ otherwise = {
286
+ type: 'ElseBlock',
287
+ start: nodes[0]?.start ?? end,
288
+ end,
289
+ children: this.nodes(trimmed(node.alternate.nodes), node as unknown as Any)
290
+ };
291
+ }
292
+ const start = node.elseif
293
+ ? (node.consequent.nodes[0]?.start ?? this.source.lastIndexOf('{', node.end - 1))
294
+ : node.start;
295
+ return {
296
+ type: 'IfBlock',
297
+ start,
298
+ end: node.end,
299
+ expression: node.test,
300
+ children: this.nodes(trimmed(node.consequent.nodes), node as unknown as Any),
301
+ else: otherwise,
302
+ elseif: node.elseif ? true : undefined
303
+ };
304
+ }
305
+
306
+ awaitBlock(node: AST.AwaitBlock): Json {
307
+ const parent = node as unknown as Any;
308
+ const branch = (type: string, part: AST.Fragment | null) => ({
309
+ type,
310
+ start: null as number | null,
311
+ end: null as number | null,
312
+ children: part === null ? [] : this.nodes(part.nodes, parent),
313
+ skip: true
314
+ });
315
+ const pending = branch('PendingBlock', node.pending);
316
+ const then = branch('ThenBlock', node.then);
317
+ const caught = branch('CatchBlock', node.catch);
318
+ const expressionEnd = node.expression.end as number;
319
+ const afterExpression = this.source.indexOf('}', expressionEnd) + 1;
320
+ if (node.pending !== null) {
321
+ pending.start = node.pending.nodes[0]?.start ?? afterExpression;
322
+ pending.end = node.pending.nodes.at(-1)?.end ?? pending.start;
323
+ pending.skip = false;
324
+ }
325
+ if (node.then !== null) {
326
+ then.start = pending.end ?? node.then.nodes[0]?.start ?? afterExpression;
327
+ then.end =
328
+ node.then.nodes.at(-1)?.end ??
329
+ this.source.lastIndexOf('}', pending.end ?? expressionEnd) + 1;
330
+ then.skip = false;
331
+ }
332
+ if (node.catch !== null) {
333
+ caught.start = then.end ?? pending.end ?? node.catch.nodes[0]?.start ?? afterExpression;
334
+ caught.end =
335
+ node.catch.nodes.at(-1)?.end ??
336
+ this.source.lastIndexOf('}', then.end ?? pending.end ?? expressionEnd) + 1;
337
+ caught.skip = false;
338
+ }
339
+ return {
340
+ type: 'AwaitBlock',
341
+ start: node.start,
342
+ end: node.end,
343
+ expression: node.expression,
344
+ value: node.value,
345
+ error: node.error,
346
+ pending,
347
+ then,
348
+ catch: caught
349
+ };
350
+ }
351
+
352
+ css(sheet: AST.Css.StyleSheet): Json {
353
+ return {
354
+ ...sheet,
355
+ attributes: this.attributes(sheet),
356
+ children: sheet.children.map((child) => this.cssNode(child)),
357
+ type: 'Style'
358
+ };
359
+ }
360
+
361
+ cssNode<T>(node: T): T {
362
+ if (node === null || typeof node !== 'object') return node;
363
+ if (Array.isArray(node)) return node.map((item) => this.cssNode(item)) as T;
364
+ const record = node as unknown as Json;
365
+ if (record.type === 'ComplexSelector') {
366
+ const complex = node as unknown as AST.Css.ComplexSelector;
367
+ const children: unknown[] = [];
368
+ for (const child of complex.children) {
369
+ if (child.combinator !== null) children.push(child.combinator);
370
+ children.push(...child.selectors);
371
+ }
372
+ return { type: 'Selector', start: complex.start, end: complex.end, children } as T;
373
+ }
374
+ if (typeof record.type !== 'string') return node;
375
+ const copy: Json = {};
376
+ for (const key in record) copy[key] = this.cssNode(record[key]);
377
+ return copy as T;
378
+ }
379
+ }
380
+
381
+ export function legacy(source: string, root: AST.Root, options: AST.ElementLike | null): Json {
382
+ const converter = new Converter(source);
383
+ const nodes = [...root.fragment.nodes];
384
+ if (options !== null && root.options !== null) {
385
+ let at = nodes.findIndex((node) => (root.options as AST.SvelteOptions).end <= node.start);
386
+ if (at === -1) at = nodes.length;
387
+ nodes.splice(at, 0, options);
388
+ }
389
+ let start: number | null = null;
390
+ let end: number | null = null;
391
+ if (nodes.length > 0) {
392
+ start = (nodes[0] as AST.TemplateNode).start;
393
+ end = (nodes.at(-1) as AST.TemplateNode).end;
394
+ while (space.test(source[start] ?? '')) start += 1;
395
+ while (space.test(source[end - 1] ?? '')) end -= 1;
396
+ }
397
+ const strip = (script: AST.Script | undefined): Json | undefined => {
398
+ if (script === undefined) return undefined;
399
+ const { attributes: _, ...rest } = script;
400
+ return rest as unknown as Json;
401
+ };
402
+ return {
403
+ html: {
404
+ type: 'Fragment',
405
+ start,
406
+ end,
407
+ children: converter.nodes(nodes, root as unknown as Any)
408
+ },
409
+ instance: strip(root.instance),
410
+ module: strip(root.module),
411
+ css: root.css !== null ? converter.css(root.css) : undefined,
412
+ _comments: root.comments.length > 0 ? root.comments : undefined
413
+ };
414
+ }
@@ -0,0 +1,20 @@
1
+ import type { Position } from './ast.ts';
2
+
3
+ export type Locator = (offset: number) => Position;
4
+
5
+ export function locator(source: string): Locator {
6
+ const starts = [0];
7
+ for (let index = source.indexOf('\n'); index !== -1; index = source.indexOf('\n', index + 1)) {
8
+ starts.push(index + 1);
9
+ }
10
+ return (offset) => {
11
+ let low = 0;
12
+ let high = starts.length - 1;
13
+ while (low < high) {
14
+ const middle = (low + high + 1) >> 1;
15
+ if ((starts[middle] ?? 0) <= offset) low = middle;
16
+ else high = middle - 1;
17
+ }
18
+ return { line: low + 1, column: offset - (starts[low] ?? 0), character: offset };
19
+ };
20
+ }