0
0
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:
Rich Harris 2019-03-27 08:21:48 -04:00 committed by GitHub
commit a59cd36a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 2 deletions

View File

@ -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;

View File

@ -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`
});

View File

@ -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
}
}]

View File

@ -0,0 +1,4 @@
<script>
console.log(foo);
</script>
<input bind:value={foo}>

View File

@ -0,0 +1,5 @@
<script>
console.log(potato);
</script>
<p>{potato}</p>

View 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
}
}]