diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index 3f82bfb584..2f90806673 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -486,6 +486,8 @@ export default class ElementWrapper extends Wrapper { // TODO dry this out — similar code for event handlers and component bindings if (has_local_function) { + const args = Array.from(contextual_dependencies).map(name => renderer.reference(name)); + // need to create a block-local function that calls an instance-level function if (animation_frame) { block.chunks.init.push(b` @@ -495,14 +497,14 @@ export default class ElementWrapper extends Wrapper { ${animation_frame} = @raf(${handler}); ${needs_lock && b`${lock} = true;`} } - #ctx[${i}].call(${this.var}, ${contextual_dependencies.size > 0 ? '#ctx' : null}); + #ctx[${i}].call(${this.var}, ${args}); } `); } else { block.chunks.init.push(b` function ${handler}() { ${needs_lock && b`${lock} = true;`} - #ctx[${i}].call(${this.var}, ${contextual_dependencies.size > 0 ? '#ctx' : null}); + #ctx[${i}].call(${this.var}, ${args}); } `); } @@ -512,21 +514,13 @@ export default class ElementWrapper extends Wrapper { callee = x`#ctx[${i}]`; } - const arg = contextual_dependencies.size > 0 && { - type: 'ObjectPattern', - properties: Array.from(contextual_dependencies).map(name => { - const id = { type: 'Identifier', name }; - return { - type: 'Property', - kind: 'init', - key: id, - value: id - }; - }) - }; + const params = Array.from(contextual_dependencies).map(name => ({ + type: 'Identifier', + name + })); this.renderer.component.partly_hoisted.push(b` - function ${handler}(${arg}) { + function ${handler}(${params}) { ${group.bindings.map(b => b.handler.mutation)} ${Array.from(dependencies) .filter(dep => dep[0] !== '$') diff --git a/test/runtime/samples/binding-input-text-contextual-deconflicted/_config.js b/test/runtime/samples/binding-input-text-contextual-deconflicted/_config.js index 37af5080b9..28cffdfa57 100644 --- a/test/runtime/samples/binding-input-text-contextual-deconflicted/_config.js +++ b/test/runtime/samples/binding-input-text-contextual-deconflicted/_config.js @@ -16,7 +16,6 @@ export default { async test({ assert, component, target, window }) { const inputs = [...target.querySelectorAll('input')]; - const items = component.items; const event = new window.Event('input'); assert.equal(inputs[0].value, 'a');