fix: deconflict generated names against globals (#9570)

fixes #9559
pull/9581/head
Rich Harris 1 year ago committed by GitHub
parent 945a90b56c
commit 1bc89b5eb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: deconflict generated names against globals

@ -184,6 +184,10 @@ export class Scope {
declaration.references.push({ node, path });
} else if (this.#parent) {
this.#parent.reference(node, path);
} else {
// no declaration was found, and this is the top level scope,
// which means this is a global
this.root.conflicts.add(node.name);
}
}
}

@ -0,0 +1,15 @@
import { test } from '../../test';
export default test({
html: `<p>hello</p>`,
before_test: () => {
// @ts-expect-error
globalThis.frag = 'hello';
},
after_test: () => {
// @ts-expect-error
delete globalThis.frag;
}
});
Loading…
Cancel
Save