Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sveltejs/svelte
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: sveltejs/svelte
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: async-fork
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.

Commits on Jan 14, 2025

  1. wip

    trueadm committed Jan 14, 2025
    Copy the full SHA
    74c483c View commit details
  2. Merge branch 'main' into experiment_s

    trueadm committed Jan 14, 2025
    Copy the full SHA
    a4bf5e3 View commit details

Commits on Jan 15, 2025

  1. wip

    trueadm committed Jan 15, 2025
    Copy the full SHA
    e6cd426 View commit details
  2. WIP

    Rich-Harris committed Jan 15, 2025
    Copy the full SHA
    ea13937 View commit details
  3. fix

    Rich-Harris committed Jan 15, 2025
    Copy the full SHA
    4ef2be3 View commit details
  4. Merge branch 'experiment_s' into aa

    Rich-Harris committed Jan 15, 2025
    Copy the full SHA
    d1d1835 View commit details
  5. fix

    Rich-Harris committed Jan 15, 2025
    Copy the full SHA
    278c490 View commit details
  6. Copy the full SHA
    3b185b7 View commit details
  7. WIP

    Rich-Harris committed Jan 15, 2025
    Copy the full SHA
    5bb5a8f View commit details
  8. fix

    Rich-Harris committed Jan 15, 2025
    Copy the full SHA
    b788ec0 View commit details
  9. preserve context

    Rich-Harris committed Jan 15, 2025
    Copy the full SHA
    964004a View commit details
  10. reduce indirection

    Rich-Harris committed Jan 15, 2025
    Copy the full SHA
    209f311 View commit details
  11. another fix

    trueadm committed Jan 15, 2025
    Copy the full SHA
    ad1c214 View commit details
  12. another fix

    trueadm committed Jan 15, 2025
    Copy the full SHA
    78bb187 View commit details
  13. Revert "another fix"

    This reverts commit 78bb187.
    trueadm committed Jan 15, 2025
    Copy the full SHA
    7addfd8 View commit details
  14. another fix

    trueadm committed Jan 15, 2025
    Copy the full SHA
    ff957d1 View commit details
  15. oops

    trueadm committed Jan 15, 2025
    Copy the full SHA
    c7d3af1 View commit details
  16. top-level await

    Rich-Harris committed Jan 15, 2025
    Copy the full SHA
    e2bc4d9 View commit details
  17. Merge branch 'experiment_s' into aa

    Rich-Harris committed Jan 15, 2025
    Copy the full SHA
    2cd6b73 View commit details
  18. more fixes

    trueadm committed Jan 15, 2025
    Copy the full SHA
    16f502a View commit details
  19. cleanup

    trueadm committed Jan 15, 2025
    Copy the full SHA
    a8a420c View commit details
  20. more tweaks

    trueadm committed Jan 15, 2025
    Copy the full SHA
    36e2469 View commit details

Commits on Jan 16, 2025

  1. more tweaks

    trueadm committed Jan 16, 2025
    Copy the full SHA
    0c0fd47 View commit details
  2. async deriveds

    Rich-Harris committed Jan 16, 2025
    Copy the full SHA
    32e12d0 View commit details
  3. add test

    Rich-Harris committed Jan 16, 2025
    Copy the full SHA
    c81e94a View commit details
  4. merge

    Rich-Harris committed Jan 16, 2025
    Copy the full SHA
    92ff62e View commit details
  5. Copy the full SHA
    fa8d459 View commit details
  6. fix

    Rich-Harris committed Jan 16, 2025
    Copy the full SHA
    53b639d View commit details
  7. fix

    Rich-Harris committed Jan 16, 2025
    Copy the full SHA
    b0a08f5 View commit details
  8. various

    Rich-Harris committed Jan 16, 2025
    Copy the full SHA
    1320130 View commit details
  9. fix

    Rich-Harris committed Jan 16, 2025
    Copy the full SHA
    1588464 View commit details
  10. fix

    Rich-Harris committed Jan 16, 2025
    Copy the full SHA
    2fe198f View commit details
  11. tests

    Rich-Harris committed Jan 16, 2025
    Copy the full SHA
    1a72d28 View commit details

