diff --git a/src/compile/Component.ts b/src/compile/Component.ts index f8ee5a0b78..21f0b6ef05 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -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; diff --git a/src/compile/nodes/Binding.ts b/src/compile/nodes/Binding.ts index 939af8a8d9..3ab2cd8ff5 100644 --- a/src/compile/nodes/Binding.ts +++ b/src/compile/nodes/Binding.ts @@ -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` }); diff --git a/test/validator/samples/binding-invalid-value-global/errors.json b/test/validator/samples/binding-invalid-value-global/errors.json new file mode 100644 index 0000000000..be23a21523 --- /dev/null +++ b/test/validator/samples/binding-invalid-value-global/errors.json @@ -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 + } +}] diff --git a/test/validator/samples/binding-invalid-value-global/input.svelte b/test/validator/samples/binding-invalid-value-global/input.svelte new file mode 100644 index 0000000000..81357cf5de --- /dev/null +++ b/test/validator/samples/binding-invalid-value-global/input.svelte @@ -0,0 +1,4 @@ + + diff --git a/test/validator/samples/undefined-value-global/input.svelte b/test/validator/samples/undefined-value-global/input.svelte new file mode 100644 index 0000000000..44e7332bf5 --- /dev/null +++ b/test/validator/samples/undefined-value-global/input.svelte @@ -0,0 +1,5 @@ + + +
{potato}
diff --git a/test/validator/samples/undefined-value-global/warnings.json b/test/validator/samples/undefined-value-global/warnings.json new file mode 100644 index 0000000000..ee9e3d6c90 --- /dev/null +++ b/test/validator/samples/undefined-value-global/warnings.json @@ -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 + } +}]