fix: error at compile time when a declaration in a snippet redeclares one of its parameters

snippet-param-duplicate
Nic 10 hours ago
parent 636eaaaa6f
commit 9adebfd719

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: error at compile time when a declaration in a snippet redeclares one of its parameters

@ -1343,6 +1343,14 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
}
context.next({ scope: child_scope });
// the parameters and what the body declares end up in the same function
const body_scope = /** @type {Scope} */ (scopes.get(node.body));
for (const [name, binding] of body_scope.declarations) {
if (child_scope.declarations.has(name)) {
e.declaration_duplicate(binding.node, name);
}
}
},
Fragment: (node, context) => {

@ -0,0 +1,14 @@
[
{
"code": "declaration_duplicate",
"message": "`item` has already been declared",
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 12
}
}
]

@ -0,0 +1,6 @@
{#snippet row(item)}
{const item = 1}
<p>{item}</p>
{/snippet}
{@render row(5)}

@ -0,0 +1,8 @@
{#snippet row(item)}
{#if item}
{const item = 1}
<p>{item}</p>
{/if}
{/snippet}
{@render row(5)}
Loading…
Cancel
Save