Commits on Jan 17, 2025

  1. parallelize

    Rich-Harris committed Jan 17, 2025
    Copy the full SHA
    0d8f27e View commit details
  2. Merge branch 'main' into experiment_s

    Rich-Harris committed Jan 17, 2025
    Copy the full SHA
    232bb6f View commit details
  3. merge

    Rich-Harris committed Jan 17, 2025
    Copy the full SHA
    c5bab8d View commit details
  4. chore: refactor task microtask dispatching + boundary scheduling

    trueadm committed Jan 17, 2025
    Copy the full SHA
    0dcc250 View commit details

Commits on Jan 20, 2025

  1. merge

    Rich-Harris committed Jan 20, 2025
    Copy the full SHA
    bc87314 View commit details
  2. merge

    Rich-Harris committed Jan 20, 2025
    Copy the full SHA
    a4eb7f7 View commit details

Commits on Jan 21, 2025

  1. Copy the full SHA
    b386784 View commit details
  2. revert some stuff for now

    Rich-Harris committed Jan 21, 2025
    Copy the full SHA
    beaa64f View commit details
  3. revert

    Rich-Harris committed Jan 21, 2025
    Copy the full SHA
    06e6119 View commit details
  4. fix

    Rich-Harris committed Jan 21, 2025
    Copy the full SHA
    02c2ca4 View commit details
  5. fix

    Rich-Harris committed Jan 21, 2025
    Copy the full SHA
    c73de77 View commit details
  6. fix

    Rich-Harris committed Jan 21, 2025
    Copy the full SHA
    085cdba View commit details
  7. fix

    Rich-Harris committed Jan 21, 2025
    Copy the full SHA
    4f78f64 View commit details

Commits on Jan 22, 2025

  1. WIP

    Rich-Harris committed Jan 22, 2025
    Copy the full SHA
    e15eae8 View commit details
  2. WIP

    Rich-Harris committed Jan 22, 2025
    Copy the full SHA
    9348259 View commit details
  3. Copy the full SHA
    39ed111 View commit details
  4. test

    Rich-Harris committed Jan 22, 2025
    Copy the full SHA
    093a3bf View commit details
