@depup/svelte 5.53.3-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (386) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +41 -0
  3. package/action.d.ts +1 -0
  4. package/animate.d.ts +1 -0
  5. package/compiler/index.js +1 -0
  6. package/compiler/package.json +3 -0
  7. package/compiler.d.ts +1 -0
  8. package/easing.d.ts +1 -0
  9. package/elements.d.ts +2078 -0
  10. package/index.d.ts +1 -0
  11. package/legacy.d.ts +1 -0
  12. package/motion.d.ts +1 -0
  13. package/package.json +185 -0
  14. package/src/animate/index.js +78 -0
  15. package/src/attachments/index.js +113 -0
  16. package/src/compiler/errors.js +1719 -0
  17. package/src/compiler/index.js +198 -0
  18. package/src/compiler/legacy.js +637 -0
  19. package/src/compiler/migrate/index.js +1996 -0
  20. package/src/compiler/phases/1-parse/acorn.js +198 -0
  21. package/src/compiler/phases/1-parse/index.js +326 -0
  22. package/src/compiler/phases/1-parse/read/context.js +116 -0
  23. package/src/compiler/phases/1-parse/read/expression.js +93 -0
  24. package/src/compiler/phases/1-parse/read/options.js +263 -0
  25. package/src/compiler/phases/1-parse/read/script.js +97 -0
  26. package/src/compiler/phases/1-parse/read/style.js +637 -0
  27. package/src/compiler/phases/1-parse/remove_typescript_nodes.js +180 -0
  28. package/src/compiler/phases/1-parse/state/element.js +937 -0
  29. package/src/compiler/phases/1-parse/state/fragment.js +17 -0
  30. package/src/compiler/phases/1-parse/state/tag.js +751 -0
  31. package/src/compiler/phases/1-parse/state/text.js +23 -0
  32. package/src/compiler/phases/1-parse/utils/bracket.js +213 -0
  33. package/src/compiler/phases/1-parse/utils/create.js +16 -0
  34. package/src/compiler/phases/1-parse/utils/entities.js +2234 -0
  35. package/src/compiler/phases/1-parse/utils/fuzzymatch.js +281 -0
  36. package/src/compiler/phases/1-parse/utils/html.js +127 -0
  37. package/src/compiler/phases/2-analyze/css/css-analyze.js +331 -0
  38. package/src/compiler/phases/2-analyze/css/css-prune.js +1206 -0
  39. package/src/compiler/phases/2-analyze/css/css-warn.js +47 -0
  40. package/src/compiler/phases/2-analyze/css/utils.js +177 -0
  41. package/src/compiler/phases/2-analyze/index.js +1300 -0
  42. package/src/compiler/phases/2-analyze/utils/check_graph_for_cycles.js +47 -0
  43. package/src/compiler/phases/2-analyze/visitors/AnimateDirective.js +15 -0
  44. package/src/compiler/phases/2-analyze/visitors/ArrowFunctionExpression.js +11 -0
  45. package/src/compiler/phases/2-analyze/visitors/AssignmentExpression.js +31 -0
  46. package/src/compiler/phases/2-analyze/visitors/AttachTag.js +17 -0
  47. package/src/compiler/phases/2-analyze/visitors/Attribute.js +66 -0
  48. package/src/compiler/phases/2-analyze/visitors/AwaitBlock.js +48 -0
  49. package/src/compiler/phases/2-analyze/visitors/AwaitExpression.js +150 -0
  50. package/src/compiler/phases/2-analyze/visitors/BindDirective.js +280 -0
  51. package/src/compiler/phases/2-analyze/visitors/CallExpression.js +339 -0
  52. package/src/compiler/phases/2-analyze/visitors/ClassBody.js +156 -0
  53. package/src/compiler/phases/2-analyze/visitors/ClassDeclaration.js +25 -0
  54. package/src/compiler/phases/2-analyze/visitors/ClassDirective.js +13 -0
  55. package/src/compiler/phases/2-analyze/visitors/Component.js +26 -0
  56. package/src/compiler/phases/2-analyze/visitors/ConstTag.js +45 -0
  57. package/src/compiler/phases/2-analyze/visitors/DebugTag.js +15 -0
  58. package/src/compiler/phases/2-analyze/visitors/EachBlock.js +97 -0
  59. package/src/compiler/phases/2-analyze/visitors/ExportDefaultDeclaration.js +20 -0
  60. package/src/compiler/phases/2-analyze/visitors/ExportNamedDeclaration.js +70 -0
  61. package/src/compiler/phases/2-analyze/visitors/ExportSpecifier.js +30 -0
  62. package/src/compiler/phases/2-analyze/visitors/ExpressionStatement.js +38 -0
  63. package/src/compiler/phases/2-analyze/visitors/ExpressionTag.js +26 -0
  64. package/src/compiler/phases/2-analyze/visitors/Fragment.js +10 -0
  65. package/src/compiler/phases/2-analyze/visitors/FunctionDeclaration.js +16 -0
  66. package/src/compiler/phases/2-analyze/visitors/FunctionExpression.js +11 -0
  67. package/src/compiler/phases/2-analyze/visitors/HtmlTag.js +19 -0
  68. package/src/compiler/phases/2-analyze/visitors/Identifier.js +194 -0
  69. package/src/compiler/phases/2-analyze/visitors/IfBlock.js +46 -0
  70. package/src/compiler/phases/2-analyze/visitors/ImportDeclaration.js +31 -0
  71. package/src/compiler/phases/2-analyze/visitors/KeyBlock.js +21 -0
  72. package/src/compiler/phases/2-analyze/visitors/LabeledStatement.js +95 -0
  73. package/src/compiler/phases/2-analyze/visitors/LetDirective.js +24 -0
  74. package/src/compiler/phases/2-analyze/visitors/Literal.js +14 -0
  75. package/src/compiler/phases/2-analyze/visitors/MemberExpression.js +28 -0
  76. package/src/compiler/phases/2-analyze/visitors/NewExpression.js +17 -0
  77. package/src/compiler/phases/2-analyze/visitors/OnDirective.js +28 -0
  78. package/src/compiler/phases/2-analyze/visitors/PropertyDefinition.js +21 -0
  79. package/src/compiler/phases/2-analyze/visitors/RegularElement.js +240 -0
  80. package/src/compiler/phases/2-analyze/visitors/RenderTag.js +68 -0
  81. package/src/compiler/phases/2-analyze/visitors/SlotElement.js +42 -0
  82. package/src/compiler/phases/2-analyze/visitors/SnippetBlock.js +113 -0
  83. package/src/compiler/phases/2-analyze/visitors/SpreadAttribute.js +13 -0
  84. package/src/compiler/phases/2-analyze/visitors/SpreadElement.js +16 -0
  85. package/src/compiler/phases/2-analyze/visitors/StyleDirective.js +39 -0
  86. package/src/compiler/phases/2-analyze/visitors/SvelteBody.js +22 -0
  87. package/src/compiler/phases/2-analyze/visitors/SvelteBoundary.js +30 -0
  88. package/src/compiler/phases/2-analyze/visitors/SvelteComponent.js +18 -0
  89. package/src/compiler/phases/2-analyze/visitors/SvelteDocument.js +24 -0
  90. package/src/compiler/phases/2-analyze/visitors/SvelteElement.js +78 -0
  91. package/src/compiler/phases/2-analyze/visitors/SvelteFragment.js +27 -0
  92. package/src/compiler/phases/2-analyze/visitors/SvelteHead.js +18 -0
  93. package/src/compiler/phases/2-analyze/visitors/SvelteSelf.js +36 -0
  94. package/src/compiler/phases/2-analyze/visitors/SvelteWindow.js +24 -0
  95. package/src/compiler/phases/2-analyze/visitors/TaggedTemplateExpression.js +16 -0
  96. package/src/compiler/phases/2-analyze/visitors/TemplateElement.js +12 -0
  97. package/src/compiler/phases/2-analyze/visitors/Text.js +52 -0
  98. package/src/compiler/phases/2-analyze/visitors/TitleElement.js +21 -0
  99. package/src/compiler/phases/2-analyze/visitors/TransitionDirective.js +19 -0
  100. package/src/compiler/phases/2-analyze/visitors/UpdateExpression.js +29 -0
  101. package/src/compiler/phases/2-analyze/visitors/UseDirective.js +18 -0
  102. package/src/compiler/phases/2-analyze/visitors/VariableDeclarator.js +160 -0
  103. package/src/compiler/phases/2-analyze/visitors/shared/a11y/constants.js +334 -0
  104. package/src/compiler/phases/2-analyze/visitors/shared/a11y/index.js +981 -0
  105. package/src/compiler/phases/2-analyze/visitors/shared/attribute.js +125 -0
  106. package/src/compiler/phases/2-analyze/visitors/shared/component.js +177 -0
  107. package/src/compiler/phases/2-analyze/visitors/shared/element.js +160 -0
  108. package/src/compiler/phases/2-analyze/visitors/shared/fragment.js +15 -0
  109. package/src/compiler/phases/2-analyze/visitors/shared/function.js +24 -0
  110. package/src/compiler/phases/2-analyze/visitors/shared/snippets.js +17 -0
  111. package/src/compiler/phases/2-analyze/visitors/shared/special-element.js +16 -0
  112. package/src/compiler/phases/2-analyze/visitors/shared/utils.js +301 -0
  113. package/src/compiler/phases/3-transform/client/transform-client.js +719 -0
  114. package/src/compiler/phases/3-transform/client/transform-template/fix-attribute-casing.js +18 -0
  115. package/src/compiler/phases/3-transform/client/transform-template/index.js +67 -0
  116. package/src/compiler/phases/3-transform/client/transform-template/template.js +164 -0
  117. package/src/compiler/phases/3-transform/client/utils.js +181 -0
  118. package/src/compiler/phases/3-transform/client/visitors/AnimateDirective.js +38 -0
  119. package/src/compiler/phases/3-transform/client/visitors/ArrowFunctionExpression.js +11 -0
  120. package/src/compiler/phases/3-transform/client/visitors/AssignmentExpression.js +247 -0
  121. package/src/compiler/phases/3-transform/client/visitors/AttachTag.js +26 -0
  122. package/src/compiler/phases/3-transform/client/visitors/Attribute.js +14 -0
  123. package/src/compiler/phases/3-transform/client/visitors/AwaitBlock.js +124 -0
  124. package/src/compiler/phases/3-transform/client/visitors/AwaitExpression.js +25 -0
  125. package/src/compiler/phases/3-transform/client/visitors/BinaryExpression.js +34 -0
  126. package/src/compiler/phases/3-transform/client/visitors/BindDirective.js +290 -0
  127. package/src/compiler/phases/3-transform/client/visitors/BlockStatement.js +32 -0
  128. package/src/compiler/phases/3-transform/client/visitors/BreakStatement.js +20 -0
  129. package/src/compiler/phases/3-transform/client/visitors/CallExpression.js +136 -0
  130. package/src/compiler/phases/3-transform/client/visitors/ClassBody.js +111 -0
  131. package/src/compiler/phases/3-transform/client/visitors/Comment.js +11 -0
  132. package/src/compiler/phases/3-transform/client/visitors/Component.js +12 -0
  133. package/src/compiler/phases/3-transform/client/visitors/ConstTag.js +134 -0
  134. package/src/compiler/phases/3-transform/client/visitors/DebugTag.js +28 -0
  135. package/src/compiler/phases/3-transform/client/visitors/EachBlock.js +362 -0
  136. package/src/compiler/phases/3-transform/client/visitors/ExportNamedDeclaration.js +19 -0
  137. package/src/compiler/phases/3-transform/client/visitors/ExpressionStatement.js +20 -0
  138. package/src/compiler/phases/3-transform/client/visitors/ForOfStatement.js +25 -0
  139. package/src/compiler/phases/3-transform/client/visitors/Fragment.js +186 -0
  140. package/src/compiler/phases/3-transform/client/visitors/FunctionDeclaration.js +12 -0
  141. package/src/compiler/phases/3-transform/client/visitors/FunctionExpression.js +11 -0
  142. package/src/compiler/phases/3-transform/client/visitors/HtmlTag.js +53 -0
  143. package/src/compiler/phases/3-transform/client/visitors/Identifier.js +45 -0
  144. package/src/compiler/phases/3-transform/client/visitors/IfBlock.js +131 -0
  145. package/src/compiler/phases/3-transform/client/visitors/KeyBlock.js +45 -0
  146. package/src/compiler/phases/3-transform/client/visitors/LabeledStatement.js +64 -0
  147. package/src/compiler/phases/3-transform/client/visitors/LetDirective.js +55 -0
  148. package/src/compiler/phases/3-transform/client/visitors/MemberExpression.js +23 -0
  149. package/src/compiler/phases/3-transform/client/visitors/OnDirective.js +38 -0
  150. package/src/compiler/phases/3-transform/client/visitors/Program.js +153 -0
  151. package/src/compiler/phases/3-transform/client/visitors/RegularElement.js +725 -0
  152. package/src/compiler/phases/3-transform/client/visitors/RenderTag.js +95 -0
  153. package/src/compiler/phases/3-transform/client/visitors/SlotElement.js +94 -0
  154. package/src/compiler/phases/3-transform/client/visitors/SnippetBlock.js +94 -0
  155. package/src/compiler/phases/3-transform/client/visitors/SpreadAttribute.js +10 -0
  156. package/src/compiler/phases/3-transform/client/visitors/SvelteBody.js +11 -0
  157. package/src/compiler/phases/3-transform/client/visitors/SvelteBoundary.js +126 -0
  158. package/src/compiler/phases/3-transform/client/visitors/SvelteComponent.js +13 -0
  159. package/src/compiler/phases/3-transform/client/visitors/SvelteDocument.js +11 -0
  160. package/src/compiler/phases/3-transform/client/visitors/SvelteElement.js +161 -0
  161. package/src/compiler/phases/3-transform/client/visitors/SvelteFragment.js +17 -0
  162. package/src/compiler/phases/3-transform/client/visitors/SvelteHead.js +23 -0
  163. package/src/compiler/phases/3-transform/client/visitors/SvelteSelf.js +13 -0
  164. package/src/compiler/phases/3-transform/client/visitors/SvelteWindow.js +11 -0
  165. package/src/compiler/phases/3-transform/client/visitors/TitleElement.js +48 -0
  166. package/src/compiler/phases/3-transform/client/visitors/TransitionDirective.js +41 -0
  167. package/src/compiler/phases/3-transform/client/visitors/UpdateExpression.js +55 -0
  168. package/src/compiler/phases/3-transform/client/visitors/UseDirective.js +49 -0
  169. package/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js +422 -0
  170. package/src/compiler/phases/3-transform/client/visitors/shared/component.js +536 -0
  171. package/src/compiler/phases/3-transform/client/visitors/shared/declarations.js +53 -0
  172. package/src/compiler/phases/3-transform/client/visitors/shared/element.js +263 -0
  173. package/src/compiler/phases/3-transform/client/visitors/shared/events.js +180 -0
  174. package/src/compiler/phases/3-transform/client/visitors/shared/fragment.js +185 -0
  175. package/src/compiler/phases/3-transform/client/visitors/shared/function.js +17 -0
  176. package/src/compiler/phases/3-transform/client/visitors/shared/special_element.js +22 -0
  177. package/src/compiler/phases/3-transform/client/visitors/shared/utils.js +513 -0
  178. package/src/compiler/phases/3-transform/css/index.js +479 -0
  179. package/src/compiler/phases/3-transform/index.js +118 -0
  180. package/src/compiler/phases/3-transform/server/transform-server.js +428 -0
  181. package/src/compiler/phases/3-transform/server/visitors/AssignmentExpression.js +124 -0
  182. package/src/compiler/phases/3-transform/server/visitors/AwaitBlock.js +36 -0
  183. package/src/compiler/phases/3-transform/server/visitors/AwaitExpression.js +40 -0
  184. package/src/compiler/phases/3-transform/server/visitors/CallExpression.js +71 -0
  185. package/src/compiler/phases/3-transform/server/visitors/ClassBody.js +81 -0
  186. package/src/compiler/phases/3-transform/server/visitors/Component.js +13 -0
  187. package/src/compiler/phases/3-transform/server/visitors/ConstTag.js +49 -0
  188. package/src/compiler/phases/3-transform/server/visitors/DebugTag.js +24 -0
  189. package/src/compiler/phases/3-transform/server/visitors/EachBlock.js +76 -0
  190. package/src/compiler/phases/3-transform/server/visitors/ExpressionStatement.js +23 -0
  191. package/src/compiler/phases/3-transform/server/visitors/Fragment.js +53 -0
  192. package/src/compiler/phases/3-transform/server/visitors/HtmlTag.js +25 -0
  193. package/src/compiler/phases/3-transform/server/visitors/Identifier.js +24 -0
  194. package/src/compiler/phases/3-transform/server/visitors/IfBlock.js +48 -0
  195. package/src/compiler/phases/3-transform/server/visitors/KeyBlock.js +22 -0
  196. package/src/compiler/phases/3-transform/server/visitors/LabeledStatement.js +24 -0
  197. package/src/compiler/phases/3-transform/server/visitors/MemberExpression.js +19 -0
  198. package/src/compiler/phases/3-transform/server/visitors/Program.js +25 -0
  199. package/src/compiler/phases/3-transform/server/visitors/PropertyDefinition.js +37 -0
  200. package/src/compiler/phases/3-transform/server/visitors/RegularElement.js +216 -0
  201. package/src/compiler/phases/3-transform/server/visitors/RenderTag.js +45 -0
  202. package/src/compiler/phases/3-transform/server/visitors/SlotElement.js +68 -0
  203. package/src/compiler/phases/3-transform/server/visitors/SnippetBlock.js +29 -0
  204. package/src/compiler/phases/3-transform/server/visitors/SpreadAttribute.js +10 -0
  205. package/src/compiler/phases/3-transform/server/visitors/SvelteBoundary.js +139 -0
  206. package/src/compiler/phases/3-transform/server/visitors/SvelteComponent.js +12 -0
  207. package/src/compiler/phases/3-transform/server/visitors/SvelteElement.js +89 -0
  208. package/src/compiler/phases/3-transform/server/visitors/SvelteFragment.js +11 -0
  209. package/src/compiler/phases/3-transform/server/visitors/SvelteHead.js +25 -0
  210. package/src/compiler/phases/3-transform/server/visitors/SvelteSelf.js +12 -0
  211. package/src/compiler/phases/3-transform/server/visitors/TitleElement.js +21 -0
  212. package/src/compiler/phases/3-transform/server/visitors/UpdateExpression.js +35 -0
  213. package/src/compiler/phases/3-transform/server/visitors/VariableDeclaration.js +247 -0
  214. package/src/compiler/phases/3-transform/server/visitors/shared/component.js +359 -0
  215. package/src/compiler/phases/3-transform/server/visitors/shared/element.js +557 -0
  216. package/src/compiler/phases/3-transform/server/visitors/shared/utils.js +408 -0
  217. package/src/compiler/phases/3-transform/shared/assignments.js +92 -0
  218. package/src/compiler/phases/3-transform/shared/transform-async.js +114 -0
  219. package/src/compiler/phases/3-transform/utils.js +451 -0
  220. package/src/compiler/phases/bindings.js +227 -0
  221. package/src/compiler/phases/css.js +14 -0
  222. package/src/compiler/phases/nodes.js +258 -0
  223. package/src/compiler/phases/patterns.js +27 -0
  224. package/src/compiler/phases/scope.js +1432 -0
  225. package/src/compiler/preprocess/decode_sourcemap.js +96 -0
  226. package/src/compiler/preprocess/index.js +368 -0
  227. package/src/compiler/preprocess/replace_in_code.js +72 -0
  228. package/src/compiler/print/index.js +911 -0
  229. package/src/compiler/state.js +144 -0
  230. package/src/compiler/utils/assert.js +9 -0
  231. package/src/compiler/utils/ast.js +639 -0
  232. package/src/compiler/utils/builders.js +698 -0
  233. package/src/compiler/utils/compile_diagnostic.js +107 -0
  234. package/src/compiler/utils/extract_svelte_ignore.js +104 -0
  235. package/src/compiler/utils/mapped_code.js +454 -0
  236. package/src/compiler/utils/push_array.js +13 -0
  237. package/src/compiler/utils/sanitize_template_string.js +7 -0
  238. package/src/compiler/utils/slot.js +20 -0
  239. package/src/compiler/utils/string.js +9 -0
  240. package/src/compiler/validate-options.js +324 -0
  241. package/src/compiler/warnings.js +845 -0
  242. package/src/constants.js +66 -0
  243. package/src/easing/index.js +286 -0
  244. package/src/escaping.js +26 -0
  245. package/src/events/index.js +1 -0
  246. package/src/html-tree-validation.js +238 -0
  247. package/src/index-client.js +255 -0
  248. package/src/index-server.js +56 -0
  249. package/src/internal/client/constants.js +77 -0
  250. package/src/internal/client/context.js +258 -0
  251. package/src/internal/client/dev/assign.js +79 -0
  252. package/src/internal/client/dev/console-log.js +37 -0
  253. package/src/internal/client/dev/css.js +31 -0
  254. package/src/internal/client/dev/debug.js +500 -0
  255. package/src/internal/client/dev/elements.js +63 -0
  256. package/src/internal/client/dev/equality.js +101 -0
  257. package/src/internal/client/dev/hmr.js +89 -0
  258. package/src/internal/client/dev/inspect.js +72 -0
  259. package/src/internal/client/dev/legacy.js +25 -0
  260. package/src/internal/client/dev/ownership.js +81 -0
  261. package/src/internal/client/dev/tracing.js +162 -0
  262. package/src/internal/client/dev/validation.js +16 -0
  263. package/src/internal/client/dom/blocks/async.js +71 -0
  264. package/src/internal/client/dom/blocks/await.js +142 -0
  265. package/src/internal/client/dom/blocks/boundary.js +534 -0
  266. package/src/internal/client/dom/blocks/branches.js +227 -0
  267. package/src/internal/client/dom/blocks/css-props.js +28 -0
  268. package/src/internal/client/dom/blocks/each.js +723 -0
  269. package/src/internal/client/dom/blocks/html.js +128 -0
  270. package/src/internal/client/dom/blocks/if.js +82 -0
  271. package/src/internal/client/dom/blocks/key.js +40 -0
  272. package/src/internal/client/dom/blocks/slot.js +44 -0
  273. package/src/internal/client/dom/blocks/snippet.js +103 -0
  274. package/src/internal/client/dom/blocks/svelte-component.js +61 -0
  275. package/src/internal/client/dom/blocks/svelte-element.js +152 -0
  276. package/src/internal/client/dom/blocks/svelte-head.js +61 -0
  277. package/src/internal/client/dom/css.js +33 -0
  278. package/src/internal/client/dom/elements/actions.js +43 -0
  279. package/src/internal/client/dom/elements/attachments.js +33 -0
  280. package/src/internal/client/dom/elements/attributes.js +657 -0
  281. package/src/internal/client/dom/elements/bindings/document.js +17 -0
  282. package/src/internal/client/dom/elements/bindings/input.js +312 -0
  283. package/src/internal/client/dom/elements/bindings/media.js +233 -0
  284. package/src/internal/client/dom/elements/bindings/navigator.js +11 -0
  285. package/src/internal/client/dom/elements/bindings/props.js +22 -0
  286. package/src/internal/client/dom/elements/bindings/select.js +159 -0
  287. package/src/internal/client/dom/elements/bindings/shared.js +76 -0
  288. package/src/internal/client/dom/elements/bindings/size.js +107 -0
  289. package/src/internal/client/dom/elements/bindings/this.js +61 -0
  290. package/src/internal/client/dom/elements/bindings/universal.js +75 -0
  291. package/src/internal/client/dom/elements/bindings/window.js +66 -0
  292. package/src/internal/client/dom/elements/class.js +51 -0
  293. package/src/internal/client/dom/elements/custom-element.js +344 -0
  294. package/src/internal/client/dom/elements/customizable-select.js +99 -0
  295. package/src/internal/client/dom/elements/events.js +355 -0
  296. package/src/internal/client/dom/elements/misc.js +58 -0
  297. package/src/internal/client/dom/elements/style.js +57 -0
  298. package/src/internal/client/dom/elements/transitions.js +471 -0
  299. package/src/internal/client/dom/hydration.js +125 -0
  300. package/src/internal/client/dom/legacy/event-modifiers.js +127 -0
  301. package/src/internal/client/dom/legacy/lifecycle.js +82 -0
  302. package/src/internal/client/dom/legacy/misc.js +68 -0
  303. package/src/internal/client/dom/operations.js +293 -0
  304. package/src/internal/client/dom/reconciler.js +25 -0
  305. package/src/internal/client/dom/task.js +42 -0
  306. package/src/internal/client/dom/template.js +401 -0
  307. package/src/internal/client/error-handling.js +118 -0
  308. package/src/internal/client/errors.js +510 -0
  309. package/src/internal/client/hydratable.js +33 -0
  310. package/src/internal/client/index.js +183 -0
  311. package/src/internal/client/legacy.js +46 -0
  312. package/src/internal/client/loop.js +48 -0
  313. package/src/internal/client/proxy.js +432 -0
  314. package/src/internal/client/reactivity/async.js +306 -0
  315. package/src/internal/client/reactivity/batch.js +1057 -0
  316. package/src/internal/client/reactivity/deriveds.js +426 -0
  317. package/src/internal/client/reactivity/effects.js +718 -0
  318. package/src/internal/client/reactivity/equality.js +31 -0
  319. package/src/internal/client/reactivity/props.js +430 -0
  320. package/src/internal/client/reactivity/sources.js +370 -0
  321. package/src/internal/client/reactivity/status.js +25 -0
  322. package/src/internal/client/reactivity/store.js +203 -0
  323. package/src/internal/client/reactivity/utils.js +40 -0
  324. package/src/internal/client/render.js +335 -0
  325. package/src/internal/client/runtime.js +827 -0
  326. package/src/internal/client/timing.js +16 -0
  327. package/src/internal/client/validate.js +54 -0
  328. package/src/internal/client/warnings.js +271 -0
  329. package/src/internal/disclose-version.js +6 -0
  330. package/src/internal/flags/async.js +3 -0
  331. package/src/internal/flags/index.js +23 -0
  332. package/src/internal/flags/legacy.js +3 -0
  333. package/src/internal/flags/tracing.js +3 -0
  334. package/src/internal/index.js +5 -0
  335. package/src/internal/server/abort-signal.js +13 -0
  336. package/src/internal/server/blocks/html.js +11 -0
  337. package/src/internal/server/blocks/snippet.js +24 -0
  338. package/src/internal/server/context.js +132 -0
  339. package/src/internal/server/crypto.js +45 -0
  340. package/src/internal/server/dev.js +115 -0
  341. package/src/internal/server/errors.js +131 -0
  342. package/src/internal/server/hydratable.js +142 -0
  343. package/src/internal/server/hydration.js +6 -0
  344. package/src/internal/server/index.js +544 -0
  345. package/src/internal/server/render-context.js +86 -0
  346. package/src/internal/server/renderer.js +923 -0
  347. package/src/internal/server/warnings.js +29 -0
  348. package/src/internal/shared/attributes.js +225 -0
  349. package/src/internal/shared/clone.js +137 -0
  350. package/src/internal/shared/dev.js +65 -0
  351. package/src/internal/shared/errors.js +134 -0
  352. package/src/internal/shared/utils.js +144 -0
  353. package/src/internal/shared/validate.js +47 -0
  354. package/src/internal/shared/warnings.js +40 -0
  355. package/src/legacy/legacy-client.js +281 -0
  356. package/src/legacy/legacy-server.js +112 -0
  357. package/src/motion/index.js +32 -0
  358. package/src/motion/spring.js +369 -0
  359. package/src/motion/tweened.js +306 -0
  360. package/src/motion/utils.js +7 -0
  361. package/src/reactivity/create-subscriber.js +95 -0
  362. package/src/reactivity/date.js +118 -0
  363. package/src/reactivity/index-client.js +7 -0
  364. package/src/reactivity/index-server.js +23 -0
  365. package/src/reactivity/map.js +273 -0
  366. package/src/reactivity/media-query.js +55 -0
  367. package/src/reactivity/reactive-value.js +24 -0
  368. package/src/reactivity/set.js +213 -0
  369. package/src/reactivity/url-search-params.js +174 -0
  370. package/src/reactivity/url.js +205 -0
  371. package/src/reactivity/window/index.js +161 -0
  372. package/src/server/index.js +1 -0
  373. package/src/store/index-client.js +169 -0
  374. package/src/store/index-server.js +101 -0
  375. package/src/store/shared/index.js +209 -0
  376. package/src/store/utils.js +36 -0
  377. package/src/transition/index.js +300 -0
  378. package/src/utils.js +504 -0
  379. package/src/version.js +8 -0
  380. package/store.d.ts +1 -0
  381. package/svelte-html.d.ts +245 -0
  382. package/transition.d.ts +1 -0
  383. package/types/compiler/interfaces.d.ts +1 -0
  384. package/types/compiler/preprocess.d.ts +1 -0
  385. package/types/index.d.ts +3744 -0
  386. package/types/index.d.ts.map +280 -0
