@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,639 @@
1
+ /** @import { AST, Scope } from '#compiler' */
2
+ /** @import * as ESTree from 'estree' */
3
+ import { walk } from 'zimmerframe';
4
+ import * as b from '#compiler/builders';
5
+
6
+ /**
7
+ * Gets the left-most identifier of a member expression or identifier.
8
+ * @param {ESTree.MemberExpression | ESTree.Identifier} expression
9
+ * @returns {ESTree.Identifier | null}
10
+ */
11
+ export function object(expression) {
12
+ while (expression.type === 'MemberExpression') {
13
+ expression = /** @type {ESTree.MemberExpression | ESTree.Identifier} */ (expression.object);
14
+ }
15
+
16
+ if (expression.type !== 'Identifier') {
17
+ return null;
18
+ }
19
+
20
+ return expression;
21
+ }
22
+
23
+ /**
24
+ * Returns true if the attribute contains a single static text node.
25
+ * @param {AST.Attribute} attribute
26
+ * @returns {attribute is AST.Attribute & { value: [AST.Text] }}
27
+ */
28
+ export function is_text_attribute(attribute) {
29
+ return (
30
+ Array.isArray(attribute.value) &&
31
+ attribute.value.length === 1 &&
32
+ attribute.value[0].type === 'Text'
33
+ );
34
+ }
35
+
36
+ /**
37
+ * Returns true if the attribute contains a single expression node.
38
+ * In Svelte 5, this also includes a single expression node wrapped in an array.
39
+ * TODO change that in a future version
40
+ * @param {AST.Attribute} attribute
41
+ * @returns {attribute is AST.Attribute & { value: [AST.ExpressionTag] | AST.ExpressionTag }}
42
+ */
43
+ export function is_expression_attribute(attribute) {
44
+ return (
45
+ (attribute.value !== true && !Array.isArray(attribute.value)) ||
46
+ (Array.isArray(attribute.value) &&
47
+ attribute.value.length === 1 &&
48
+ attribute.value[0].type === 'ExpressionTag')
49
+ );
50
+ }
51
+
52
+ /**
53
+ * Returns the single attribute expression node.
54
+ * In Svelte 5, this also includes a single expression node wrapped in an array.
55
+ * TODO change that in a future version
56
+ * @param { AST.Attribute & { value: [AST.ExpressionTag] | AST.ExpressionTag }} attribute
57
+ * @returns {ESTree.Expression}
58
+ */
59
+ export function get_attribute_expression(attribute) {
60
+ return Array.isArray(attribute.value)
61
+ ? /** @type {AST.ExpressionTag} */ (attribute.value[0]).expression
62
+ : attribute.value.expression;
63
+ }
64
+
65
+ /**
66
+ * Returns the expression chunks of an attribute value
67
+ * @param {AST.Attribute['value']} value
68
+ * @returns {Array<AST.Text | AST.ExpressionTag>}
69
+ */
70
+ export function get_attribute_chunks(value) {
71
+ return Array.isArray(value) ? value : typeof value === 'boolean' ? [] : [value];
72
+ }
73
+
74
+ /**
75
+ * Returns true if the attribute starts with `on` and contains a single expression node.
76
+ * @param {AST.Attribute} attribute
77
+ * @returns {attribute is AST.Attribute & { value: [AST.ExpressionTag] | AST.ExpressionTag }}
78
+ */
79
+ export function is_event_attribute(attribute) {
80
+ return is_expression_attribute(attribute) && attribute.name.startsWith('on');
81
+ }
82
+
83
+ /**
84
+ * Extracts all identifiers and member expressions from a pattern.
85
+ * @param {ESTree.Pattern} pattern
86
+ * @param {Array<ESTree.Identifier | ESTree.MemberExpression>} [nodes]
87
+ * @returns {Array<ESTree.Identifier | ESTree.MemberExpression>}
88
+ */
89
+ export function unwrap_pattern(pattern, nodes = []) {
90
+ switch (pattern.type) {
91
+ case 'Identifier':
92
+ nodes.push(pattern);
93
+ break;
94
+
95
+ case 'MemberExpression':
96
+ // member expressions can be part of an assignment pattern, but not a binding pattern
97
+ // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#binding_and_assignment
98
+ nodes.push(pattern);
99
+ break;
100
+
101
+ case 'ObjectPattern':
102
+ for (const prop of pattern.properties) {
103
+ if (prop.type === 'RestElement') {
104
+ unwrap_pattern(prop.argument, nodes);
105
+ } else {
106
+ unwrap_pattern(prop.value, nodes);
107
+ }
108
+ }
109
+
110
+ break;
111
+
112
+ case 'ArrayPattern':
113
+ for (const element of pattern.elements) {
114
+ if (element) unwrap_pattern(element, nodes);
115
+ }
116
+
117
+ break;
118
+
119
+ case 'RestElement':
120
+ unwrap_pattern(pattern.argument, nodes);
121
+ break;
122
+
123
+ case 'AssignmentPattern':
124
+ unwrap_pattern(pattern.left, nodes);
125
+ break;
126
+ }
127
+
128
+ return nodes;
129
+ }
130
+
131
+ /**
132
+ * Extracts all identifiers from a pattern.
133
+ * @param {ESTree.Pattern} pattern
134
+ * @returns {ESTree.Identifier[]}
135
+ */
136
+ export function extract_identifiers(pattern) {
137
+ return unwrap_pattern(pattern, []).filter((node) => node.type === 'Identifier');
138
+ }
139
+
140
+ /**
141
+ * Extracts all identifiers and a stringified keypath from an expression.
142
+ * TODO replace this with `expression.dependencies`
143
+ * @param {ESTree.Expression} expr
144
+ * @returns {[keypath: string, ids: ESTree.Identifier[]]}
145
+ */
146
+ export function extract_all_identifiers_from_expression(expr) {
147
+ /** @type {ESTree.Identifier[]} */
148
+ let nodes = [];
149
+ /** @type {string[]} */
150
+ let keypath = [];
151
+
152
+ walk(
153
+ expr,
154
+ {},
155
+ {
156
+ Identifier(node, { path }) {
157
+ const parent = path.at(-1);
158
+ if (parent?.type !== 'MemberExpression' || parent.property !== node || parent.computed) {
159
+ nodes.push(node);
160
+ }
161
+
162
+ if (parent?.type === 'MemberExpression' && parent.computed && parent.property === node) {
163
+ keypath.push(`[${node.name}]`);
164
+ } else {
165
+ keypath.push(node.name);
166
+ }
167
+ },
168
+ Literal(node, { path }) {
169
+ const value = typeof node.value === 'string' ? `"${node.value}"` : String(node.value);
170
+ const parent = path.at(-1);
171
+ if (parent?.type === 'MemberExpression' && parent.computed && parent.property === node) {
172
+ keypath.push(`[${value}]`);
173
+ } else {
174
+ keypath.push(value);
175
+ }
176
+ },
177
+ ThisExpression(_, { next }) {
178
+ keypath.push('this');
179
+ next();
180
+ }
181
+ }
182
+ );
183
+
184
+ return [keypath.join('.'), nodes];
185
+ }
186
+
187
+ /**
188
+ * Extracts all leaf identifiers from a destructuring expression.
189
+ * @param {ESTree.Identifier | ESTree.ObjectExpression | ESTree.ArrayExpression} node
190
+ * @param {ESTree.Identifier[]} [nodes]
191
+ * @returns
192
+ */
193
+ export function extract_identifiers_from_destructuring(node, nodes = []) {
194
+ // TODO This isn't complete, but it should be enough for our purposes
195
+ switch (node.type) {
196
+ case 'Identifier':
197
+ nodes.push(node);
198
+ break;
199
+
200
+ case 'ObjectExpression':
201
+ for (const prop of node.properties) {
202
+ if (prop.type === 'Property') {
203
+ extract_identifiers_from_destructuring(/** @type {any} */ (prop.value), nodes);
204
+ } else {
205
+ extract_identifiers_from_destructuring(/** @type {any} */ (prop.argument), nodes);
206
+ }
207
+ }
208
+
209
+ break;
210
+
211
+ case 'ArrayExpression':
212
+ for (const element of node.elements) {
213
+ if (element) extract_identifiers_from_destructuring(/** @type {any} */ (element), nodes);
214
+ }
215
+
216
+ break;
217
+ }
218
+
219
+ return nodes;
220
+ }
221
+
222
+ /**
223
+ * Represents the path of a destructured assignment from either a declaration
224
+ * or assignment expression. For example, given `const { foo: { bar: baz } } = quux`,
225
+ * the path of `baz` is `foo.bar`
226
+ * @typedef {Object} DestructuredAssignment
227
+ * @property {ESTree.Identifier | ESTree.MemberExpression} node The node the destructuring path end in. Can be a member expression only for assignment expressions
228
+ * @property {boolean} is_rest `true` if this is a `...rest` destructuring
229
+ * @property {boolean} has_default_value `true` if this has a fallback value like `const { foo = 'bar } = ..`
230
+ * @property {ESTree.Expression} expression The value of the current path
231
+ * This will be a call expression if a rest element or default is involved — e.g. `const { foo: { bar: baz = 42 }, ...rest } = quux` — since we can't represent `baz` or `rest` purely as a path
232
+ * Will be an await expression in case of an async default value (`const { foo = await bar } = ...`)
233
+ * @property {ESTree.Expression} update_expression Like `expression` but without default values.
234
+ */
235
+
236
+ /**
237
+ * Extracts all destructured assignments from a pattern.
238
+ * For each `id` in the returned `inserts`, make sure to adjust the `name`.
239
+ * @param {ESTree.Node} param
240
+ * @param {ESTree.Expression} initial
241
+ * @returns {{ inserts: Array<{ id: ESTree.Identifier, value: ESTree.Expression }>, paths: DestructuredAssignment[] }}
242
+ */
243
+ export function extract_paths(param, initial) {
244
+ /**
245
+ * When dealing with array destructuring patterns (`let [a, b, c] = $derived(blah())`)
246
+ * we need an intermediate declaration that creates an array, since `blah()` could
247
+ * return a non-array-like iterator
248
+ * @type {Array<{ id: ESTree.Identifier, value: ESTree.Expression }>}
249
+ */
250
+ const inserts = [];
251
+
252
+ /** @type {DestructuredAssignment[]} */
253
+ const paths = [];
254
+
255
+ _extract_paths(paths, inserts, param, initial, initial, false);
256
+
257
+ return { inserts, paths };
258
+ }
259
+
260
+ /**
261
+ * @param {DestructuredAssignment[]} paths
262
+ * @param {Array<{ id: ESTree.Identifier, value: ESTree.Expression }>} inserts
263
+ * @param {ESTree.Node} param
264
+ * @param {ESTree.Expression} expression
265
+ * @param {ESTree.Expression} update_expression
266
+ * @param {boolean} has_default_value
267
+ * @returns {DestructuredAssignment[]}
268
+ */
269
+ function _extract_paths(paths, inserts, param, expression, update_expression, has_default_value) {
270
+ switch (param.type) {
271
+ case 'Identifier':
272
+ case 'MemberExpression':
273
+ paths.push({
274
+ node: param,
275
+ is_rest: false,
276
+ has_default_value,
277
+ expression,
278
+ update_expression
279
+ });
280
+ break;
281
+
282
+ case 'ObjectPattern':
283
+ for (const prop of param.properties) {
284
+ if (prop.type === 'RestElement') {
285
+ /** @type {ESTree.Expression[]} */
286
+ const props = [];
287
+
288
+ for (const p of param.properties) {
289
+ if (p.type === 'Property' && p.key.type !== 'PrivateIdentifier') {
290
+ if (p.key.type === 'Identifier' && !p.computed) {
291
+ props.push(b.literal(p.key.name));
292
+ } else if (p.key.type === 'Literal') {
293
+ props.push(b.literal(String(p.key.value)));
294
+ } else {
295
+ props.push(b.call('String', p.key));
296
+ }
297
+ }
298
+ }
299
+
300
+ const rest_expression = b.call('$.exclude_from_object', expression, b.array(props));
301
+
302
+ if (prop.argument.type === 'Identifier') {
303
+ paths.push({
304
+ node: prop.argument,
305
+ is_rest: true,
306
+ has_default_value,
307
+ expression: rest_expression,
308
+ update_expression: rest_expression
309
+ });
310
+ } else {
311
+ _extract_paths(
312
+ paths,
313
+ inserts,
314
+ prop.argument,
315
+ rest_expression,
316
+ rest_expression,
317
+ has_default_value
318
+ );
319
+ }
320
+ } else {
321
+ const object_expression = b.member(
322
+ expression,
323
+ prop.key,
324
+ prop.computed || prop.key.type !== 'Identifier'
325
+ );
326
+
327
+ _extract_paths(
328
+ paths,
329
+ inserts,
330
+ prop.value,
331
+ object_expression,
332
+ object_expression,
333
+ has_default_value
334
+ );
335
+ }
336
+ }
337
+
338
+ break;
339
+
340
+ case 'ArrayPattern': {
341
+ // we create an intermediate declaration to convert iterables to arrays if necessary.
342
+ // the consumer is responsible for setting the name of the identifier
343
+ const id = b.id('#');
344
+
345
+ const value = b.call(
346
+ '$.to_array',
347
+ expression,
348
+ param.elements.at(-1)?.type === 'RestElement' ? undefined : b.literal(param.elements.length)
349
+ );
350
+
351
+ inserts.push({ id, value });
352
+
353
+ for (let i = 0; i < param.elements.length; i += 1) {
354
+ const element = param.elements[i];
355
+ if (element) {
356
+ if (element.type === 'RestElement') {
357
+ const rest_expression = b.call(b.member(id, 'slice'), b.literal(i));
358
+
359
+ if (element.argument.type === 'Identifier') {
360
+ paths.push({
361
+ node: element.argument,
362
+ is_rest: true,
363
+ has_default_value,
364
+ expression: rest_expression,
365
+ update_expression: rest_expression
366
+ });
367
+ } else {
368
+ _extract_paths(
369
+ paths,
370
+ inserts,
371
+ element.argument,
372
+ rest_expression,
373
+ rest_expression,
374
+ has_default_value
375
+ );
376
+ }
377
+ } else {
378
+ const array_expression = b.member(id, b.literal(i), true);
379
+
380
+ _extract_paths(
381
+ paths,
382
+ inserts,
383
+ element,
384
+ array_expression,
385
+ array_expression,
386
+ has_default_value
387
+ );
388
+ }
389
+ }
390
+ }
391
+
392
+ break;
393
+ }
394
+
395
+ case 'AssignmentPattern': {
396
+ const fallback_expression = build_fallback(expression, param.right);
397
+
398
+ if (param.left.type === 'Identifier') {
399
+ paths.push({
400
+ node: param.left,
401
+ is_rest: false,
402
+ has_default_value: true,
403
+ expression: fallback_expression,
404
+ update_expression
405
+ });
406
+ } else {
407
+ _extract_paths(paths, inserts, param.left, fallback_expression, update_expression, true);
408
+ }
409
+
410
+ break;
411
+ }
412
+ }
413
+
414
+ return paths;
415
+ }
416
+
417
+ /**
418
+ * Like `path.at(x)`, but skips over `TSNonNullExpression` and `TSAsExpression` nodes and eases assertions a bit
419
+ * by removing the `| undefined` from the resulting type.
420
+ *
421
+ * @template {AST.SvelteNode} T
422
+ * @param {T[]} path
423
+ * @param {number} at
424
+ */
425
+ export function get_parent(path, at) {
426
+ let node = path.at(at);
427
+ // @ts-expect-error
428
+ if (node.type === 'TSNonNullExpression' || node.type === 'TSAsExpression') {
429
+ return /** @type {T} */ (path.at(at < 0 ? at - 1 : at + 1));
430
+ }
431
+ return /** @type {T} */ (node);
432
+ }
433
+
434
+ /**
435
+ * Returns `true` if the expression is an identifier, a literal, a function expression,
436
+ * or a logical expression that only contains simple expressions. Used to determine whether
437
+ * something needs to be treated as though accessing it could have side-effects (i.e.
438
+ * reading signals prematurely)
439
+ * @param {ESTree.Expression} node
440
+ * @returns {boolean}
441
+ */
442
+ export function is_simple_expression(node) {
443
+ if (
444
+ node.type === 'Literal' ||
445
+ node.type === 'Identifier' ||
446
+ node.type === 'ArrowFunctionExpression' ||
447
+ node.type === 'FunctionExpression'
448
+ ) {
449
+ return true;
450
+ }
451
+
452
+ if (node.type === 'ConditionalExpression') {
453
+ return (
454
+ is_simple_expression(node.test) &&
455
+ is_simple_expression(node.consequent) &&
456
+ is_simple_expression(node.alternate)
457
+ );
458
+ }
459
+
460
+ if (node.type === 'BinaryExpression' || node.type === 'LogicalExpression') {
461
+ return (
462
+ node.left.type !== 'PrivateIdentifier' &&
463
+ is_simple_expression(node.left) &&
464
+ is_simple_expression(node.right)
465
+ );
466
+ }
467
+
468
+ return false;
469
+ }
470
+
471
+ /**
472
+ * @template {ESTree.SimpleCallExpression | ESTree.MemberExpression} T
473
+ * @param {ESTree.ChainExpression & { expression : T } | T} node
474
+ * @returns {T}
475
+ */
476
+ export function unwrap_optional(node) {
477
+ return node.type === 'ChainExpression' ? node.expression : node;
478
+ }
479
+
480
+ /**
481
+ * @param {ESTree.Expression | ESTree.Pattern} expression
482
+ * @returns {boolean}
483
+ */
484
+ export function is_expression_async(expression) {
485
+ switch (expression.type) {
486
+ case 'AwaitExpression': {
487
+ return true;
488
+ }
489
+ case 'ArrayPattern': {
490
+ return expression.elements.some((element) => element && is_expression_async(element));
491
+ }
492
+ case 'ArrayExpression': {
493
+ return expression.elements.some((element) => {
494
+ if (!element) {
495
+ return false;
496
+ } else if (element.type === 'SpreadElement') {
497
+ return is_expression_async(element.argument);
498
+ } else {
499
+ return is_expression_async(element);
500
+ }
501
+ });
502
+ }
503
+ case 'AssignmentPattern':
504
+ case 'AssignmentExpression':
505
+ case 'BinaryExpression':
506
+ case 'LogicalExpression': {
507
+ return (
508
+ (expression.left.type !== 'PrivateIdentifier' && is_expression_async(expression.left)) ||
509
+ is_expression_async(expression.right)
510
+ );
511
+ }
512
+ case 'CallExpression':
513
+ case 'NewExpression': {
514
+ return (
515
+ (expression.callee.type !== 'Super' && is_expression_async(expression.callee)) ||
516
+ expression.arguments.some((element) => {
517
+ if (element.type === 'SpreadElement') {
518
+ return is_expression_async(element.argument);
519
+ } else {
520
+ return is_expression_async(element);
521
+ }
522
+ })
523
+ );
524
+ }
525
+ case 'ChainExpression': {
526
+ return is_expression_async(expression.expression);
527
+ }
528
+ case 'ConditionalExpression': {
529
+ return (
530
+ is_expression_async(expression.test) ||
531
+ is_expression_async(expression.alternate) ||
532
+ is_expression_async(expression.consequent)
533
+ );
534
+ }
535
+ case 'ImportExpression': {
536
+ return is_expression_async(expression.source);
537
+ }
538
+ case 'MemberExpression': {
539
+ return (
540
+ (expression.object.type !== 'Super' && is_expression_async(expression.object)) ||
541
+ (expression.property.type !== 'PrivateIdentifier' &&
542
+ is_expression_async(expression.property))
543
+ );
544
+ }
545
+ case 'ObjectPattern':
546
+ case 'ObjectExpression': {
547
+ return expression.properties.some((property) => {
548
+ if (property.type === 'SpreadElement') {
549
+ return is_expression_async(property.argument);
550
+ } else if (property.type === 'Property') {
551
+ return (
552
+ (property.key.type !== 'PrivateIdentifier' && is_expression_async(property.key)) ||
553
+ is_expression_async(property.value)
554
+ );
555
+ }
556
+ });
557
+ }
558
+ case 'RestElement': {
559
+ return is_expression_async(expression.argument);
560
+ }
561
+ case 'SequenceExpression':
562
+ case 'TemplateLiteral': {
563
+ return expression.expressions.some((subexpression) => is_expression_async(subexpression));
564
+ }
565
+ case 'TaggedTemplateExpression': {
566
+ return is_expression_async(expression.tag) || is_expression_async(expression.quasi);
567
+ }
568
+ case 'UnaryExpression':
569
+ case 'UpdateExpression': {
570
+ return is_expression_async(expression.argument);
571
+ }
572
+ case 'YieldExpression': {
573
+ return expression.argument ? is_expression_async(expression.argument) : false;
574
+ }
575
+ default:
576
+ return false;
577
+ }
578
+ }
579
+
580
+ /**
581
+ *
582
+ * @param {ESTree.Expression} expression
583
+ * @param {ESTree.Expression} fallback
584
+ */
585
+ export function build_fallback(expression, fallback) {
586
+ if (is_simple_expression(fallback)) {
587
+ return b.call('$.fallback', expression, fallback);
588
+ }
589
+
590
+ if (fallback.type === 'AwaitExpression' && is_simple_expression(fallback.argument)) {
591
+ return b.await(b.call('$.fallback', expression, fallback.argument));
592
+ }
593
+
594
+ return is_expression_async(fallback)
595
+ ? b.await(b.call('$.fallback', expression, b.thunk(fallback, true), b.true))
596
+ : b.call('$.fallback', expression, b.thunk(fallback), b.true);
597
+ }
598
+
599
+ /**
600
+ * @param {ESTree.AssignmentOperator} operator
601
+ * @param {ESTree.Identifier | ESTree.MemberExpression} left
602
+ * @param {ESTree.Expression} right
603
+ */
604
+ export function build_assignment_value(operator, left, right) {
605
+ return operator === '='
606
+ ? right
607
+ : // turn something like x += 1 into x = x + 1
608
+ ['||=', '&&=', '??='].includes(operator)
609
+ ? b.logical(/** @type {ESTree.LogicalOperator} */ (operator.slice(0, -1)), left, right)
610
+ : b.binary(/** @type {ESTree.BinaryOperator} */ (operator.slice(0, -1)), left, right);
611
+ }
612
+
613
+ /**
614
+ * @param {ESTree.Node} node
615
+ */
616
+ export function has_await_expression(node) {
617
+ let has_await = false;
618
+
619
+ walk(node, null, {
620
+ AwaitExpression(_node, context) {
621
+ has_await = true;
622
+ context.stop();
623
+ },
624
+ // don't traverse into these
625
+ FunctionDeclaration() {},
626
+ FunctionExpression() {},
627
+ ArrowFunctionExpression() {}
628
+ });
629
+
630
+ return has_await;
631
+ }
632
+
633
+ /**
634
+ * Turns `await ...` to `(await $.save(...))()`
635
+ * @param {ESTree.Expression} expression
636
+ */
637
+ export function save(expression) {
638
+ return b.call(b.await(b.call('$.save', expression)));
639
+ }