Showing with 3,954 additions and 744 deletions.
  1. +5 −0 .changeset/eleven-weeks-dance.md
  2. +5 −0 .changeset/long-moles-join.md
  3. +16 −0 documentation/docs/98-reference/.generated/client-warnings.md
  4. +12 −0 documentation/docs/98-reference/.generated/compile-errors.md
  5. +8 −0 documentation/docs/98-reference/.generated/shared-errors.md
  6. +1 −1 package.json
  7. +0 −18 packages/svelte/CHANGELOG.md
  8. +12 −0 packages/svelte/messages/client-warnings/warnings.md
  9. +8 −0 packages/svelte/messages/compile-errors/script.md
  10. +6 −0 packages/svelte/messages/shared-errors/errors.md
  11. +2 −2 packages/svelte/package.json
  12. +18 −0 packages/svelte/src/compiler/errors.js
  13. +4 −1 packages/svelte/src/compiler/migrate/index.js
  14. +2 −0 packages/svelte/src/compiler/phases/1-parse/state/element.js
  15. +16 −4 packages/svelte/src/compiler/phases/1-parse/state/tag.js
  16. +24 −9 packages/svelte/src/compiler/phases/2-analyze/index.js
  17. +50 −0 packages/svelte/src/compiler/phases/2-analyze/visitors/AwaitExpression.js
  18. +15 −2 packages/svelte/src/compiler/phases/2-analyze/visitors/CallExpression.js
  19. +4 −1 packages/svelte/src/compiler/phases/2-analyze/visitors/HtmlTag.js
  20. +7 −1 packages/svelte/src/compiler/phases/2-analyze/visitors/IfBlock.js
  21. +6 −1 packages/svelte/src/compiler/phases/2-analyze/visitors/KeyBlock.js
  22. +1 −0 packages/svelte/src/compiler/phases/2-analyze/visitors/StyleDirective.js
  23. +1 −1 packages/svelte/src/compiler/phases/2-analyze/visitors/SvelteBoundary.js
  24. +13 −1 packages/svelte/src/compiler/phases/2-analyze/visitors/SvelteElement.js
  25. +33 −4 packages/svelte/src/compiler/phases/3-transform/client/transform-client.js
  26. +12 −1 packages/svelte/src/compiler/phases/3-transform/client/types.d.ts
  27. +26 −0 packages/svelte/src/compiler/phases/3-transform/client/visitors/AwaitExpression.js
  28. +22 −2 packages/svelte/src/compiler/phases/3-transform/client/visitors/EachBlock.js
  29. +3 −1 packages/svelte/src/compiler/phases/3-transform/client/visitors/Fragment.js
  30. +32 −11 packages/svelte/src/compiler/phases/3-transform/client/visitors/HtmlTag.js
  31. +20 −2 packages/svelte/src/compiler/phases/3-transform/client/visitors/IfBlock.js
  32. +28 −3 packages/svelte/src/compiler/phases/3-transform/client/visitors/KeyBlock.js
  33. +11 −3 packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js
  34. +50 −13 packages/svelte/src/compiler/phases/3-transform/client/visitors/RenderTag.js
  35. +4 −1 packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteBoundary.js
  36. +31 −15 packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteElement.js
  37. +34 −8 packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js
  38. +69 −25 packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js
  39. +24 −8 packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/element.js
  40. +32 −15 packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js
  41. +2 −0 packages/svelte/src/compiler/phases/3-transform/server/transform-server.js
  42. +25 −0 packages/svelte/src/compiler/phases/3-transform/server/visitors/AwaitExpression.js
  43. +26 −5 packages/svelte/src/compiler/phases/3-transform/server/visitors/SvelteBoundary.js
  44. +2 −1 packages/svelte/src/compiler/phases/nodes.js
  45. +18 −0 packages/svelte/src/compiler/phases/scope.js
  46. +15 −1 packages/svelte/src/compiler/phases/types.d.ts
  47. +7 −0 packages/svelte/src/compiler/types/index.d.ts
  48. +13 −0 packages/svelte/src/compiler/types/template.d.ts
  49. +12 −9 packages/svelte/src/compiler/utils/builders.js
  50. +5 −1 packages/svelte/src/compiler/validate-options.js
  51. +1 −0 packages/svelte/src/constants.js
  52. +1 −0 packages/svelte/src/index-client.js
  53. +18 −13 packages/svelte/src/internal/client/constants.js
  54. +89 −0 packages/svelte/src/internal/client/dev/debug.js
  55. +22 −0 packages/svelte/src/internal/client/dom/blocks/async.js
  56. +393 −47 packages/svelte/src/internal/client/dom/blocks/boundary.js
  57. +161 −47 packages/svelte/src/internal/client/dom/blocks/each.js
  58. +54 −61 packages/svelte/src/internal/client/dom/blocks/html.js
  59. +60 −22 packages/svelte/src/internal/client/dom/blocks/if.js
  60. +42 −3 packages/svelte/src/internal/client/dom/blocks/key.js
  61. +42 −3 packages/svelte/src/internal/client/dom/blocks/svelte-component.js
  62. +9 −26 packages/svelte/src/internal/client/dom/elements/attributes.js
  63. +1 −0 packages/svelte/src/internal/client/dom/elements/events.js
  64. +14 −1 packages/svelte/src/internal/client/dom/operations.js
  65. +41 −25 packages/svelte/src/internal/client/dom/task.js
  66. +4 −2 packages/svelte/src/internal/client/index.js
  67. +110 −6 packages/svelte/src/internal/client/reactivity/deriveds.js
  68. +62 −22 packages/svelte/src/internal/client/reactivity/effects.js
  69. +96 −6 packages/svelte/src/internal/client/reactivity/sources.js
  70. +154 −50 packages/svelte/src/internal/client/runtime.js
  71. +23 −0 packages/svelte/src/internal/client/warnings.js
  72. +2 −0 packages/svelte/src/internal/server/index.js
  73. +15 −0 packages/svelte/src/internal/shared/errors.js
  74. +1 −1 packages/svelte/src/version.js
  75. +2 −1 packages/svelte/tests/helpers.js
  76. +1 −1 packages/svelte/tests/hydration/samples/repair-mismatched-a-href/_expected.html
  77. +0 −1 packages/svelte/tests/hydration/samples/repair-mismatched-a-href/main.svelte
  78. +3 −0 packages/svelte/tests/runtime-legacy/shared.ts
  79. +36 −0 packages/svelte/tests/runtime-runes/samples/async-attribute/_config.js
  80. +11 −0 packages/svelte/tests/runtime-runes/samples/async-attribute/main.svelte
  81. +9 −0 packages/svelte/tests/runtime-runes/samples/async-derived-invalidation-during-init/Child.svelte
  82. +43 −0 packages/svelte/tests/runtime-runes/samples/async-derived-invalidation-during-init/_config.js
  83. +13 −0 packages/svelte/tests/runtime-runes/samples/async-derived-invalidation-during-init/main.svelte
  84. +20 −0 packages/svelte/tests/runtime-runes/samples/async-derived-module/Child.svelte
  85. +66 −0 packages/svelte/tests/runtime-runes/samples/async-derived-module/_config.js
  86. +15 −0 packages/svelte/tests/runtime-runes/samples/async-derived-module/main.svelte
  87. +9 −0 packages/svelte/tests/runtime-runes/samples/async-derived-module/state.svelte.js
  88. +15 −0 packages/svelte/tests/runtime-runes/samples/async-derived/Child.svelte
  89. +64 −0 packages/svelte/tests/runtime-runes/samples/async-derived/_config.js
  90. +15 −0 packages/svelte/tests/runtime-runes/samples/async-derived/main.svelte
  91. +42 −0 packages/svelte/tests/runtime-runes/samples/async-each-await-item/_config.js
  92. +13 −0 packages/svelte/tests/runtime-runes/samples/async-each-await-item/main.svelte
  93. +36 −0 packages/svelte/tests/runtime-runes/samples/async-each/_config.js
  94. +13 −0 packages/svelte/tests/runtime-runes/samples/async-each/main.svelte
  95. +37 −0 packages/svelte/tests/runtime-runes/samples/async-error/_config.js
  96. +16 −0 packages/svelte/tests/runtime-runes/samples/async-error/main.svelte
  97. +35 −0 packages/svelte/tests/runtime-runes/samples/async-expression/_config.js
  98. +11 −0 packages/svelte/tests/runtime-runes/samples/async-expression/main.svelte
  99. +35 −0 packages/svelte/tests/runtime-runes/samples/async-html-tag/_config.js
  100. +11 −0 packages/svelte/tests/runtime-runes/samples/async-html-tag/main.svelte
  101. +36 −0 packages/svelte/tests/runtime-runes/samples/async-if/_config.js
  102. +15 −0 packages/svelte/tests/runtime-runes/samples/async-if/main.svelte
  103. +51 −0 packages/svelte/tests/runtime-runes/samples/async-key/_config.js
  104. +13 −0 packages/svelte/tests/runtime-runes/samples/async-key/main.svelte
  105. +11 −0 packages/svelte/tests/runtime-runes/samples/async-nested-derived/Child.svelte
  106. +14 −0 packages/svelte/tests/runtime-runes/samples/async-nested-derived/_config.js
  107. +17 −0 packages/svelte/tests/runtime-runes/samples/async-nested-derived/main.svelte
  108. +42 −0 packages/svelte/tests/runtime-runes/samples/async-pending-timeout/_config.js
  109. +11 −0 packages/svelte/tests/runtime-runes/samples/async-pending-timeout/main.svelte
  110. +5 −0 packages/svelte/tests/runtime-runes/samples/async-prop/Child.svelte
  111. +36 −0 packages/svelte/tests/runtime-runes/samples/async-prop/_config.js
  112. +13 −0 packages/svelte/tests/runtime-runes/samples/async-prop/main.svelte
  113. +26 −0 packages/svelte/tests/runtime-runes/samples/async-reactivity-loss/_config.js
  114. +19 −0 packages/svelte/tests/runtime-runes/samples/async-reactivity-loss/main.svelte
  115. +35 −0 packages/svelte/tests/runtime-runes/samples/async-render-tag/_config.js
  116. +15 −0 packages/svelte/tests/runtime-runes/samples/async-render-tag/main.svelte
  117. +35 −0 packages/svelte/tests/runtime-runes/samples/async-svelte-element/_config.js
  118. +11 −0 packages/svelte/tests/runtime-runes/samples/async-svelte-element/main.svelte
  119. +7 −0 packages/svelte/tests/runtime-runes/samples/async-top-level/Child.svelte
  120. +28 −0 packages/svelte/tests/runtime-runes/samples/async-top-level/_config.js
  121. +13 −0 packages/svelte/tests/runtime-runes/samples/async-top-level/main.svelte
  122. +4 −9 packages/svelte/tests/runtime-runes/samples/custom-element-attributes/_config.js
  123. +0 −20 packages/svelte/tests/runtime-runes/samples/custom-element-attributes/main.svelte
  124. +0 −22 packages/svelte/tests/signals/test.ts
  125. +1 −1 packages/svelte/tests/snapshot/samples/skip-static-subtree/_expected/client/index.svelte.js
  126. +11 −0 packages/svelte/types/index.d.ts
  127. +2 −2 playgrounds/sandbox/package.json
  128. +8 −2 playgrounds/sandbox/run.js
  129. +4 −1 playgrounds/sandbox/vite.config.js
  130. +693 −178 pnpm-lock.yaml
