Skip to content

Commit a33ff30

Browse files
committed
Merge branch 'main' into state-onchange
2 parents 458ed29 + 3080c13 commit a33ff30

File tree

20 files changed

+152
-5
lines changed

20 files changed

+152
-5
lines changed

.changeset/nice-pianos-punch.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: prevent state runes from being called with spread

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,12 @@ Cannot access a computed property of a rune
660660
`%name%` is not a valid rune
661661
```
662662

663+
### rune_invalid_spread
664+
665+
```
666+
`%rune%` cannot be called with a spread argument
667+
```
668+
663669
### rune_invalid_usage
664670

665671
```

packages/svelte/CHANGELOG.md

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

3+
## 5.25.2
4+
5+
### Patch Changes
6+
7+
- feat: migrate reassigned deriveds to `$derived` ([#15581](https://github.com/sveltejs/svelte/pull/15581))
8+
9+
## 5.25.1
10+
11+
### Patch Changes
12+
13+
- fix: prevent dev server from throwing errors when attempting to retrieve the proxied value of an iframe's contentWindow ([#15577](https://github.com/sveltejs/svelte/pull/15577))
14+
315
## 5.25.0
416

517
### Minor Changes

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ This turned out to be buggy and unpredictable, particularly when working with de
162162

163163
> `%name%` is not a valid rune
164164
165+
## rune_invalid_spread
166+
167+
> `%rune%` cannot be called with a spread argument
168+
165169
## rune_invalid_usage
166170

167171
> Cannot use `%rune%` rune in non-runes mode

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.25.0",
5+
"version": "5.25.2",
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
@@ -383,6 +383,16 @@ export function rune_invalid_name(node, name) {
383383
e(node, 'rune_invalid_name', `\`${name}\` is not a valid rune\nhttps://svelte.dev/e/rune_invalid_name`);
384384
}
385385

386+
/**
387+
* `%rune%` cannot be called with a spread argument
388+
* @param {null | number | NodeLike} node
389+
* @param {string} rune
390+
* @returns {never}
391+
*/
392+
export function rune_invalid_spread(node, rune) {
393+
e(node, 'rune_invalid_spread', `\`${rune}\` cannot be called with a spread argument\nhttps://svelte.dev/e/rune_invalid_spread`);
394+
}
395+
386396
/**
387397
* Cannot use `%rune%` rune in non-runes mode
388398
* @param {null | number | NodeLike} node

packages/svelte/src/compiler/migrate/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ const instance_script = {
952952
const reassigned_bindings = bindings.filter((b) => b?.reassigned);
953953

954954
if (
955-
reassigned_bindings.length === 0 &&
955+
node.body.expression.right.type !== 'Literal' &&
956956
!bindings.some((b) => b?.kind === 'store_sub') &&
957957
node.body.expression.left.type !== 'MemberExpression'
958958
) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ export function CallExpression(node, context) {
1717

1818
const rune = get_rune(node, context.state.scope);
1919

20+
if (rune && rune !== '$inspect') {
21+
for (const arg of node.arguments) {
22+
if (arg.type === 'SpreadElement') {
23+
e.rune_invalid_spread(node, rune);
24+
}
25+
}
26+
}
27+
2028
switch (rune) {
2129
case null:
2230
if (!is_safe_identifier(node.callee, context.state.scope)) {

packages/svelte/src/internal/client/proxy.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,18 @@ function update_version(signal, d = 1) {
483483
* @param {any} value
484484
*/
485485
export function get_proxied_value(value) {
486-
if (value !== null && typeof value === 'object' && STATE_SYMBOL in value) {
487-
return value[STATE_SYMBOL];
486+
try {
487+
if (value !== null && typeof value === 'object' && STATE_SYMBOL in value) {
488+
return value[STATE_SYMBOL];
489+
}
490+
} catch {
491+
// the above if check can throw an error if the value in question
492+
// is the contentWindow of an iframe on another domain, in which
493+
// case we want to just return the value (because it's definitely
494+
// not a proxied value) so we don't break any JavaScript interacting
495+
// with that iframe (such as various payment companies client side
496+
// JavaScript libraries interacting with their iframes on the same
497+
// domain)
488498
}
489499

490500
return value;

packages/svelte/src/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* The current version, as set in package.json.
55
* @type {string}
66
*/
7-
export const VERSION = '5.25.0';
7+
export const VERSION = '5.25.2';
88
export const PUBLIC_VERSION = '5';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
let name = 'world';
3+
4+
$: upper = name.toUpperCase();
5+
</script>
6+
7+
<input bind:value={name} />
8+
<input bind:value={upper} />
9+
10+
{upper}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
let name = $state('world');
3+
4+
let upper = $derived(name.toUpperCase());
5+
</script>
6+
7+
<input bind:value={name} />
8+
<input bind:value={upper} />
9+
10+
{upper}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"code": "rune_invalid_spread",
4+
"end": {
5+
"column": 35,
6+
"line": 3
7+
},
8+
"message": "`$derived.by` cannot be called with a spread argument",
9+
"start": {
10+
"column": 15,
11+
"line": 3
12+
}
13+
}
14+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
const args = [0];
3+
const count = $derived.by(...args);
4+
</script>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"code": "rune_invalid_spread",
4+
"end": {
5+
"column": 32,
6+
"line": 3
7+
},
8+
"message": "`$derived` cannot be called with a spread argument",
9+
"start": {
10+
"column": 15,
11+
"line": 3
12+
}
13+
}
14+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
const args = [0];
3+
const count = $derived(...args);
4+
</script>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"code": "rune_invalid_spread",
4+
"end": {
5+
"column": 34,
6+
"line": 3
7+
},
8+
"message": "`$state.raw` cannot be called with a spread argument",
9+
"start": {
10+
"column": 15,
11+
"line": 3
12+
}
13+
}
14+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
const args = [0];
3+
const count = $state.raw(...args);
4+
</script>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"code": "rune_invalid_spread",
4+
"end": {
5+
"column": 30,
6+
"line": 3
7+
},
8+
"message": "`$state` cannot be called with a spread argument",
9+
"start": {
10+
"column": 15,
11+
"line": 3
12+
}
13+
}
14+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
const args = [0];
3+
const count = $state(...args);
4+
</script>

0 commit comments

Comments
 (0)