@@ -0,0 +1,937 @@
1
+ /** @import { Expression, Identifier, SourceLocation } from 'estree' */
2
+ /** @import { Location } from 'locate-character' */
3
+ /** @import { AST } from '#compiler' */
4
+ /** @import { Parser } from '../index.js' */
5
+ import { is_void, REGEX_VALID_TAG_NAME } from '../../../../utils.js';
6
+ import read_expression from '../read/expression.js';
7
+ import { read_script } from '../read/script.js';
8
+ import read_style from '../read/style.js';
9
+ import { decode_character_references } from '../utils/html.js';
10
+ import * as e from '../../../errors.js';
11
+ import * as w from '../../../warnings.js';
12
+ import { create_fragment } from '../utils/create.js';
13
+ import { create_attribute, ExpressionMetadata, is_element_node } from '../../nodes.js';
14
+ import { get_attribute_expression, is_expression_attribute } from '../../../utils/ast.js';
15
+ import { closing_tag_omitted } from '../../../../html-tree-validation.js';
16
+ import { list } from '../../../utils/string.js';
17
+ import { locator } from '../../../state.js';
18
+ import * as b from '#compiler/builders';
19
+
20
+ const regex_invalid_unquoted_attribute_value = /^(\/>|[\s"'=<>`])/;
21
+ const regex_closing_textarea_tag = /^<\/textarea(\s[^>]*)?>/i;
22
+ const regex_closing_comment = /-->/;
23
+ const regex_whitespace_or_slash_or_closing_tag = /(\s|\/|>)/;
24
+ const regex_token_ending_character = /[\s=/>"']/;
25
+ const regex_starts_with_quote_characters = /^["']/;
26
+ const regex_attribute_value = /^(?:"([^"]*)"|'([^'])*'|([^>\s]+))/;
27
+ /** @param {string} name */
28
+ function is_valid_element_name(name) {
29
+ // DOCTYPE (e.g. !DOCTYPE)
30
+ if (/^![a-zA-Z]+$/.test(name)) return true;
31
+ // svelte:* meta tags (e.g. svelte:element, svelte:head)
32
+ if (/^[a-zA-Z][a-zA-Z0-9]*:[a-zA-Z][a-zA-Z0-9-]*[a-zA-Z0-9]$/.test(name)) return true;
33
+ // standard HTML/SVG/MathML elements and custom elements
34
+ return REGEX_VALID_TAG_NAME.test(name);
35
+ }
36
+ export const regex_valid_component_name =
37
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers adjusted for our needs
38
+ // (must start with uppercase letter if no dots, can contain dots)
39
+ /^(?:\p{Lu}[$\u200c\u200d\p{ID_Continue}.]*|\p{ID_Start}[$\u200c\u200d\p{ID_Continue}]*(?:\.[$\u200c\u200d\p{ID_Continue}]+)+)$/u;
40
+
41
+ /** @type {Map<string, AST.ElementLike['type']>} */
42
+ const root_only_meta_tags = new Map([
43
+ ['svelte:head', 'SvelteHead'],
44
+ ['svelte:options', 'SvelteOptions'],
45
+ ['svelte:window', 'SvelteWindow'],
46
+ ['svelte:document', 'SvelteDocument'],
47
+ ['svelte:body', 'SvelteBody']
48
+ ]);
49
+
50
+ /** @type {Map<string, AST.ElementLike['type']>} */
51
+ const meta_tags = new Map([
52
+ ...root_only_meta_tags,
53
+ ['svelte:element', 'SvelteElement'],
54
+ ['svelte:component', 'SvelteComponent'],
55
+ ['svelte:self', 'SvelteSelf'],
56
+ ['svelte:fragment', 'SvelteFragment'],
57
+ ['svelte:boundary', 'SvelteBoundary']
58
+ ]);
59
+
60
+ /** @param {Parser} parser */
61
+ export default function element(parser) {
62
+ const start = parser.index++;
63
+
64
+ let parent = parser.current();
65
+
66
+ if (parser.eat('!--')) {
67
+ const data = parser.read_until(regex_closing_comment);
68
+ parser.eat('-->', true);
69
+
70
+ parser.append({
71
+ type: 'Comment',
72
+ start,
73
+ end: parser.index,
74
+ data
75
+ });
76
+
77
+ return;
78
+ }
79
+
80
+ if (parser.eat('/')) {
81
+ const name = parser.read_until(regex_whitespace_or_slash_or_closing_tag);
82
+
83
+ parser.allow_whitespace();
84
+ parser.eat('>', true);
85
+
86
+ if (is_void(name)) {
87
+ e.void_element_invalid_content(start);
88
+ }
89
+
90
+ // close any elements that don't have their own closing tags, e.g. <div><p></div>
91
+ while (/** @type {AST.RegularElement} */ (parent).name !== name) {
92
+ if (parser.loose) {
93
+ // If the previous element did interpret the next opening tag as an attribute, backtrack
94
+ if (is_element_node(parent)) {
95
+ const last = parent.attributes.at(-1);
96
+ if (last?.type === 'Attribute' && last.name === `<${name}`) {
97
+ parser.index = last.start;
98
+ parent.attributes.pop();
99
+ break;
100
+ }
101
+ }
102
+ }
103
+
104
+ if (parent.type === 'RegularElement') {
105
+ if (!parser.last_auto_closed_tag || parser.last_auto_closed_tag.tag !== name) {
106
+ const end = parent.fragment.nodes[0]?.start ?? start;
107
+ w.element_implicitly_closed(
108
+ { start: parent.start, end },
109
+ `</${name}>`,
110
+ `</${parent.name}>`
111
+ );
112
+ }
113
+ } else if (!parser.loose) {
114
+ if (parser.last_auto_closed_tag && parser.last_auto_closed_tag.tag === name) {
115
+ e.element_invalid_closing_tag_autoclosed(start, name, parser.last_auto_closed_tag.reason);
116
+ } else {
117
+ e.element_invalid_closing_tag(start, name);
118
+ }
119
+ }
120
+
121
+ parent.end = start;
122
+ parser.pop();
123
+
124
+ parent = parser.current();
125
+ }
126
+
127
+ parent.end = parser.index;
128
+ parser.pop();
129
+
130
+ if (parser.last_auto_closed_tag && parser.stack.length < parser.last_auto_closed_tag.depth) {
131
+ parser.last_auto_closed_tag = undefined;
132
+ }
133
+
134
+ return;
135
+ }
136
+
137
+ const tag = read_tag(parser, regex_whitespace_or_slash_or_closing_tag);
138
+
139
+ if (tag.name.startsWith('svelte:') && !meta_tags.has(tag.name)) {
140
+ const bounds = { start: start + 1, end: start + 1 + tag.name.length };
141
+ e.svelte_meta_invalid_tag(bounds, list(Array.from(meta_tags.keys())));
142
+ }
143
+
144
+ if (!is_valid_element_name(tag.name) && !regex_valid_component_name.test(tag.name)) {
145
+ // <div. -> in the middle of typing -> allow in loose mode
146
+ if (!parser.loose || !tag.name.endsWith('.')) {
147
+ const bounds = { start: start + 1, end: start + 1 + tag.name.length };
148
+ e.tag_invalid_name(bounds);
149
+ }
150
+ }
151
+
152
+ if (root_only_meta_tags.has(tag.name)) {
153
+ if (tag.name in parser.meta_tags) {
154
+ e.svelte_meta_duplicate(start, tag.name);
155
+ }
156
+
157
+ if (parent.type !== 'Root') {
158
+ e.svelte_meta_invalid_placement(start, tag.name);
159
+ }
160
+
161
+ parser.meta_tags[tag.name] = true;
162
+ }
163
+
164
+ const type = meta_tags.has(tag.name)
165
+ ? meta_tags.get(tag.name)
166
+ : regex_valid_component_name.test(tag.name) || (parser.loose && tag.name.endsWith('.'))
167
+ ? 'Component'
168
+ : tag.name === 'title' && parent_is_head(parser.stack)
169
+ ? 'TitleElement'
170
+ : // TODO Svelte 6/7: once slots are removed in favor of snippets, always keep slot as a regular element
171
+ tag.name === 'slot' && !parent_is_shadowroot_template(parser.stack)
172
+ ? 'SlotElement'
173
+ : 'RegularElement';
174
+
175
+ /** @type {AST.ElementLike} */
176
+ const element =
177
+ type === 'RegularElement'
178
+ ? {
179
+ type,
180
+ start,
181
+ end: -1,
182
+ name: tag.name,
183
+ name_loc: tag.loc,
184
+ attributes: [],
185
+ fragment: create_fragment(true),
186
+ metadata: {
187
+ svg: false,
188
+ mathml: false,
189
+ scoped: false,
190
+ has_spread: false,
191
+ path: [],
192
+ synthetic_value_node: null
193
+ }
194
+ }
195
+ : /** @type {AST.ElementLike} */ ({
196
+ type,
197
+ start,
198
+ end: -1,
199
+ name: tag.name,
200
+ name_loc: tag.loc,
201
+ attributes: [],
202
+ fragment: create_fragment(true),
203
+ metadata: {
204
+ // unpopulated at first, differs between types
205
+ }
206
+ });
207
+
208
+ parser.allow_whitespace();
209
+
210
+ if (parent.type === 'RegularElement' && closing_tag_omitted(parent.name, tag.name)) {
211
+ const end = parent.fragment.nodes[0]?.start ?? start;
212
+ w.element_implicitly_closed({ start: parent.start, end }, `<${tag.name}>`, `</${parent.name}>`);
213
+ parent.end = start;
214
+ parser.pop();
215
+ parser.last_auto_closed_tag = {
216
+ tag: parent.name,
217
+ reason: tag.name,
218
+ depth: parser.stack.length
219
+ };
220
+ }
221
+
222
+ /** @type {string[]} */
223
+ const unique_names = [];
224
+
225
+ const current = parser.current();
226
+ const is_top_level_script_or_style =
227
+ (tag.name === 'script' || tag.name === 'style') && current.type === 'Root';
228
+
229
+ const read = is_top_level_script_or_style ? read_static_attribute : read_attribute;
230
+
231
+ let attribute;
232
+ while ((attribute = read(parser))) {
233
+ // animate and transition can only be specified once per element so no need
234
+ // to check here, use can be used multiple times, same for the on directive
235
+ // finally let already has error handling in case of duplicate variable names
236
+ if (
237
+ attribute.type === 'Attribute' ||
238
+ attribute.type === 'BindDirective' ||
239
+ attribute.type === 'StyleDirective' ||
240
+ attribute.type === 'ClassDirective'
241
+ ) {
242
+ // `bind:attribute` and `attribute` are just the same but `class:attribute`,
243
+ // `style:attribute` and `attribute` are different and should be allowed together
244
+ // so we concatenate the type while normalizing the type for BindDirective
245
+ const type = attribute.type === 'BindDirective' ? 'Attribute' : attribute.type;
246
+ if (unique_names.includes(type + attribute.name)) {
247
+ e.attribute_duplicate(attribute);
248
+ // <svelte:element bind:this this=..> is allowed
249
+ } else if (attribute.name !== 'this') {
250
+ unique_names.push(type + attribute.name);
251
+ }
252
+ }
253
+
254
+ element.attributes.push(attribute);
255
+ parser.allow_whitespace();
256
+ }
257
+
258
+ if (element.type === 'Component') {
259
+ element.metadata.expression = new ExpressionMetadata();
260
+ }
261
+
262
+ if (element.type === 'SvelteComponent') {
263
+ const index = element.attributes.findIndex(
264
+ /** @param {any} attr */
265
+ (attr) => attr.type === 'Attribute' && attr.name === 'this'
266
+ );
267
+ if (index === -1) {
268
+ e.svelte_component_missing_this(start);
269
+ }
270
+
271
+ const definition = /** @type {AST.Attribute} */ (element.attributes.splice(index, 1)[0]);
272
+ if (!is_expression_attribute(definition)) {
273
+ e.svelte_component_invalid_this(definition.start);
274
+ }
275
+
276
+ element.expression = get_attribute_expression(definition);
277
+ element.metadata.expression = new ExpressionMetadata();
278
+ }
279
+
280
+ if (element.type === 'SvelteElement') {
281
+ const index = element.attributes.findIndex(
282
+ /** @param {any} attr */
283
+ (attr) => attr.type === 'Attribute' && attr.name === 'this'
284
+ );
285
+ if (index === -1) {
286
+ e.svelte_element_missing_this(start);
287
+ }
288
+
289
+ const definition = /** @type {AST.Attribute} */ (element.attributes.splice(index, 1)[0]);
290
+
291
+ if (definition.value === true) {
292
+ e.svelte_element_missing_this(definition);
293
+ }
294
+
295
+ if (!is_expression_attribute(definition)) {
296
+ w.svelte_element_invalid_this(definition);
297
+
298
+ // note that this is wrong, in the case of e.g. `this="h{n}"` — it will result in `<h>`.
299
+ // it would be much better to just error here, but we are preserving the existing buggy
300
+ // Svelte 4 behaviour out of an overabundance of caution regarding breaking changes.
301
+ // TODO in 6.0, error
302
+ const chunk = /** @type {Array<AST.ExpressionTag | AST.Text>} */ (definition.value)[0];
303
+ element.tag =
304
+ chunk.type === 'Text'
305
+ ? {
306
+ type: 'Literal',
307
+ value: chunk.data,
308
+ raw: `'${chunk.raw}'`,
309
+ start: chunk.start,
310
+ end: chunk.end
311
+ }
312
+ : chunk.expression;
313
+ } else {
314
+ element.tag = get_attribute_expression(definition);
315
+ }
316
+
317
+ element.metadata.expression = new ExpressionMetadata();
318
+ }
319
+
320
+ if (is_top_level_script_or_style) {
321
+ parser.eat('>', true);
322
+
323
+ /** @type {AST.Comment | null} */
324
+ let prev_comment = null;
325
+ for (let i = current.fragment.nodes.length - 1; i >= 0; i--) {
326
+ const node = current.fragment.nodes[i];
327
+
328
+ if (i === current.fragment.nodes.length - 1 && node.end !== start) {
329
+ break;
330
+ }
331
+
332
+ if (node.type === 'Comment') {
333
+ prev_comment = node;
334
+ break;
335
+ } else if (node.type !== 'Text' || node.data.trim()) {
336
+ break;
337
+ }
338
+ }
339
+
340
+ if (tag.name === 'script') {
341
+ const content = read_script(parser, start, element.attributes);
342
+ if (prev_comment) {
343
+ // We take advantage of the fact that the root will never have leadingComments set,
344
+ // and set the previous comment to it so that the warning mechanism can later
345
+ // inspect the root and see if there was a html comment before it silencing specific warnings.
346
+ content.content.leadingComments = [{ type: 'Line', value: prev_comment.data }];
347
+ }
348
+
349
+ if (content.context === 'module') {
350
+ if (current.module) e.script_duplicate(start);
351
+ current.module = content;
352
+ } else {
353
+ if (current.instance) e.script_duplicate(start);
354
+ current.instance = content;
355
+ }
356
+ } else {
357
+ const content = read_style(parser, start, element.attributes);
358
+ content.content.comment = prev_comment;
359
+
360
+ if (current.css) e.style_duplicate(start);
361
+ current.css = content;
362
+ }
363
+ return;
364
+ }
365
+
366
+ parser.append(element);
367
+
368
+ const self_closing = parser.eat('/') || is_void(tag.name);
369
+ const closed = parser.eat('>', true, false);
370
+
371
+ // Loose parsing mode
372
+ if (!closed) {
373
+ // We may have eaten an opening `<` of the next element and treated it as an attribute...
374
+ const last = element.attributes.at(-1);
375
+ if (last?.type === 'Attribute' && last.name === '<') {
376
+ parser.index = last.start;
377
+ element.attributes.pop();
378
+ } else {
379
+ // ... or we may have eaten part of a following block ...
380
+ const prev_1 = parser.template[parser.index - 1];
381
+ const prev_2 = parser.template[parser.index - 2];
382
+ const current = parser.template[parser.index];
383
+ if (prev_2 === '{' && prev_1 === '/') {
384
+ parser.index -= 2;
385
+ } else if (prev_1 === '{' && (current === '#' || current === '@' || current === ':')) {
386
+ parser.index -= 1;
387
+ } else {
388
+ // ... or we're followed by whitespace, for example near the end of the template,
389
+ // which we want to take in so that language tools has more room to work with
390
+ parser.allow_whitespace();
391
+ }
392
+ }
393
+ }
394
+
395
+ if (self_closing || !closed) {
396
+ // don't push self-closing elements onto the stack
397
+ element.end = parser.index;
398
+ } else if (tag.name === 'textarea') {
399
+ // special case
400
+ element.fragment.nodes = read_sequence(
401
+ parser,
402
+ () => regex_closing_textarea_tag.test(parser.template.slice(parser.index)),
403
+ 'inside <textarea>'
404
+ );
405
+ parser.read(regex_closing_textarea_tag);
406
+ element.end = parser.index;
407
+ } else if (tag.name === 'script' || tag.name === 'style') {
408
+ // special case
409
+ const start = parser.index;
410
+ const data = parser.read_until(new RegExp(`</${tag.name}>`));
411
+ const end = parser.index;
412
+
413
+ /** @type {AST.Text} */
414
+ const node = {
415
+ start,
416
+ end,
417
+ type: 'Text',
418
+ data,
419
+ raw: data
420
+ };
421
+
422
+ element.fragment.nodes.push(node);
423
+ parser.eat(`</${tag.name}>`, true);
424
+ element.end = parser.index;
425
+ } else {
426
+ parser.stack.push(element);
427
+ parser.fragments.push(element.fragment);
428
+ }
429
+ }
430
+
431
+ /** @param {AST.TemplateNode[]} stack */
432
+ function parent_is_head(stack) {
433
+ let i = stack.length;
434
+ while (i--) {
435
+ const { type } = stack[i];
436
+ if (type === 'SvelteHead') return true;
437
+ if (type === 'RegularElement' || type === 'Component') return false;
438
+ }
439
+ return false;
440
+ }
441
+
442
+ /** @param {AST.TemplateNode[]} stack */
443
+ function parent_is_shadowroot_template(stack) {
444
+ // https://developer.chrome.com/docs/css-ui/declarative-shadow-dom#building_a_declarative_shadow_root
445
+ let i = stack.length;
446
+ while (i--) {
447
+ if (
448
+ stack[i].type === 'RegularElement' &&
449
+ /** @type {AST.RegularElement} */ (stack[i]).attributes.some(
450
+ (a) => a.type === 'Attribute' && a.name === 'shadowrootmode'
451
+ )
452
+ ) {
453
+ return true;
454
+ }
455
+ }
456
+ return false;
457
+ }
458
+
459
+ /**
460
+ * @param {Parser} parser
461
+ * @returns {AST.Attribute | null}
462
+ */
463
+ function read_static_attribute(parser) {
464
+ const start = parser.index;
465
+
466
+ const tag = read_tag(parser, regex_token_ending_character);
467
+ if (!tag.name) return null;
468
+
469
+ /** @type {true | Array<AST.Text | AST.ExpressionTag>} */
470
+ let value = true;
471
+
472
+ if (parser.eat('=')) {
473
+ parser.allow_whitespace();
474
+ let raw = parser.match_regex(regex_attribute_value);
475
+ if (!raw) {
476
+ e.expected_attribute_value(parser.index);
477
+ }
478
+
479
+ parser.index += raw.length;
480
+
481
+ const quoted = raw[0] === '"' || raw[0] === "'";
482
+ if (quoted) {
483
+ raw = raw.slice(1, -1);
484
+ }
485
+
486
+ value = [
487
+ {
488
+ start: parser.index - raw.length - (quoted ? 1 : 0),
489
+ end: quoted ? parser.index - 1 : parser.index,
490
+ type: 'Text',
491
+ raw: raw,
492
+ data: decode_character_references(raw, true)
493
+ }
494
+ ];
495
+ }
496
+
497
+ if (parser.match_regex(regex_starts_with_quote_characters)) {
498
+ e.expected_token(parser.index, '=');
499
+ }
500
+
501
+ return create_attribute(tag.name, tag.loc, start, parser.index, value);
502
+ }
503
+
504
+ /**
505
+ * @param {Parser} parser
506
+ * @returns {AST.Attribute | AST.SpreadAttribute | AST.Directive | AST.AttachTag | null}
507
+ */
508
+ function read_attribute(parser) {
509
+ /** @type {AST.JSComment | null} */
510
+ // eslint-disable-next-line no-useless-assignment -- it is, in fact, eslint that is useless
511
+ let comment = null;
512
+
513
+ while ((comment = read_comment(parser))) {
514
+ parser.root.comments.push(comment);
515
+ parser.allow_whitespace();
516
+ }
517
+
518
+ const start = parser.index;
519
+
520
+ if (parser.eat('{')) {
521
+ parser.allow_whitespace();
522
+
523
+ if (parser.eat('@attach')) {
524
+ parser.require_whitespace();
525
+
526
+ const expression = read_expression(parser);
527
+ parser.allow_whitespace();
528
+ parser.eat('}', true);
529
+
530
+ /** @type {AST.AttachTag} */
531
+ const attachment = {
532
+ type: 'AttachTag',
533
+ start,
534
+ end: parser.index,
535
+ expression,
536
+ metadata: {
537
+ expression: new ExpressionMetadata()
538
+ }
539
+ };
540
+
541
+ return attachment;
542
+ }
543
+
544
+ if (parser.eat('...')) {
545
+ const expression = read_expression(parser);
546
+
547
+ parser.allow_whitespace();
548
+ parser.eat('}', true);
549
+
550
+ /** @type {AST.SpreadAttribute} */
551
+ const spread = {
552
+ type: 'SpreadAttribute',
553
+ start,
554
+ end: parser.index,
555
+ expression,
556
+ metadata: {
557
+ expression: new ExpressionMetadata()
558
+ }
559
+ };
560
+
561
+ return spread;
562
+ } else {
563
+ const id = parser.read_identifier();
564
+
565
+ if (id.name === '') {
566
+ if (
567
+ parser.loose &&
568
+ (parser.match('#') || parser.match('/') || parser.match('@') || parser.match(':'))
569
+ ) {
570
+ // We're likely in an unclosed opening tag and did read part of a block.
571
+ // Return null to not crash the parser so it can continue with closing the tag.
572
+ return null;
573
+ } else if (parser.loose && parser.match('}')) {
574
+ // Likely in the middle of typing, just created the shorthand
575
+ } else {
576
+ e.attribute_empty_shorthand(start);
577
+ }
578
+ }
579
+
580
+ parser.allow_whitespace();
581
+ parser.eat('}', true);
582
+
583
+ /** @type {AST.ExpressionTag} */
584
+ const expression = {
585
+ type: 'ExpressionTag',
586
+ start: id.start,
587
+ end: id.end,
588
+ expression: id,
589
+ metadata: {
590
+ expression: new ExpressionMetadata()
591
+ }
592
+ };
593
+
594
+ return create_attribute(id.name, id.loc, start, parser.index, expression);
595
+ }
596
+ }
597
+
598
+ const tag = read_tag(parser, regex_token_ending_character);
599
+
600
+ if (!tag.name) return null;
601
+
602
+ let end = parser.index;
603
+
604
+ parser.allow_whitespace();
605
+
606
+ const colon_index = tag.name.indexOf(':');
607
+ const type = colon_index !== -1 && get_directive_type(tag.name.slice(0, colon_index));
608
+
609
+ /** @type {true | AST.ExpressionTag | Array<AST.Text | AST.ExpressionTag>} */
610
+ let value = true;
611
+ if (parser.eat('=')) {
612
+ parser.allow_whitespace();
613
+
614
+ if (parser.template[parser.index] === '/' && parser.template[parser.index + 1] === '>') {
615
+ const char_start = parser.index;
616
+ parser.index++; // consume '/'
617
+ value = [
618
+ {
619
+ start: char_start,
620
+ end: char_start + 1,
621
+ type: 'Text',
622
+ raw: '/',
623
+ data: '/'
624
+ }
625
+ ];
626
+ end = parser.index;
627
+ } else {
628
+ value = read_attribute_value(parser);
629
+ end = parser.index;
630
+ }
631
+ } else if (parser.match_regex(regex_starts_with_quote_characters)) {
632
+ e.expected_token(parser.index, '=');
633
+ }
634
+
635
+ if (type) {
636
+ const [directive_name, ...modifiers] = tag.name.slice(colon_index + 1).split('|');
637
+
638
+ if (directive_name === '') {
639
+ e.directive_missing_name({ start, end: start + colon_index + 1 }, tag.name);
640
+ }
641
+
642
+ if (type === 'StyleDirective') {
643
+ return {
644
+ start,
645
+ end,
646
+ type,
647
+ name: directive_name,
648
+ name_loc: tag.loc,
649
+ modifiers: /** @type {Array<'important'>} */ (modifiers),
650
+ value,
651
+ metadata: {
652
+ expression: new ExpressionMetadata()
653
+ }
654
+ };
655
+ }
656
+
657
+ const first_value = value === true ? undefined : Array.isArray(value) ? value[0] : value;
658
+
659
+ /** @type {Expression | null} */
660
+ let expression = null;
661
+
662
+ if (first_value) {
663
+ const attribute_contains_text =
664
+ /** @type {any[]} */ (value).length > 1 || first_value.type === 'Text';
665
+ if (attribute_contains_text) {
666
+ e.directive_invalid_value(/** @type {number} */ (first_value.start));
667
+ } else {
668
+ // TODO throw a parser error in a future version here if this `[ExpressionTag]` instead of `ExpressionTag`,
669
+ // which means stringified value, which isn't allowed for some directives?
670
+ expression = first_value.expression;
671
+ }
672
+ }
673
+
674
+ const directive = /** @type {AST.Directive} */ ({
675
+ start,
676
+ end,
677
+ type,
678
+ name: directive_name,
679
+ name_loc: tag.loc,
680
+ expression,
681
+ metadata: {
682
+ expression: new ExpressionMetadata()
683
+ }
684
+ });
685
+
686
+ // @ts-expect-error we do this separately from the declaration to avoid upsetting typescript
687
+ directive.modifiers = modifiers;
688
+
689
+ if (directive.type === 'TransitionDirective') {
690
+ const direction = tag.name.slice(0, colon_index);
691
+ directive.intro = direction === 'in' || direction === 'transition';
692
+ directive.outro = direction === 'out' || direction === 'transition';
693
+ }
694
+
695
+ // Directive name is expression, e.g. <p class:isRed />
696
+ if (
697
+ (directive.type === 'BindDirective' || directive.type === 'ClassDirective') &&
698
+ !directive.expression
699
+ ) {
700
+ directive.expression = /** @type {any} */ ({
701
+ start: start + colon_index + 1,
702
+ end,
703
+ type: 'Identifier',
704
+ name: directive.name
705
+ });
706
+ }
707
+
708
+ return directive;
709
+ }
710
+
711
+ return create_attribute(tag.name, tag.loc, start, end, value);
712
+ }
713
+
714
+ /**
715
+ * @param {Parser} parser
716
+ * @returns {AST.JSComment | null}
717
+ */
718
+ function read_comment(parser) {
719
+ const start = parser.index;
720
+
721
+ if (parser.eat('//')) {
722
+ const value = parser.read_until(/\n/);
723
+ const end = parser.index;
724
+
725
+ return {
726
+ type: 'Line',
727
+ start,
728
+ end,
729
+ value,
730
+ loc: {
731
+ start: locator(start),
732
+ end: locator(end)
733
+ }
734
+ };
735
+ }
736
+
737
+ if (parser.eat('/*')) {
738
+ const value = parser.read_until(/\*\//);
739
+
740
+ parser.eat('*/');
741
+ const end = parser.index;
742
+
743
+ return {
744
+ type: 'Block',
745
+ start,
746
+ end,
747
+ value,
748
+ loc: {
749
+ start: locator(start),
750
+ end: locator(end)
751
+ }
752
+ };
753
+ }
754
+
755
+ return null;
756
+ }
757
+
758
+ /**
759
+ * @param {string} name
760
+ * @returns {any}
761
+ */
762
+ function get_directive_type(name) {
763
+ if (name === 'use') return 'UseDirective';
764
+ if (name === 'animate') return 'AnimateDirective';
765
+ if (name === 'bind') return 'BindDirective';
766
+ if (name === 'class') return 'ClassDirective';
767
+ if (name === 'style') return 'StyleDirective';
768
+ if (name === 'on') return 'OnDirective';
769
+ if (name === 'let') return 'LetDirective';
770
+ if (name === 'in' || name === 'out' || name === 'transition') return 'TransitionDirective';
771
+ return false;
772
+ }
773
+
774
+ /**
775
+ * @param {Parser} parser
776
+ * @return {AST.ExpressionTag | Array<AST.ExpressionTag | AST.Text>}
777
+ */
778
+ function read_attribute_value(parser) {
779
+ const quote_mark = parser.eat("'") ? "'" : parser.eat('"') ? '"' : null;
780
+ if (quote_mark && parser.eat(quote_mark)) {
781
+ return [
782
+ {
783
+ start: parser.index - 1,
784
+ end: parser.index - 1,
785
+ type: 'Text',
786
+ raw: '',
787
+ data: ''
788
+ }
789
+ ];
790
+ }
791
+
792
+ /** @type {Array<AST.ExpressionTag | AST.Text>} */
793
+ let value;
794
+ try {
795
+ value = read_sequence(
796
+ parser,
797
+ () => {
798
+ // handle common case of quote marks existing outside of regex for performance reasons
799
+ if (quote_mark) return parser.match(quote_mark);
800
+ return !!parser.match_regex(regex_invalid_unquoted_attribute_value);
801
+ },
802
+ 'in attribute value'
803
+ );
804
+ } catch (/** @type {any} */ error) {
805
+ if (error.code === 'js_parse_error') {
806
+ // if the attribute value didn't close + self-closing tag
807
+ // eg: `<Component test={{a:1} />`
808
+ // acorn may throw a `Unterminated regular expression` because of `/>`
809
+ const pos = error.position?.[0];
810
+ if (pos !== undefined && parser.template.slice(pos - 1, pos + 1) === '/>') {
811
+ parser.index = pos;
812
+ e.expected_token(pos, quote_mark || '}');
813
+ }
814
+ }
815
+ throw error;
816
+ }
817
+
818
+ if (value.length === 0 && !quote_mark) {
819
+ e.expected_attribute_value(parser.index);
820
+ }
821
+
822
+ if (quote_mark) parser.index += 1;
823
+
824
+ if (quote_mark || value.length > 1 || value[0].type === 'Text') {
825
+ return value;
826
+ } else {
827
+ return value[0];
828
+ }
829
+ }
830
+
831
+ /**
832
+ * @param {Parser} parser
833
+ * @param {() => boolean} done
834
+ * @param {string} location
835
+ * @returns {any[]}
836
+ */
837
+ function read_sequence(parser, done, location) {
838
+ /** @type {AST.Text} */
839
+ let current_chunk = {
840
+ start: parser.index,
841
+ end: -1,
842
+ type: 'Text',
843
+ raw: '',
844
+ data: ''
845
+ };
846
+
847
+ /** @type {Array<AST.Text | AST.ExpressionTag>} */
848
+ const chunks = [];
849
+
850
+ /** @param {number} end */
851
+ function flush(end) {
852
+ if (current_chunk.raw) {
853
+ current_chunk.data = decode_character_references(current_chunk.raw, true);
854
+ current_chunk.end = end;
855
+ chunks.push(current_chunk);
856
+ }
857
+ }
858
+
859
+ while (parser.index < parser.template.length) {
860
+ const index = parser.index;
861
+
862
+ if (done()) {
863
+ flush(parser.index);
864
+ return chunks;
865
+ } else if (parser.eat('{')) {
866
+ if (parser.match('#')) {
867
+ const index = parser.index - 1;
868
+ parser.eat('#');
869
+ const name = parser.read_until(/[^a-z]/);
870
+ e.block_invalid_placement(index, name, location);
871
+ } else if (parser.match('@')) {
872
+ const index = parser.index - 1;
873
+ parser.eat('@');
874
+ const name = parser.read_until(/[^a-z]/);
875
+ e.tag_invalid_placement(index, name, location);
876
+ }
877
+
878
+ flush(parser.index - 1);
879
+
880
+ parser.allow_whitespace();
881
+ const expression = read_expression(parser);
882
+ parser.allow_whitespace();
883
+ parser.eat('}', true);
884
+
885
+ /** @type {AST.ExpressionTag} */
886
+ const chunk = {
887
+ type: 'ExpressionTag',
888
+ start: index,
889
+ end: parser.index,
890
+ expression,
891
+ metadata: {
892
+ expression: new ExpressionMetadata()
893
+ }
894
+ };
895
+
896
+ chunks.push(chunk);
897
+
898
+ current_chunk = {
899
+ start: parser.index,
900
+ end: -1,
901
+ type: 'Text',
902
+ raw: '',
903
+ data: ''
904
+ };
905
+ } else {
906
+ current_chunk.raw += parser.template[parser.index++];
907
+ }
908
+ }
909
+
910
+ if (parser.loose) {
911
+ return chunks;
912
+ } else {
913
+ e.unexpected_eof(parser.template.length);
914
+ }
915
+ }
916
+
917
+ /**
918
+ * @param {Parser} parser
919
+ * @param {RegExp} regex
920
+ * @returns {Identifier & { start: number, end: number, loc: SourceLocation }}
921
+ */
922
+ function read_tag(parser, regex) {
923
+ const start = parser.index;
924
+ const name = parser.read_until(regex);
925
+ const end = parser.index;
926
+
927
+ return {
928
+ type: 'Identifier',
929
+ name,
930
+ start,
931
+ end,
932
+ loc: {
933
+ start: locator(start),
934
+ end: locator(end)
935
+ }
936
+ };
937
+ }