5 changes: 5 additions & 0 deletions .changeset/eleven-weeks-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

feat: support `await` in components
5 changes: 5 additions & 0 deletions .changeset/long-moles-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure tracking returns true, even if in unowned
16 changes: 16 additions & 0 deletions documentation/docs/98-reference/.generated/client-warnings.md
Original file line number Diff line number Diff line change
@@ -34,6 +34,22 @@ function add() {
}
```
### await_reactivity_loss
```
Detected reactivity loss
```
TODO
### await_waterfall
```
An async value (%location%) was not read immediately after it resolved. This often indicates an unnecessary waterfall, which can slow down your app.
```
TODO
### binding_property_non_reactive
```
12 changes: 12 additions & 0 deletions documentation/docs/98-reference/.generated/compile-errors.md
Original file line number Diff line number Diff line change
@@ -444,6 +444,12 @@ Expected token %token%
Expected whitespace
```

### experimental_async

```
Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless the `experimental.async` compiler option is `true`
```

### export_undefined

```
@@ -498,6 +504,12 @@ The arguments keyword cannot be used within the template or at the top level of
%message%
```

### legacy_await_invalid

```
Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless in runes mode
```

### legacy_export_invalid

```
8 changes: 8 additions & 0 deletions documentation/docs/98-reference/.generated/shared-errors.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<!-- This file is generated by scripts/process-messages/index.js. Do not edit! -->

