diff --git a/src/compiler/compile/nodes/Binding.ts b/src/compiler/compile/nodes/Binding.ts index 39f6fa374e..594490a5fb 100644 --- a/src/compiler/compile/nodes/Binding.ts +++ b/src/compiler/compile/nodes/Binding.ts @@ -11,6 +11,7 @@ import InlineComponent from './InlineComponent'; import Window from './Window'; import { clone } from '../../utils/clone'; import compiler_errors from '../compiler_errors'; +import compiler_warnings from '../compiler_warnings'; // TODO this should live in a specific binding const read_only_media_attributes = new Set([ @@ -47,6 +48,7 @@ export default class Binding extends Node { const { name } = get_object(this.expression.node); this.is_contextual = Array.from(this.expression.references).some(name => scope.names.has(name)); + if (this.is_contextual) this.validate_binding_rest_properties(scope); // make sure we track this as a mutable ref if (scope.is_let(name)) { @@ -95,6 +97,18 @@ export default class Binding extends Node { is_readonly_media_attribute() { return read_only_media_attributes.has(this.name); } + + validate_binding_rest_properties(scope: TemplateScope) { + this.expression.references.forEach(name => { + const each_block = scope.get_owner(name); + if (each_block && each_block.type === 'EachBlock') { + const rest_node = each_block.context_rest_properties.get(name); + if (rest_node) { + this.component.warn(rest_node as any, compiler_warnings.invalid_rest_eachblock_binding(name)); + } + } + }); + } } function isElement(node: Node): node is Element { diff --git a/src/compiler/compile/render_dom/wrappers/shared/mark_each_block_bindings.ts b/src/compiler/compile/render_dom/wrappers/shared/mark_each_block_bindings.ts index 76b3ee5c49..df7185bb69 100644 --- a/src/compiler/compile/render_dom/wrappers/shared/mark_each_block_bindings.ts +++ b/src/compiler/compile/render_dom/wrappers/shared/mark_each_block_bindings.ts @@ -2,7 +2,6 @@ import EachBlock from '../../../nodes/EachBlock'; import InlineComponentWrapper from '../InlineComponent'; import ElementWrapper from '../Element'; import Binding from '../../../nodes/Binding'; -import compiler_warnings from '../../../compiler_warnings'; export default function mark_each_block_bindings( parent: ElementWrapper | InlineComponentWrapper, @@ -12,12 +11,6 @@ export default function mark_each_block_bindings( // the list and the index, if they're not otherwise referenced binding.expression.references.forEach(name => { const each_block = parent.node.scope.get_owner(name); - if (each_block && each_block.type === 'EachBlock') { - const rest_node = each_block.context_rest_properties.get(name); - if (rest_node) { - parent.renderer.component.warn(rest_node as any, compiler_warnings.invalid_rest_eachblock_binding(name)); - } - } if (each_block) { (each_block as EachBlock).has_binding = true; }