throw error if $ is referenced as global - fixes #3272

pull/3348/head
Richard Harris 5 years ago
parent 4e004fdfa3
commit 4c8f3a296c

@ -662,7 +662,7 @@ export default class Component {
this.node_for_declaration.set(name, node); this.node_for_declaration.set(name, node);
}); });
globals.forEach((_node, name) => { globals.forEach((node, name) => {
if (this.var_lookup.has(name)) return; if (this.var_lookup.has(name)) return;
if (this.injected_reactive_declaration_vars.has(name)) { if (this.injected_reactive_declaration_vars.has(name)) {
@ -679,6 +679,13 @@ export default class Component {
injected: true injected: true
}); });
} else if (name[0] === '$') { } else if (name[0] === '$') {
if (name === '$') {
this.error(node, {
code: 'illegal-global',
message: 'The $ sign is an illegal variable name'
});
}
this.add_var({ this.add_var({
name, name,
injected: true, injected: true,
@ -1239,6 +1246,12 @@ export default class Component {
this.has_reactive_assignments = true; // TODO does this belong here? this.has_reactive_assignments = true; // TODO does this belong here?
if (name[0] === '$') return; // $$props if (name[0] === '$') return; // $$props
if (name === '') {
this.error(node, {
code: 'illegal-global',
message: 'The $ sign is an illegal variable name'
});
}
} }
if (this.var_lookup.has(name) && !this.var_lookup.get(name).global) return; if (this.var_lookup.has(name) && !this.var_lookup.get(name).global) return;

@ -0,0 +1,15 @@
[{
"code": "illegal-global",
"message": "The $ sign is an illegal variable name",
"pos": 1,
"start": {
"line": 1,
"column": 1,
"character": 1
},
"end": {
"line": 1,
"column": 2,
"character": 2
}
}]

@ -0,0 +1,15 @@
[{
"code": "illegal-global",
"message": "The $ sign is an illegal variable name",
"pos": 10,
"start": {
"line": 2,
"column": 1,
"character": 10
},
"end": {
"line": 2,
"column": 2,
"character": 11
}
}]
Loading…
Cancel
Save