Skip to content

Commit caf2675

Browse files
committed
fix: allow multiple optional parameters with defaults
1 parent 3da2646 commit caf2675

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

.changeset/ten-geese-share.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: allow multiple optional parameters with defaults

packages/svelte/src/compiler/phases/1-parse/state/tag.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,14 @@ function open(parser) {
281281
parser.allow_whitespace();
282282
if (parser.eat('=')) {
283283
parser.allow_whitespace();
284-
const right = read_expression(parser);
284+
let right = read_expression(parser);
285+
// multiple assignment expression will be confused by the parser for a sequence expression
286+
// so if the returned value is a sequence expression we use the first expression as the
287+
// right and we reset the parser.index
288+
if (right.type === 'SequenceExpression') {
289+
right = right.expressions[0];
290+
parser.index = right.end ?? parser.index;
291+
}
285292
pattern = {
286293
type: 'AssignmentPattern',
287294
left: pattern,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
html: '012',
6+
ssrHtml: '012'
7+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{#snippet snip(a, b = 1, c=2)}
2+
{a}{b}{c}
3+
{/snippet}
4+
5+
{@render snip(0)}

0 commit comments

Comments
 (0)