disallow declarations and imports with $ prefix

pull/1880/head
Rich Harris 7 years ago
parent ae4767a4dc
commit 102d28fb12

@ -428,6 +428,13 @@ export default class Component {
imports.push(node); imports.push(node);
node.specifiers.forEach((specifier: 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.userVars.add(specifier.local.name);
this.imported_declarations.add(specifier.local.name); this.imported_declarations.add(specifier.local.name);
}); });
@ -481,7 +488,14 @@ export default class Component {
let { scope } = createScopes(script.content); let { scope } = createScopes(script.content);
this.module_scope = scope; 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); this.extract_imports_and_exports(script.content, this.imports, this.module_exports);
remove_indentation(this.code, script.content); remove_indentation(this.code, script.content);
@ -498,6 +512,15 @@ export default class Component {
this.instance_scope = instance_scope; this.instance_scope = instance_scope;
this.instance_scope_map = map; 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) => { instance_scope.declarations.forEach((node, name) => {
this.userVars.add(name); this.userVars.add(name);
this.declarations.push(name); this.declarations.push(name);

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

@ -0,0 +1,6 @@
<script>
export let count;
let $count;
</script>
<button on:click="{() => count.update(n => n + 1)}">count {$count}</button>
Loading…
Cancel
Save