|
|
|
|
@ -22,7 +22,6 @@ const read_only_media_attributes = new Set([
|
|
|
|
|
|
|
|
|
|
/** @extends Node */
|
|
|
|
|
export default class Binding extends Node {
|
|
|
|
|
|
|
|
|
|
/** @type {'Binding'} */
|
|
|
|
|
type;
|
|
|
|
|
|
|
|
|
|
@ -57,15 +56,15 @@ export default class Binding extends Node {
|
|
|
|
|
this.expression = new Expression(component, this, scope, info.expression);
|
|
|
|
|
this.raw_expression = clone(info.expression);
|
|
|
|
|
const { name } = get_object(this.expression.node);
|
|
|
|
|
this.is_contextual = Array.from(this.expression.references).some(/** @param {any} name */ (name) => scope.names.has(name));
|
|
|
|
|
if (this.is_contextual)
|
|
|
|
|
this.validate_binding_rest_properties(scope);
|
|
|
|
|
this.is_contextual = Array.from(this.expression.references).some(
|
|
|
|
|
/** @param {any} name */ (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)) {
|
|
|
|
|
component.error(this, compiler_errors.invalid_binding_let);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (scope.names.has(name)) {
|
|
|
|
|
} else if (scope.names.has(name)) {
|
|
|
|
|
if (scope.is_await(name)) {
|
|
|
|
|
component.error(this, compiler_errors.invalid_binding_await);
|
|
|
|
|
return;
|
|
|
|
|
@ -73,22 +72,29 @@ export default class Binding extends Node {
|
|
|
|
|
if (scope.is_const(name)) {
|
|
|
|
|
component.error(this, compiler_errors.invalid_binding_const);
|
|
|
|
|
}
|
|
|
|
|
scope.dependencies_for_name.get(name).forEach(/** @param {any} name */ (name) => {
|
|
|
|
|
scope.dependencies_for_name.get(name).forEach(
|
|
|
|
|
/** @param {any} name */ (name) => {
|
|
|
|
|
const variable = component.var_lookup.get(name);
|
|
|
|
|
if (variable) {
|
|
|
|
|
variable.mutated = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
const variable = component.var_lookup.get(name);
|
|
|
|
|
if (!variable || variable.global) {
|
|
|
|
|
component.error(/** @type {any} */ (this.expression.node), compiler_errors.binding_undeclared(name));
|
|
|
|
|
component.error(
|
|
|
|
|
/** @type {any} */ (this.expression.node),
|
|
|
|
|
compiler_errors.binding_undeclared(name)
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
variable[this.expression.node.type === 'MemberExpression' ? 'mutated' : 'reassigned'] = true;
|
|
|
|
|
if (info.expression.type === 'Identifier' && !variable.writable) {
|
|
|
|
|
component.error(/** @type {any} */ (this.expression.node), compiler_errors.invalid_binding_writable);
|
|
|
|
|
component.error(
|
|
|
|
|
/** @type {any} */ (this.expression.node),
|
|
|
|
|
compiler_errors.invalid_binding_writable
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -106,17 +112,20 @@ export default class Binding extends Node {
|
|
|
|
|
|
|
|
|
|
/** @param {import('./shared/TemplateScope.js').default} scope */
|
|
|
|
|
validate_binding_rest_properties(scope) {
|
|
|
|
|
this.expression.references.forEach(/** @param {any} name */ (name) => {
|
|
|
|
|
this.expression.references.forEach(
|
|
|
|
|
/** @param {any} name */ (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(
|
|
|
|
|
|
|
|
|
|
/** @type {any} */ (rest_node), compiler_warnings.invalid_rest_eachblock_binding(name));
|
|
|
|
|
/** @type {any} */ (rest_node),
|
|
|
|
|
compiler_warnings.invalid_rest_eachblock_binding(name)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -125,9 +134,5 @@ export default class Binding extends Node {
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
|
|
|
|
function isElement(node) {
|
|
|
|
|
return !!( /** @type {any} */(node)).is_media_node;
|
|
|
|
|
return !!/** @type {any} */ (node).is_media_node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|