pull/2317/head
Rich Harris 7 years ago
parent a3a2e51352
commit af6f73c486

@ -636,23 +636,6 @@ export default class Element extends Node {
}); });
} }
get_static_attribute_value(name: string) {
const attribute = this.attributes.find(
(attr: Attribute) => attr.type === 'Attribute' && attr.name.toLowerCase() === name
);
if (!attribute) return null;
if (attribute.is_true) return true;
if (attribute.chunks.length === 0) return '';
if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') {
return attribute.chunks[0].data;
}
return null;
}
is_media_node() { is_media_node() {
return this.name === 'audio' || this.name === 'video'; return this.name === 'audio' || this.name === 'video';
} }

@ -53,21 +53,4 @@ export default class Slot extends Element {
// }); // });
// } // }
} }
get_static_attribute_value(name: string) {
const attribute = this.attributes.find(
attr => attr.name.toLowerCase() === name
);
if (!attribute) return null;
if (attribute.is_true) return true;
if (attribute.chunks.length === 0) return '';
if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') {
return attribute.chunks[0].data;
}
return null;
}
} }

@ -37,17 +37,34 @@ export default class Node {
} }
} }
find_nearest(selector: RegExp) {
if (selector.test(this.type)) return this;
if (this.parent) return this.parent.find_nearest(selector);
}
get_static_attribute_value(name: string) {
const attribute = this.attributes.find(
(attr: Attribute) => attr.type === 'Attribute' && attr.name.toLowerCase() === name
);
if (!attribute) return null;
if (attribute.is_true) return true;
if (attribute.chunks.length === 0) return '';
if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') {
return attribute.chunks[0].data;
}
return null;
}
has_ancestor(type: string) { has_ancestor(type: string) {
return this.parent ? return this.parent ?
this.parent.type === type || this.parent.has_ancestor(type) : this.parent.type === type || this.parent.has_ancestor(type) :
false; false;
} }
find_nearest(selector: RegExp) {
if (selector.test(this.type)) return this;
if (this.parent) return this.parent.find_nearest(selector);
}
warn_if_empty_block() { warn_if_empty_block() {
if (!/Block$/.test(this.type) || !this.children) return; if (!/Block$/.test(this.type) || !this.children) return;
if (this.children.length > 1) return; if (this.children.length > 1) return;

@ -117,7 +117,7 @@ export default class AttributeWrapper {
updater = `@set_input_type(${element.var}, ${should_cache ? last : value});`; updater = `@set_input_type(${element.var}, ${should_cache ? last : value});`;
} else if (is_select_value_attribute) { } else if (is_select_value_attribute) {
// annoying special case // annoying special case
const is_multiple_select = element.get_static_attribute_value('multiple'); const is_multiple_select = element.node.get_static_attribute_value('multiple');
const i = block.get_unique_name('i'); const i = block.get_unique_name('i');
const option = block.get_unique_name('option'); const option = block.get_unique_name('option');

@ -153,7 +153,7 @@ export default class BindingWrapper {
break; break;
case 'value': case 'value':
if (parent.get_static_attribute_value('type') === 'file') { if (parent.node.get_static_attribute_value('type') === 'file') {
update_dom = null; update_dom = null;
} }
} }

@ -213,8 +213,8 @@ export default class ElementWrapper extends Wrapper {
const { renderer } = this; const { renderer } = this;
if (this.node.name === 'slot') { if (this.node.name === 'slot') {
const slotName = this.get_static_attribute_value('name') || 'default'; const slot_name = this.node.get_static_attribute_value('name') || 'default';
renderer.slots.add(slotName); renderer.slots.add(slot_name);
} }
if (this.node.name === 'noscript') return; if (this.node.name === 'noscript') return;
@ -804,23 +804,6 @@ export default class ElementWrapper extends Wrapper {
}); });
} }
get_static_attribute_value(name: string) {
const attribute = this.node.attributes.find(
(attr: Attribute) => attr.type === 'Attribute' && attr.name.toLowerCase() === name
);
if (!attribute) return null;
if (attribute.is_true) return true;
if (attribute.chunks.length === 0) return '';
if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') {
return attribute.chunks[0].data;
}
return null;
}
add_css_class(class_name = this.component.stylesheet.id) { add_css_class(class_name = this.component.stylesheet.id) {
const class_attribute = this.attributes.find(a => a.name === 'class'); const class_attribute = this.attributes.find(a => a.name === 'class');
if (class_attribute && !class_attribute.is_true) { if (class_attribute && !class_attribute.is_true) {

Loading…
Cancel
Save