|
|
|
|
|
|
|
|
|
export default class Node { |
|
|
|
|
|
|
|
|
|
start; |
|
|
|
|
|
|
|
|
|
|
|
end; |
|
|
|
|
|
|
|
|
|
|
|
component; |
|
|
|
|
|
|
|
|
|
|
|
parent; |
|
|
|
|
|
|
|
|
|
|
|
type; |
|
|
|
|
|
prev; |
|
|
|
|
|
next; |
|
|
|
|
|
can_use_innerhtml; |
|
|
|
|
|
is_static_content; |
|
|
|
|
|
var; |
|
|
|
|
|
attributes = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(component, parent, _scope, info) { |
|
this.start = info.start; |
|
this.end = info.end; |
|
this.type = (info.type); |
|
|
|
|
|
Object.defineProperties(this, { |
|
component: { |
|
value: component |
|
}, |
|
parent: { |
|
value: parent |
|
} |
|
}); |
|
this.can_use_innerhtml = true; |
|
this.is_static_content = true; |
|
} |
|
cannot_use_innerhtml() { |
|
if (this.can_use_innerhtml !== false) { |
|
this.can_use_innerhtml = false; |
|
if (this.parent) this.parent.cannot_use_innerhtml(); |
|
} |
|
} |
|
not_static_content() { |
|
this.is_static_content = false; |
|
if (this.parent) this.parent.not_static_content(); |
|
} |
|
|
|
|
|
find_nearest(selector) { |
|
if (selector.test(this.type)) return this; |
|
if (this.parent) return this.parent.find_nearest(selector); |
|
} |
|
|
|
|
|
get_static_attribute_value(name) { |
|
const attribute = this.attributes.find( |
|
|
|
(attr) => 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) { |
|
return this.parent ? this.parent.type === type || this.parent.has_ancestor(type) : false; |
|
} |
|
} |
|
|