### await_outside_boundary

```
Cannot await outside a `<svelte:boundary>` with a `pending` snippet
```

TODO

### invalid_default_snippet

```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -44,6 +44,6 @@
"typescript": "^5.5.4",
"typescript-eslint": "^8.2.0",
"v8-natives": "^1.2.5",
"vitest": "^2.1.9"
"vitest": "^2.0.5"
}
}
18 changes: 0 additions & 18 deletions packages/svelte/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
# svelte

## 5.19.9

### Patch Changes

- fix: ensure unowned derived dependencies are not duplicated when reactions are skipped ([#15232](https://github.com/sveltejs/svelte/pull/15232))

- fix: hydrate `href` that is part of spread attributes ([#15226](https://github.com/sveltejs/svelte/pull/15226))

## 5.19.8

### Patch Changes

- fix: properly set `value` property of custom elements ([#15206](https://github.com/sveltejs/svelte/pull/15206))

- fix: ensure custom element updates don't run in hydration mode ([#15217](https://github.com/sveltejs/svelte/pull/15217))

- fix: ensure tracking returns true, even if in unowned ([#15214](https://github.com/sveltejs/svelte/pull/15214))

## 5.19.7

### Patch Changes
12 changes: 12 additions & 0 deletions packages/svelte/messages/client-warnings/warnings.md
Original file line number Diff line number Diff line change
@@ -30,6 +30,18 @@ function add() {
}
```
## await_reactivity_loss
> Detected reactivity loss
TODO
## await_waterfall
> An async value (%location%) was not read immediately after it resolved. This often indicates an unnecessary waterfall, which can slow down your app.
TODO
## binding_property_non_reactive
> `%binding%` is binding to a non-reactive property
8 changes: 8 additions & 0 deletions packages/svelte/messages/compile-errors/script.md
Original file line number Diff line number Diff line change
@@ -70,6 +70,10 @@ This turned out to be buggy and unpredictable, particularly when working with de

