Skip to content

Commit 73b0475

Browse files
committed
fix: better error message for global variable assignments
1 parent e33f774 commit 73b0475

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

.changeset/slick-teeth-exist.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: better error message for global variable assignments

packages/svelte/src/compiler/phases/2-analyze/visitors/shared/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export function validate_assignment(node, argument, context) {
2222
const binding = context.state.scope.get(argument.name);
2323

2424
if (context.state.analysis.runes) {
25-
if (binding?.node === context.state.analysis.props_id) {
25+
if (
26+
context.state.analysis.props_id != null &&
27+
binding?.node === context.state.analysis.props_id
28+
) {
2629
e.constant_assignment(node, '$props.id()');
2730
}
2831

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
error: 'x is not defined',
5+
async test() {}
6+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x = 1;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script>
2+
import "./foo.svelte.js";
3+
</script>

0 commit comments

Comments
 (0)