mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
Merge pull request #2321 from sveltejs/gh-2295
Fix exception and warning for global variables
This commit is contained in:
commit
a59cd36a39
@ -1182,7 +1182,7 @@ export default class Component {
|
||||
if (name[0] === '$') return; // $$props
|
||||
}
|
||||
|
||||
if (this.var_lookup.has(name)) return;
|
||||
if (this.var_lookup.has(name) && !this.var_lookup.get(name).global) return;
|
||||
if (template_scope && template_scope.names.has(name)) return;
|
||||
if (globals.has(name)) return;
|
||||
|
||||
|
@ -39,7 +39,7 @@ export default class Binding extends Node {
|
||||
} else {
|
||||
const variable = component.var_lookup.get(name);
|
||||
|
||||
if (!variable) component.error(this.expression.node, {
|
||||
if (!variable || variable.global) component.error(this.expression.node, {
|
||||
code: 'binding-undeclared',
|
||||
message: `${name} is not declared`
|
||||
});
|
||||
|
@ -0,0 +1,15 @@
|
||||
[{
|
||||
"code": "binding-undeclared",
|
||||
"message": "foo is not declared",
|
||||
"pos": 58,
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 19,
|
||||
"character": 58
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 22,
|
||||
"character": 61
|
||||
}
|
||||
}]
|
@ -0,0 +1,4 @@
|
||||
<script>
|
||||
console.log(foo);
|
||||
</script>
|
||||
<input bind:value={foo}>
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
console.log(potato);
|
||||
</script>
|
||||
|
||||
<p>{potato}</p>
|
15
test/validator/samples/undefined-value-global/warnings.json
Normal file
15
test/validator/samples/undefined-value-global/warnings.json
Normal file
@ -0,0 +1,15 @@
|
||||
[{
|
||||
"code": "missing-declaration",
|
||||
"message": "'potato' is not defined",
|
||||
"pos": 46,
|
||||
"start": {
|
||||
"line": 5,
|
||||
"column": 4,
|
||||
"character": 46
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 10,
|
||||
"character": 52
|
||||
}
|
||||
}]
|
Loading…
Reference in New Issue
Block a user