Skip to content

Commit fa79a72

Browse files
committed
disallow bindings to global variables (sveltejs#2295)
1 parent d637211 commit fa79a72

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/compile/nodes/Binding.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class Binding extends Node {
3939
} else {
4040
const variable = component.var_lookup.get(name);
4141

42-
if (!variable) component.error(this.expression.node, {
42+
if (!variable || variable.global) component.error(this.expression.node, {
4343
code: 'binding-undeclared',
4444
message: `${name} is not declared`
4545
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[{
2+
"code": "binding-undeclared",
3+
"message": "foo is not declared",
4+
"pos": 58,
5+
"start": {
6+
"line": 4,
7+
"column": 19,
8+
"character": 58
9+
},
10+
"end": {
11+
"line": 4,
12+
"column": 22,
13+
"character": 61
14+
}
15+
}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
console.log(foo);
3+
</script>
4+
<input bind:value={foo}>

0 commit comments

Comments
 (0)