fix a few stats glitches

pull/2011/head
Richard Harris 7 years ago
parent c24850a32f
commit 0c7e79f8d4

@ -99,7 +99,7 @@ export default class Stats {
return { return {
timings, timings,
warnings: this.warnings, warnings: this.warnings,
vars: component.vars.map(variable => ({ vars: component.vars.filter(variable => variable.kind !== 'global').map(variable => ({
name: variable.name, name: variable.name,
kind: variable.kind, kind: variable.kind,
import_name: variable.import_name || null, import_name: variable.import_name || null,

@ -603,10 +603,18 @@ export default class Component {
globals.forEach(name => { globals.forEach(name => {
if (this.module_scope && this.module_scope.declarations.has(name)) return; if (this.module_scope && this.module_scope.declarations.has(name)) return;
this.add_var({ if (name[0] === '$') {
name, this.add_var({
kind: 'global' name,
}); kind: 'injected',
mutated: true
});
} else {
this.add_var({
name,
kind: 'global'
});
}
}); });
this.extract_imports(script.content, false); this.extract_imports(script.content, false);
@ -682,9 +690,6 @@ export default class Component {
if (name[0] === '$' && !scope.has(name)) { if (name[0] === '$' && !scope.has(name)) {
component.warn_if_undefined(object, null); component.warn_if_undefined(object, null);
// cheeky hack
component.add_reference(name);
} }
} }
}, },

@ -195,7 +195,7 @@ export default class Expression {
if (this.template_scope.is_let(name)) return true; if (this.template_scope.is_let(name)) return true;
const variable = this.component.var_lookup.get(name); const variable = this.component.var_lookup.get(name);
return variable.mutated; return variable && variable.mutated;
}); });
} }
@ -479,7 +479,7 @@ function isContextual(component: Component, scope: TemplateScope, name: string)
const variable = component.var_lookup.get(name); const variable = component.var_lookup.get(name);
// hoistables, module declarations, and imports are non-contextual // hoistables, module declarations, and imports are non-contextual
if (variable.hoistable) return false; if (!variable || variable.hoistable) return false;
// assume contextual // assume contextual
return true; return true;

@ -0,0 +1,26 @@
export default {
test(assert, stats) {
assert.deepEqual(stats.vars, [
{
name: 'foo',
kind: 'let',
import_name: null,
export_name: null,
source: null,
module: false,
mutated: false,
referenced: false
},
{
name: '$foo',
kind: 'injected',
import_name: null,
export_name: null,
source: null,
module: false,
mutated: true,
referenced: true
}
]);
}
};

@ -0,0 +1,5 @@
<script>
let foo;
</script>
{$foo}

@ -0,0 +1,26 @@
export default {
test(assert, stats) {
assert.deepEqual(stats.vars, [
{
name: 'foo',
kind: 'let',
import_name: null,
export_name: null,
source: null,
module: false,
mutated: false,
referenced: false
},
{
name: '$foo',
kind: 'injected',
import_name: null,
export_name: null,
source: null,
module: false,
mutated: true,
referenced: false
}
]);
}
};

@ -0,0 +1,4 @@
<script>
let foo;
console.log($foo);
</script>

@ -0,0 +1,5 @@
export default {
test(assert, stats) {
assert.deepEqual(stats.vars, []);
},
};

@ -0,0 +1,3 @@
<script></script>
{foo}
Loading…
Cancel
Save