@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,1432 @@
1
+ /** @import { BinaryOperator, ClassDeclaration, Expression, FunctionDeclaration, Identifier, ImportDeclaration, MemberExpression, LogicalOperator, Node, Pattern, UnaryOperator, VariableDeclarator, Super, SimpleLiteral, FunctionExpression, ArrowFunctionExpression } from 'estree' */
2
+ /** @import { Context, Visitor } from 'zimmerframe' */
3
+ /** @import { AST, BindingKind, DeclarationKind } from '#compiler' */
4
+ import is_reference from 'is-reference';
5
+ import { walk } from 'zimmerframe';
6
+ import { ExpressionMetadata } from './nodes.js';
7
+ import * as b from '#compiler/builders';
8
+ import * as e from '../errors.js';
9
+ import {
10
+ extract_identifiers,
11
+ extract_identifiers_from_destructuring,
12
+ object,
13
+ unwrap_pattern
14
+ } from '../utils/ast.js';
15
+ import { is_reserved, is_rune } from '../../utils.js';
16
+ import { determine_slot } from '../utils/slot.js';
17
+ import { validate_identifier_name } from './2-analyze/visitors/shared/utils.js';
18
+
19
+ const UNKNOWN = Symbol('unknown');
20
+ /** Includes `BigInt` */
21
+ const NUMBER = Symbol('number');
22
+ const STRING = Symbol('string');
23
+ const FUNCTION = Symbol('string');
24
+
25
+ /** @type {Record<string, [type: typeof NUMBER | typeof STRING | typeof UNKNOWN, fn?: Function]>} */
26
+ const globals = {
27
+ BigInt: [NUMBER],
28
+ 'Math.min': [NUMBER, Math.min],
29
+ 'Math.max': [NUMBER, Math.max],
30
+ 'Math.random': [NUMBER],
31
+ 'Math.floor': [NUMBER, Math.floor],
32
+ // @ts-ignore
33
+ 'Math.f16round': [NUMBER, Math.f16round],
34
+ 'Math.round': [NUMBER, Math.round],
35
+ 'Math.abs': [NUMBER, Math.abs],
36
+ 'Math.acos': [NUMBER, Math.acos],
37
+ 'Math.asin': [NUMBER, Math.asin],
38
+ 'Math.atan': [NUMBER, Math.atan],
39
+ 'Math.atan2': [NUMBER, Math.atan2],
40
+ 'Math.ceil': [NUMBER, Math.ceil],
41
+ 'Math.cos': [NUMBER, Math.cos],
42
+ 'Math.sin': [NUMBER, Math.sin],
43
+ 'Math.tan': [NUMBER, Math.tan],
44
+ 'Math.exp': [NUMBER, Math.exp],
45
+ 'Math.log': [NUMBER, Math.log],
46
+ 'Math.pow': [NUMBER, Math.pow],
47
+ 'Math.sqrt': [NUMBER, Math.sqrt],
48
+ 'Math.clz32': [NUMBER, Math.clz32],
49
+ 'Math.imul': [NUMBER, Math.imul],
50
+ 'Math.sign': [NUMBER, Math.sign],
51
+ 'Math.log10': [NUMBER, Math.log10],
52
+ 'Math.log2': [NUMBER, Math.log2],
53
+ 'Math.log1p': [NUMBER, Math.log1p],
54
+ 'Math.expm1': [NUMBER, Math.expm1],
55
+ 'Math.cosh': [NUMBER, Math.cosh],
56
+ 'Math.sinh': [NUMBER, Math.sinh],
57
+ 'Math.tanh': [NUMBER, Math.tanh],
58
+ 'Math.acosh': [NUMBER, Math.acosh],
59
+ 'Math.asinh': [NUMBER, Math.asinh],
60
+ 'Math.atanh': [NUMBER, Math.atanh],
61
+ 'Math.trunc': [NUMBER, Math.trunc],
62
+ 'Math.fround': [NUMBER, Math.fround],
63
+ 'Math.cbrt': [NUMBER, Math.cbrt],
64
+ Number: [NUMBER, Number],
65
+ 'Number.isInteger': [NUMBER, Number.isInteger],
66
+ 'Number.isFinite': [NUMBER, Number.isFinite],
67
+ 'Number.isNaN': [NUMBER, Number.isNaN],
68
+ 'Number.isSafeInteger': [NUMBER, Number.isSafeInteger],
69
+ 'Number.parseFloat': [NUMBER, Number.parseFloat],
70
+ 'Number.parseInt': [NUMBER, Number.parseInt],
71
+ String: [STRING, String],
72
+ 'String.fromCharCode': [STRING, String.fromCharCode],
73
+ 'String.fromCodePoint': [STRING, String.fromCodePoint]
74
+ };
75
+
76
+ /** @type {Record<string, any>} */
77
+ const global_constants = {
78
+ 'Math.PI': Math.PI,
79
+ 'Math.E': Math.E,
80
+ 'Math.LN10': Math.LN10,
81
+ 'Math.LN2': Math.LN2,
82
+ 'Math.LOG10E': Math.LOG10E,
83
+ 'Math.LOG2E': Math.LOG2E,
84
+ 'Math.SQRT2': Math.SQRT2,
85
+ 'Math.SQRT1_2': Math.SQRT1_2
86
+ };
87
+
88
+ export class Binding {
89
+ /** @type {Scope} */
90
+ scope;
91
+
92
+ /** @type {Identifier} */
93
+ node;
94
+
95
+ /** @type {BindingKind} */
96
+ kind;
97
+
98
+ /** @type {DeclarationKind} */
99
+ declaration_kind;
100
+
101
+ /**
102
+ * What the value was initialized with.
103
+ * For destructured props such as `let { foo = 'bar' } = $props()` this is `'bar'` and not `$props()`
104
+ * @type {null | Expression | FunctionDeclaration | ClassDeclaration | ImportDeclaration | AST.EachBlock | AST.SnippetBlock}
105
+ */
106
+ initial = null;
107
+
108
+ /** @type {Array<{ node: Identifier; path: AST.SvelteNode[] }>} */
109
+ references = [];
110
+
111
+ /**
112
+ * (Re)assignments of this binding. Includes declarations such as `function x() {}`.
113
+ * @type {Array<{ value: Expression; scope: Scope }>}
114
+ */
115
+ assignments = [];
116
+
117
+ /**
118
+ * For `legacy_reactive`: its reactive dependencies
119
+ * @type {Binding[]}
120
+ */
121
+ legacy_dependencies = [];
122
+
123
+ /**
124
+ * Bindings that should be invalidated when this binding is invalidated
125
+ * @type {Set<Binding>}
126
+ */
127
+ legacy_indirect_bindings = new Set();
128
+
129
+ /**
130
+ * Legacy props: the `class` in `{ export klass as class}`. $props(): The `class` in { class: klass } = $props()
131
+ * @type {string | null}
132
+ */
133
+ prop_alias = null;
134
+
135
+ /**
136
+ * Additional metadata, varies per binding type
137
+ * @type {null | { inside_rest?: boolean; is_template_declaration?: boolean; exclude_props?: string[] }}
138
+ */
139
+ metadata = null;
140
+
141
+ mutated = false;
142
+ reassigned = false;
143
+
144
+ /**
145
+ * Instance-level declarations may follow (or contain) a top-level `await`. In these cases,
146
+ * any reads that occur in the template must wait for the corresponding promise to resolve
147
+ * otherwise the initial value will not have been assigned.
148
+ * It is a member expression of the form `$$blockers[n]`.
149
+ * TODO the blocker is set during transform which feels a bit grubby
150
+ * @type {MemberExpression | null}
151
+ */
152
+ blocker = null;
153
+
154
+ /**
155
+ *
156
+ * @param {Scope} scope
157
+ * @param {Identifier} node
158
+ * @param {BindingKind} kind
159
+ * @param {DeclarationKind} declaration_kind
160
+ * @param {Binding['initial']} initial
161
+ */
162
+ constructor(scope, node, kind, declaration_kind, initial) {
163
+ this.scope = scope;
164
+ this.node = node;
165
+ this.initial = initial;
166
+ this.kind = kind;
167
+ this.declaration_kind = declaration_kind;
168
+
169
+ if (initial) {
170
+ this.assignments.push({ value: /** @type {Expression} */ (initial), scope });
171
+ }
172
+ }
173
+
174
+ get updated() {
175
+ return this.mutated || this.reassigned;
176
+ }
177
+
178
+ /**
179
+ * @returns {this is Binding & { initial: ArrowFunctionExpression | FunctionDeclaration | FunctionExpression }}
180
+ */
181
+ is_function() {
182
+ if (this.updated) {
183
+ // even if it's reassigned to another function,
184
+ // we can't use it directly as e.g. an event handler
185
+ return false;
186
+ }
187
+
188
+ const type = this.initial?.type;
189
+
190
+ return (
191
+ type === 'ArrowFunctionExpression' ||
192
+ type === 'FunctionExpression' ||
193
+ type === 'FunctionDeclaration'
194
+ );
195
+ }
196
+ }
197
+
198
+ class Evaluation {
199
+ /** @type {Set<any>} */
200
+ values;
201
+
202
+ /**
203
+ * True if there is exactly one possible value
204
+ * @readonly
205
+ * @type {boolean}
206
+ */
207
+ is_known = true;
208
+
209
+ /**
210
+ * True if the possible values contains `UNKNOWN`
211
+ * @readonly
212
+ * @type {boolean}
213
+ */
214
+ has_unknown = false;
215
+
216
+ /**
217
+ * True if the value is known to not be null/undefined
218
+ * @readonly
219
+ * @type {boolean}
220
+ */
221
+ is_defined = true;
222
+
223
+ /**
224
+ * True if the value is known to be a string
225
+ * @readonly
226
+ * @type {boolean}
227
+ */
228
+ is_string = true;
229
+
230
+ /**
231
+ * True if the value is known to be a number
232
+ * @readonly
233
+ * @type {boolean}
234
+ */
235
+ is_number = true;
236
+
237
+ /**
238
+ * True if the value is known to be a primitive
239
+ * @readonly
240
+ * @type {boolean}
241
+ */
242
+ is_primitive = true;
243
+
244
+ /**
245
+ * True if the value is known to be a function
246
+ * @readonly
247
+ * @type {boolean}
248
+ */
249
+ is_function = true;
250
+
251
+ /**
252
+ * @readonly
253
+ * @type {any}
254
+ */
255
+ value = undefined;
256
+
257
+ /**
258
+ *
259
+ * @param {Scope} scope
260
+ * @param {Expression | FunctionDeclaration} expression
261
+ * @param {Set<any>} values
262
+ */
263
+ constructor(scope, expression, values) {
264
+ current_evaluations.set(expression, this);
265
+
266
+ this.values = values;
267
+
268
+ switch (expression.type) {
269
+ case 'Literal': {
270
+ this.values.add(expression.value);
271
+ break;
272
+ }
273
+
274
+ case 'Identifier': {
275
+ const binding = scope.get(expression.name);
276
+
277
+ if (binding) {
278
+ if (
279
+ binding.initial?.type === 'CallExpression' &&
280
+ get_rune(binding.initial, scope) === '$props.id'
281
+ ) {
282
+ this.values.add(STRING);
283
+ break;
284
+ }
285
+
286
+ const is_prop =
287
+ binding.kind === 'prop' ||
288
+ binding.kind === 'rest_prop' ||
289
+ binding.kind === 'bindable_prop';
290
+
291
+ if (binding.initial?.type === 'EachBlock' && binding.initial.index === expression.name) {
292
+ this.values.add(NUMBER);
293
+ break;
294
+ }
295
+
296
+ if (binding.initial?.type === 'SnippetBlock') {
297
+ this.is_defined = true;
298
+ this.is_known = false;
299
+ this.values.add(UNKNOWN);
300
+ break;
301
+ }
302
+
303
+ if (!binding.updated && binding.initial !== null && !is_prop) {
304
+ binding.scope.evaluate(/** @type {Expression} */ (binding.initial), this.values);
305
+ break;
306
+ }
307
+ } else if (expression.name === 'undefined') {
308
+ this.values.add(undefined);
309
+ break;
310
+ }
311
+
312
+ // TODO glean what we can from reassignments
313
+ // TODO one day, expose props and imports somehow
314
+
315
+ this.values.add(UNKNOWN);
316
+ break;
317
+ }
318
+
319
+ case 'BinaryExpression': {
320
+ const a = scope.evaluate(/** @type {Expression} */ (expression.left)); // `left` cannot be `PrivateIdentifier` unless operator is `in`
321
+ const b = scope.evaluate(expression.right);
322
+
323
+ if (a.is_known && b.is_known) {
324
+ this.values.add(binary[expression.operator](a.value, b.value));
325
+ break;
326
+ }
327
+
328
+ switch (expression.operator) {
329
+ case '!=':
330
+ case '!==':
331
+ case '<':
332
+ case '<=':
333
+ case '>':
334
+ case '>=':
335
+ case '==':
336
+ case '===':
337
+ case 'in':
338
+ case 'instanceof':
339
+ this.values.add(true);
340
+ this.values.add(false);
341
+ break;
342
+
343
+ case '%':
344
+ case '&':
345
+ case '*':
346
+ case '**':
347
+ case '-':
348
+ case '/':
349
+ case '<<':
350
+ case '>>':
351
+ case '>>>':
352
+ case '^':
353
+ case '|':
354
+ this.values.add(NUMBER);
355
+ break;
356
+
357
+ case '+':
358
+ if (a.is_string || b.is_string) {
359
+ this.values.add(STRING);
360
+ } else if (a.is_number && b.is_number) {
361
+ this.values.add(NUMBER);
362
+ } else {
363
+ this.values.add(STRING);
364
+ this.values.add(NUMBER);
365
+ }
366
+ break;
367
+
368
+ default:
369
+ this.values.add(UNKNOWN);
370
+ }
371
+ break;
372
+ }
373
+
374
+ case 'ConditionalExpression': {
375
+ const test = scope.evaluate(expression.test);
376
+ const consequent = scope.evaluate(expression.consequent);
377
+ const alternate = scope.evaluate(expression.alternate);
378
+
379
+ if (test.is_known) {
380
+ for (const value of (test.value ? consequent : alternate).values) {
381
+ this.values.add(value);
382
+ }
383
+ } else {
384
+ for (const value of consequent.values) {
385
+ this.values.add(value);
386
+ }
387
+
388
+ for (const value of alternate.values) {
389
+ this.values.add(value);
390
+ }
391
+ }
392
+ break;
393
+ }
394
+
395
+ case 'LogicalExpression': {
396
+ const a = scope.evaluate(expression.left);
397
+ const b = scope.evaluate(expression.right);
398
+
399
+ if (a.is_known) {
400
+ if (b.is_known) {
401
+ this.values.add(logical[expression.operator](a.value, b.value));
402
+ break;
403
+ }
404
+
405
+ if (
406
+ (expression.operator === '&&' && !a.value) ||
407
+ (expression.operator === '||' && a.value) ||
408
+ (expression.operator === '??' && a.value != null)
409
+ ) {
410
+ this.values.add(a.value);
411
+ } else {
412
+ for (const value of b.values) {
413
+ this.values.add(value);
414
+ }
415
+ }
416
+
417
+ break;
418
+ }
419
+
420
+ for (const value of a.values) {
421
+ this.values.add(value);
422
+ }
423
+
424
+ for (const value of b.values) {
425
+ this.values.add(value);
426
+ }
427
+ break;
428
+ }
429
+
430
+ case 'UnaryExpression': {
431
+ const argument = scope.evaluate(expression.argument);
432
+
433
+ if (argument.is_known) {
434
+ this.values.add(unary[expression.operator](argument.value));
435
+ break;
436
+ }
437
+
438
+ switch (expression.operator) {
439
+ case '!':
440
+ case 'delete':
441
+ this.values.add(false);
442
+ this.values.add(true);
443
+ break;
444
+
445
+ case '+':
446
+ case '-':
447
+ case '~':
448
+ this.values.add(NUMBER);
449
+ break;
450
+
451
+ case 'typeof':
452
+ this.values.add(STRING);
453
+ break;
454
+
455
+ case 'void':
456
+ this.values.add(undefined);
457
+ break;
458
+
459
+ default:
460
+ this.values.add(UNKNOWN);
461
+ }
462
+ break;
463
+ }
464
+
465
+ case 'CallExpression': {
466
+ const keypath = get_global_keypath(expression.callee, scope);
467
+
468
+ if (keypath) {
469
+ if (is_rune(keypath)) {
470
+ const arg = /** @type {Expression | undefined} */ (expression.arguments[0]);
471
+
472
+ switch (keypath) {
473
+ case '$state':
474
+ case '$state.raw':
475
+ case '$derived':
476
+ if (arg) {
477
+ scope.evaluate(arg, this.values);
478
+ } else {
479
+ this.values.add(undefined);
480
+ }
481
+ break;
482
+
483
+ case '$props.id':
484
+ this.values.add(STRING);
485
+ break;
486
+
487
+ case '$effect.tracking':
488
+ this.values.add(false);
489
+ this.values.add(true);
490
+ break;
491
+
492
+ case '$derived.by':
493
+ if (arg?.type === 'ArrowFunctionExpression' && arg.body.type !== 'BlockStatement') {
494
+ scope.evaluate(arg.body, this.values);
495
+ break;
496
+ }
497
+
498
+ this.values.add(UNKNOWN);
499
+ break;
500
+
501
+ default: {
502
+ this.values.add(UNKNOWN);
503
+ }
504
+ }
505
+
506
+ break;
507
+ }
508
+
509
+ if (
510
+ Object.hasOwn(globals, keypath) &&
511
+ expression.arguments.every((arg) => arg.type !== 'SpreadElement')
512
+ ) {
513
+ const [type, fn] = globals[keypath];
514
+ const values = expression.arguments.map((arg) => scope.evaluate(arg));
515
+
516
+ if (fn && values.every((e) => e.is_known)) {
517
+ this.values.add(fn(...values.map((e) => e.value)));
518
+ } else {
519
+ this.values.add(type);
520
+ }
521
+
522
+ break;
523
+ }
524
+ }
525
+
526
+ this.values.add(UNKNOWN);
527
+ break;
528
+ }
529
+
530
+ case 'TemplateLiteral': {
531
+ let result = expression.quasis[0].value.cooked;
532
+
533
+ for (let i = 0; i < expression.expressions.length; i += 1) {
534
+ const e = scope.evaluate(expression.expressions[i]);
535
+
536
+ if (e.is_known) {
537
+ result += e.value + expression.quasis[i + 1].value.cooked;
538
+ } else {
539
+ this.values.add(STRING);
540
+ break;
541
+ }
542
+ }
543
+
544
+ this.values.add(result);
545
+ break;
546
+ }
547
+
548
+ case 'MemberExpression': {
549
+ const keypath = get_global_keypath(expression, scope);
550
+
551
+ if (keypath && Object.hasOwn(global_constants, keypath)) {
552
+ this.values.add(global_constants[keypath]);
553
+ break;
554
+ }
555
+
556
+ this.values.add(UNKNOWN);
557
+ break;
558
+ }
559
+
560
+ case 'ArrowFunctionExpression':
561
+ case 'FunctionExpression':
562
+ case 'FunctionDeclaration': {
563
+ this.values.add(FUNCTION);
564
+ break;
565
+ }
566
+
567
+ default: {
568
+ this.values.add(UNKNOWN);
569
+ }
570
+ }
571
+
572
+ for (const value of this.values) {
573
+ this.value = value; // saves having special logic for `size === 1`
574
+
575
+ if (value !== STRING && typeof value !== 'string') {
576
+ this.is_string = false;
577
+ }
578
+
579
+ if (value !== NUMBER && typeof value !== 'number') {
580
+ this.is_number = false;
581
+ }
582
+
583
+ if (value !== FUNCTION) {
584
+ this.is_function = false;
585
+ }
586
+
587
+ if (value == null || value === UNKNOWN) {
588
+ this.is_defined = false;
589
+ }
590
+
591
+ if (value === UNKNOWN) {
592
+ this.has_unknown = true;
593
+ this.is_primitive = false;
594
+ }
595
+ }
596
+
597
+ if (this.values.size > 1 || typeof this.value === 'symbol') {
598
+ this.is_known = false;
599
+ }
600
+
601
+ current_evaluations.delete(expression);
602
+ }
603
+ }
604
+
605
+ export class Scope {
606
+ /** @type {ScopeRoot} */
607
+ root;
608
+
609
+ /**
610
+ * The immediate parent scope
611
+ * @type {Scope | null}
612
+ */
613
+ parent;
614
+
615
+ /**
616
+ * Whether or not `var` declarations are contained by this scope
617
+ * @type {boolean}
618
+ */
619
+ #porous;
620
+
621
+ /**
622
+ * A map of every identifier declared by this scope, and all the
623
+ * identifiers that reference it
624
+ * @type {Map<string, Binding>}
625
+ */
626
+ declarations = new Map();
627
+
628
+ /**
629
+ * A map of declarators to the bindings they declare
630
+ * @type {Map<VariableDeclarator | AST.LetDirective, Binding[]>}
631
+ */
632
+ declarators = new Map();
633
+
634
+ /**
635
+ * A set of all the names referenced with this scope
636
+ * — useful for generating unique names
637
+ * @type {Map<string, { node: Identifier; path: AST.SvelteNode[] }[]>}
638
+ */
639
+ references = new Map();
640
+
641
+ /**
642
+ * The scope depth allows us to determine if a state variable is referenced in its own scope,
643
+ * which is usually an error. Block statements do not increase this value
644
+ */
645
+ function_depth = 0;
646
+
647
+ /**
648
+ * If tracing of reactive dependencies is enabled for this scope
649
+ * @type {null | Expression}
650
+ */
651
+ tracing = null;
652
+
653
+ /**
654
+ *
655
+ * @param {ScopeRoot} root
656
+ * @param {Scope | null} parent
657
+ * @param {boolean} porous
658
+ */
659
+ constructor(root, parent, porous) {
660
+ this.root = root;
661
+ this.parent = parent;
662
+ this.#porous = porous;
663
+ this.function_depth = parent ? parent.function_depth + (porous ? 0 : 1) : 0;
664
+ }
665
+
666
+ /**
667
+ * @param {Identifier} node
668
+ * @param {Binding['kind']} kind
669
+ * @param {DeclarationKind} declaration_kind
670
+ * @param {null | Expression | FunctionDeclaration | ClassDeclaration | ImportDeclaration | AST.EachBlock | AST.SnippetBlock} initial
671
+ * @returns {Binding}
672
+ */
673
+ declare(node, kind, declaration_kind, initial = null) {
674
+ if (this.parent) {
675
+ if (declaration_kind === 'var' && this.#porous) {
676
+ return this.parent.declare(node, kind, declaration_kind);
677
+ }
678
+
679
+ if (declaration_kind === 'import') {
680
+ return this.parent.declare(node, kind, declaration_kind, initial);
681
+ }
682
+ }
683
+
684
+ if (this.declarations.has(node.name)) {
685
+ const binding = this.declarations.get(node.name);
686
+ if (binding && binding.declaration_kind !== 'var' && declaration_kind !== 'var') {
687
+ // This also errors on function types, but that's arguably a good thing
688
+ // declaring function twice is also caught by acorn in the parse phase
689
+ e.declaration_duplicate(node, node.name);
690
+ }
691
+ }
692
+
693
+ const binding = new Binding(this, node, kind, declaration_kind, initial);
694
+
695
+ validate_identifier_name(binding, this.function_depth);
696
+
697
+ this.declarations.set(node.name, binding);
698
+ this.root.conflicts.add(node.name);
699
+ return binding;
700
+ }
701
+
702
+ child(porous = false) {
703
+ return new Scope(this.root, this, porous);
704
+ }
705
+
706
+ /**
707
+ * @param {string} preferred_name
708
+ * @returns {string}
709
+ */
710
+ generate(preferred_name) {
711
+ if (this.#porous) {
712
+ return /** @type {Scope} */ (this.parent).generate(preferred_name);
713
+ }
714
+
715
+ preferred_name = preferred_name.replace(/[^a-zA-Z0-9_$]/g, '_').replace(/^[0-9]/, '_');
716
+ let name = preferred_name;
717
+ let n = 1;
718
+
719
+ while (
720
+ this.references.has(name) ||
721
+ this.declarations.has(name) ||
722
+ this.root.conflicts.has(name) ||
723
+ is_reserved(name)
724
+ ) {
725
+ name = `${preferred_name}_${n++}`;
726
+ }
727
+
728
+ this.references.set(name, []);
729
+ this.root.conflicts.add(name);
730
+ return name;
731
+ }
732
+
733
+ /**
734
+ * @param {string} name
735
+ * @returns {Binding | null}
736
+ */
737
+ get(name) {
738
+ return this.declarations.get(name) ?? this.parent?.get(name) ?? null;
739
+ }
740
+
741
+ /**
742
+ * @param {VariableDeclarator | AST.LetDirective} node
743
+ * @returns {Binding[]}
744
+ */
745
+ get_bindings(node) {
746
+ const bindings = this.declarators.get(node);
747
+ if (!bindings) {
748
+ throw new Error('No binding found for declarator');
749
+ }
750
+ return bindings;
751
+ }
752
+
753
+ /**
754
+ * @param {string} name
755
+ * @returns {Scope | null}
756
+ */
757
+ owner(name) {
758
+ return this.declarations.has(name) ? this : this.parent && this.parent.owner(name);
759
+ }
760
+
761
+ /**
762
+ * @param {Identifier} node
763
+ * @param {AST.SvelteNode[]} path
764
+ */
765
+ reference(node, path) {
766
+ path = [...path]; // ensure that mutations to path afterwards don't affect this reference
767
+ let references = this.references.get(node.name);
768
+
769
+ if (!references) this.references.set(node.name, (references = []));
770
+
771
+ references.push({ node, path });
772
+
773
+ const binding = this.declarations.get(node.name);
774
+ if (binding) {
775
+ binding.references.push({ node, path });
776
+ } else if (this.parent) {
777
+ this.parent.reference(node, path);
778
+ } else {
779
+ // no binding was found, and this is the top level scope,
780
+ // which means this is a global
781
+ this.root.conflicts.add(node.name);
782
+ }
783
+ }
784
+
785
+ /**
786
+ * Does partial evaluation to find an exact value or at least the rough type of the expression.
787
+ * Only call this once scope has been fully generated in a first pass,
788
+ * else this evaluates on incomplete data and may yield wrong results.
789
+ * @param {Expression} expression
790
+ * @param {Set<any>} [values]
791
+ */
792
+ evaluate(expression, values = new Set()) {
793
+ const current = current_evaluations.get(expression);
794
+ if (current) return current;
795
+
796
+ return new Evaluation(this, expression, values);
797
+ }
798
+ }
799
+
800
+ /**
801
+ * Track which expressions are currently being evaluated — this allows
802
+ * us to prevent cyclical evaluations without passing the map around
803
+ * @type {Map<Expression | FunctionDeclaration, Evaluation>}
804
+ */
805
+ const current_evaluations = new Map();
806
+
807
+ /** @type {Record<BinaryOperator, (left: any, right: any) => any>} */
808
+ const binary = {
809
+ '!=': (left, right) => left != right,
810
+ '!==': (left, right) => left !== right,
811
+ '<': (left, right) => left < right,
812
+ '<=': (left, right) => left <= right,
813
+ '>': (left, right) => left > right,
814
+ '>=': (left, right) => left >= right,
815
+ '==': (left, right) => left == right,
816
+ '===': (left, right) => left === right,
817
+ in: (left, right) => left in right,
818
+ instanceof: (left, right) => left instanceof right,
819
+ '%': (left, right) => left % right,
820
+ '&': (left, right) => left & right,
821
+ '*': (left, right) => left * right,
822
+ '**': (left, right) => left ** right,
823
+ '+': (left, right) => left + right,
824
+ '-': (left, right) => left - right,
825
+ '/': (left, right) => left / right,
826
+ '<<': (left, right) => left << right,
827
+ '>>': (left, right) => left >> right,
828
+ '>>>': (left, right) => left >>> right,
829
+ '^': (left, right) => left ^ right,
830
+ '|': (left, right) => left | right
831
+ };
832
+
833
+ /** @type {Record<UnaryOperator, (argument: any) => any>} */
834
+ const unary = {
835
+ '-': (argument) => -argument,
836
+ '+': (argument) => +argument,
837
+ '!': (argument) => !argument,
838
+ '~': (argument) => ~argument,
839
+ typeof: (argument) => typeof argument,
840
+ void: () => undefined,
841
+ delete: () => true
842
+ };
843
+
844
+ /** @type {Record<LogicalOperator, (left: any, right: any) => any>} */
845
+ const logical = {
846
+ '||': (left, right) => left || right,
847
+ '&&': (left, right) => left && right,
848
+ '??': (left, right) => left ?? right
849
+ };
850
+
851
+ export class ScopeRoot {
852
+ /** @type {Set<string>} */
853
+ conflicts = new Set();
854
+
855
+ /**
856
+ * @param {string} preferred_name
857
+ */
858
+ unique(preferred_name) {
859
+ preferred_name = preferred_name.replace(/[^a-zA-Z0-9_$]/g, '_');
860
+ let final_name = preferred_name;
861
+ let n = 1;
862
+
863
+ while (this.conflicts.has(final_name)) {
864
+ final_name = `${preferred_name}_${n++}`;
865
+ }
866
+
867
+ this.conflicts.add(final_name);
868
+ const id = b.id(final_name);
869
+ return id;
870
+ }
871
+ }
872
+
873
+ /**
874
+ * @param {AST.SvelteNode} ast
875
+ * @param {ScopeRoot} root
876
+ * @param {boolean} allow_reactive_declarations
877
+ * @param {Scope | null} parent
878
+ */
879
+ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
880
+ /** @typedef {{ scope: Scope }} State */
881
+
882
+ /**
883
+ * A map of node->associated scope. A node appearing in this map does not necessarily mean that it created a scope
884
+ * @type {Map<AST.SvelteNode, Scope>}
885
+ */
886
+ const scopes = new Map();
887
+ const scope = new Scope(root, parent, false);
888
+ scopes.set(ast, scope);
889
+
890
+ /** @type {State} */
891
+ const state = { scope };
892
+
893
+ /** @type {[Scope, { node: Identifier; path: AST.SvelteNode[] }][]} */
894
+ const references = [];
895
+
896
+ /** @type {[Scope, Pattern | MemberExpression, Expression][]} */
897
+ const updates = [];
898
+
899
+ /**
900
+ * An array of reactive declarations, i.e. the `a` in `$: a = b * 2`
901
+ * @type {Identifier[]}
902
+ */
903
+ const possible_implicit_declarations = [];
904
+
905
+ /**
906
+ * @param {Scope} scope
907
+ * @param {Pattern[]} params
908
+ */
909
+ function add_params(scope, params) {
910
+ for (const param of params) {
911
+ for (const node of extract_identifiers(param)) {
912
+ scope.declare(node, 'normal', param.type === 'RestElement' ? 'rest_param' : 'param');
913
+ }
914
+ }
915
+ }
916
+
917
+ /**
918
+ * @type {Visitor<Node, State, AST.SvelteNode>}
919
+ */
920
+ const create_block_scope = (node, { state, next }) => {
921
+ const scope = state.scope.child(true);
922
+ scopes.set(node, scope);
923
+
924
+ next({ scope });
925
+ };
926
+
927
+ /**
928
+ * @type {Visitor<AST.ElementLike, State, AST.SvelteNode>}
929
+ */
930
+ const SvelteFragment = (node, { state, next }) => {
931
+ const scope = state.scope.child();
932
+ scopes.set(node, scope);
933
+ next({ scope });
934
+ };
935
+
936
+ /**
937
+ * @type {Visitor<AST.Component | AST.SvelteComponent | AST.SvelteSelf, State, AST.SvelteNode>}
938
+ */
939
+ const Component = (node, context) => {
940
+ node.metadata.scopes = {
941
+ default: context.state.scope.child()
942
+ };
943
+
944
+ if (node.type === 'SvelteComponent') {
945
+ context.visit(node.expression);
946
+ }
947
+
948
+ const default_state = determine_slot(node)
949
+ ? context.state
950
+ : { scope: node.metadata.scopes.default };
951
+
952
+ for (const attribute of node.attributes) {
953
+ if (attribute.type === 'LetDirective') {
954
+ context.visit(attribute, default_state);
955
+ } else {
956
+ context.visit(attribute);
957
+ }
958
+ }
959
+
960
+ for (const child of node.fragment.nodes) {
961
+ let state = default_state;
962
+
963
+ const slot_name = determine_slot(child);
964
+
965
+ if (slot_name !== null) {
966
+ node.metadata.scopes[slot_name] = context.state.scope.child();
967
+
968
+ state = {
969
+ scope: node.metadata.scopes[slot_name]
970
+ };
971
+ }
972
+
973
+ context.visit(child, state);
974
+ }
975
+ };
976
+
977
+ /**
978
+ * @type {Visitor<AST.AnimateDirective | AST.TransitionDirective | AST.UseDirective, State, AST.SvelteNode>}
979
+ */
980
+ const SvelteDirective = (node, { state, path, visit }) => {
981
+ state.scope.reference(b.id(node.name.split('.')[0]), path);
982
+
983
+ if (node.expression) {
984
+ visit(node.expression);
985
+ }
986
+ };
987
+
988
+ let has_await = false;
989
+
990
+ walk(ast, state, {
991
+ AwaitExpression(node, context) {
992
+ // this doesn't _really_ belong here, but it allows us to
993
+ // automatically opt into runes mode on encountering
994
+ // blocking awaits, without doing an additional walk
995
+ // before the analysis occurs
996
+ // TODO remove this in Svelte 7.0 or whenever we get rid of legacy support
997
+ has_await ||= context.path.every(
998
+ ({ type }) =>
999
+ type !== 'ArrowFunctionExpression' &&
1000
+ type !== 'FunctionExpression' &&
1001
+ type !== 'FunctionDeclaration'
1002
+ );
1003
+
1004
+ context.next();
1005
+ },
1006
+
1007
+ // references
1008
+ Identifier(node, { path, state }) {
1009
+ const parent = path.at(-1);
1010
+ if (
1011
+ parent &&
1012
+ is_reference(node, /** @type {Node} */ (parent)) &&
1013
+ // TSTypeAnnotation, TSInterfaceDeclaration etc - these are normally already filtered out,
1014
+ // but for the migration they aren't, so we need to filter them out here
1015
+ // TODO -> once migration script is gone we can remove this check
1016
+ !parent.type.startsWith('TS')
1017
+ ) {
1018
+ references.push([state.scope, { node, path: path.slice() }]);
1019
+ }
1020
+ },
1021
+ LabeledStatement(node, { path, next }) {
1022
+ if (path.length > 1 || !allow_reactive_declarations) return next();
1023
+ if (node.label.name !== '$') return next();
1024
+
1025
+ // create a scope for the $: block
1026
+ const scope = state.scope.child();
1027
+ scopes.set(node, scope);
1028
+
1029
+ if (
1030
+ node.body.type === 'ExpressionStatement' &&
1031
+ node.body.expression.type === 'AssignmentExpression'
1032
+ ) {
1033
+ for (const id of extract_identifiers(node.body.expression.left)) {
1034
+ if (!id.name.startsWith('$')) {
1035
+ possible_implicit_declarations.push(id);
1036
+ }
1037
+ }
1038
+ }
1039
+
1040
+ next({ scope });
1041
+ },
1042
+
1043
+ SvelteFragment,
1044
+ SlotElement: SvelteFragment,
1045
+ SvelteElement: SvelteFragment,
1046
+ RegularElement: SvelteFragment,
1047
+
1048
+ LetDirective(node, context) {
1049
+ const scope = context.state.scope;
1050
+
1051
+ /** @type {Binding[]} */
1052
+ const bindings = [];
1053
+ scope.declarators.set(node, bindings);
1054
+
1055
+ if (node.expression) {
1056
+ for (const id of extract_identifiers_from_destructuring(node.expression)) {
1057
+ const binding = scope.declare(id, 'template', 'const');
1058
+ scope.reference(id, [context.path[context.path.length - 1], node]);
1059
+ bindings.push(binding);
1060
+ }
1061
+ } else {
1062
+ /** @type {Identifier} */
1063
+ const id = {
1064
+ name: node.name,
1065
+ type: 'Identifier',
1066
+ start: node.start,
1067
+ end: node.end
1068
+ };
1069
+ const binding = scope.declare(id, 'template', 'const');
1070
+ scope.reference(id, [context.path[context.path.length - 1], node]);
1071
+ bindings.push(binding);
1072
+ }
1073
+ },
1074
+
1075
+ Component: (node, context) => {
1076
+ context.state.scope.reference(b.id(node.name.split('.')[0]), context.path);
1077
+ Component(node, context);
1078
+ },
1079
+ SvelteSelf: Component,
1080
+ SvelteComponent: Component,
1081
+
1082
+ // updates
1083
+ AssignmentExpression(node, { state, next }) {
1084
+ updates.push([state.scope, node.left, node.right]);
1085
+ next();
1086
+ },
1087
+
1088
+ UpdateExpression(node, { state, next }) {
1089
+ const expression = /** @type {Identifier | MemberExpression} */ (node.argument);
1090
+ updates.push([state.scope, expression, expression]);
1091
+ next();
1092
+ },
1093
+
1094
+ ImportDeclaration(node, { state }) {
1095
+ for (const specifier of node.specifiers) {
1096
+ state.scope.declare(specifier.local, 'normal', 'import', node);
1097
+ }
1098
+ },
1099
+
1100
+ FunctionExpression(node, { state, next }) {
1101
+ const scope = state.scope.child();
1102
+ scopes.set(node, scope);
1103
+
1104
+ if (node.id) {
1105
+ scopes.set(node.id, state.scope); // so that declarations within with the same name are not confused with the function name
1106
+ scope.declare(node.id, 'normal', 'function');
1107
+ }
1108
+
1109
+ add_params(scope, node.params);
1110
+ next({ scope });
1111
+ },
1112
+
1113
+ FunctionDeclaration(node, { state, next }) {
1114
+ if (node.id) {
1115
+ scopes.set(node.id, state.scope); // so that declarations within with the same name are not confused with the function name
1116
+ state.scope.declare(node.id, 'normal', 'function', node);
1117
+ }
1118
+
1119
+ const scope = state.scope.child();
1120
+ scopes.set(node, scope);
1121
+
1122
+ add_params(scope, node.params);
1123
+ next({ scope });
1124
+ },
1125
+
1126
+ ArrowFunctionExpression(node, { state, next }) {
1127
+ const scope = state.scope.child();
1128
+ scopes.set(node, scope);
1129
+
1130
+ add_params(scope, node.params);
1131
+ next({ scope });
1132
+ },
1133
+
1134
+ ForStatement: create_block_scope,
1135
+ ForInStatement: create_block_scope,
1136
+ ForOfStatement: create_block_scope,
1137
+ SwitchStatement: create_block_scope,
1138
+ BlockStatement(node, context) {
1139
+ const parent = context.path.at(-1);
1140
+ if (
1141
+ parent?.type === 'FunctionDeclaration' ||
1142
+ parent?.type === 'FunctionExpression' ||
1143
+ parent?.type === 'ArrowFunctionExpression'
1144
+ ) {
1145
+ // We already created a new scope for the function
1146
+ context.next();
1147
+ } else {
1148
+ create_block_scope(node, context);
1149
+ }
1150
+ },
1151
+
1152
+ ClassDeclaration(node, { state, next }) {
1153
+ if (node.id) state.scope.declare(node.id, 'normal', 'let', node);
1154
+ next();
1155
+ },
1156
+
1157
+ VariableDeclaration(node, { state, path, next }) {
1158
+ const is_parent_const_tag = path.at(-1)?.type === 'ConstTag';
1159
+ for (const declarator of node.declarations) {
1160
+ /** @type {Binding[]} */
1161
+ const bindings = [];
1162
+
1163
+ state.scope.declarators.set(declarator, bindings);
1164
+
1165
+ for (const id of extract_identifiers(declarator.id)) {
1166
+ const binding = state.scope.declare(
1167
+ id,
1168
+ is_parent_const_tag ? 'template' : 'normal',
1169
+ node.kind,
1170
+ declarator.init
1171
+ );
1172
+ binding.metadata = { is_template_declaration: true };
1173
+ bindings.push(binding);
1174
+ }
1175
+ }
1176
+
1177
+ next();
1178
+ },
1179
+
1180
+ CatchClause(node, { state, next }) {
1181
+ if (node.param) {
1182
+ const scope = state.scope.child(true);
1183
+ scopes.set(node, scope);
1184
+
1185
+ for (const id of extract_identifiers(node.param)) {
1186
+ scope.declare(id, 'normal', 'let');
1187
+ }
1188
+
1189
+ next({ scope });
1190
+ } else {
1191
+ next();
1192
+ }
1193
+ },
1194
+
1195
+ EachBlock(node, { state, visit }) {
1196
+ visit(node.expression);
1197
+
1198
+ // context and children are a new scope
1199
+ const scope = state.scope.child();
1200
+ scopes.set(node, scope);
1201
+
1202
+ if (node.context) {
1203
+ // declarations
1204
+ for (const id of extract_identifiers(node.context)) {
1205
+ const binding = scope.declare(id, 'each', 'const');
1206
+
1207
+ let inside_rest = false;
1208
+ let is_rest_id = false;
1209
+ walk(node.context, null, {
1210
+ Identifier(node) {
1211
+ if (inside_rest && node === id) {
1212
+ is_rest_id = true;
1213
+ }
1214
+ },
1215
+ RestElement(_, { next }) {
1216
+ const prev = inside_rest;
1217
+ inside_rest = true;
1218
+ next();
1219
+ inside_rest = prev;
1220
+ }
1221
+ });
1222
+
1223
+ binding.metadata = { inside_rest: is_rest_id };
1224
+ }
1225
+
1226
+ // Visit to pick up references from default initializers
1227
+ visit(node.context, { scope });
1228
+ }
1229
+
1230
+ if (node.index) {
1231
+ const is_keyed =
1232
+ node.key &&
1233
+ (node.key.type !== 'Identifier' || !node.index || node.key.name !== node.index);
1234
+ scope.declare(b.id(node.index), is_keyed ? 'template' : 'static', 'const', node);
1235
+ }
1236
+ if (node.key) visit(node.key, { scope });
1237
+
1238
+ // children
1239
+ for (const child of node.body.nodes) {
1240
+ visit(child, { scope });
1241
+ }
1242
+ if (node.fallback) visit(node.fallback, { scope });
1243
+
1244
+ node.metadata = {
1245
+ expression: new ExpressionMetadata(),
1246
+ keyed: false,
1247
+ contains_group_binding: false,
1248
+ index: scope.root.unique('$$index'),
1249
+ declarations: scope.declarations,
1250
+ is_controlled: false,
1251
+ // filled in during analysis
1252
+ transitive_deps: new Set()
1253
+ };
1254
+ },
1255
+
1256
+ AwaitBlock(node, context) {
1257
+ context.visit(node.expression);
1258
+
1259
+ if (node.pending) {
1260
+ context.visit(node.pending);
1261
+ }
1262
+
1263
+ if (node.then) {
1264
+ context.visit(node.then);
1265
+ if (node.value) {
1266
+ const then_scope = /** @type {Scope} */ (scopes.get(node.then));
1267
+ const value_scope = context.state.scope.child();
1268
+ scopes.set(node.value, value_scope);
1269
+ context.visit(node.value, { scope: value_scope });
1270
+ for (const id of extract_identifiers(node.value)) {
1271
+ then_scope.declare(id, 'template', 'const');
1272
+ value_scope.declare(id, 'normal', 'const');
1273
+ }
1274
+ }
1275
+ }
1276
+
1277
+ if (node.catch) {
1278
+ context.visit(node.catch);
1279
+ if (node.error) {
1280
+ const catch_scope = /** @type {Scope} */ (scopes.get(node.catch));
1281
+ const error_scope = context.state.scope.child();
1282
+ scopes.set(node.error, error_scope);
1283
+ context.visit(node.error, { scope: error_scope });
1284
+ for (const id of extract_identifiers(node.error)) {
1285
+ catch_scope.declare(id, 'template', 'const');
1286
+ error_scope.declare(id, 'normal', 'const');
1287
+ }
1288
+ }
1289
+ }
1290
+ },
1291
+
1292
+ SnippetBlock(node, context) {
1293
+ const state = context.state;
1294
+ let scope = state.scope;
1295
+
1296
+ scope.declare(node.expression, 'normal', 'function', node);
1297
+
1298
+ const child_scope = state.scope.child();
1299
+ scopes.set(node, child_scope);
1300
+
1301
+ for (const param of node.parameters) {
1302
+ for (const id of extract_identifiers(param)) {
1303
+ child_scope.declare(id, 'snippet', 'let');
1304
+ }
1305
+ }
1306
+
1307
+ context.next({ scope: child_scope });
1308
+ },
1309
+
1310
+ Fragment: (node, context) => {
1311
+ const scope = context.state.scope.child(node.metadata.transparent);
1312
+ scopes.set(node, scope);
1313
+ context.next({ scope });
1314
+ },
1315
+
1316
+ BindDirective(node, context) {
1317
+ if (node.expression.type !== 'SequenceExpression') {
1318
+ const expression = /** @type {Identifier | MemberExpression} */ (node.expression);
1319
+ updates.push([context.state.scope, expression, expression]);
1320
+ }
1321
+
1322
+ context.next();
1323
+ },
1324
+
1325
+ TransitionDirective: SvelteDirective,
1326
+ AnimateDirective: SvelteDirective,
1327
+ UseDirective: SvelteDirective,
1328
+ // using it's own function instead of `SvelteDirective` because
1329
+ // StyleDirective doesn't have expressions and are generally already
1330
+ // handled by `Identifier`. This is the special case for the shorthand
1331
+ // eg <button style:height /> where the variable has the same name of
1332
+ // the css property
1333
+ StyleDirective(node, { path, state, next }) {
1334
+ if (node.value === true) {
1335
+ state.scope.reference(b.id(node.name), path.concat(node));
1336
+ }
1337
+ next();
1338
+ }
1339
+
1340
+ // TODO others
1341
+ });
1342
+
1343
+ for (const id of possible_implicit_declarations) {
1344
+ const binding = scope.get(id.name);
1345
+ if (binding) continue; // TODO can also be legacy_reactive if declared outside of reactive statement
1346
+
1347
+ scope.declare(id, 'legacy_reactive', 'let');
1348
+ }
1349
+
1350
+ // we do this after the fact, so that we don't need to worry
1351
+ // about encountering references before their declarations
1352
+ for (const [scope, { node, path }] of references) {
1353
+ scope.reference(node, path);
1354
+ }
1355
+
1356
+ for (const [scope, node, value] of updates) {
1357
+ for (const expression of unwrap_pattern(node)) {
1358
+ const left = object(expression);
1359
+ const binding = left && scope.get(left.name);
1360
+
1361
+ if (binding !== null && left !== binding.node) {
1362
+ if (left === expression) {
1363
+ binding.reassigned = true;
1364
+ binding.assignments.push({ value, scope });
1365
+ } else {
1366
+ binding.mutated = true;
1367
+ }
1368
+ }
1369
+ }
1370
+ }
1371
+
1372
+ return {
1373
+ has_await,
1374
+ scope,
1375
+ scopes
1376
+ };
1377
+ }
1378
+
1379
+ /**
1380
+ * @template {{ scope: Scope, scopes: Map<AST.SvelteNode, Scope> }} State
1381
+ * @param {AST.SvelteNode} node
1382
+ * @param {Context<AST.SvelteNode, State>} context
1383
+ */
1384
+ export function set_scope(node, { next, state }) {
1385
+ const scope = state.scopes.get(node);
1386
+ next(scope !== undefined && scope !== state.scope ? { ...state, scope } : state);
1387
+ }
1388
+
1389
+ /**
1390
+ * Returns the name of the rune if the given expression is a `CallExpression` using a rune.
1391
+ * @param {Node | null | undefined} node
1392
+ * @param {Scope} scope
1393
+ */
1394
+ export function get_rune(node, scope) {
1395
+ if (!node) return null;
1396
+ if (node.type !== 'CallExpression') return null;
1397
+
1398
+ const keypath = get_global_keypath(node.callee, scope);
1399
+
1400
+ if (!keypath || !is_rune(keypath)) return null;
1401
+ return keypath;
1402
+ }
1403
+
1404
+ /**
1405
+ * Returns the name of the rune if the given expression is a `CallExpression` using a rune.
1406
+ * @param {Expression | Super} node
1407
+ * @param {Scope} scope
1408
+ */
1409
+ function get_global_keypath(node, scope) {
1410
+ let n = node;
1411
+
1412
+ let joined = '';
1413
+
1414
+ while (n.type === 'MemberExpression') {
1415
+ if (n.computed) return null;
1416
+ if (n.property.type !== 'Identifier') return null;
1417
+ joined = '.' + n.property.name + joined;
1418
+ n = n.object;
1419
+ }
1420
+
1421
+ if (n.type === 'CallExpression' && n.callee.type === 'Identifier') {
1422
+ joined = '()' + joined;
1423
+ n = n.callee;
1424
+ }
1425
+
1426
+ if (n.type !== 'Identifier') return null;
1427
+
1428
+ const binding = scope.get(n.name);
1429
+ if (binding !== null) return null; // rune name, but references a variable or store
1430
+
1431
+ return n.name + joined;
1432
+ }