remove mutables in favour of unified mutability tracking

pull/2011/head
Richard Harris 7 years ago
parent 0f878f55a2
commit c3e0f3fd31

@ -170,11 +170,6 @@ export default class Component {
// TODO remove this // TODO remove this
this.props = props.map(name => ({ name, as: name })); this.props = props.map(name => ({ name, as: name }));
} }
// tell the root fragment scope about all of the mutable names we know from the script
this.vars.forEach(variable => {
if (variable.mutated) this.fragment.scope.mutables.add(name);
});
} }
add_var(variable: Var) { add_var(variable: Var) {
@ -933,7 +928,7 @@ export default class Component {
this.ast.instance.content.body.forEach(node => { this.ast.instance.content.body.forEach(node => {
if (node.type === 'VariableDeclaration') { if (node.type === 'VariableDeclaration') {
if (node.declarations.every(d => d.init && d.init.type === 'Literal' && !this.var_lookup.get(d.id.name).mutated && !template_scope.containsMutable([d.id.name]))) { if (node.declarations.every(d => d.init && d.init.type === 'Literal' && !this.var_lookup.get(d.id.name).mutated)) {
node.declarations.forEach(d => { node.declarations.forEach(d => {
hoistable_names.add(d.id.name); hoistable_names.add(d.id.name);
}); });

@ -9,7 +9,6 @@ type NodeWithScope = EachBlock | ThenBlock | CatchBlock | InlineComponent | Elem
export default class TemplateScope { export default class TemplateScope {
names: Set<string>; names: Set<string>;
dependenciesForName: Map<string, Set<string>>; dependenciesForName: Map<string, Set<string>>;
mutables: Set<string> = new Set();
owners: Map<string, NodeWithScope> = new Map(); owners: Map<string, NodeWithScope> = new Map();
parent?: TemplateScope; parent?: TemplateScope;
@ -31,21 +30,6 @@ export default class TemplateScope {
return child; return child;
} }
containsMutable(names: Iterable<string>) {
for (const name of names) {
const owner = this.getOwner(name);
const is_let = owner && (owner.type === 'InlineComponent' || owner.type === 'Element');
if (is_let) return true;
if (name[0] === '$') return true;
if (this.mutables.has(name)) return true;
else if (this.dependenciesForName.has(name) && this.containsMutable(this.dependenciesForName.get(name))) return true;
}
if (this.parent) return this.parent.containsMutable(names);
else return false;
}
isTopLevel(name: string) { isTopLevel(name: string) {
return !this.parent || !this.names.has(name) && this.parent.isTopLevel(name); return !this.parent || !this.names.has(name) && this.parent.isTopLevel(name);
} }

Loading…
Cancel
Save