-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: treat spread elements the same as call expressions (#14488)
- Loading branch information
1 parent
9fcfd7f
commit fe15ad4
Showing
6 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: treat spread elements the same as call expressions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/svelte/src/compiler/phases/2-analyze/visitors/SpreadElement.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** @import { SpreadElement } from 'estree' */ | ||
/** @import { Context } from '../types' */ | ||
|
||
/** | ||
* @param {SpreadElement} node | ||
* @param {Context} context | ||
*/ | ||
export function SpreadElement(node, context) { | ||
if (context.state.expression) { | ||
// treat e.g. `[...x]` the same as `[...x.values()]` | ||
context.state.expression.has_call = true; | ||
context.state.expression.has_state = true; | ||
} | ||
|
||
context.next(); | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/svelte/tests/runtime-runes/samples/props-spread-operator/Child.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script> | ||
let { numbers } = $props(); | ||
</script> | ||
|
||
{numbers.join(', ')} |
13 changes: 13 additions & 0 deletions
13
packages/svelte/tests/runtime-runes/samples/props-spread-operator/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
html: '<button>+1</button> 0, 1, 2', | ||
|
||
test({ target, assert }) { | ||
const btn = target.querySelector('button'); | ||
|
||
flushSync(() => btn?.click()); | ||
assert.htmlEqual(target.innerHTML, '<button>+1</button> 0, 1, 2, 3'); | ||
} | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/svelte/tests/runtime-runes/samples/props-spread-operator/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script> | ||
import { SvelteSet } from 'svelte/reactivity'; | ||
import Child from './Child.svelte'; | ||
const numbers = new SvelteSet([0, 1, 2]); | ||
</script> | ||
|
||
<button onclick={() => numbers.add(numbers.size)}>+1</button> | ||
|
||
<Child numbers={[...numbers]} /> |