From c3e0f3fd31405170db211f87981b39ddef08fdb0 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 27 Jan 2019 17:26:26 -0500 Subject: [PATCH] remove mutables in favour of unified mutability tracking --- src/compile/Component.ts | 7 +------ src/compile/nodes/shared/TemplateScope.ts | 16 ---------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 8261283a87..cce955dd8c 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -170,11 +170,6 @@ export default class Component { // TODO remove this 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) { @@ -933,7 +928,7 @@ export default class Component { this.ast.instance.content.body.forEach(node => { 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 => { hoistable_names.add(d.id.name); }); diff --git a/src/compile/nodes/shared/TemplateScope.ts b/src/compile/nodes/shared/TemplateScope.ts index 0a6be650f1..24b9d1830b 100644 --- a/src/compile/nodes/shared/TemplateScope.ts +++ b/src/compile/nodes/shared/TemplateScope.ts @@ -9,7 +9,6 @@ type NodeWithScope = EachBlock | ThenBlock | CatchBlock | InlineComponent | Elem export default class TemplateScope { names: Set; dependenciesForName: Map>; - mutables: Set = new Set(); owners: Map = new Map(); parent?: TemplateScope; @@ -31,21 +30,6 @@ export default class TemplateScope { return child; } - containsMutable(names: Iterable) { - 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) { return !this.parent || !this.names.has(name) && this.parent.isTopLevel(name); }