@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,319 @@
1
+ import type * as AST from '../ast.ts';
2
+ import { fail } from '../diagnostics.ts';
3
+ import { decode } from './decode.ts';
4
+ import { readExpression } from './expression.ts';
5
+ import { isWhitespace } from './html.ts';
6
+ import type { Identifier, Parser } from './parser.ts';
7
+
8
+ const unquotedEnd = /(\/>|[\s"'=<>`])/y;
9
+ const quote = /["']/y;
10
+ const staticValue = /(?:"([^"]*)"|'([^'])*'|([^>\s]+))/y;
11
+
12
+ export function isExpressionAttribute(
13
+ attribute: AST.Attribute
14
+ ): attribute is AST.Attribute & { value: AST.ExpressionTag | [AST.ExpressionTag] } {
15
+ const value = attribute.value;
16
+ return (
17
+ value !== true &&
18
+ (!Array.isArray(value) || (value.length === 1 && value[0]?.type === 'ExpressionTag'))
19
+ );
20
+ }
21
+
22
+ export function attributeExpression(attribute: AST.Attribute): AST.Expression {
23
+ const value = attribute.value as AST.ExpressionTag | AST.ExpressionTag[];
24
+ return Array.isArray(value) ? (value[0] as AST.ExpressionTag).expression : value.expression;
25
+ }
26
+
27
+ function attribute(
28
+ name: string,
29
+ loc: AST.NameLocation | null,
30
+ start: number,
31
+ end: number,
32
+ value: AST.AttributeValue
33
+ ): AST.Attribute {
34
+ return { type: 'Attribute', start, end, name, name_loc: loc, value };
35
+ }
36
+
37
+ export function readStaticAttribute(parser: Parser): AST.Attribute | null {
38
+ const start = parser.index;
39
+ const tag = readTag(parser, true);
40
+ if (!tag.name) return null;
41
+ let value: AST.AttributeValue = true;
42
+ if (parser.eat('=')) {
43
+ parser.allowWhitespace();
44
+ let raw = parser.matchRegex(staticValue);
45
+ if (!raw) fail('expected_attribute_value', parser.index);
46
+ parser.index += raw.length;
47
+ const quoted = raw[0] === '"' || raw[0] === "'";
48
+ if (quoted) raw = raw.slice(1, -1);
49
+ value = [
50
+ {
51
+ start: parser.index - raw.length - (quoted ? 1 : 0),
52
+ end: quoted ? parser.index - 1 : parser.index,
53
+ type: 'Text',
54
+ raw,
55
+ data: decode(raw, true)
56
+ }
57
+ ];
58
+ }
59
+ if (parser.matchRegex(quote)) fail('expected_token', parser.index, { token: '=' });
60
+ return attribute(tag.name, tag.loc, start, parser.index, value);
61
+ }
62
+
63
+ function readComment(parser: Parser): AST.JSComment | null {
64
+ const start = parser.index;
65
+ if (parser.eat('//')) {
66
+ const value = parser.readUntil('\n');
67
+ const end = parser.index;
68
+ return { type: 'Line', start, end, value, loc: location(parser, start, end) };
69
+ }
70
+ if (parser.eat('/*')) {
71
+ const value = parser.readUntil('*/');
72
+ parser.eat('*/');
73
+ const end = parser.index;
74
+ return { type: 'Block', start, end, value, loc: location(parser, start, end) };
75
+ }
76
+ return null;
77
+ }
78
+
79
+ function location(parser: Parser, start: number, end: number): AST.NameLocation {
80
+ return { start: parser.locate(start), end: parser.locate(end) };
81
+ }
82
+
83
+ const directives: Readonly<Record<string, AST.DirectiveType>> = {
84
+ use: 'UseDirective',
85
+ animate: 'AnimateDirective',
86
+ bind: 'BindDirective',
87
+ class: 'ClassDirective',
88
+ on: 'OnDirective',
89
+ let: 'LetDirective',
90
+ in: 'TransitionDirective',
91
+ out: 'TransitionDirective',
92
+ transition: 'TransitionDirective'
93
+ };
94
+
95
+ function directiveType(prefix: string): AST.DirectiveType | 'StyleDirective' | null {
96
+ if (prefix === 'style') return 'StyleDirective';
97
+ return Object.hasOwn(directives, prefix) ? (directives[prefix] as AST.DirectiveType) : null;
98
+ }
99
+
100
+ export function readAttribute(parser: Parser): AST.AttributeLike | null {
101
+ for (let comment = readComment(parser); comment !== null; comment = readComment(parser)) {
102
+ parser.comments.push(comment);
103
+ parser.allowWhitespace();
104
+ }
105
+
106
+ const start = parser.index;
107
+
108
+ if (parser.eat('{')) {
109
+ parser.allowWhitespace();
110
+ if (parser.eat('@attach')) {
111
+ parser.requireWhitespace();
112
+ const expression = readExpression(parser);
113
+ parser.allowWhitespace();
114
+ parser.eat('}', true);
115
+ return { type: 'AttachTag', start, end: parser.index, expression };
116
+ }
117
+ if (parser.eat('...')) {
118
+ const expression = readExpression(parser);
119
+ parser.allowWhitespace();
120
+ parser.eat('}', true);
121
+ return { type: 'SpreadAttribute', start, end: parser.index, expression };
122
+ }
123
+ const id = parser.readIdentifier();
124
+ if (id.name === '') {
125
+ if (
126
+ parser.loose &&
127
+ (parser.match('#') || parser.match('/') || parser.match('@') || parser.match(':'))
128
+ ) {
129
+ return null;
130
+ }
131
+ if (!(parser.loose && parser.match('}'))) fail('attribute_empty_shorthand', start);
132
+ }
133
+ parser.allowWhitespace();
134
+ parser.eat('}', true);
135
+ const expression: AST.ExpressionTag = {
136
+ type: 'ExpressionTag',
137
+ start: id.start,
138
+ end: id.end,
139
+ expression: id as AST.Expression
140
+ };
141
+ return attribute(id.name, id.loc, start, parser.index, expression);
142
+ }
143
+
144
+ const tag = readTag(parser, true);
145
+ if (!tag.name) return null;
146
+
147
+ let end = parser.index;
148
+ parser.allowWhitespace();
149
+
150
+ const colon = tag.name.indexOf(':');
151
+ const type = colon === -1 ? null : directiveType(tag.name.slice(0, colon));
152
+
153
+ let value: AST.AttributeValue = true;
154
+ if (parser.eat('=')) {
155
+ parser.allowWhitespace();
156
+ if (parser.template[parser.index] === '/' && parser.template[parser.index + 1] === '>') {
157
+ const at = parser.index++;
158
+ value = [{ start: at, end: at + 1, type: 'Text', raw: '/', data: '/' }];
159
+ } else {
160
+ value = readAttributeValue(parser);
161
+ }
162
+ end = parser.index;
163
+ } else if (parser.matchRegex(quote)) {
164
+ fail('expected_token', parser.index, { token: '=' });
165
+ }
166
+
167
+ if (type === null) return attribute(tag.name, tag.loc, start, end, value);
168
+
169
+ const [name = '', ...modifiers] = tag.name.slice(colon + 1).split('|');
170
+ if (name === '') {
171
+ fail('directive_missing_name', { start, end: start + colon + 1 }, { type: tag.name });
172
+ }
173
+
174
+ if (type === 'StyleDirective') {
175
+ return { start, end, type, name, name_loc: tag.loc, modifiers, value };
176
+ }
177
+
178
+ const first = value === true ? undefined : Array.isArray(value) ? value[0] : value;
179
+ let expression: AST.Expression | null = null;
180
+ if (first !== undefined) {
181
+ if ((value as unknown[]).length > 1 || first.type === 'Text') {
182
+ fail('directive_invalid_value', first.start);
183
+ }
184
+ expression = (first as AST.ExpressionTag).expression;
185
+ }
186
+
187
+ const directive: AST.Directive = {
188
+ start,
189
+ end,
190
+ type,
191
+ name,
192
+ name_loc: tag.loc,
193
+ expression,
194
+ modifiers
195
+ };
196
+ if (type === 'TransitionDirective') {
197
+ const direction = tag.name.slice(0, colon);
198
+ directive.intro = direction === 'in' || direction === 'transition';
199
+ directive.outro = direction === 'out' || direction === 'transition';
200
+ }
201
+ if ((type === 'BindDirective' || type === 'ClassDirective') && directive.expression === null) {
202
+ directive.expression = {
203
+ start: start + colon + 1,
204
+ end,
205
+ type: 'Identifier',
206
+ name: directive.name
207
+ } as AST.Expression;
208
+ }
209
+ return directive;
210
+ }
211
+
212
+ function readAttributeValue(parser: Parser): AST.ExpressionTag | (AST.Text | AST.ExpressionTag)[] {
213
+ const mark = parser.eat("'") ? "'" : parser.eat('"') ? '"' : null;
214
+ if (mark !== null && parser.eat(mark)) {
215
+ return [{ start: parser.index - 1, end: parser.index - 1, type: 'Text', raw: '', data: '' }];
216
+ }
217
+ let value: (AST.Text | AST.ExpressionTag)[];
218
+ try {
219
+ value = readSequence(
220
+ parser,
221
+ () => (mark !== null ? parser.match(mark) : parser.matchRegex(unquotedEnd) !== null),
222
+ 'in attribute value'
223
+ );
224
+ } catch (error) {
225
+ const diagnostic = (error as { diagnostic?: { code: string; start: number } }).diagnostic;
226
+ if (diagnostic?.code === 'js_parse_error') {
227
+ const at = diagnostic.start;
228
+ if (parser.template.slice(at - 1, at + 1) === '/>') {
229
+ parser.index = at;
230
+ fail('expected_token', at, { token: mark ?? '}' });
231
+ }
232
+ }
233
+ throw error;
234
+ }
235
+ if (value.length === 0 && mark === null) fail('expected_attribute_value', parser.index);
236
+ if (mark !== null) parser.index += 1;
237
+ if (mark !== null || value.length > 1 || value[0]?.type === 'Text') return value;
238
+ return value[0] as AST.ExpressionTag;
239
+ }
240
+
241
+ export function readSequence(
242
+ parser: Parser,
243
+ done: () => boolean,
244
+ where: string
245
+ ): (AST.Text | AST.ExpressionTag)[] {
246
+ const chunks: (AST.Text | AST.ExpressionTag)[] = [];
247
+ let chunkStart = parser.index;
248
+ const flush = (end: number): void => {
249
+ if (end > chunkStart) {
250
+ const raw = parser.template.slice(chunkStart, end);
251
+ chunks.push({ start: chunkStart, end, type: 'Text', raw, data: decode(raw, true) });
252
+ }
253
+ };
254
+ while (parser.index < parser.template.length) {
255
+ const index = parser.index;
256
+ if (done()) {
257
+ flush(parser.index);
258
+ return chunks;
259
+ }
260
+ if (parser.eat('{')) {
261
+ if (parser.match('#')) {
262
+ const at = parser.index - 1;
263
+ parser.eat('#');
264
+ fail('block_invalid_placement', at, { name: lowercaseName(parser), location: where });
265
+ } else if (parser.match('@')) {
266
+ const at = parser.index - 1;
267
+ parser.eat('@');
268
+ fail('tag_invalid_placement', at, { name: lowercaseName(parser), location: where });
269
+ }
270
+ flush(parser.index - 1);
271
+ parser.allowWhitespace();
272
+ const expression = readExpression(parser);
273
+ parser.allowWhitespace();
274
+ parser.eat('}', true);
275
+ chunks.push({ type: 'ExpressionTag', start: index, end: parser.index, expression });
276
+ chunkStart = parser.index;
277
+ } else {
278
+ parser.index++;
279
+ }
280
+ }
281
+ if (parser.loose) return chunks;
282
+ fail('unexpected_eof', parser.template.length);
283
+ }
284
+
285
+ export function readTagName(parser: Parser, attribute = false): string {
286
+ const start = parser.index;
287
+ if (start >= parser.template.length && !parser.loose)
288
+ fail('unexpected_eof', parser.template.length);
289
+ while (parser.index < parser.template.length) {
290
+ const code = parser.template.charCodeAt(parser.index);
291
+ if (
292
+ isWhitespace(code) ||
293
+ code === 47 ||
294
+ code === 62 ||
295
+ (attribute && (code === 34 || code === 39 || code === 61))
296
+ ) {
297
+ break;
298
+ }
299
+ parser.index += 1;
300
+ }
301
+ return parser.template.slice(start, parser.index);
302
+ }
303
+
304
+ export function readTag(parser: Parser, attribute = false): Identifier {
305
+ const start = parser.index;
306
+ const name = readTagName(parser, attribute);
307
+ const end = parser.index;
308
+ return { type: 'Identifier', name, start, end, loc: location(parser, start, end) };
309
+ }
310
+
311
+ function lowercaseName(parser: Parser): string {
312
+ const start = parser.index;
313
+ while (parser.index < parser.template.length) {
314
+ const code = parser.template.charCodeAt(parser.index);
315
+ if (code < 97 || code > 122) break;
316
+ parser.index += 1;
317
+ }
318
+ return parser.template.slice(start, parser.index);
319
+ }
@@ -0,0 +1,99 @@
1
+ import { fail } from '../diagnostics.ts';
2
+
3
+ const pairs: Readonly<Record<string, string>> = { '{': '}', '(': ')', '[': ']' };
4
+
5
+ function unescaped(text: string, from: number, char: string): number {
6
+ for (let index = text.indexOf(char, from); index !== -1; index = text.indexOf(char, index + 1)) {
7
+ let slashes = 0;
8
+ for (let back = index - 1; text[back] === '\\'; back--) slashes++;
9
+ if (slashes % 2 === 0) return index;
10
+ }
11
+ return Infinity;
12
+ }
13
+
14
+ function stringEnd(text: string, from: number, quote: string): number {
15
+ if (quote === '`') return unescaped(text, from, quote);
16
+ const line = text.indexOf('\n', from);
17
+ return unescaped(line === -1 ? text : text.slice(0, line), from, quote);
18
+ }
19
+
20
+ function regexEnd(text: string, from: number): number {
21
+ const slash = unescaped(text, from, '/');
22
+ return slash < unescaped(text, from, '\n') ? slash : Infinity;
23
+ }
24
+
25
+ function after(text: string, needle: string, from: number): number {
26
+ const found = text.indexOf(needle, from);
27
+ return (found === -1 ? Infinity : found) + needle.length;
28
+ }
29
+
30
+ export function findMatchingBracket(text: string, from: number, open: string): number | undefined {
31
+ const close = pairs[open];
32
+ let depth = 1;
33
+ let index = from;
34
+ while (depth > 0 && index < text.length) {
35
+ const char = text[index];
36
+ if (char === "'" || char === '"' || char === '`') {
37
+ index = stringEnd(text, index + 1, char) + 1;
38
+ continue;
39
+ }
40
+ if (char === '/') {
41
+ const next = text[index + 1];
42
+ if (next === undefined || next === '') index++;
43
+ else if (next === '/') index = after(text, '\n', index + 1);
44
+ else if (next === '*') index = after(text, '*/', index + 1);
45
+ else {
46
+ const end = regexEnd(text, index + 1) + 1;
47
+ index = end === Infinity ? index + 1 : end;
48
+ }
49
+ continue;
50
+ }
51
+ if (char === open) depth++;
52
+ else if (char === close) depth--;
53
+ if (depth === 0) return index;
54
+ index++;
55
+ }
56
+ return undefined;
57
+ }
58
+
59
+ export function matchBracket(
60
+ template: string,
61
+ start: number,
62
+ brackets: Readonly<Record<string, string>> = pairs
63
+ ): number {
64
+ const closers = new Set(Object.values(brackets));
65
+ const stack: string[] = [];
66
+ let index = start;
67
+ while (index < template.length) {
68
+ const char = template[index++] as string;
69
+ if (char === "'" || char === '"' || char === '`') {
70
+ index = matchQuote(template, index, char);
71
+ continue;
72
+ }
73
+ if (char in brackets) {
74
+ stack.push(char);
75
+ } else if (closers.has(char)) {
76
+ const expected = brackets[stack.pop() as string] as string;
77
+ if (char !== expected) fail('expected_token', index - 1, { token: expected });
78
+ if (stack.length === 0) return index;
79
+ }
80
+ }
81
+ fail('unexpected_eof', template.length);
82
+ }
83
+
84
+ function matchQuote(template: string, start: number, quote: string): number {
85
+ let escaped = false;
86
+ let index = start;
87
+ while (index < template.length) {
88
+ const char = template[index++];
89
+ if (escaped) {
90
+ escaped = false;
91
+ continue;
92
+ }
93
+ if (char === quote) return index;
94
+ if (char === '\\') escaped = true;
95
+ if (quote === '`' && char === '$' && template[index] === '{')
96
+ index = matchBracket(template, index);
97
+ }
98
+ fail('unterminated_string_constant', start);
99
+ }
@@ -0,0 +1,19 @@
1
+ const lineSeparators = String.fromCharCode(0x2028, 0x2029);
2
+
3
+ const bidirectionalControls = String.fromCharCode(
4
+ 0x202a,
5
+ 0x202b,
6
+ 0x202c,
7
+ 0x202d,
8
+ 0x202e,
9
+ 0x2066,
10
+ 0x2067,
11
+ 0x2068,
12
+ 0x2069
13
+ );
14
+
15
+ export const nonLfLineBreak = new RegExp(`\\r(?!\\n)|[${lineSeparators}]`);
16
+
17
+ export const bidirectionalRun = new RegExp(`[${bidirectionalControls}]+`, 'g');
18
+
19
+ export const bidirectionalChar = new RegExp(`[${bidirectionalControls}]`);
@@ -0,0 +1,87 @@
1
+ import { entities } from './entities.ts';
2
+
3
+ const longest = Math.max(...Object.keys(entities).map((name) => name.length));
4
+
5
+ const windows1252 = [
6
+ 8364, 129, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 141, 381, 143, 144, 8216,
7
+ 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 157, 382, 376
8
+ ];
9
+
10
+ function valid(code: number, attribute: boolean): number {
11
+ if (code === 10 && !attribute) return 32;
12
+ if (code < 128) return code;
13
+ if (code <= 159) return windows1252[code - 128] as number;
14
+ if (code < 55296) return code;
15
+ if (code <= 57343) return 0;
16
+ if (code <= 196607) return code;
17
+ if ((code >= 917504 && code <= 917631) || (code >= 917760 && code <= 917999)) return code;
18
+ return 0;
19
+ }
20
+
21
+ const word = /\w/;
22
+
23
+ function isHex(char: string | undefined): boolean {
24
+ return char !== undefined && /[0-9a-fA-F]/.test(char);
25
+ }
26
+
27
+ function isDigit(char: string | undefined): boolean {
28
+ return char !== undefined && char >= '0' && char <= '9';
29
+ }
30
+
31
+ interface Reference {
32
+ readonly end: number;
33
+ readonly code: number;
34
+ }
35
+
36
+ function numeric(text: string, at: number): Reference | null {
37
+ let index = at + 1;
38
+ let code: number;
39
+ if ((text[index] === 'x' || text[index] === 'X') && isHex(text[index + 1])) {
40
+ const from = ++index;
41
+ while (isHex(text[index])) index++;
42
+ code = parseInt(text.slice(from, index), 16);
43
+ } else if (isDigit(text[index])) {
44
+ const from = index;
45
+ while (isDigit(text[index])) index++;
46
+ code = parseInt(text.slice(from, index), 10);
47
+ } else {
48
+ return null;
49
+ }
50
+ if (text[index] === ';') index++;
51
+ return { end: index, code };
52
+ }
53
+
54
+ function named(text: string, at: number, attribute: boolean): Reference | null {
55
+ for (let length = Math.min(longest, text.length - at); length > 0; length--) {
56
+ const name = text.slice(at, at + length);
57
+ const code = entities[name];
58
+ if (code === undefined) continue;
59
+ if (attribute && !name.endsWith(';')) {
60
+ const next = text[at + length];
61
+ if (next !== undefined && (word.test(next) || next === '=')) continue;
62
+ }
63
+ return { end: at + length, code };
64
+ }
65
+ return null;
66
+ }
67
+
68
+ export function decode(text: string, attribute: boolean): string {
69
+ let index = text.indexOf('&');
70
+ if (index === -1) return text;
71
+ let out = '';
72
+ let copied = 0;
73
+ while (index !== -1) {
74
+ const at = index + 1;
75
+ const reference = text[at] === '#' ? numeric(text, at) : named(text, at, attribute);
76
+ if (reference === null) {
77
+ index = text.indexOf('&', at);
78
+ continue;
79
+ }
80
+ if (reference.code) {
81
+ out += text.slice(copied, index) + String.fromCodePoint(valid(reference.code, attribute));
82
+ copied = reference.end;
83
+ }
84
+ index = text.indexOf('&', reference.end);
85
+ }
86
+ return out + text.slice(copied);
87
+ }