diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index c0da7ea5c0..6d9c8059f5 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -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() { return this.name === 'audio' || this.name === 'video'; } diff --git a/src/compile/nodes/Slot.ts b/src/compile/nodes/Slot.ts index 0a4f4af848..31026e302a 100644 --- a/src/compile/nodes/Slot.ts +++ b/src/compile/nodes/Slot.ts @@ -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; - } } \ No newline at end of file diff --git a/src/compile/nodes/shared/Node.ts b/src/compile/nodes/shared/Node.ts index 4317e23e4f..92c1cc40d7 100644 --- a/src/compile/nodes/shared/Node.ts +++ b/src/compile/nodes/shared/Node.ts @@ -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) { return this.parent ? this.parent.type === type || this.parent.has_ancestor(type) : 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() { if (!/Block$/.test(this.type) || !this.children) return; if (this.children.length > 1) return; diff --git a/src/compile/render-dom/wrappers/Element/Attribute.ts b/src/compile/render-dom/wrappers/Element/Attribute.ts index 5b581677d8..c0c8327bb0 100644 --- a/src/compile/render-dom/wrappers/Element/Attribute.ts +++ b/src/compile/render-dom/wrappers/Element/Attribute.ts @@ -117,7 +117,7 @@ export default class AttributeWrapper { updater = `@set_input_type(${element.var}, ${should_cache ? last : value});`; } else if (is_select_value_attribute) { // 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 option = block.get_unique_name('option'); diff --git a/src/compile/render-dom/wrappers/Element/Binding.ts b/src/compile/render-dom/wrappers/Element/Binding.ts index 8657a1b054..f2bf82a826 100644 --- a/src/compile/render-dom/wrappers/Element/Binding.ts +++ b/src/compile/render-dom/wrappers/Element/Binding.ts @@ -153,7 +153,7 @@ export default class BindingWrapper { break; case 'value': - if (parent.get_static_attribute_value('type') === 'file') { + if (parent.node.get_static_attribute_value('type') === 'file') { update_dom = null; } } diff --git a/src/compile/render-dom/wrappers/Element/index.ts b/src/compile/render-dom/wrappers/Element/index.ts index d54a66dffa..32c8063f05 100644 --- a/src/compile/render-dom/wrappers/Element/index.ts +++ b/src/compile/render-dom/wrappers/Element/index.ts @@ -213,8 +213,8 @@ export default class ElementWrapper extends Wrapper { const { renderer } = this; if (this.node.name === 'slot') { - const slotName = this.get_static_attribute_value('name') || 'default'; - renderer.slots.add(slotName); + const slot_name = this.node.get_static_attribute_value('name') || 'default'; + renderer.slots.add(slot_name); } 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) { const class_attribute = this.attributes.find(a => a.name === 'class'); if (class_attribute && !class_attribute.is_true) {