Lint and format src/compiler/compile/render_dom/wrappers/Element/Binding.js

pull/8569/head
Simon Holthausen 3 years ago
parent 00a3597fb4
commit 5c7b9594dd

@ -8,217 +8,220 @@ import handle_select_value_binding from './handle_select_value_binding';
import { regex_box_size } from '../../../../utils/patterns'; import { regex_box_size } from '../../../../utils/patterns';
/** */ /** */
export default class BindingWrapper { export default class BindingWrapper {
/** @type {import('../../../nodes/Binding.js').default} */
node = undefined;
/** @type {import('../../../nodes/Binding.js').default} */ /** @type {ElementWrapper | InlineComponentWrapper} */
node = undefined; parent = undefined;
/** @type {ElementWrapper | InlineComponentWrapper} */ /** @type {string} */
parent = undefined; object = undefined;
/**
* @type {{
* uses_context: boolean;
* mutation: Node | Node[];
* contextual_dependencies: Set<string>;
* lhs?: Node;
* }}
*/
handler = undefined;
/** @type {string} */ /** @type {import('estree').Node} */
object = undefined; snippet = undefined;
/**
* @type {{
* uses_context: boolean;
* mutation: Node | Node[];
* contextual_dependencies: Set<string>;
* lhs?: Node;
* }}
*/
handler = undefined;
/** @type {import('estree').Node} */ /** @type {boolean} */
snippet = undefined; is_readonly = undefined;
/** @type {boolean} */ /** @type {boolean} */
is_readonly = undefined; needs_lock = undefined;
/** @type {boolean} */ /** @type {import('../../Renderer.js').BindingGroup} */
needs_lock = undefined; binding_group = undefined;
/** @type {import('../../Renderer.js').BindingGroup} */ /**
binding_group = undefined; * @param {import('../../Block.js').default} block
* @param {import('../../../nodes/Binding.js').default} node
* @param {ElementWrapper | InlineComponentWrapper} parent
*/
constructor(block, node, parent) {
this.node = node;
this.parent = parent;
const { dependencies } = this.node.expression;
block.add_dependencies(dependencies);
// TODO does this also apply to e.g. `<input type='checkbox' bind:group='foo'>`?
handle_select_value_binding(this, dependencies);
if (node.is_contextual) {
mark_each_block_bindings(this.parent, this.node);
}
this.object = get_object(this.node.expression.node).name;
if (this.node.name === 'group') {
this.binding_group = get_binding_group(parent.renderer, this, block);
}
// view to model
this.handler = get_event_handler(
this,
parent.renderer,
block,
this.object,
this.node.raw_expression
);
this.snippet = this.node.expression.manipulate(block);
this.is_readonly = this.node.is_readonly;
this.needs_lock = this.node.name === 'currentTime'; // TODO others?
}
get_dependencies() {
const dependencies = new Set(this.node.expression.dependencies);
this.node.expression.dependencies.forEach((prop) => {
const indirect_dependencies = this.parent.renderer.component.indirect_dependencies.get(prop);
if (indirect_dependencies) {
indirect_dependencies.forEach((indirect_dependency) => {
dependencies.add(indirect_dependency);
});
}
});
if (this.binding_group) {
this.binding_group.list_dependencies.forEach((dep) => dependencies.add(dep));
}
return dependencies;
}
get_update_dependencies() {
const object = this.object;
const dependencies = new Set();
if (this.node.expression.template_scope.names.has(object)) {
this.node.expression.template_scope.dependencies_for_name
.get(object)
.forEach((name) => dependencies.add(name));
} else {
dependencies.add(object);
}
const result = new Set(dependencies);
dependencies.forEach((dependency) => {
const indirect_dependencies =
this.parent.renderer.component.indirect_dependencies.get(dependency);
if (indirect_dependencies) {
indirect_dependencies.forEach((indirect_dependency) => {
result.add(indirect_dependency);
});
}
});
return result;
}
is_readonly_media_attribute() {
return this.node.is_readonly_media_attribute();
}
/** /**
* @param {import('../../Block.js').default} block * @param {import('../../Block.js').default} block
* @param {import('../../../nodes/Binding.js').default} node * @param {import('estree').Identifier} lock
* @param {ElementWrapper | InlineComponentWrapper} parent */
*/ render(block, lock) {
constructor(block, node, parent) { if (this.is_readonly) return;
this.node = node; const { parent } = this;
this.parent = parent;
const { dependencies } = this.node.expression;
block.add_dependencies(dependencies);
// TODO does this also apply to e.g. `<input type='checkbox' bind:group='foo'>`?
handle_select_value_binding(this, dependencies);
if (node.is_contextual) {
mark_each_block_bindings(this.parent, this.node);
}
this.object = get_object(this.node.expression.node).name;
if (this.node.name === 'group') {
this.binding_group = get_binding_group(parent.renderer, this, block);
}
// view to model
this.handler = get_event_handler(this, parent.renderer, block, this.object, this.node.raw_expression);
this.snippet = this.node.expression.manipulate(block);
this.is_readonly = this.node.is_readonly;
this.needs_lock = this.node.name === 'currentTime'; // TODO others?
}
get_dependencies() {
const dependencies = new Set(this.node.expression.dependencies);
this.node.expression.dependencies.forEach((prop) => {
const indirect_dependencies = this.parent.renderer.component.indirect_dependencies.get(prop);
if (indirect_dependencies) {
indirect_dependencies.forEach((indirect_dependency) => {
dependencies.add(indirect_dependency);
});
}
});
if (this.binding_group) {
this.binding_group.list_dependencies.forEach((dep) => dependencies.add(dep));
}
return dependencies;
}
get_update_dependencies() {
const object = this.object;
const dependencies = new Set();
if (this.node.expression.template_scope.names.has(object)) {
this.node.expression.template_scope.dependencies_for_name
.get(object)
.forEach((name) => dependencies.add(name));
}
else {
dependencies.add(object);
}
const result = new Set(dependencies);
dependencies.forEach((dependency) => {
const indirect_dependencies = this.parent.renderer.component.indirect_dependencies.get(dependency);
if (indirect_dependencies) {
indirect_dependencies.forEach((indirect_dependency) => {
result.add(indirect_dependency);
});
}
});
return result;
}
is_readonly_media_attribute() {
return this.node.is_readonly_media_attribute();
}
/** /** @type {any[]} */
* @param {import('../../Block.js').default} block const update_conditions = this.needs_lock ? [x`!${lock}`] : [];
* @param {import('estree').Identifier} lock
*/
render(block, lock) {
if (this.is_readonly)
return;
const { parent } = this;
/** @type {any[]} */ /** @type {any[]} */
const update_conditions = this.needs_lock ? [x `!${lock}`] : []; const mount_conditions = [];
/** @type {any[]} */ /** @type {any} */
const mount_conditions = []; let update_or_condition = null;
const dependency_array = Array.from(this.get_dependencies());
/** @type {any} */ if (dependency_array.length > 0) {
let update_or_condition = null; update_conditions.push(block.renderer.dirty(dependency_array));
const dependency_array = Array.from(this.get_dependencies()); }
if (dependency_array.length > 0) { if (parent.node.name === 'input') {
update_conditions.push(block.renderer.dirty(dependency_array)); const type = parent.node.get_static_attribute_value('type');
} if (
if (parent.node.name === 'input') { type === null ||
const type = parent.node.get_static_attribute_value('type'); type === '' ||
if (type === null || type === 'text' ||
type === '' || type === 'email' ||
type === 'text' || type === 'password' ||
type === 'email' || type === 'search' ||
type === 'password' || type === 'url'
type === 'search' || ) {
type === 'url') { update_conditions.push(x`${parent.var}.${this.node.name} !== ${this.snippet}`);
update_conditions.push(x `${parent.var}.${this.node.name} !== ${this.snippet}`); } else if (type === 'number') {
} update_conditions.push(x`@to_number(${parent.var}.${this.node.name}) !== ${this.snippet}`);
else if (type === 'number') { }
update_conditions.push(x `@to_number(${parent.var}.${this.node.name}) !== ${this.snippet}`); }
} // model to view
} let update_dom = get_dom_updater(parent, this, false);
// model to view let mount_dom = get_dom_updater(parent, this, true);
let update_dom = get_dom_updater(parent, this, false); // special cases
let mount_dom = get_dom_updater(parent, this, true); switch (this.node.name) {
// special cases case 'group': {
switch (this.node.name) { block.renderer.add_to_context('$$binding_groups');
case 'group': { this.binding_group.add_element(block, this.parent.var);
block.renderer.add_to_context('$$binding_groups'); if (/** @type {import('../Element.js').default} */ (this.parent).has_dynamic_value) {
this.binding_group.add_element(block, this.parent.var); update_or_condition = /** @type {import('../Element.js').default} */ (this.parent)
if (( /** @type {import('../Element.js').default} */(this.parent)).has_dynamic_value) { .dynamic_value_condition;
update_or_condition = ( /** @type {import('../Element.js').default} */(this.parent)).dynamic_value_condition; }
} break;
break; }
} case 'textContent':
case 'textContent': update_conditions.push(x`${this.snippet} !== ${parent.var}.textContent`);
update_conditions.push(x `${this.snippet} !== ${parent.var}.textContent`); mount_conditions.push(x`${this.snippet} !== void 0`);
mount_conditions.push(x `${this.snippet} !== void 0`); break;
break; case 'innerText':
case 'innerText': update_conditions.push(x`${this.snippet} !== ${parent.var}.innerText`);
update_conditions.push(x `${this.snippet} !== ${parent.var}.innerText`); mount_conditions.push(x`${this.snippet} !== void 0`);
mount_conditions.push(x `${this.snippet} !== void 0`); break;
break; case 'innerHTML':
case 'innerHTML': update_conditions.push(x`${this.snippet} !== ${parent.var}.innerHTML`);
update_conditions.push(x `${this.snippet} !== ${parent.var}.innerHTML`); mount_conditions.push(x`${this.snippet} !== void 0`);
mount_conditions.push(x `${this.snippet} !== void 0`); break;
break; case 'currentTime':
case 'currentTime': update_conditions.push(x`!@_isNaN(${this.snippet})`);
update_conditions.push(x `!@_isNaN(${this.snippet})`); mount_dom = null;
mount_dom = null; break;
break; case 'playbackRate':
case 'playbackRate': case 'volume':
case 'volume': update_conditions.push(x`!@_isNaN(${this.snippet})`);
update_conditions.push(x `!@_isNaN(${this.snippet})`); mount_conditions.push(x`!@_isNaN(${this.snippet})`);
mount_conditions.push(x `!@_isNaN(${this.snippet})`); break;
break; case 'paused': {
case 'paused': { // this is necessary to prevent audio restarting by itself
// this is necessary to prevent audio restarting by itself const last = block.get_unique_name(`${parent.var.name}_is_paused`);
const last = block.get_unique_name(`${parent.var.name}_is_paused`); block.add_variable(last, x`true`);
block.add_variable(last, x `true`); update_conditions.push(x`${last} !== (${last} = ${this.snippet})`);
update_conditions.push(x `${last} !== (${last} = ${this.snippet})`); update_dom = b`${parent.var}[${last} ? "pause" : "play"]();`;
update_dom = b `${parent.var}[${last} ? "pause" : "play"]();`; mount_dom = null;
mount_dom = null; break;
break; }
} case 'value':
case 'value': if (parent.node.get_static_attribute_value('type') === 'file') {
if (parent.node.get_static_attribute_value('type') === 'file') { update_dom = null;
update_dom = null; mount_dom = null;
mount_dom = null; }
} }
} if (update_dom) {
if (update_dom) { if (update_conditions.length > 0) {
if (update_conditions.length > 0) { let condition = update_conditions.reduce((lhs, rhs) => x`${lhs} && ${rhs}`);
let condition = update_conditions.reduce((lhs, rhs) => x `${lhs} && ${rhs}`); if (update_or_condition) condition = x`${update_or_condition} || (${condition})`;
if (update_or_condition) block.chunks.update.push(b`
condition = x `${update_or_condition} || (${condition})`;
block.chunks.update.push(b `
if (${condition}) { if (${condition}) {
${update_dom} ${update_dom}
} }
`); `);
} } else {
else { block.chunks.update.push(update_dom);
block.chunks.update.push(update_dom); }
} }
} if (mount_dom) {
if (mount_dom) { if (mount_conditions.length > 0) {
if (mount_conditions.length > 0) { const condition = mount_conditions.reduce((lhs, rhs) => x`${lhs} && ${rhs}`);
const condition = mount_conditions.reduce((lhs, rhs) => x `${lhs} && ${rhs}`); block.chunks.mount.push(b`
block.chunks.mount.push(b `
if (${condition}) { if (${condition}) {
${mount_dom} ${mount_dom}
} }
`); `);
} } else {
else { block.chunks.mount.push(mount_dom);
block.chunks.mount.push(mount_dom); }
} }
} }
}
} }
/** /**
@ -227,31 +230,32 @@ export default class BindingWrapper {
* @param {boolean} mounting * @param {boolean} mounting
*/ */
function get_dom_updater(element, binding, mounting) { function get_dom_updater(element, binding, mounting) {
const { node } = element; const { node } = element;
if (binding.is_readonly_media_attribute()) { if (binding.is_readonly_media_attribute()) {
return null; return null;
} }
if (binding.node.name === 'this') { if (binding.node.name === 'this') {
return null; return null;
} }
if (node.name === 'select') { if (node.name === 'select') {
return node.get_static_attribute_value('multiple') === true return node.get_static_attribute_value('multiple') === true
? b `@select_options(${element.var}, ${binding.snippet})` ? b`@select_options(${element.var}, ${binding.snippet})`
: mounting : mounting
? b `@select_option(${element.var}, ${binding.snippet}, true)` ? b`@select_option(${element.var}, ${binding.snippet}, true)`
: b `@select_option(${element.var}, ${binding.snippet})`; : b`@select_option(${element.var}, ${binding.snippet})`;
} }
if (binding.node.name === 'group') { if (binding.node.name === 'group') {
const type = node.get_static_attribute_value('type'); const type = node.get_static_attribute_value('type');
const condition = type === 'checkbox' const condition =
? x `~(${binding.snippet} || []).indexOf(${element.var}.__value)` type === 'checkbox'
: x `${element.var}.__value === ${binding.snippet}`; ? x`~(${binding.snippet} || []).indexOf(${element.var}.__value)`
return b `${element.var}.checked = ${condition};`; : x`${element.var}.__value === ${binding.snippet}`;
} return b`${element.var}.checked = ${condition};`;
if (binding.node.name === 'value') { }
return b `@set_input_value(${element.var}, ${binding.snippet});`; if (binding.node.name === 'value') {
} return b`@set_input_value(${element.var}, ${binding.snippet});`;
return b `${element.var}.${binding.node.name} = ${binding.snippet};`; }
return b`${element.var}.${binding.node.name} = ${binding.snippet};`;
} }
/** /**
@ -260,107 +264,113 @@ function get_dom_updater(element, binding, mounting) {
* @param {import('../../Block.js').default} block * @param {import('../../Block.js').default} block
*/ */
function get_binding_group(renderer, binding, block) { function get_binding_group(renderer, binding, block) {
const value = binding.node; const value = binding.node;
const { parts } = flatten_reference(value.raw_expression); const { parts } = flatten_reference(value.raw_expression);
let keypath = parts.join('.'); let keypath = parts.join('.');
const contexts = []; const contexts = [];
const contextual_dependencies = new Set(); const contextual_dependencies = new Set();
const { template_scope } = value.expression; const { template_scope } = value.expression;
/** @param {string} dep */ /** @param {string} dep */
const add_contextual_dependency = (dep) => { const add_contextual_dependency = (dep) => {
contextual_dependencies.add(dep); contextual_dependencies.add(dep);
const owner = template_scope.get_owner(dep); const owner = template_scope.get_owner(dep);
if (owner.type === 'EachBlock') { if (owner.type === 'EachBlock') {
for (const dep of owner.expression.contextual_dependencies) { for (const dep of owner.expression.contextual_dependencies) {
add_contextual_dependency(dep); add_contextual_dependency(dep);
} }
} }
}; };
for (const dep of value.expression.contextual_dependencies) { for (const dep of value.expression.contextual_dependencies) {
add_contextual_dependency(dep); add_contextual_dependency(dep);
} }
for (const dep of contextual_dependencies) { for (const dep of contextual_dependencies) {
const context = block.bindings.get(dep); const context = block.bindings.get(dep);
let key; let key;
let name; let name;
if (context) { if (context) {
key = context.object.name; key = context.object.name;
name = context.property.name; name = context.property.name;
} } else {
else { key = dep;
key = dep; name = dep;
name = dep; }
} keypath = `${key}@${keypath}`;
keypath = `${key}@${keypath}`; contexts.push(name);
contexts.push(name); }
} // create a global binding_group across blocks
// create a global binding_group across blocks if (!renderer.binding_groups.has(keypath)) {
if (!renderer.binding_groups.has(keypath)) { const index = renderer.binding_groups.size;
const index = renderer.binding_groups.size; // the bind:group depends on the list in the {#each} block as well
// the bind:group depends on the list in the {#each} block as well // as reordering (removing and adding back to the DOM) may affect the value
// as reordering (removing and adding back to the DOM) may affect the value const list_dependencies = new Set();
const list_dependencies = new Set(); let parent = value.parent;
let parent = value.parent; while (parent) {
while (parent) { if (parent.type === 'EachBlock') {
if (parent.type === 'EachBlock') { for (const dep of parent.expression.dynamic_dependencies()) {
for (const dep of parent.expression.dynamic_dependencies()) { list_dependencies.add(dep);
list_dependencies.add(dep); }
} }
} parent = parent.parent;
parent = parent.parent; }
} /**
/** * When using bind:group with logic blocks, the inputs with bind:group may be scattered across different blocks.
* When using bind:group with logic blocks, the inputs with bind:group may be scattered across different blocks. * This therefore keeps track of all the <input> elements that have the same bind:group within the same block.
* This therefore keeps track of all the <input> elements that have the same bind:group within the same block. */
*/ const elements = new Map();
const elements = new Map(); contexts.forEach((context) => {
contexts.forEach((context) => { renderer.add_to_context(context, true);
renderer.add_to_context(context, true); });
}); renderer.binding_groups.set(keypath, {
renderer.binding_groups.set(keypath, { binding_group: () => {
binding_group: () => { let obj = x`$$binding_groups[${index}]`;
let obj = x `$$binding_groups[${index}]`; if (contexts.length > 0) {
if (contexts.length > 0) { contexts.forEach((secondary_index) => {
contexts.forEach((secondary_index) => { obj = x`${obj}[${secondary_index}]`;
obj = x `${obj}[${secondary_index}]`; });
}); }
} return obj;
return obj; },
}, contexts,
contexts, list_dependencies,
list_dependencies, keypath,
keypath, add_element(block, element) {
add_element(block, element) { if (!elements.has(block)) {
if (!elements.has(block)) { elements.set(block, []);
elements.set(block, []); }
} elements.get(block).push(element);
elements.get(block).push(element); },
}, render(block) {
render(block) { const local_name = block.get_unique_name('binding_group');
const local_name = block.get_unique_name('binding_group'); const binding_group = block.renderer.reference('$$binding_groups');
const binding_group = block.renderer.reference('$$binding_groups'); block.add_variable(local_name);
block.add_variable(local_name); if (contexts.length > 0) {
if (contexts.length > 0) { const indexes = {
const indexes = { type: 'ArrayExpression',
type: 'ArrayExpression', elements: contexts.map((name) => block.renderer.reference(name))
elements: contexts.map((name) => block.renderer.reference(name)) };
}; block.chunks.init.push(
block.chunks.init.push(b `${local_name} = @init_binding_group_dynamic(${binding_group}[${index}], ${indexes})`); b`${local_name} = @init_binding_group_dynamic(${binding_group}[${index}], ${indexes})`
block.chunks.update.push(b `if (${block.renderer.dirty(Array.from(list_dependencies))}) ${local_name}.u(${indexes})`); );
} block.chunks.update.push(
else { b`if (${block.renderer.dirty(
block.chunks.init.push(b `${local_name} = @init_binding_group(${binding_group}[${index}])`); Array.from(list_dependencies)
} )}) ${local_name}.u(${indexes})`
block.chunks.hydrate.push(b `${local_name}.p(${elements.get(block)})`); );
block.chunks.destroy.push(b `${local_name}.r()`); } else {
} block.chunks.init.push(
}); b`${local_name} = @init_binding_group(${binding_group}[${index}])`
} );
// register the binding_group for the block }
const binding_group = renderer.binding_groups.get(keypath); block.chunks.hydrate.push(b`${local_name}.p(${elements.get(block)})`);
block.binding_groups.add(binding_group); block.chunks.destroy.push(b`${local_name}.r()`);
return binding_group; }
});
}
// register the binding_group for the block
const binding_group = renderer.binding_groups.get(keypath);
block.binding_groups.add(binding_group);
return binding_group;
} }
/** /**
@ -372,39 +382,38 @@ function get_binding_group(renderer, binding, block) {
* @returns {{ uses_context: boolean; mutation: import("C:/repos/svelte/svelte/node_modules/.pnpm/@types+estree@1.0.0/node_modules/@types/estree/index").Node | import("C:/repos/svelte/svelte/node_modules/.pnpm/@types+estree@1.0.0/node_modules/@types/estree/index").Node[]; contextual_dependencies: Set<string>; lhs?: import("C:/repos/svelte/svelte/node_modules/.pnpm/@types+estree@1.0.0/node_modules/@types/estree/index").Node; }} * @returns {{ uses_context: boolean; mutation: import("C:/repos/svelte/svelte/node_modules/.pnpm/@types+estree@1.0.0/node_modules/@types/estree/index").Node | import("C:/repos/svelte/svelte/node_modules/.pnpm/@types+estree@1.0.0/node_modules/@types/estree/index").Node[]; contextual_dependencies: Set<string>; lhs?: import("C:/repos/svelte/svelte/node_modules/.pnpm/@types+estree@1.0.0/node_modules/@types/estree/index").Node; }}
*/ */
function get_event_handler(binding, renderer, block, name, lhs) { function get_event_handler(binding, renderer, block, name, lhs) {
const contextual_dependencies = new Set(binding.node.expression.contextual_dependencies); const contextual_dependencies = new Set(binding.node.expression.contextual_dependencies);
const context = block.bindings.get(name); const context = block.bindings.get(name);
/** @type {Node[] | undefined} */ /** @type {Node[] | undefined} */
let set_store; let set_store;
if (context) { if (context) {
const { object, property, store, snippet } = context; const { object, property, store, snippet } = context;
lhs = replace_object(lhs, snippet); lhs = replace_object(lhs, snippet);
contextual_dependencies.add(object.name); contextual_dependencies.add(object.name);
contextual_dependencies.add(property.name); contextual_dependencies.add(property.name);
contextual_dependencies.delete(name); contextual_dependencies.delete(name);
if (store) { if (store) {
set_store = b `${store}.set(${`$${store}`});`; set_store = b`${store}.set(${`$${store}`});`;
} }
} } else {
else { const object = get_object(lhs);
const object = get_object(lhs); if (object.name[0] === '$') {
if (object.name[0] === '$') { const store = object.name.slice(1);
const store = object.name.slice(1); set_store = b`${store}.set(${object.name});`;
set_store = b `${store}.set(${object.name});`; }
} }
} const value = get_value_from_dom(renderer, binding.parent, binding, contextual_dependencies);
const value = get_value_from_dom(renderer, binding.parent, binding, contextual_dependencies); const mutation = b`
const mutation = b `
${lhs} = ${value}; ${lhs} = ${value};
${set_store} ${set_store}
`; `;
return { return {
uses_context: binding.node.is_contextual || binding.node.expression.uses_context, uses_context: binding.node.is_contextual || binding.node.expression.uses_context,
mutation, mutation,
contextual_dependencies, contextual_dependencies,
lhs lhs
}; };
} }
/** /**
@ -414,42 +423,38 @@ function get_event_handler(binding, renderer, block, name, lhs) {
* @param {Set<string>} contextual_dependencies * @param {Set<string>} contextual_dependencies
*/ */
function get_value_from_dom(_renderer, element, binding, contextual_dependencies) { function get_value_from_dom(_renderer, element, binding, contextual_dependencies) {
const { node } = element; const { node } = element;
const { name } = binding.node; const { name } = binding.node;
if (name === 'this') { if (name === 'this') {
return x `$$value`; return x`$$value`;
} }
// <div bind:contentRect|contentBoxSize|borderBoxSize|devicePixelContentBoxSize> // <div bind:contentRect|contentBoxSize|borderBoxSize|devicePixelContentBoxSize>
if (regex_box_size.test(name)) { if (regex_box_size.test(name)) {
return x `@ResizeObserverSingleton.entries.get(this)?.${name}`; return x`@ResizeObserverSingleton.entries.get(this)?.${name}`;
} }
// <select bind:value='selected> // <select bind:value='selected>
if (node.name === 'select') { if (node.name === 'select') {
return node.get_static_attribute_value('multiple') === true return node.get_static_attribute_value('multiple') === true
? x `@select_multiple_value(this)` ? x`@select_multiple_value(this)`
: x `@select_value(this)`; : x`@select_value(this)`;
} }
const type = node.get_static_attribute_value('type'); const type = node.get_static_attribute_value('type');
// <input type='checkbox' bind:group='foo'> // <input type='checkbox' bind:group='foo'>
if (name === 'group') { if (name === 'group') {
if (type === 'checkbox') { if (type === 'checkbox') {
const { binding_group, contexts } = binding.binding_group; const { binding_group, contexts } = binding.binding_group;
add_to_set(contextual_dependencies, contexts); add_to_set(contextual_dependencies, contexts);
return x `@get_binding_group_value(${binding_group()}, this.__value, this.checked)`; return x`@get_binding_group_value(${binding_group()}, this.__value, this.checked)`;
} }
return x `this.__value`; return x`this.__value`;
} }
// <input type='range|number' bind:value> // <input type='range|number' bind:value>
if (type === 'range' || type === 'number') { if (type === 'range' || type === 'number') {
return x `@to_number(this.${name})`; return x`@to_number(this.${name})`;
} }
if (name === 'buffered' || name === 'seekable' || name === 'played') { if (name === 'buffered' || name === 'seekable' || name === 'played') {
return x `@time_ranges_to_array(this.${name})`; return x`@time_ranges_to_array(this.${name})`;
} }
// everything else // everything else
return x `this.${name}`; return x`this.${name}`;
} }

Loading…
Cancel
Save