@vigla/svelte 0.0.0-stage → 5.57.4

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 +128 -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,85 @@
1
+ import type * as AST from '../ast.ts';
2
+ import { findMatchingBracket } from './bracket.ts';
3
+ import { isReserved } from './html.ts';
4
+ import { identifierEnd as wordEnd } from './identifier.ts';
5
+ import { lfLineBreaksOnly, parseExpressionAt, removeParens } from './js.ts';
6
+ import type { Parser } from './parser.ts';
7
+
8
+ export function looseIdentifier(parser: Parser, open?: string): AST.Expression | undefined {
9
+ const end = findMatchingBracket(parser.template, parser.index, open ?? '{');
10
+ if (!end) return undefined;
11
+ const start = parser.index;
12
+ parser.index = end;
13
+ return { type: 'Identifier', start, end, name: '' } as AST.Expression;
14
+ }
15
+
16
+ export function readExpression(parser: Parser, open?: string, strict?: boolean): AST.Expression {
17
+ const simple = readSimple(parser);
18
+ if (simple !== null) return simple;
19
+ try {
20
+ const node = parseExpressionAt(parser, parser.template, parser.index);
21
+ let index = node.end;
22
+ const last = parser.comments.at(-1);
23
+ if (last !== undefined && last.end > index) index = last.end;
24
+ parser.index = index;
25
+ return removeParens(node) as unknown as AST.Expression;
26
+ } catch (error) {
27
+ if (parser.loose && !strict) {
28
+ const expression = looseIdentifier(parser, open);
29
+ if (expression !== undefined) return expression;
30
+ }
31
+ throw error;
32
+ }
33
+ }
34
+
35
+ function readSimple(parser: Parser): AST.Expression | null {
36
+ if (!lfLineBreaksOnly(parser.template)) return null;
37
+ const template = parser.template;
38
+ const index = parser.index;
39
+ parser.allowWhitespace();
40
+ const start = parser.index;
41
+ let end = wordEnd(template, start);
42
+ if (end === -1 || isReserved(template.slice(start, end))) {
43
+ parser.index = index;
44
+ return null;
45
+ }
46
+ const position = (offset: number): { line: number; column: number } => {
47
+ const { line, column } = parser.locate(offset);
48
+ return { line, column };
49
+ };
50
+ const identifier = (from: number, to: number): AST.Expression =>
51
+ ({
52
+ type: 'Identifier',
53
+ start: from,
54
+ end: to,
55
+ loc: { start: position(from), end: position(to) },
56
+ name: template.slice(from, to)
57
+ }) as AST.Expression;
58
+ let node = identifier(start, end);
59
+ while (template[end] === '.') {
60
+ const propertyEnd = wordEnd(template, end + 1);
61
+ if (propertyEnd === -1) {
62
+ parser.index = index;
63
+ return null;
64
+ }
65
+ node = {
66
+ type: 'MemberExpression',
67
+ start,
68
+ end: propertyEnd,
69
+ loc: { start: position(start), end: position(propertyEnd) },
70
+ object: node,
71
+ property: identifier(end + 1, propertyEnd),
72
+ computed: false,
73
+ optional: false
74
+ } as AST.Expression;
75
+ end = propertyEnd;
76
+ }
77
+ parser.index = end;
78
+ parser.allowWhitespace();
79
+ if (!parser.match('}')) {
80
+ parser.index = index;
81
+ return null;
82
+ }
83
+ parser.index = end;
84
+ return node;
85
+ }
@@ -0,0 +1,158 @@
1
+ const voids = new Set([
2
+ 'area',
3
+ 'base',
4
+ 'br',
5
+ 'col',
6
+ 'command',
7
+ 'embed',
8
+ 'hr',
9
+ 'img',
10
+ 'input',
11
+ 'keygen',
12
+ 'link',
13
+ 'meta',
14
+ 'param',
15
+ 'source',
16
+ 'track',
17
+ 'wbr'
18
+ ]);
19
+
20
+ export function isVoid(name: string): boolean {
21
+ return voids.has(name) || name.toLowerCase() === '!doctype';
22
+ }
23
+
24
+ const reservedWords = new Set([
25
+ 'arguments',
26
+ 'await',
27
+ 'break',
28
+ 'case',
29
+ 'catch',
30
+ 'class',
31
+ 'const',
32
+ 'continue',
33
+ 'debugger',
34
+ 'default',
35
+ 'delete',
36
+ 'do',
37
+ 'else',
38
+ 'enum',
39
+ 'eval',
40
+ 'export',
41
+ 'extends',
42
+ 'false',
43
+ 'finally',
44
+ 'for',
45
+ 'function',
46
+ 'if',
47
+ 'implements',
48
+ 'import',
49
+ 'in',
50
+ 'instanceof',
51
+ 'interface',
52
+ 'let',
53
+ 'new',
54
+ 'null',
55
+ 'package',
56
+ 'private',
57
+ 'protected',
58
+ 'public',
59
+ 'return',
60
+ 'static',
61
+ 'super',
62
+ 'switch',
63
+ 'this',
64
+ 'throw',
65
+ 'true',
66
+ 'try',
67
+ 'typeof',
68
+ 'var',
69
+ 'void',
70
+ 'while',
71
+ 'with',
72
+ 'yield'
73
+ ]);
74
+
75
+ export function isReserved(word: string): boolean {
76
+ return reservedWords.has(word);
77
+ }
78
+
79
+ const blockStarters = [
80
+ 'address',
81
+ 'article',
82
+ 'aside',
83
+ 'blockquote',
84
+ 'div',
85
+ 'dl',
86
+ 'fieldset',
87
+ 'footer',
88
+ 'form',
89
+ 'h1',
90
+ 'h2',
91
+ 'h3',
92
+ 'h4',
93
+ 'h5',
94
+ 'h6',
95
+ 'header',
96
+ 'hgroup',
97
+ 'hr',
98
+ 'main',
99
+ 'menu',
100
+ 'nav',
101
+ 'ol',
102
+ 'p',
103
+ 'pre',
104
+ 'section',
105
+ 'table',
106
+ 'ul'
107
+ ];
108
+
109
+ const closers: Readonly<Record<string, readonly string[]>> = {
110
+ li: ['li'],
111
+ dt: ['dt', 'dd'],
112
+ dd: ['dt', 'dd'],
113
+ p: blockStarters,
114
+ rt: ['rt', 'rp'],
115
+ rp: ['rt', 'rp'],
116
+ optgroup: ['optgroup'],
117
+ option: ['option', 'optgroup'],
118
+ thead: ['tbody', 'tfoot'],
119
+ tbody: ['tbody', 'tfoot'],
120
+ tfoot: ['tbody'],
121
+ tr: ['tr', 'tbody'],
122
+ td: ['td', 'th', 'tr'],
123
+ th: ['td', 'th', 'tr']
124
+ };
125
+
126
+ export function closingTagOmitted(current: string, next?: string): boolean {
127
+ const closing = closers[current];
128
+ return closing !== undefined && (next === undefined || closing.includes(next));
129
+ }
130
+
131
+ export const validTagName =
132
+ /^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9.\-_\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]*)?$/u;
133
+
134
+ export const validComponentName =
135
+ /^(?:\p{Lu}[$\u200C\u200D\p{ID_Continue}.]*|\p{ID_Start}[$\u200C\u200D\p{ID_Continue}]*(?:\.[$\u200C\u200D\p{ID_Continue}]+)+)$/u;
136
+
137
+ const doctype = /^![a-zA-Z]+$/;
138
+ const namespaced = /^[a-zA-Z][a-zA-Z0-9]*:[a-zA-Z][a-zA-Z0-9-]*[a-zA-Z0-9]$/;
139
+
140
+ export function validElementName(name: string): boolean {
141
+ return doctype.test(name) || namespaced.test(name) || validTagName.test(name);
142
+ }
143
+
144
+ export function isWhitespace(code: number): boolean {
145
+ if (code === 32 || (code <= 13 && code >= 9)) return true;
146
+ if (code < 160) return false;
147
+ return (
148
+ code === 160 ||
149
+ code === 5760 ||
150
+ (code >= 8192 && code <= 8202) ||
151
+ code === 8232 ||
152
+ code === 8233 ||
153
+ code === 8239 ||
154
+ code === 8287 ||
155
+ code === 12288 ||
156
+ code === 65279
157
+ );
158
+ }
@@ -0,0 +1,29 @@
1
+ import * as acorn from 'acorn';
2
+
3
+ interface Classes {
4
+ isIdentifierStart(code: number, astral: boolean): boolean;
5
+ isIdentifierChar(code: number, astral: boolean): boolean;
6
+ }
7
+
8
+ const classes = acorn as unknown as Classes;
9
+
10
+ export function identifierStart(code: number): boolean {
11
+ return classes.isIdentifierStart(code, true);
12
+ }
13
+
14
+ export function identifierChar(code: number): boolean {
15
+ return classes.isIdentifierChar(code, true);
16
+ }
17
+
18
+ export function identifierEnd(text: string, start: number): number {
19
+ if (start >= text.length) return -1;
20
+ const code = text.codePointAt(start) as number;
21
+ if (!identifierStart(code)) return -1;
22
+ let end = start + (code <= 0xffff ? 1 : 2);
23
+ while (end < text.length) {
24
+ const next = text.codePointAt(end) as number;
25
+ if (!identifierChar(next)) break;
26
+ end += next <= 0xffff ? 1 : 2;
27
+ }
28
+ return end;
29
+ }
@@ -0,0 +1,88 @@
1
+ import type { Diagnostic } from 'vigla/compiler';
2
+ import type * as AST from '../ast.ts';
3
+ import { fail } from '../diagnostics.ts';
4
+ import { locator, type Locator } from '../locate.ts';
5
+ import { element } from './element.ts';
6
+ import { readOptions } from './options.ts';
7
+ import { Parser, Scanner } from './parser.ts';
8
+ import { readStylesheet } from './style.ts';
9
+ import { tag } from './tag.ts';
10
+ import { decode } from './decode.ts';
11
+
12
+ export interface Parsed {
13
+ readonly root: AST.Root;
14
+ readonly ts: boolean;
15
+ readonly options: AST.ElementLike | null;
16
+ readonly warnings: readonly Diagnostic[];
17
+ readonly locate: Locator;
18
+ }
19
+
20
+ function text(parser: Parser): void {
21
+ const start = parser.index;
22
+ const template = parser.template;
23
+ let index = start;
24
+ while (index < template.length) {
25
+ const char = template[index];
26
+ if (char === '<' || char === '{') break;
27
+ index++;
28
+ }
29
+ parser.index = index;
30
+ const data = template.slice(start, index);
31
+ parser.append({ type: 'Text', start, end: index, raw: data, data: decode(data, false) });
32
+ }
33
+
34
+ export function parseComponent(source: string, loose = false): Parsed {
35
+ const locate = locator(source);
36
+ const parser = new Parser(source, loose, locate);
37
+ while (parser.index < parser.template.length) {
38
+ if (parser.match('<')) element(parser);
39
+ else if (parser.match('{')) tag(parser);
40
+ else text(parser);
41
+ }
42
+
43
+ if (parser.stack.length > 1) {
44
+ const current = parser.current() as AST.ElementLike | AST.Block;
45
+ if (parser.loose) {
46
+ current.end = parser.template.length;
47
+ } else {
48
+ current.end = current.start + 1;
49
+ if (current.type === 'RegularElement')
50
+ fail('element_unclosed', current, { name: current.name });
51
+ fail('block_unclosed', current);
52
+ }
53
+ }
54
+
55
+ const root = parser.root;
56
+ const nodes = root.fragment.nodes;
57
+ const at = nodes.findIndex((node) => node.type === 'SvelteOptions');
58
+ let options: AST.ElementLike | null = null;
59
+ if (at !== -1) {
60
+ options = nodes.splice(at, 1)[0] as AST.ElementLike;
61
+ root.options = readOptions(options);
62
+ const children = options.fragment.nodes;
63
+ if (children.length > 0) {
64
+ fail(
65
+ 'svelte_meta_invalid_content',
66
+ {
67
+ start: (children[0] as AST.TemplateNode).start,
68
+ end: (children.at(-1) as AST.TemplateNode).end
69
+ },
70
+ { name: options.name }
71
+ );
72
+ }
73
+ }
74
+
75
+ return { root, ts: parser.ts, options, warnings: parser.warnings, locate };
76
+ }
77
+
78
+ export function parseStylesheet(source: string): AST.Css.StyleSheetFile {
79
+ const scanner = new Scanner(source, false);
80
+ const children = readStylesheet(scanner);
81
+ return {
82
+ type: 'StyleSheetFile',
83
+ start: 0,
84
+ end: source.length,
85
+ children,
86
+ comments: scanner.cssComments
87
+ };
88
+ }
@@ -0,0 +1,284 @@
1
+ import * as acorn from 'acorn';
2
+ import { tsPlugin } from '@sveltejs/acorn-typescript';
3
+ import type { JSComment, Located } from '../ast.ts';
4
+ import { fail } from '../diagnostics.ts';
5
+ import type { Locator } from '../locate.ts';
6
+ import { nonLfLineBreak } from './characters.ts';
7
+
8
+ interface Internals {
9
+ undefinedExports: Record<string, unknown>;
10
+ parseStatement(context: null, topLevel: boolean, exports: object): unknown;
11
+ nextToken(): void;
12
+ }
13
+
14
+ type Constructor = typeof acorn.Parser;
15
+
16
+ function scripted(base: Constructor): Constructor {
17
+ return class extends (base as unknown as new (...args: never[]) => Internals) {
18
+ override parseStatement(context: null, topLevel: boolean, exports: object): unknown {
19
+ const statement = super.parseStatement(context, topLevel, exports);
20
+ this.undefinedExports = {};
21
+ return statement;
22
+ }
23
+ } as unknown as Constructor;
24
+ }
25
+
26
+ const plain = acorn.Parser;
27
+ const typed = plain.extend(tsPlugin());
28
+ const plainScript = scripted(plain);
29
+ const typedScript = scripted(typed);
30
+
31
+ export interface Node extends Located {
32
+ type: string;
33
+ leadingComments?: Attached[];
34
+ trailingComments?: Attached[];
35
+ [key: string]: unknown;
36
+ }
37
+
38
+ interface Attached {
39
+ type: 'Line' | 'Block';
40
+ value: string;
41
+ start: number;
42
+ end: number;
43
+ }
44
+
45
+ export interface Context {
46
+ readonly template: string;
47
+ readonly ts: boolean;
48
+ readonly comments: JSComment[];
49
+ readonly locate: Locator;
50
+ }
51
+
52
+ const nonLf = nonLfLineBreak;
53
+ let lastTemplate = '';
54
+ let lfOnly = true;
55
+
56
+ export function lfLineBreaksOnly(template: string): boolean {
57
+ if (template !== lastTemplate) {
58
+ lastTemplate = template;
59
+ lfOnly = !nonLf.test(template);
60
+ }
61
+ return lfOnly;
62
+ }
63
+
64
+ const positionSuffix = / \(\d+:\d+\)$/;
65
+
66
+ function rethrow(error: unknown): never {
67
+ if (!(error instanceof SyntaxError)) throw error;
68
+ const position = (error as SyntaxError & { pos: number }).pos;
69
+ fail('js_parse_error', position, { message: error.message.replace(positionSuffix, '') });
70
+ }
71
+
72
+ function leading(source: string, start: number): string {
73
+ let lineStart = start;
74
+ while (lineStart > 0 && source[lineStart - 1] !== '\n') lineStart -= 1;
75
+ let end = lineStart;
76
+ while (source[end] === ' ' || source[end] === '\t') end += 1;
77
+ return source.slice(lineStart, end);
78
+ }
79
+
80
+ const trailingGap = /^[,) \t]*$/;
81
+
82
+ class Comments {
83
+ readonly source: string;
84
+ readonly into: JSComment[];
85
+ readonly from: number;
86
+
87
+ constructor(source: string, into: JSComment[], from = 0) {
88
+ this.source = source;
89
+ this.into = into;
90
+ this.from = from;
91
+ }
92
+
93
+ readonly onComment = (
94
+ block: boolean,
95
+ text: string,
96
+ start: number,
97
+ end: number,
98
+ startLoc?: acorn.Position,
99
+ endLoc?: acorn.Position
100
+ ): void => {
101
+ let value = text;
102
+ if (block && value.includes('\n')) {
103
+ const indentation = leading(this.source, start);
104
+ value = value.replace(new RegExp(`^${indentation}`, 'gm'), '');
105
+ }
106
+ this.into.push({
107
+ type: block ? 'Block' : 'Line',
108
+ value,
109
+ start,
110
+ end,
111
+ loc: {
112
+ start: startLoc as acorn.Position,
113
+ end: endLoc as acorn.Position
114
+ }
115
+ });
116
+ };
117
+
118
+ attach(ast: Node): void {
119
+ if (this.into.length === 0) return;
120
+ let first = this.into.length;
121
+ while (first > 0 && (this.into[first - 1] as JSComment).start >= this.from) first--;
122
+ const queue: Attached[] = [];
123
+ for (let index = first; index < this.into.length; index++) {
124
+ const comment = this.into[index] as JSComment;
125
+ queue.push({
126
+ type: comment.type,
127
+ value: comment.value,
128
+ start: comment.start,
129
+ end: comment.end
130
+ });
131
+ }
132
+ let head = 0;
133
+ const source = this.source;
134
+ const path: Node[] = [];
135
+
136
+ const visit = (node: Node, final: boolean): void => {
137
+ while (head < queue.length && (queue[head] as Attached).start < node.start) {
138
+ (node.leadingComments ??= []).push(queue[head++] as Attached);
139
+ }
140
+ path.push(node);
141
+ const listed = lists[node.type];
142
+ for (const key in node) {
143
+ if (key === 'type') continue;
144
+ const child = node[key];
145
+ if (child === null || typeof child !== 'object') continue;
146
+ if (Array.isArray(child)) {
147
+ const tracked = key === listed;
148
+ for (let index = 0; index < child.length; index++) {
149
+ const item = child[index] as Node | null;
150
+ if (item !== null && typeof item === 'object' && item.type) {
151
+ visit(item, tracked && index === child.length - 1);
152
+ }
153
+ }
154
+ } else if ((child as Node).type) {
155
+ visit(child as Node, false);
156
+ }
157
+ }
158
+ path.pop();
159
+ const next = queue[head];
160
+ if (next === undefined) return;
161
+ const parent = path.at(-1) as (Node & Record<string, unknown>) | undefined;
162
+ if (parent !== undefined && node.end === parent.end) return;
163
+ const gap = source.slice(node.end, next.start);
164
+ if (final) {
165
+ while (head < queue.length) {
166
+ const comment = queue[head] as Attached;
167
+ if (parent !== undefined && comment.start >= parent.end) break;
168
+ (node.trailingComments ??= []).push(comment);
169
+ head++;
170
+ }
171
+ } else if (node.end <= next.start && trailingGap.test(gap)) {
172
+ node.trailingComments = [next];
173
+ head++;
174
+ }
175
+ };
176
+
177
+ visit(ast, false);
178
+ if (head < queue.length) {
179
+ const rest = queue[head] as Attached;
180
+ if (rest.start >= ast.end || ast.type === 'Program') {
181
+ (ast.trailingComments ??= []).push(...queue.slice(head));
182
+ }
183
+ }
184
+ }
185
+ }
186
+
187
+ const lists: Readonly<Record<string, string>> = {
188
+ BlockStatement: 'body',
189
+ Program: 'body',
190
+ ArrayExpression: 'elements',
191
+ ObjectExpression: 'properties'
192
+ };
193
+
194
+ function startLocation(context: Context, index: number): acorn.Position | undefined {
195
+ if (!lfLineBreaksOnly(context.template)) return undefined;
196
+ const { line, column } = context.locate(index);
197
+ return { line, column, offset: index } as acorn.Position;
198
+ }
199
+
200
+ export function parseScript(source: string, comments: JSComment[], ts: boolean): Node {
201
+ const parser = ts ? typedScript : plainScript;
202
+ const handler = new Comments(source, comments);
203
+ try {
204
+ const ast = parser.parse(source, {
205
+ onComment: handler.onComment,
206
+ sourceType: 'module',
207
+ ecmaVersion: 16,
208
+ locations: true
209
+ }) as unknown as Node;
210
+ handler.attach(ast);
211
+ return ast;
212
+ } catch (error) {
213
+ rethrow(error);
214
+ }
215
+ }
216
+
217
+ export function parseExpressionAt(context: Context, source: string, index: number): Node {
218
+ const parser = context.ts ? typed : plain;
219
+ const handler = new Comments(source, context.comments, index);
220
+ try {
221
+ const ast = parser.parseExpressionAt(source, index, {
222
+ onComment: handler.onComment,
223
+ sourceType: 'module',
224
+ ecmaVersion: 16,
225
+ locations: true,
226
+ preserveParens: true,
227
+ startLocation: startLocation(context, index)
228
+ } as acorn.Options) as unknown as Node;
229
+ handler.attach(ast);
230
+ return ast;
231
+ } catch (error) {
232
+ rethrow(error);
233
+ }
234
+ }
235
+
236
+ export function parseStatementAt(context: Context, source: string, index: number): Node {
237
+ const Parser = (context.ts ? typed : plain) as unknown as new (
238
+ options: acorn.Options,
239
+ input: string,
240
+ start: number
241
+ ) => Internals;
242
+ const handler = new Comments(source, context.comments, index);
243
+ try {
244
+ const parser = new Parser(
245
+ {
246
+ onComment: handler.onComment,
247
+ sourceType: 'module',
248
+ ecmaVersion: 16,
249
+ locations: true,
250
+ startLocation: startLocation(context, index)
251
+ } as acorn.Options,
252
+ source,
253
+ index
254
+ );
255
+ parser.nextToken();
256
+ const statement = parser.parseStatement(null, true, Object.create(null)) as Node;
257
+ handler.attach(statement);
258
+ return statement;
259
+ } catch (error) {
260
+ if ((error as { pos?: number }).pos === source.length) fail('unexpected_eof', source.length);
261
+ rethrow(error);
262
+ }
263
+ }
264
+
265
+ export function removeParens<T>(node: T): T {
266
+ if (node === null || typeof node !== 'object') return node;
267
+ let current = node as unknown as Node;
268
+ while (current.type === 'ParenthesizedExpression') current = current.expression as Node;
269
+ for (const key in current) {
270
+ if (key === 'type') continue;
271
+ const child = current[key];
272
+ if (child === null || typeof child !== 'object') continue;
273
+ if (Array.isArray(child)) {
274
+ for (let index = 0; index < child.length; index++) {
275
+ const item = child[index] as Node | null;
276
+ if (item !== null && typeof item === 'object' && item.type)
277
+ child[index] = removeParens(item);
278
+ }
279
+ } else if ((child as Node).type) {
280
+ current[key] = removeParens(child);
281
+ }
282
+ }
283
+ return current as unknown as T;
284
+ }