Skip to content

Commit 449f0a5

Browse files
committed
Merge branch 'main' into class-enhancements
2 parents 343bef1 + 88a15cd commit 449f0a5

File tree

55 files changed

+1638
-216
lines changed

Some content is hidden

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

55 files changed

+1638
-216
lines changed

documentation/docs/02-runes/07-$inspect.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,20 @@ A convenient way to find the origin of some change is to pass `console.trace` to
4242
// @errors: 2304
4343
$inspect(stuff).with(console.trace);
4444
```
45+
46+
## $inspect.trace(...)
47+
48+
This rune, added in 5.14, causes the surrounding function to be _traced_ in development. Any time the function re-runs as part of an [effect]($effect) or a [derived]($derived), information will be printed to the console about which pieces of reactive state caused the effect to fire.
49+
50+
```svelte
51+
<script>
52+
import { doSomeWork } from './elsewhere';
53+
54+
$effect(() => {
55+
+++$inspect.trace();+++
56+
doSomeWork();
57+
});
58+
</script>
59+
```
60+
61+
`$inspect.trace` takes an optional first argument which will be used as the label.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,18 @@ Expected whitespace
442442
Imports of `svelte/internal/*` are forbidden. It contains private runtime code which is subject to change without notice. If you're importing from `svelte/internal/*` to work around a limitation of Svelte, please open an issue at https://github.com/sveltejs/svelte and explain your use case
443443
```
444444

445+
### inspect_trace_generator
446+
447+
```
448+
`$inspect.trace(...)` cannot be used inside a generator function
449+
```
450+
451+
### inspect_trace_invalid_placement
452+
453+
```
454+
`$inspect.trace(...)` must be the first statement of a function body
455+
```
456+
445457
### invalid_arguments_usage
446458

447459
```

documentation/docs/99-legacy/30-legacy-svelte-component.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: <svelte:component>
33
---
44

5-
In runes mode, `<MyComponent>` will re-render if the value of `MyComponent` changes.
5+
In runes mode, `<MyComponent>` will re-render if the value of `MyComponent` changes. See the [Svelte 5 migration guide](/docs/svelte/v5-migration-guide#Breaking-changes-in-runes-mode-svelte:component-is-no-longer-necessary) for an example.
66

77
In legacy mode, it won't — we must use `<svelte:component>`, which destroys and recreates the component instance when the value of its `this` expression changes:
88

packages/svelte/CHANGELOG.md

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

3+
## 5.14.4
4+
5+
### Patch Changes
6+
7+
- fix: remove implements from class declarations ([#14749](https://github.com/sveltejs/svelte/pull/14749))
8+
9+
- fix: remove unwanted properties from both replaced and unreplaced nodes ([#14744](https://github.com/sveltejs/svelte/pull/14744))
10+
11+
## 5.14.3
12+
13+
### Patch Changes
14+
15+
- fix: bump esrap, prevent malformed AST ([#14742](https://github.com/sveltejs/svelte/pull/14742))
16+
17+
- fix: compare array contents for equality mismatch detections, not the arrays themselves ([#14738](https://github.com/sveltejs/svelte/pull/14738))
18+
19+
## 5.14.2
20+
21+
### Patch Changes
22+
23+
- fix: correctly highlight first rerun of `$inspect.trace` ([#14734](https://github.com/sveltejs/svelte/pull/14734))
24+
25+
- chore: more loose parser improvements ([#14733](https://github.com/sveltejs/svelte/pull/14733))
26+
27+
## 5.14.1
28+
29+
### Patch Changes
30+
31+
- fix: improve unowned derived performance ([#14724](https://github.com/sveltejs/svelte/pull/14724))
32+
33+
## 5.14.0
34+
35+
### Minor Changes
36+
37+
- feat: adds $inspect.trace rune ([#14290](https://github.com/sveltejs/svelte/pull/14290))
38+
339
## 5.13.0
440

541
### Minor Changes

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454

5555
> Imports of `svelte/internal/*` are forbidden. It contains private runtime code which is subject to change without notice. If you're importing from `svelte/internal/*` to work around a limitation of Svelte, please open an issue at https://github.com/sveltejs/svelte and explain your use case
5656
57+
## inspect_trace_generator
58+
59+
> `$inspect.trace(...)` cannot be used inside a generator function
60+
61+
## inspect_trace_invalid_placement
62+
63+
> `$inspect.trace(...)` must be the first statement of a function body
64+
5765
## invalid_arguments_usage
5866

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

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.13.0",
5+
"version": "5.14.4",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {
@@ -148,7 +148,7 @@
148148
"axobject-query": "^4.1.0",
149149
"clsx": "^2.1.1",
150150
"esm-env": "^1.2.1",
151-
"esrap": "^1.2.3",
151+
"esrap": "^1.3.1",
152152
"is-reference": "^3.0.3",
153153
"locate-character": "^3.0.0",
154154
"magic-string": "^0.30.11",

packages/svelte/src/ambient.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,25 @@ declare function $inspect<T extends any[]>(
371371
...values: T
372372
): { with: (fn: (type: 'init' | 'update', ...values: T) => void) => void };
373373

374+
declare namespace $inspect {
375+
/**
376+
* Tracks which reactive state changes caused an effect to re-run. Must be the first
377+
* statement of a function body. Example:
378+
*
379+
* ```svelte
380+
* <script>
381+
* let count = $state(0);
382+
*
383+
* $effect(() => {
384+
* $inspect.trace('my effect');
385+
*
386+
* count;
387+
* });
388+
* </script>
389+
*/
390+
export function trace(name: string): void;
391+
}
392+
374393
/**
375394
* Retrieves the `this` reference of the custom element that contains this component. Example:
376395
*

packages/svelte/src/compiler/errors.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,24 @@ export function import_svelte_internal_forbidden(node) {
206206
e(node, "import_svelte_internal_forbidden", `Imports of \`svelte/internal/*\` are forbidden. It contains private runtime code which is subject to change without notice. If you're importing from \`svelte/internal/*\` to work around a limitation of Svelte, please open an issue at https://github.com/sveltejs/svelte and explain your use case\nhttps://svelte.dev/e/import_svelte_internal_forbidden`);
207207
}
208208

209+
/**
210+
* `$inspect.trace(...)` cannot be used inside a generator function
211+
* @param {null | number | NodeLike} node
212+
* @returns {never}
213+
*/
214+
export function inspect_trace_generator(node) {
215+
e(node, "inspect_trace_generator", `\`$inspect.trace(...)\` cannot be used inside a generator function\nhttps://svelte.dev/e/inspect_trace_generator`);
216+
}
217+
218+
/**
219+
* `$inspect.trace(...)` must be the first statement of a function body
220+
* @param {null | number | NodeLike} node
221+
* @returns {never}
222+
*/
223+
export function inspect_trace_invalid_placement(node) {
224+
e(node, "inspect_trace_invalid_placement", `\`$inspect.trace(...)\` must be the first statement of a function body\nhttps://svelte.dev/e/inspect_trace_invalid_placement`);
225+
}
226+
209227
/**
210228
* The arguments keyword cannot be used within the template or at the top level of a component
211229
* @param {null | number | NodeLike} node

packages/svelte/src/compiler/phases/1-parse/read/expression.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import { find_matching_bracket } from '../utils/bracket.js';
77

88
/**
99
* @param {Parser} parser
10+
* @param {string} [opening_token]
1011
* @returns {Expression}
1112
*/
12-
export default function read_expression(parser) {
13+
export default function read_expression(parser, opening_token) {
1314
try {
1415
const node = parse_expression_at(parser.template, parser.ts, parser.index);
1516

@@ -42,7 +43,7 @@ export default function read_expression(parser) {
4243
} catch (err) {
4344
if (parser.loose) {
4445
// Find the next } and treat it as the end of the expression
45-
const end = find_matching_bracket(parser.template, parser.index, '{');
46+
const end = find_matching_bracket(parser.template, parser.index, opening_token ?? '{');
4647
if (end) {
4748
const start = parser.index;
4849
parser.index = end;

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ function remove_this_param(node, context) {
1717

1818
/** @type {Visitors<any, null>} */
1919
const visitors = {
20+
_(node, context) {
21+
const n = context.next() ?? node;
22+
23+
// TODO there may come a time when we decide to preserve type annotations.
24+
// until that day comes, we just delete them so they don't confuse esrap
25+
delete n.typeAnnotation;
26+
delete n.typeParameters;
27+
delete n.returnType;
28+
delete n.accessibility;
29+
},
2030
Decorator(node) {
2131
e.typescript_invalid_feature(node, 'decorators (related TSC proposal is not stage 4 yet)');
2232
},
@@ -78,23 +88,12 @@ const visitors = {
7888
TSNonNullExpression(node, context) {
7989
return context.visit(node.expression);
8090
},
81-
TSTypeAnnotation() {
82-
// This isn't correct, strictly speaking, and could result in invalid ASTs (like an empty statement within function parameters),
83-
// but esrap, our printing tool, just ignores these AST nodes at invalid positions, so it's fine
84-
return b.empty;
85-
},
8691
TSInterfaceDeclaration() {
8792
return b.empty;
8893
},
8994
TSTypeAliasDeclaration() {
9095
return b.empty;
9196
},
92-
TSTypeParameterDeclaration() {
93-
return b.empty;
94-
},
95-
TSTypeParameterInstantiation() {
96-
return b.empty;
97-
},
9897
TSEnumDeclaration(node) {
9998
e.typescript_invalid_feature(node, 'enums');
10099
},
@@ -116,6 +115,7 @@ const visitors = {
116115
if (node.declare) {
117116
return b.empty;
118117
}
118+
delete node.implements;
119119
return context.next();
120120
},
121121
VariableDeclaration(node, context) {

0 commit comments

Comments
 (0)