Skip to content

Commit c2ec0d9

Browse files
fix: allow for duplicate var declarations (#15382)
1 parent bbeeed4 commit c2ec0d9

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

.changeset/spotty-drinks-tan.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 for duplicate `var` declarations

packages/svelte/src/compiler/phases/scope.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ export class Scope {
161161
}
162162

163163
if (this.declarations.has(node.name)) {
164-
// This also errors on var/function types, but that's arguably a good thing
165-
e.declaration_duplicate(node, node.name);
164+
const binding = this.declarations.get(node.name);
165+
if (binding && binding.declaration_kind !== 'var' && declaration_kind !== 'var') {
166+
// This also errors on function types, but that's arguably a good thing
167+
// declaring function twice is also caught by acorn in the parse phase
168+
e.declaration_duplicate(node, node.name);
169+
}
166170
}
167171

168172
const binding = new Binding(this, node, kind, declaration_kind, initial);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
var test = "";
3+
var test = 42;
4+
</script>
5+
6+
{test}

0 commit comments

Comments
 (0)