From 8f233aee8b8e0d5897d6b85cbd71fadfc94cf3c3 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Wed, 18 Sep 2019 23:57:21 -0400 Subject: [PATCH] more binding stuff --- src/compiler/compile/nodes/Attribute.ts | 7 +- .../compile/nodes/shared/Expression.ts | 11 +-- .../render_dom/wrappers/Element/Binding.ts | 81 +++---------------- 3 files changed, 23 insertions(+), 76 deletions(-) diff --git a/src/compiler/compile/nodes/Attribute.ts b/src/compiler/compile/nodes/Attribute.ts index a43bf2e8f6..5bedc21838 100644 --- a/src/compiler/compile/nodes/Attribute.ts +++ b/src/compiler/compile/nodes/Attribute.ts @@ -20,7 +20,8 @@ export default class Attribute extends Node { is_spread: boolean; is_true: boolean; is_static: boolean; - is_synthetic: boolean; + // TODO apparently unnecessary? + // is_synthetic: boolean; expression?: Expression; chunks: Array; dependencies: Set; @@ -33,7 +34,7 @@ export default class Attribute extends Node { this.name = null; this.is_spread = true; this.is_true = false; - this.is_synthetic = false; + // this.is_synthetic = false; this.expression = new Expression(component, this, scope, info.expression); this.dependencies = this.expression.dependencies; @@ -46,7 +47,7 @@ export default class Attribute extends Node { this.name = info.name; this.is_true = info.value === true; this.is_static = true; - this.is_synthetic = info.synthetic; + // this.is_synthetic = info.synthetic; this.dependencies = new Set(); diff --git a/src/compiler/compile/nodes/shared/Expression.ts b/src/compiler/compile/nodes/shared/Expression.ts index f4ed48a056..fe3d5a83f0 100644 --- a/src/compiler/compile/nodes/shared/Expression.ts +++ b/src/compiler/compile/nodes/shared/Expression.ts @@ -77,7 +77,9 @@ export default class Expression { scope: Scope; scope_map: WeakMap; - is_synthetic: boolean; + // TODO apparently unnecessary? + // is_synthetic: boolean; + declarations: (Node | Node[])[] = []; uses_context = false; @@ -96,7 +98,7 @@ export default class Expression { this.template_scope = template_scope; this.owner = owner; // @ts-ignore - this.is_synthetic = owner.is_synthetic; + // this.is_synthetic = owner.is_synthetic; const { dependencies, contextual_dependencies } = this; @@ -233,8 +235,7 @@ export default class Expression { declarations, scope_map: map, template_scope, - owner, - is_synthetic + owner } = this; let scope = this.scope; @@ -271,7 +272,7 @@ export default class Expression { dependencies.add(name); component.add_reference(name); // TODO is this redundant/misplaced? } - } else if (!is_synthetic && is_contextual(component, template_scope, name)) { + } else if (is_contextual(component, template_scope, name)) { this.replace(x`#ctx.${node}`); } diff --git a/src/compiler/compile/render_dom/wrappers/Element/Binding.ts b/src/compiler/compile/render_dom/wrappers/Element/Binding.ts index ee30d440a7..2b9aeea78e 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/Binding.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/Binding.ts @@ -228,12 +228,6 @@ function get_binding_group(renderer: Renderer, value: Node) { return index; } -function mutate_store(store, value, tail) { - return tail - ? b`${store}.update($$value => ($$value${tail} = ${value}, $$value));` - : b`${store}.set(${value});`; -} - function get_event_handler( binding: BindingWrapper, renderer: Renderer, @@ -259,75 +253,26 @@ function get_event_handler( contextual_dependencies.add(object.name); contextual_dependencies.add(property.name); - } else { - // (lhs as MemberExpression).object = x`${object}[${property}]`; } } + let mutation = b`${lhs} = ${value}`; + + const object = get_object(lhs); + if (object.name[0] === '$') { + const store = object.name.slice(1); + + mutation = b` + ${mutation} + ${store}.set(${object.name}); + `; + } + return { uses_context: binding.node.is_contextual || binding.node.expression.uses_context, // TODO this is messy - mutation: b`${lhs} = ${value}`, + mutation, contextual_dependencies }; - - // if (lhs.type === 'MemberExpression') { - // return { - // uses_context: binding.node.is_contextual || binding.node.expression.uses_context, // TODO this is messy - // mutation: b`${lhs} = ${value}`, - // contextual_dependencies - // }; - // } else { - - // } - - // const binding_info = block.bindings.get(name); - // console.log(binding_info); - - // let store = binding.object[0] === '$' ? binding.object.slice(1) : null; - - // let tail = null; - // if (binding.node.expression.node.type === 'MemberExpression') { - // // const { start, end } = get_tail(binding.node.expression.node); - // // tail = renderer.component.source.slice(start, end); - // tail = binding.node.expression.node.object; - // } - - // if (binding.node.is_contextual) { - // const binding = block.bindings.get(name); - // const { object, property, snippet } = binding; - - // if (binding.store) { - // store = binding.store; - // tail = x`${binding.tail}.${tail}`; - // } - - // return { - // uses_context: true, - // mutation: store - // ? mutate_store(store, value, tail) - // : b`${snippet} = ${value};`, - // contextual_dependencies: new Set([object.name, property.name]) - // }; - // } - - // const mutation = store - // ? mutate_store(store, value, tail) - // : b`${snippet} = ${value};`; - - // if (binding.node.expression.node.type === 'MemberExpression') { - // return { - // uses_context: binding.node.expression.uses_context, - // mutation, - // contextual_dependencies: binding.node.expression.contextual_dependencies, - // snippet - // }; - // } - - // return { - // uses_context: false, - // mutation, - // contextual_dependencies: new Set() - // }; } function get_value_from_dom(