Skip to content

Commit c6d0db4

Browse files
committed
Merge branch 'main' into $inspect.trace-source-tagging
2 parents 3480a35 + fd08cb0 commit c6d0db4

File tree

58 files changed

+533
-408
lines changed

Some content is hidden

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

58 files changed

+533
-408
lines changed

.changeset/flat-points-kick.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: reset `is_flushing` if `flushSync` is called and there's no scheduled effect

documentation/docs/07-misc/07-v5-migration-guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,9 +833,9 @@ Svelte 5 is more strict about the HTML structure and will throw a compiler error
833833

834834
Assignments to destructured parts of a `@const` declaration are no longer allowed. It was an oversight that this was ever allowed.
835835

836-
### :is(...) and :where(...) are scoped
836+
### :is(...), :has(...), and :where(...) are scoped
837837

838-
Previously, Svelte did not analyse selectors inside `:is(...)` and `:where(...)`, effectively treating them as global. Svelte 5 analyses them in the context of the current component. As such, some selectors may now be treated as unused if they were relying on this treatment. To fix this, use `:global(...)` inside the `:is(...)/:where(...)` selectors.
838+
Previously, Svelte did not analyse selectors inside `:is(...)`, `:has(...)`, and `:where(...)`, effectively treating them as global. Svelte 5 analyses them in the context of the current component. As such, some selectors may now be treated as unused if they were relying on this treatment. To fix this, use `:global(...)` inside the `:is(...)/:has(...)/:where(...)` selectors.
839839

840840
When using Tailwind's `@apply` directive, add a `:global` selector to preserve rules that use Tailwind-generated `:is(...)` selectors:
841841

packages/svelte/CHANGELOG.md

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

