diff --git a/src/generators/dom/visitors/Component.js b/src/generators/dom/visitors/Component.js index 46ba6d4aa1..569ab112d0 100644 --- a/src/generators/dom/visitors/Component.js +++ b/src/generators/dom/visitors/Component.js @@ -98,7 +98,7 @@ export default { const bindings = local.bindings.map( binding => { const parts = binding.value.split( '.' ); const tail = parts.pop(); - return `if ( '${tail}' in ${parts.join( '.' )} ) ${name}_initialData.${binding.name} = ${binding.value};`; + return `if ( ${binding.prop} in ${binding.obj} ) ${name}_initialData.${binding.name} = ${binding.value};`; }); statements.push( bindings.join( '\n' ) ); diff --git a/src/generators/dom/visitors/attributes/binding/index.js b/src/generators/dom/visitors/attributes/binding/index.js index b6adbde630..9e04ee3479 100644 --- a/src/generators/dom/visitors/attributes/binding/index.js +++ b/src/generators/dom/visitors/attributes/binding/index.js @@ -11,10 +11,21 @@ export default function createBinding ( generator, node, attribute, current, loc if ( contextual ) local.allUsedContexts.add( parts[0] ); if ( local.isComponent ) { - local.bindings.push({ - name: attribute.name, - value: contextual ? attribute.value : `root.${attribute.value}` - }); + let obj; + let prop; + let value; + + if ( contextual ) { + obj = current.listNames[ parts[0] ]; + prop = current.indexNames[ parts[0] ]; + value = attribute.value; + } else { + prop = `'${parts.slice( -1 )}'`; + obj = parts.length > 1 ? `root.${parts.slice( 0, -1 ).join( '.' )}` : `root`; + value = `root.${attribute.value}`; + } + + local.bindings.push({ name: attribute.name, value, obj, prop }); } const handler = current.getUniqueName( `${local.name}ChangeHandler` ); @@ -59,9 +70,11 @@ export default function createBinding ( generator, node, attribute, current, loc const listName = current.listNames[ parts[0] ]; const indexName = current.indexNames[ parts[0] ]; + const context = local.isComponent ? `_context` : `__svelte`; + setter = deindent` - var list = this.__svelte.${listName}; - var index = this.__svelte.${indexName}; + var list = this.${context}.${listName}; + var index = this.${context}.${indexName}; list[index]${parts.slice( 1 ).map( part => `.${part}` ).join( '' )} = ${value}; component._set({ ${prop}: component.get( '${prop}' ) });