Skip to content

Commit 1bc89b5

Browse files
authored
fix: deconflict generated names against globals (#9570)
fixes #9559
1 parent 945a90b commit 1bc89b5

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

.changeset/green-hounds-play.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: deconflict generated names against globals

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ export class Scope {
184184
declaration.references.push({ node, path });
185185
} else if (this.#parent) {
186186
this.#parent.reference(node, path);
187+
} else {
188+
// no declaration was found, and this is the top level scope,
189+
// which means this is a global
190+
this.root.conflicts.add(node.name);
187191
}
188192
}
189193
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `<p>hello</p>`,
5+
6+
before_test: () => {
7+
// @ts-expect-error
8+
globalThis.frag = 'hello';
9+
},
10+
11+
after_test: () => {
12+
// @ts-expect-error
13+
delete globalThis.frag;
14+
}
15+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>{frag}</p>

0 commit comments

Comments
 (0)