move the binding validation to Binding node

pull/7526/head
tanhauhau 4 years ago
parent 4af59e463f
commit 415fa51473

@ -11,6 +11,7 @@ import InlineComponent from './InlineComponent';
import Window from './Window'; import Window from './Window';
import { clone } from '../../utils/clone'; import { clone } from '../../utils/clone';
import compiler_errors from '../compiler_errors'; import compiler_errors from '../compiler_errors';
import compiler_warnings from '../compiler_warnings';
// TODO this should live in a specific binding // TODO this should live in a specific binding
const read_only_media_attributes = new Set([ const read_only_media_attributes = new Set([
@ -47,6 +48,7 @@ export default class Binding extends Node {
const { name } = get_object(this.expression.node); const { name } = get_object(this.expression.node);
this.is_contextual = Array.from(this.expression.references).some(name => scope.names.has(name)); 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 // make sure we track this as a mutable ref
if (scope.is_let(name)) { if (scope.is_let(name)) {
@ -95,6 +97,18 @@ export default class Binding extends Node {
is_readonly_media_attribute() { is_readonly_media_attribute() {
return read_only_media_attributes.has(this.name); 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 { function isElement(node: Node): node is Element {

@ -2,7 +2,6 @@ import EachBlock from '../../../nodes/EachBlock';
import InlineComponentWrapper from '../InlineComponent'; import InlineComponentWrapper from '../InlineComponent';
import ElementWrapper from '../Element'; import ElementWrapper from '../Element';
import Binding from '../../../nodes/Binding'; import Binding from '../../../nodes/Binding';
import compiler_warnings from '../../../compiler_warnings';
export default function mark_each_block_bindings( export default function mark_each_block_bindings(
parent: ElementWrapper | InlineComponentWrapper, 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 // the list and the index, if they're not otherwise referenced
binding.expression.references.forEach(name => { binding.expression.references.forEach(name => {
const each_block = parent.node.scope.get_owner(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) { if (each_block) {
(each_block as EachBlock).has_binding = true; (each_block as EachBlock).has_binding = true;
} }

Loading…
Cancel
Save