@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,194 @@
1
+ import type * as ES from 'estree';
2
+ import type * as AST from '../ast.ts';
3
+ import { fail, type At } from '../diagnostics.ts';
4
+
5
+ const svgNamespace = 'http://www.w3.org/2000/svg';
6
+ const mathmlNamespace = 'http://www.w3.org/1998/Math/MathML';
7
+
8
+ const tagChar =
9
+ '[a-z0-9_.\xB7\xC0-\xD6\xD8-\xF6\xF8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}-]';
10
+ const customTag = new RegExp(`^[a-z]${tagChar}*-${tagChar}*$`, 'u');
11
+ const reservedTags = new Set([
12
+ 'annotation-xml',
13
+ 'color-profile',
14
+ 'font-face',
15
+ 'font-face-src',
16
+ 'font-face-uri',
17
+ 'font-face-format',
18
+ 'font-face-name',
19
+ 'missing-glyph'
20
+ ]);
21
+
22
+ const propTypes = new Set(['String', 'Number', 'Boolean', 'Array', 'Object']);
23
+
24
+ type Static = string | number | boolean | RegExp | bigint | null | undefined;
25
+
26
+ function staticValue(attribute: AST.Attribute): Static {
27
+ const { value } = attribute;
28
+ if (value === true) return true;
29
+ const chunk = Array.isArray(value) ? value[0] : value;
30
+ if (chunk === undefined) return true;
31
+ if (Array.isArray(value) && value.length > 1) return null;
32
+ if (chunk.type === 'Text') return chunk.data;
33
+ if (chunk.expression.type !== 'Literal') return null;
34
+ return chunk.expression.value;
35
+ }
36
+
37
+ function booleanValue(attribute: AST.Attribute): boolean {
38
+ const value = staticValue(attribute);
39
+ if (typeof value !== 'boolean') {
40
+ fail('svelte_options_invalid_attribute_value', attribute, { list: 'true or false' });
41
+ }
42
+ return value;
43
+ }
44
+
45
+ function validateTag(at: At, tag: unknown): asserts tag is string {
46
+ if (typeof tag !== 'string') fail('svelte_options_invalid_tagname', at);
47
+ if (tag) {
48
+ if (!customTag.test(tag)) fail('svelte_options_invalid_tagname', at);
49
+ if (reservedTags.has(tag)) fail('svelte_options_reserved_tagname', at);
50
+ }
51
+ }
52
+
53
+ function plainKey(property: ES.Property | ES.SpreadElement): property is ES.Property & {
54
+ key: ES.Identifier;
55
+ } {
56
+ return property.type === 'Property' && !property.computed && property.key.type === 'Identifier';
57
+ }
58
+
59
+ function customElement(attribute: AST.Attribute): AST.CustomElementOptions | undefined {
60
+ const options: AST.CustomElementOptions = {};
61
+ const raw = attribute.value;
62
+ if (raw === true) fail('svelte_options_invalid_customelement', attribute);
63
+ const value = Array.isArray(raw) ? raw : [raw];
64
+ const first = value[0] as AST.Text | AST.ExpressionTag;
65
+ if (first.type === 'Text') {
66
+ const tag = staticValue(attribute);
67
+ validateTag(attribute, tag);
68
+ options.tag = tag;
69
+ return options;
70
+ }
71
+ const expression = first.expression;
72
+ if (expression.type !== 'ObjectExpression') {
73
+ if (expression.type === 'Literal' && expression.value === null) return undefined;
74
+ fail('svelte_options_invalid_customelement', attribute);
75
+ }
76
+ const properties: [string, ES.Node][] = [];
77
+ for (const property of expression.properties) {
78
+ if (!plainKey(property)) fail('svelte_options_invalid_customelement', attribute);
79
+ properties.push([property.key.name, property.value]);
80
+ }
81
+ const find = (name: string): ES.Node | undefined => properties.find(([key]) => key === name)?.[1];
82
+
83
+ const tag = properties.find(([name]) => name === 'tag');
84
+ if (tag !== undefined) {
85
+ const tagValue = (tag[1] as ES.Literal | undefined)?.value;
86
+ validateTag(tag as unknown as At, tagValue);
87
+ options.tag = tagValue;
88
+ }
89
+
90
+ const props = find('props');
91
+ if (props !== undefined) {
92
+ if (props.type !== 'ObjectExpression')
93
+ fail('svelte_options_invalid_customelement_props', attribute);
94
+ options.props = {};
95
+ for (const property of props.properties) {
96
+ if (!plainKey(property) || property.value.type !== 'ObjectExpression') {
97
+ fail('svelte_options_invalid_customelement_props', attribute);
98
+ }
99
+ const prop: AST.CustomElementProp = {};
100
+ options.props[property.key.name] = prop;
101
+ for (const entry of property.value.properties) {
102
+ if (!plainKey(entry) || entry.value.type !== 'Literal') {
103
+ fail('svelte_options_invalid_customelement_props', attribute);
104
+ }
105
+ const literal = entry.value.value;
106
+ if (entry.key.name === 'type') {
107
+ if (!propTypes.has(literal as string)) {
108
+ fail('svelte_options_invalid_customelement_props', attribute);
109
+ }
110
+ prop.type = literal as AST.CustomElementProp['type'];
111
+ } else if (entry.key.name === 'reflect') {
112
+ if (typeof literal !== 'boolean')
113
+ fail('svelte_options_invalid_customelement_props', attribute);
114
+ prop.reflect = literal;
115
+ } else if (entry.key.name === 'attribute') {
116
+ if (typeof literal !== 'string')
117
+ fail('svelte_options_invalid_customelement_props', attribute);
118
+ prop.attribute = literal;
119
+ } else {
120
+ fail('svelte_options_invalid_customelement_props', attribute);
121
+ }
122
+ }
123
+ }
124
+ }
125
+
126
+ const shadow = find('shadow');
127
+ if (shadow) {
128
+ if (shadow.type === 'Literal' && (shadow.value === 'open' || shadow.value === 'none')) {
129
+ options.shadow = shadow.value;
130
+ } else if (shadow.type === 'ObjectExpression') {
131
+ options.shadow = shadow;
132
+ } else {
133
+ fail('svelte_options_invalid_customelement_shadow', attribute);
134
+ }
135
+ }
136
+
137
+ const extend = find('extend');
138
+ if (extend) options.extend = extend as AST.Expression;
139
+ return options;
140
+ }
141
+
142
+ export function readOptions(node: AST.ElementLike): AST.SvelteOptions {
143
+ const options: AST.SvelteOptions = {
144
+ start: node.start,
145
+ end: node.end,
146
+ attributes: node.attributes
147
+ };
148
+ for (const attribute of node.attributes) {
149
+ if (attribute.type !== 'Attribute') fail('svelte_options_invalid_attribute', attribute);
150
+ const { name } = attribute;
151
+ switch (name) {
152
+ case 'runes':
153
+ options.runes = booleanValue(attribute);
154
+ break;
155
+ case 'tag':
156
+ fail('svelte_options_deprecated_tag', attribute);
157
+ case 'customElement': {
158
+ const element = customElement(attribute);
159
+ if (element !== undefined) options.customElement = element;
160
+ break;
161
+ }
162
+ case 'namespace': {
163
+ const value = staticValue(attribute);
164
+ if (value === svgNamespace) options.namespace = 'svg';
165
+ else if (value === mathmlNamespace) options.namespace = 'mathml';
166
+ else if (value === 'html' || value === 'mathml' || value === 'svg')
167
+ options.namespace = value;
168
+ else {
169
+ fail('svelte_options_invalid_attribute_value', attribute, {
170
+ list: '"html", "mathml" or "svg"'
171
+ });
172
+ }
173
+ break;
174
+ }
175
+ case 'css': {
176
+ if (staticValue(attribute) === 'injected') options.css = 'injected';
177
+ else fail('svelte_options_invalid_attribute_value', attribute, { list: '"injected"' });
178
+ break;
179
+ }
180
+ case 'immutable':
181
+ options.immutable = booleanValue(attribute);
182
+ break;
183
+ case 'preserveWhitespace':
184
+ options.preserveWhitespace = booleanValue(attribute);
185
+ break;
186
+ case 'accessors':
187
+ options.accessors = booleanValue(attribute);
188
+ break;
189
+ default:
190
+ fail('svelte_options_unknown_attribute', attribute, { name });
191
+ }
192
+ }
193
+ return options;
194
+ }
@@ -0,0 +1,189 @@
1
+ import type * as ES from 'estree';
2
+ import type { Diagnostic } from 'vigla/compiler';
3
+ import type * as AST from '../ast.ts';
4
+ import { fail, warning, type Args, type At } from '../diagnostics.ts';
5
+ import type { Locator } from '../locate.ts';
6
+ import { isReserved, isWhitespace } from './html.ts';
7
+ import { identifierEnd } from './identifier.ts';
8
+ import type { Context } from './js.ts';
9
+
10
+ export type Open = AST.Root | AST.ElementLike | AST.Block;
11
+
12
+ export interface AutoClosed {
13
+ readonly tag: string;
14
+ readonly reason: string;
15
+ readonly depth: number;
16
+ }
17
+
18
+ export type Identifier = ES.Identifier & AST.Located & { loc: AST.NameLocation };
19
+
20
+ const scriptLang =
21
+ /<!--[^]*?-->|<script\s+(?:[^>]*|(?:[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)\s+)*)lang=(["'])?([^"' >]+)\1[^>]*>/g;
22
+
23
+ function typescript(source: string): boolean {
24
+ scriptLang.lastIndex = 0;
25
+ let match: RegExpExecArray | null;
26
+ do match = scriptLang.exec(source);
27
+ while (match !== null && match[0][1] !== 's');
28
+ scriptLang.lastIndex = 0;
29
+ return match?.[2] === 'ts';
30
+ }
31
+
32
+ export class Scanner {
33
+ template: string;
34
+ readonly loose: boolean;
35
+ cssComments: AST.Css.Comment[] = [];
36
+ index = 0;
37
+
38
+ constructor(template: string, loose: boolean) {
39
+ this.template = template;
40
+ this.loose = loose;
41
+ }
42
+
43
+ match(text: string): boolean {
44
+ return text.length === 1
45
+ ? this.template[this.index] === text
46
+ : this.template.startsWith(text, this.index);
47
+ }
48
+
49
+ eat(text: string, required = false, requiredInLoose = true): boolean {
50
+ if (this.match(text)) {
51
+ this.index += text.length;
52
+ return true;
53
+ }
54
+ if (required && (!this.loose || requiredInLoose))
55
+ fail('expected_token', this.index, { token: text });
56
+ return false;
57
+ }
58
+
59
+ matchRegex(pattern: RegExp): string | null {
60
+ pattern.lastIndex = this.index;
61
+ const match = pattern.exec(this.template);
62
+ if (match === null || match.index !== this.index) return null;
63
+ return match[0];
64
+ }
65
+
66
+ read(pattern: RegExp): string | null {
67
+ const result = this.matchRegex(pattern);
68
+ if (result) this.index += result.length;
69
+ return result;
70
+ }
71
+
72
+ allowWhitespace(): void {
73
+ while (
74
+ this.index < this.template.length &&
75
+ isWhitespace(this.template.charCodeAt(this.index))
76
+ ) {
77
+ this.index++;
78
+ }
79
+ }
80
+
81
+ readUntil(delimiter: string): string {
82
+ if (this.index >= this.template.length) {
83
+ if (this.loose) return '';
84
+ fail('unexpected_eof', this.template.length);
85
+ }
86
+ const start = this.index;
87
+ const found = this.template.indexOf(delimiter, start);
88
+ this.index = found === -1 ? this.template.length : found;
89
+ return this.template.slice(start, this.index);
90
+ }
91
+
92
+ readUntilRegex(pattern: RegExp): string {
93
+ if (this.index >= this.template.length) {
94
+ if (this.loose) return '';
95
+ fail('unexpected_eof', this.template.length);
96
+ }
97
+ const start = this.index;
98
+ const match = pattern.exec(this.template.slice(start));
99
+ this.index = match === null ? this.template.length : start + match.index;
100
+ return this.template.slice(start, this.index);
101
+ }
102
+ }
103
+
104
+ export class Parser extends Scanner implements Context {
105
+ readonly ts: boolean;
106
+ readonly locate: Locator;
107
+ readonly root: AST.Root;
108
+ readonly stack: Open[] = [];
109
+ readonly fragments: AST.Fragment[] = [];
110
+ readonly meta = new Set<string>();
111
+ readonly warnings: Diagnostic[] = [];
112
+ lastAutoClosed: AutoClosed | undefined;
113
+
114
+ constructor(source: string, loose: boolean, locate: Locator) {
115
+ super(source.trimEnd(), loose);
116
+ this.locate = locate;
117
+ this.ts = typescript(source);
118
+ this.root = {
119
+ css: null,
120
+ js: [],
121
+ start: 0,
122
+ end: source.length,
123
+ type: 'Root',
124
+ fragment: { type: 'Fragment', nodes: [] },
125
+ options: null,
126
+ comments: []
127
+ };
128
+ this.stack.push(this.root);
129
+ this.fragments.push(this.root.fragment);
130
+ }
131
+
132
+ get comments(): AST.JSComment[] {
133
+ return this.root.comments;
134
+ }
135
+
136
+ current(): Open {
137
+ return this.stack[this.stack.length - 1] as Open;
138
+ }
139
+
140
+ warn(code: string, at: At, args?: Args): void {
141
+ this.warnings.push(warning(code, at, args));
142
+ }
143
+
144
+ requireWhitespace(): void {
145
+ if (!isWhitespace(this.template.charCodeAt(this.index)))
146
+ fail('expected_whitespace', this.index);
147
+ this.index++;
148
+ this.allowWhitespace();
149
+ }
150
+
151
+ readIdentifier(): Identifier {
152
+ const start = this.index;
153
+ let end = identifierEnd(this.template, start);
154
+ let name = '';
155
+ if (end === -1) {
156
+ end = start;
157
+ } else {
158
+ name = this.template.slice(start, end);
159
+ this.index = end;
160
+ if (isReserved(name)) fail('unexpected_reserved_word', start, { word: name });
161
+ }
162
+ return {
163
+ type: 'Identifier',
164
+ name,
165
+ start,
166
+ end,
167
+ loc: { start: this.locate(start), end: this.locate(end) }
168
+ };
169
+ }
170
+
171
+ push(node: Open, fragment: AST.Fragment): void {
172
+ this.stack.push(node);
173
+ this.fragments.push(fragment);
174
+ }
175
+
176
+ pop(): Open | undefined {
177
+ this.fragments.pop();
178
+ return this.stack.pop();
179
+ }
180
+
181
+ append<T extends AST.TemplateNode>(node: T): T {
182
+ this.fragments.at(-1)?.nodes.push(node);
183
+ return node;
184
+ }
185
+ }
186
+
187
+ export function fragment(): AST.Fragment {
188
+ return { type: 'Fragment', nodes: [] };
189
+ }
@@ -0,0 +1,57 @@
1
+ import type * as AST from '../ast.ts';
2
+ import { fail } from '../diagnostics.ts';
3
+ import { matchBracket } from './bracket.ts';
4
+ import { parseExpressionAt, removeParens, type Node } from './js.ts';
5
+ import type { Parser } from './parser.ts';
6
+
7
+ export function readPattern(parser: Parser): AST.Pattern {
8
+ const start = parser.index;
9
+ const id = parser.readIdentifier();
10
+ if (id.name !== '') {
11
+ return { ...id, typeAnnotation: readTypeAnnotation(parser) } as AST.Pattern;
12
+ }
13
+ const char = parser.template[start];
14
+ if (char !== '{' && char !== '[') fail('expected_pattern', start);
15
+ const end = matchBracket(parser.template, start);
16
+ parser.index = end;
17
+ const assignment = removeParens(
18
+ parseExpressionAt(parser, `${parser.template.slice(0, end)} = 1`, start)
19
+ );
20
+ const pattern = assignment.left as Node;
21
+ pattern.typeAnnotation = readTypeAnnotation(parser);
22
+ if (pattern.typeAnnotation) pattern.end = (pattern.typeAnnotation as Node).end;
23
+ return pattern as unknown as AST.Pattern;
24
+ }
25
+
26
+ const optionalColon = /\?\s*:/g;
27
+
28
+ function readTypeAnnotation(parser: Parser): Node | undefined {
29
+ const start = parser.index;
30
+ parser.allowWhitespace();
31
+ if (!parser.eat(':')) {
32
+ parser.index = start;
33
+ return undefined;
34
+ }
35
+ const insert = '_ as ';
36
+ const from = parser.index - insert.length;
37
+ const template =
38
+ parser.template.slice(0, from) +
39
+ insert +
40
+ parser.template.slice(parser.index).replace(optionalColon, ':');
41
+ let expression = removeParens(parseExpressionAt(parser, template, from));
42
+ if (expression.type === 'AssignmentExpression') {
43
+ let equals = (expression.right as Node).start;
44
+ while (template[equals] !== '=') equals -= 1;
45
+ expression = removeParens(parseExpressionAt(parser, template.slice(0, equals), from));
46
+ }
47
+ if (expression.type === 'SequenceExpression') {
48
+ expression = (expression.expressions as Node[])[0] as Node;
49
+ }
50
+ parser.index = expression.end;
51
+ return {
52
+ type: 'TSTypeAnnotation',
53
+ start,
54
+ end: parser.index,
55
+ typeAnnotation: expression.typeAnnotation
56
+ } as unknown as Node;
57
+ }
@@ -0,0 +1,74 @@
1
+ import type * as AST from '../ast.ts';
2
+ import { fail } from '../diagnostics.ts';
3
+ import { parseScript } from './js.ts';
4
+ import type { Parser } from './parser.ts';
5
+
6
+ const closing = /<\/script\s*>/;
7
+ const closingHere = /<\/script\s*>/y;
8
+ const notNewline = /[^\n]/g;
9
+
10
+ const reserved = new Set(['server', 'client', 'worker', 'test', 'default']);
11
+ const allowed = new Set(['context', 'generics', 'lang', 'module']);
12
+
13
+ export function readScript(
14
+ parser: Parser,
15
+ start: number,
16
+ attributes: AST.AttributeLike[]
17
+ ): AST.Script {
18
+ const contentStart = parser.index;
19
+ const data = parser.readUntilRegex(closing);
20
+ if (parser.index >= parser.template.length) {
21
+ fail('element_unclosed', parser.template.length, { name: 'script' });
22
+ }
23
+ const source = parser.template.slice(0, contentStart).replace(notNewline, ' ') + data;
24
+ parser.read(closingHere);
25
+
26
+ const ast = parseScript(source, parser.comments, parser.ts);
27
+ ast.start = contentStart;
28
+ const loc = ast.loc as {
29
+ start: { line: number; column: number };
30
+ end: { line: number; column: number };
31
+ };
32
+ const from = parser.locate(start);
33
+ const to = parser.locate(parser.index);
34
+ loc.start.line = from.line;
35
+ loc.start.column = from.column;
36
+ loc.end.line = to.line;
37
+ loc.end.column = to.column;
38
+
39
+ let context: 'default' | 'module' = 'default';
40
+ for (const attribute of attributes as AST.Attribute[]) {
41
+ if (reserved.has(attribute.name)) {
42
+ fail('script_reserved_attribute', attribute, { name: attribute.name });
43
+ }
44
+ if (!allowed.has(attribute.name)) parser.warn('script_unknown_attribute', attribute);
45
+ if (attribute.name === 'module') {
46
+ if (attribute.value !== true) {
47
+ fail('script_invalid_attribute_value', attribute, { name: attribute.name });
48
+ }
49
+ context = 'module';
50
+ }
51
+ if (attribute.name === 'context') {
52
+ const value = attribute.value;
53
+ if (
54
+ value === true ||
55
+ !Array.isArray(value) ||
56
+ value.length !== 1 ||
57
+ value[0]?.type !== 'Text'
58
+ ) {
59
+ fail('script_invalid_context', attribute);
60
+ }
61
+ if (value[0].data !== 'module') fail('script_invalid_context', attribute);
62
+ context = 'module';
63
+ }
64
+ }
65
+
66
+ return {
67
+ type: 'Script',
68
+ start,
69
+ end: parser.index,
70
+ context,
71
+ content: ast as unknown as AST.Script['content'],
72
+ attributes
73
+ };
74
+ }