diff --git a/src/compile/Component.ts b/src/compile/Component.ts index fba0bb0a86..75c557a11e 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -428,6 +428,13 @@ export default class Component { imports.push(node); node.specifiers.forEach((specifier: Node) => { + if (specifier.local.name[0] === '$') { + this.error(specifier.local, { + code: 'illegal-declaration', + message: `The $ prefix is reserved, and cannot be used for variable and import names` + }); + } + this.userVars.add(specifier.local.name); this.imported_declarations.add(specifier.local.name); }); @@ -481,7 +488,14 @@ export default class Component { let { scope } = createScopes(script.content); this.module_scope = scope; - // TODO unindent + scope.declarations.forEach((node, name) => { + if (name[0] === '$') { + this.error(node, { + code: 'illegal-declaration', + message: `The $ prefix is reserved, and cannot be used for variable and import names` + }); + } + }); this.extract_imports_and_exports(script.content, this.imports, this.module_exports); remove_indentation(this.code, script.content); @@ -498,6 +512,15 @@ export default class Component { this.instance_scope = instance_scope; this.instance_scope_map = map; + instance_scope.declarations.forEach((node, name) => { + if (name[0] === '$') { + this.error(node, { + code: 'illegal-declaration', + message: `The $ prefix is reserved, and cannot be used for variable and import names` + }); + } + }); + instance_scope.declarations.forEach((node, name) => { this.userVars.add(name); this.declarations.push(name); diff --git a/test/runtime/samples/store-prevent-user-declarations/_config.js b/test/runtime/samples/store-prevent-user-declarations/_config.js new file mode 100644 index 0000000000..312348eba4 --- /dev/null +++ b/test/runtime/samples/store-prevent-user-declarations/_config.js @@ -0,0 +1,9 @@ +import { writable } from '../../../../store.js'; + +export default { + props: { + count: writable(0) + }, + + error: `The $ prefix is reserved, and cannot be used for variable and import names` +}; \ No newline at end of file diff --git a/test/runtime/samples/store-prevent-user-declarations/main.html b/test/runtime/samples/store-prevent-user-declarations/main.html new file mode 100644 index 0000000000..78bed1d520 --- /dev/null +++ b/test/runtime/samples/store-prevent-user-declarations/main.html @@ -0,0 +1,6 @@ + + + \ No newline at end of file