diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 2ce2852d7e..709db1447d 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -679,10 +679,10 @@ export default class Component { injected: true }); } else if (name[0] === '$') { - if (name === '$') { + if (name === '$' || name[1] === '$') { this.error(node, { code: 'illegal-global', - message: 'The $ sign is an illegal variable name' + message: `${name} is an illegal variable name` }); } @@ -1242,16 +1242,18 @@ export default class Component { warn_if_undefined(name: string, node, template_scope: TemplateScope) { if (name[0] === '$') { - name = name.slice(1); - this.has_reactive_assignments = true; // TODO does this belong here? - - if (name[0] === '$') return; // $$props - if (name === '') { + if (name === '$' || name[1] === '$' && name !== '$$props') { this.error(node, { code: 'illegal-global', - message: 'The $ sign is an illegal variable name' + message: `${name} is an illegal variable name` }); } + + this.has_reactive_assignments = true; // TODO does this belong here? + + if (name === '$$props') return; + + name = name.slice(1); } if (this.var_lookup.has(name) && !this.var_lookup.get(name).global) return; diff --git a/test/validator/samples/dollar-dollar-global-in-markup/errors.json b/test/validator/samples/dollar-dollar-global-in-markup/errors.json new file mode 100644 index 0000000000..4730c5152e --- /dev/null +++ b/test/validator/samples/dollar-dollar-global-in-markup/errors.json @@ -0,0 +1,15 @@ +[{ + "code": "illegal-global", + "message": "$$billsyall is an illegal variable name", + "pos": 1, + "start": { + "line": 1, + "column": 1, + "character": 1 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } +}] \ No newline at end of file diff --git a/test/validator/samples/dollar-dollar-global-in-markup/input.svelte b/test/validator/samples/dollar-dollar-global-in-markup/input.svelte new file mode 100644 index 0000000000..d197237056 --- /dev/null +++ b/test/validator/samples/dollar-dollar-global-in-markup/input.svelte @@ -0,0 +1 @@ +{$$billsyall} \ No newline at end of file diff --git a/test/validator/samples/dollar-dollar-global-in-script/errors.json b/test/validator/samples/dollar-dollar-global-in-script/errors.json new file mode 100644 index 0000000000..5c923e35f7 --- /dev/null +++ b/test/validator/samples/dollar-dollar-global-in-script/errors.json @@ -0,0 +1,15 @@ +[{ + "code": "illegal-global", + "message": "$$billsyall is an illegal variable name", + "pos": 10, + "start": { + "line": 2, + "column": 1, + "character": 10 + }, + "end": { + "line": 2, + "column": 12, + "character": 21 + } +}] \ No newline at end of file diff --git a/test/validator/samples/dollar-dollar-global-in-script/input.svelte b/test/validator/samples/dollar-dollar-global-in-script/input.svelte new file mode 100644 index 0000000000..9f7fc06a7d --- /dev/null +++ b/test/validator/samples/dollar-dollar-global-in-script/input.svelte @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/test/validator/samples/dollar-global-in-markup/errors.json b/test/validator/samples/dollar-global-in-markup/errors.json index 6447844f5c..6cdf67e872 100644 --- a/test/validator/samples/dollar-global-in-markup/errors.json +++ b/test/validator/samples/dollar-global-in-markup/errors.json @@ -1,6 +1,6 @@ [{ "code": "illegal-global", - "message": "The $ sign is an illegal variable name", + "message": "$ is an illegal variable name", "pos": 1, "start": { "line": 1, diff --git a/test/validator/samples/dollar-global-in-script/errors.json b/test/validator/samples/dollar-global-in-script/errors.json index a9fe6bb5d8..2a6bd7ce7a 100644 --- a/test/validator/samples/dollar-global-in-script/errors.json +++ b/test/validator/samples/dollar-global-in-script/errors.json @@ -1,6 +1,6 @@ [{ "code": "illegal-global", - "message": "The $ sign is an illegal variable name", + "message": "$ is an illegal variable name", "pos": 10, "start": { "line": 2,