3+
## 5.33.18
4+
5+
### Patch Changes
6+
7+
- chore: bump `esrap` dependency ([#16106](https://github.com/sveltejs/svelte/pull/16106))
8+
9+
- fix: destructuring state in ssr ([#16102](https://github.com/sveltejs/svelte/pull/16102))
10+
11+
## 5.33.17
12+
13+
### Patch Changes
14+
15+
- chore: update acorn parser `ecmaVersion` to parse import attributes ([#16098](https://github.com/sveltejs/svelte/pull/16098))
16+
17+
## 5.33.16
18+
19+
### Patch Changes
20+
21+
- fix: visit expression when destructuring state declarations ([#16081](https://github.com/sveltejs/svelte/pull/16081))
22+
23+
- fix: move xmlns attribute from SVGAttributes to to DOMAttributes ([#16080](https://github.com/sveltejs/svelte/pull/16080))
24+
25+
## 5.33.15
26+
27+
### Patch Changes
28+
29+
- fix: invoke parent boundary of deriveds that throw ([#16091](https://github.com/sveltejs/svelte/pull/16091))
30+
31+
## 5.33.14
32+
33+
### Patch Changes
34+
35+
- Revert "feat: enable TS autocomplete for Svelte HTML element definitions" ([#16063](https://github.com/sveltejs/svelte/pull/16063))
36+
37+
- fix: destructuring snippet arguments ([#16068](https://github.com/sveltejs/svelte/pull/16068))
38+
39+
## 5.33.13
40+
41+
### Patch Changes
42+
43+
- fix: avoid recursion error in `EachBlock` visitor ([#16058](https://github.com/sveltejs/svelte/pull/16058))
44+
345
## 5.33.12
446

547
### Patch Changes

packages/svelte/elements.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ export interface DOMAttributes<T extends EventTarget> {
463463
'on:fullscreenerror'?: EventHandler<Event, T> | undefined | null;
464464
onfullscreenerror?: EventHandler<Event, T> | undefined | null;
465465
onfullscreenerrorcapture?: EventHandler<Event, T> | undefined | null;
466+
467+
xmlns?: string | undefined | null;
466468
}
467469

468470
// All the WAI-ARIA 1.1 attributes from https://www.w3.org/TR/wai-aria-1.1/
@@ -1809,7 +1811,6 @@ export interface SVGAttributes<T extends EventTarget> extends AriaAttributes, DO
18091811
'xlink:type'?: string | undefined | null;
18101812
'xml:base'?: string | undefined | null;
18111813
'xml:lang'?: string | undefined | null;
1812-
xmlns?: string | undefined | null;
18131814
'xmlns:xlink'?: string | undefined | null;
18141815
'xml:space'?: string | undefined | null;
18151816
y1?: number | string | undefined | null;
@@ -2066,7 +2067,7 @@ export interface SvelteHTMLElements {
20662067
failed?: import('svelte').Snippet<[error: unknown, reset: () => void]>;
20672068
};
20682069

2069-
[name: string & {}]: { [name: string]: any };
2070+
[name: string]: { [name: string]: any };
20702071
}
20712072

20722073
export type ClassValue = string | import('clsx').ClassArray | import('clsx').ClassDictionary;

packages/svelte/package.json

Lines changed: 2 additions & 2 deletions
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.33.12",
5+
"version": "5.33.18",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {
@@ -171,7 +171,7 @@
171171
"axobject-query": "^4.1.0",
172172
"clsx": "^2.1.1",
173173
"esm-env": "^1.2.1",
174-
"esrap": "^1.4.6",
174+
"esrap": "^1.4.8",
175175
"is-reference": "^3.0.3",
176176
"locate-character": "^3.0.0",
177177
"magic-string": "^0.30.11",

packages/svelte/src/compiler/phases/1-parse/acorn.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function parse(source, typescript, is_script) {
3636
ast = parser.parse(source, {
3737
onComment,
3838
sourceType: 'module',
39-
ecmaVersion: 13,
39+
ecmaVersion: 16,
4040
locations: true
4141
});
4242
} finally {
@@ -64,7 +64,7 @@ export function parse_expression_at(source, typescript, index) {
6464
const ast = parser.parseExpressionAt(source, index, {
6565
onComment,
6666
sourceType: 'module',
67-
ecmaVersion: 13,
67+
ecmaVersion: 16,
6868
locations: true
6969
});
7070

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ export function EachBlock(node, context) {
7777
* @returns {void}
7878
*/
7979
function collect_transitive_dependencies(binding, bindings) {
80+
if (bindings.has(binding)) {
81+
return;
82+
}
8083
bindings.add(binding);
8184

8285
if (binding.kind === 'legacy_reactive') {

packages/svelte/src/compiler/phases/3-transform/client/visitors/SnippetBlock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function SnippetBlock(node, context) {
5757
for (const path of paths) {
5858
const name = /** @type {Identifier} */ (path.node).name;
5959
const needs_derived = path.has_default_value; // to ensure that default value is only called once
60-
const fn = b.thunk(/** @type {Expression} */ (context.visit(path.expression)));
60+
const fn = b.thunk(/** @type {Expression} */ (context.visit(path.expression, child_state)));
6161

6262
declarations.push(b.let(path.node, needs_derived ? b.call('$.derived_safe_equal', fn) : fn));
6363

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @import { BlockStatement, Statement, Expression } from 'estree' */
1+
/** @import { BlockStatement, Statement, Expression, FunctionDeclaration, VariableDeclaration, ArrowFunctionExpression } from 'estree' */
22
/** @import { AST } from '#compiler' */
33
/** @import { ComponentContext } from '../types' */
44
import { dev } from '../../../../state.js';
@@ -34,62 +34,61 @@ export function SvelteBoundary(node, context) {
3434
const nodes = [];
3535

3636
/** @type {Statement[]} */
37-
const external_statements = [];
37+
const const_tags = [];
3838

3939
/** @type {Statement[]} */
40-
const internal_statements = [];
40+
const hoisted = [];
4141

42-
const snippets_visits = [];
42+
// const tags need to live inside the boundary, but might also be referenced in hoisted snippets.
43+
// to resolve this we cheat: we duplicate const tags inside snippets
44+
for (const child of node.fragment.nodes) {
45+
if (child.type === 'ConstTag') {
46+
context.visit(child, { ...context.state, init: const_tags });
47+
}
48+
}
4349

44-
// Capture the `failed` implicit snippet prop
4550
for (const child of node.fragment.nodes) {
46-
if (child.type === 'SnippetBlock' && child.expression.name === 'failed') {
47-
// we need to delay the visit of the snippets in case they access a ConstTag that is declared
48-
// after the snippets so that the visitor for the const tag can be updated
49-
snippets_visits.push(() => {
50-
/** @type {Statement[]} */
51-
const init = [];
52-
context.visit(child, { ...context.state, init });
53-
props.properties.push(b.prop('init', child.expression, child.expression));
54-
external_statements.push(...init);
55-
});
56-
} else if (child.type === 'ConstTag') {
51+
if (child.type === 'ConstTag') {
52+
continue;
53+
}
54+
55+
if (child.type === 'SnippetBlock') {
5756
/** @type {Statement[]} */
58-
const init = [];
59-
context.visit(child, { ...context.state, init });
60-
61-
if (dev) {
62-
// In dev we must separate the declarations from the code
63-
// that eagerly evaluate the expression...
64-
for (const statement of init) {
65-
if (statement.type === 'VariableDeclaration') {
66-
external_statements.push(statement);
67-
} else {
68-
internal_statements.push(statement);
69-
}
70-
}
71-
} else {
72-
external_statements.push(...init);
57+
const statements = [];
58+
59+
context.visit(child, { ...context.state, init: statements });
60+
61+
const snippet = /** @type {VariableDeclaration} */ (statements[0]);
62+
63+
const snippet_fn = dev
64+
? // @ts-expect-error we know this shape is correct
65+
snippet.declarations[0].init.arguments[1]
66+
: snippet.declarations[0].init;
67+
68+
snippet_fn.body.body.unshift(
69+
...const_tags.filter((node) => node.type === 'VariableDeclaration')
70+
);
71+
72+
hoisted.push(snippet);
73+
74+
if (child.expression.name === 'failed') {
75+
props.properties.push(b.prop('init', child.expression, child.expression));
7376
}
74-
} else {
75-
nodes.push(child);
77+
78+
continue;
7679
}
77-
}
7880

79-
snippets_visits.forEach((visit) => visit());
81+
nodes.push(child);
82+
}
8083

8184
const block = /** @type {BlockStatement} */ (context.visit({ ...node.fragment, nodes }));
8285

83-
if (dev && internal_statements.length) {
84-
block.body.unshift(...internal_statements);
85-
}
86+
block.body.unshift(...const_tags);
8687

8788
const boundary = b.stmt(
8889
b.call('$.boundary', context.state.node, props, b.arrow([b.id('$$anchor')], block))
8990
);
9091

9192
context.state.template.push_comment();
92-
context.state.init.push(
93-
external_statements.length > 0 ? b.block([...external_statements, boundary]) : boundary
94-
);
93+
context.state.init.push(hoisted.length > 0 ? b.block([...hoisted, boundary]) : boundary);
9594
}

packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export function VariableDeclaration(node, context) {
164164
const { inserts, paths } = extract_paths(declarator.id, tmp);
165165

166166
declarations.push(
167-
b.declarator(tmp, value),
167+
b.declarator(tmp, /** @type {Expression} */ (context.visit(value))),
168168
...inserts.map(({ id, value }) => {
169169
id.name = context.state.scope.generate('$$array');
170170
context.state.transform[id.name] = { read: get_value };

0 commit comments

Comments
 (0)