> `$effect()` can only be used as an expression statement
## experimental_async

> Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless the `experimental.async` compiler option is `true`
## export_undefined

> `%name%` is not defined
@@ -98,6 +102,10 @@ This turned out to be buggy and unpredictable, particularly when working with de

> The arguments keyword cannot be used within the template or at the top level of a component
## legacy_await_invalid

> Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless in runes mode
## legacy_export_invalid

> Cannot use `export let` in runes mode — use `$props()` instead
6 changes: 6 additions & 0 deletions packages/svelte/messages/shared-errors/errors.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## await_outside_boundary

> Cannot await outside a `<svelte:boundary>` with a `pending` snippet
TODO

## invalid_default_snippet

> Cannot use `{@render children(...)}` if the parent component uses `let:` directives. Consider using a named snippet instead
4 changes: 2 additions & 2 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"name": "svelte",
"description": "Cybernetically enhanced web apps",
"license": "MIT",
"version": "5.19.9",
"version": "5.19.7",
"type": "module",
"types": "./types/index.d.ts",
"engines": {
@@ -143,7 +143,7 @@
"source-map": "^0.7.4",
"tiny-glob": "^0.2.9",
"typescript": "^5.5.4",
"vitest": "^2.1.9"
"vitest": "^2.0.5"
},
"dependencies": {
"@ampproject/remapping": "^2.3.0",
18 changes: 18 additions & 0 deletions packages/svelte/src/compiler/errors.js
Original file line number Diff line number Diff line change
@@ -168,6 +168,15 @@ export function effect_invalid_placement(node) {
e(node, 'effect_invalid_placement', `\`$effect()\` can only be used as an expression statement\nhttps://svelte.dev/e/effect_invalid_placement`);
}

/**
* Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless the `experimental.async` compiler option is `true`
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function experimental_async(node) {
e(node, 'experimental_async', `Cannot use \`await\` in deriveds and template expressions, or at the top level of a component, unless the \`experimental.async\` compiler option is \`true\`\nhttps://svelte.dev/e/experimental_async`);
}

/**
* `%name%` is not defined
* @param {null | number | NodeLike} node
@@ -233,6 +242,15 @@ export function invalid_arguments_usage(node) {
e(node, 'invalid_arguments_usage', `The arguments keyword cannot be used within the template or at the top level of a component\nhttps://svelte.dev/e/invalid_arguments_usage`);
}

/**
* Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless in runes mode
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function legacy_await_invalid(node) {
e(node, 'legacy_await_invalid', `Cannot use \`await\` in deriveds and template expressions, or at the top level of a component, unless in runes mode\nhttps://svelte.dev/e/legacy_await_invalid`);
}

/**
* Cannot use `export let` in runes mode — use `$props()` instead
* @param {null | number | NodeLike} node
5 changes: 4 additions & 1 deletion packages/svelte/src/compiler/migrate/index.js
Original file line number Diff line number Diff line change
@@ -146,7 +146,10 @@ export function migrate(source, { filename, use_ts } = {}) {
...validate_component_options({}, ''),
...parsed_options,
customElementOptions,
filename: filename ?? '(unknown)'
filename: filename ?? '(unknown)',
experimental: {
async: true
}
};

const str = new MagicString(source);
2 changes: 2 additions & 0 deletions packages/svelte/src/compiler/phases/1-parse/state/element.js
Original file line number Diff line number Diff line change
@@ -284,6 +284,8 @@ export default function element(parser) {
} else {
element.tag = get_attribute_expression(definition);
}

element.metadata.expression = create_expression_metadata();
}

if (is_top_level_script_or_style) {
20 changes: 16 additions & 4 deletions packages/svelte/src/compiler/phases/1-parse/state/tag.js
Original file line number Diff line number Diff line change
@@ -60,7 +60,10 @@ function open(parser) {
end: -1,
test: read_expression(parser),
consequent: create_fragment(),
alternate: null
alternate: null,
metadata: {
expression: create_expression_metadata()
}
});

parser.allow_whitespace();
@@ -323,7 +326,10 @@ function open(parser) {
start,
end: -1,
expression,
fragment: create_fragment()
fragment: create_fragment(),
metadata: {
expression: create_expression_metadata()
}
});

parser.stack.push(block);
@@ -441,7 +447,10 @@ function next(parser) {
elseif: true,
test: expression,
consequent: create_fragment(),
alternate: null
alternate: null,
metadata: {
expression: create_expression_metadata()
}
});

parser.stack.push(child);
@@ -604,7 +613,10 @@ function special(parser) {
type: 'HtmlTag',
start,
end: parser.index,
expression
expression,
metadata: {
expression: create_expression_metadata()
}
});

return;
33 changes: 24 additions & 9 deletions packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ import { ArrowFunctionExpression } from './visitors/ArrowFunctionExpression.js';
import { AssignmentExpression } from './visitors/AssignmentExpression.js';
import { Attribute } from './visitors/Attribute.js';
import { AwaitBlock } from './visitors/AwaitBlock.js';
import { AwaitExpression } from './visitors/AwaitExpression.js';
import { BindDirective } from './visitors/BindDirective.js';
import { CallExpression } from './visitors/CallExpression.js';
import { ClassBody } from './visitors/ClassBody.js';
@@ -133,6 +134,7 @@ const visitors = {
AssignmentExpression,
Attribute,
AwaitBlock,
AwaitExpression,
BindDirective,
CallExpression,
ClassBody,
@@ -201,9 +203,9 @@ function js(script, root, allow_reactive_declarations, parent) {
body: []
};

const { scope, scopes } = create_scopes(ast, root, allow_reactive_declarations, parent);
const { scope, scopes, is_async } = create_scopes(ast, root, allow_reactive_declarations, parent);

return { ast, scope, scopes };
return { ast, scope, scopes, is_async };
}

/**
@@ -228,7 +230,7 @@ const RESERVED = ['$$props', '$$restProps', '$$slots'];
* @returns {Analysis}
*/
export function analyze_module(ast, options) {
const { scope, scopes } = create_scopes(ast, new ScopeRoot(), false, null);
const { scope, scopes, is_async } = create_scopes(ast, new ScopeRoot(), false, null);

for (const [name, references] of scope.references) {
if (name[0] !== '$' || RESERVED.includes(name)) continue;
@@ -245,12 +247,14 @@ export function analyze_module(ast, options) {

/** @type {Analysis} */
const analysis = {
module: { ast, scope, scopes },
module: { ast, scope, scopes, is_async },
name: options.filename,
accessors: false,
runes: true,
immutable: true,
tracing: false
tracing: false,
async_deriveds: new Set(),
context_preserving_awaits: new Set()
};

walk(
@@ -259,7 +263,9 @@ export function analyze_module(ast, options) {
scope,
scopes,
// @ts-expect-error TODO
analysis
analysis,
// @ts-expect-error TODO
options
},
visitors
);
@@ -279,7 +285,12 @@ export function analyze_component(root, source, options) {
const module = js(root.module, scope_root, false, null);
const instance = js(root.instance, scope_root, true, module.scope);

const { scope, scopes } = create_scopes(root.fragment, scope_root, false, instance.scope);
const { scope, scopes, is_async } = create_scopes(
root.fragment,
scope_root,
false,
instance.scope
);

/** @type {Template} */
const template = { ast: root.fragment, scope, scopes };
@@ -387,7 +398,9 @@ export function analyze_component(root, source, options) {

const component_name = get_component_name(options.filename);

const runes = options.runes ?? Array.from(module.scope.references.keys()).some(is_rune);
const runes =
options.runes ??
(is_async || instance.is_async || Array.from(module.scope.references.keys()).some(is_rune));

if (!runes) {
for (let check of synthetic_stores_legacy_check) {
@@ -449,7 +462,9 @@ export function analyze_component(root, source, options) {
source,
undefined_exports: new Map(),
snippet_renderers: new Map(),
snippets: new Set()
snippets: new Set(),
async_deriveds: new Set(),
context_preserving_awaits: new Set()
};

if (!runes) {
Loading