Skip to content

Commit

Permalink
fix: allow for duplicate var declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti committed Feb 24, 2025
1 parent bbeeed4 commit 025e511
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-drinks-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: allow for duplicate `var` declarations
8 changes: 6 additions & 2 deletions packages/svelte/src/compiler/phases/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,12 @@ export class Scope {
}

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

const binding = new Binding(this, node, kind, declaration_kind, initial);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
var test = "";
var test = 42;
</script>

{test}

0 comments on commit 025e511

Please sign in to comment.