Skip to content

Commit a7b9f57

Browse files
authored
Merge branch 'main' into missing-effects
2 parents 942228e + 5912754 commit a7b9f57

File tree

93 files changed

+1336
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1336
-253
lines changed

.changeset/khaki-feet-teach.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/metal-months-fail.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/orange-chefs-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure async deriveds always get dependencies from thennable

documentation/docs/98-reference/.generated/compile-errors.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,51 @@ Cyclical dependency detected: %cycle%
196196
`{@const}` must be the immediate child of `{#snippet}`, `{#if}`, `{:else if}`, `{:else}`, `{#each}`, `{:then}`, `{:catch}`, `<svelte:fragment>`, `<svelte:boundary` or `<Component>`
197197
```
198198

199+
### const_tag_invalid_reference
200+
201+
```
202+
The `{@const %name% = ...}` declaration is not available in this snippet
203+
```
204+
205+
The following is an error:
206+
207+
```svelte
208+
<svelte:boundary>
209+
{@const foo = 'bar'}
210+
211+
{#snippet failed()}
212+
{foo}
213+
{/snippet}
214+
</svelte:boundary>
215+
```
216+
217+
Here, `foo` is not available inside `failed`. The top level code inside `<svelte:boundary>` becomes part of the implicit `children` snippet, in other words the above code is equivalent to this:
218+
219+
```svelte
220+
<svelte:boundary>
221+
{#snippet children()}
222+
{@const foo = 'bar'}
223+
{/snippet}
224+
225+
{#snippet failed()}
226+
{foo}
227+
{/snippet}
228+
</svelte:boundary>
229+
```
230+
231+
The same applies to components:
232+
233+
```svelte
234+
<Component>
235+
{@const foo = 'bar'}
236+
237+
{#snippet someProp()}
238+
<!-- error -->
239+
{foo}
240+
{/snippet}
241+
</Component>
242+
```
243+
199244
### constant_assignment
200245

201246
```

packages/svelte/CHANGELOG.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
11
# svelte
22

3+
## 5.38.4
4+
5+
### Patch Changes
6+
7+
- fix: place instance-level snippets inside async body ([#16666](https://github.com/sveltejs/svelte/pull/16666))
8+
9+
- fix: Add check for builtin custom elements in `set_custom_element_data` ([#16592](https://github.com/sveltejs/svelte/pull/16592))
10+
11+
- fix: restore batch along with effect context ([#16668](https://github.com/sveltejs/svelte/pull/16668))
12+
13+
- fix: wait until changes propagate before updating input selection state ([#16649](https://github.com/sveltejs/svelte/pull/16649))
14+
15+
- fix: add "Accept-CH" as valid value for `http-equiv` ([#16671](https://github.com/sveltejs/svelte/pull/16671))
16+
17+
## 5.38.3
18+
19+
### Patch Changes
20+
21+
- fix: ensure correct order of template effect values ([#16655](https://github.com/sveltejs/svelte/pull/16655))
22+
23+
- fix: allow async `{@const}` in more places ([#16643](https://github.com/sveltejs/svelte/pull/16643))
24+
25+
- fix: properly catch top level await errors ([#16619](https://github.com/sveltejs/svelte/pull/16619))
26+
27+
- perf: prune effects without dependencies ([#16625](https://github.com/sveltejs/svelte/pull/16625))
28+
29+
- fix: only emit `for_await_track_reactivity_loss` in async mode ([#16644](https://github.com/sveltejs/svelte/pull/16644))
30+
31+
## 5.38.2
32+
33+
### Patch Changes
34+
35+
- perf: run blocks eagerly during flush instead of aborting ([#16631](https://github.com/sveltejs/svelte/pull/16631))
36+
37+
- fix: don't clone non-proxies in `$inspect` ([#16617](https://github.com/sveltejs/svelte/pull/16617))
38+
39+
- fix: avoid recursion error when tagging circular references ([#16622](https://github.com/sveltejs/svelte/pull/16622))
40+
41+
## 5.38.1
42+
43+
### Patch Changes
44+
45+
- fix: wrap `abort` in `without_reactive_context` ([#16570](https://github.com/sveltejs/svelte/pull/16570))
46+
47+
- fix: add `hint` as a possible value for `popover` attribute ([#16581](https://github.com/sveltejs/svelte/pull/16581))
48+
49+
- fix: skip effects inside dynamic component that is about to be destroyed ([#16601](https://github.com/sveltejs/svelte/pull/16601))
50+
351
## 5.38.0
452

553
### Minor Changes

packages/svelte/elements.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,7 @@ export interface HTMLMetaAttributes extends HTMLAttributes<HTMLMetaElement> {
12681268
charset?: string | undefined | null;
12691269
content?: string | undefined | null;
12701270
'http-equiv'?:
1271+
| 'accept-ch'
12711272
| 'content-security-policy'
12721273
| 'content-type'
12731274
| 'default-style'

packages/svelte/messages/compile-errors/template.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,49 @@
124124

125125
> `{@const}` must be the immediate child of `{#snippet}`, `{#if}`, `{:else if}`, `{:else}`, `{#each}`, `{:then}`, `{:catch}`, `<svelte:fragment>`, `<svelte:boundary` or `<Component>`
126126
127+
## const_tag_invalid_reference
128+
129+
> The `{@const %name% = ...}` declaration is not available in this snippet
130+
131+
The following is an error:
132+
133+
```svelte
134+
<svelte:boundary>
135+
{@const foo = 'bar'}
136+
137+
{#snippet failed()}
138+
{foo}
139+
{/snippet}
140+
</svelte:boundary>
141+
```
142+
143+
Here, `foo` is not available inside `failed`. The top level code inside `<svelte:boundary>` becomes part of the implicit `children` snippet, in other words the above code is equivalent to this:
144+
145+
```svelte
146+
<svelte:boundary>
147+
{#snippet children()}
148+
{@const foo = 'bar'}
149+
{/snippet}
150+
151+
{#snippet failed()}
152+
{foo}
153+
{/snippet}
154+
</svelte:boundary>
155+
```
156+
157+
The same applies to components:
158+
159+
```svelte
160+
<Component>
161+
{@const foo = 'bar'}
162+
163+
{#snippet someProp()}
164+
<!-- error -->
165+
{foo}
166+
{/snippet}
167+
</Component>
168+
```
169+
127170
## debug_tag_invalid_arguments
128171

129172
> {@debug ...} arguments must be identifiers, not arbitrary expressions

packages/svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "svelte",
33
"description": "Cybernetically enhanced web apps",
44
"license": "MIT",
5-
"version": "5.38.0",
5+
"version": "5.38.4",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {

packages/svelte/src/compiler/errors.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,16 @@ export function const_tag_invalid_placement(node) {
985985
e(node, 'const_tag_invalid_placement', `\`{@const}\` must be the immediate child of \`{#snippet}\`, \`{#if}\`, \`{:else if}\`, \`{:else}\`, \`{#each}\`, \`{:then}\`, \`{:catch}\`, \`<svelte:fragment>\`, \`<svelte:boundary\` or \`<Component>\`\nhttps://svelte.dev/e/const_tag_invalid_placement`);
986986
}
987987

988+
/**
989+
* The `{@const %name% = ...}` declaration is not available in this snippet
990+
* @param {null | number | NodeLike} node
991+
* @param {string} name
992+
* @returns {never}
993+
*/
994+
export function const_tag_invalid_reference(node, name) {
995+
e(node, 'const_tag_invalid_reference', `The \`{@const ${name} = ...}\` declaration is not available in this snippet \nhttps://svelte.dev/e/const_tag_invalid_reference`);
996+
}
997+
988998
/**
989999
* {@debug ...} arguments must be identifiers, not arbitrary expressions
9901000
* @param {null | number | NodeLike} node

packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as w from '../../../warnings.js';
77
import { is_rune } from '../../../../utils.js';
88
import { mark_subtree_dynamic } from './shared/fragment.js';
99
import { get_rune } from '../../scope.js';
10+
import { is_component_node } from '../../nodes.js';
1011

1112
/**
1213
* @param {Identifier} node
@@ -155,5 +156,37 @@ export function Identifier(node, context) {
155156
) {
156157
w.reactive_declaration_module_script_dependency(node);
157158
}
159+
160+
if (binding.metadata?.is_template_declaration && context.state.options.experimental.async) {
161+
let snippet_name;
162+
163+
// Find out if this references a {@const ...} declaration of an implicit children snippet
164+
// when it is itself inside a snippet block at the same level. If so, error.
165+
for (let i = context.path.length - 1; i >= 0; i--) {
166+
const parent = context.path[i];
167+
const grand_parent = context.path[i - 1];
168+
169+
if (parent.type === 'SnippetBlock') {
170+
snippet_name = parent.expression.name;
171+
} else if (
172+
snippet_name &&
173+
grand_parent &&
174+
parent.type === 'Fragment' &&
175+
(is_component_node(grand_parent) ||
176+
(grand_parent.type === 'SvelteBoundary' &&
177+
(snippet_name === 'failed' || snippet_name === 'pending')))
178+
) {
179+
if (
180+
is_component_node(grand_parent)
181+
? grand_parent.metadata.scopes.default === binding.scope
182+
: context.state.scopes.get(parent) === binding.scope
183+
) {
184+
e.const_tag_invalid_reference(node, node.name);
185+
} else {
186+
break;
187+
}
188+
}
189+
}
190+
}
158191
}
159192
}

0 commit comments

Comments
 (0)