Lint and format src/compiler/compile/nodes/shared/Node.js

pull/8569/head
Simon Holthausen 3 years ago
parent 8e5fb225c6
commit c409d1bbb8

@ -1,122 +1,111 @@
export default class Node { export default class Node {
/**
/** * @readonly
* @readonly * @type {number}
* @type {number} */
*/ start;
start;
/**
/** * @readonly
* @readonly * @type {number}
* @type {number} */
*/ end;
end;
/**
/** * @readonly
* @readonly * @type {import('../../Component.js').default}
* @type {import('../../Component.js').default} */
*/ component;
component;
/**
/** * @readonly
* @readonly * @type {import('../interfaces.js').INode}
* @type {import('../interfaces.js').INode} */
*/ parent;
parent;
/**
/** * @readonly
* @readonly * @type {string}
* @type {string} */
*/ type;
type;
/** @type {import('../interfaces.js').INode} */
/** @type {import('../interfaces.js').INode} */ prev;
prev;
/** @type {import('../interfaces.js').INode} */
/** @type {import('../interfaces.js').INode} */ next;
next;
/** @type {boolean} */
/** @type {boolean} */ can_use_innerhtml;
can_use_innerhtml;
/** @type {boolean} */
/** @type {boolean} */ is_static_content;
is_static_content;
/** @type {string} */
/** @type {string} */ var;
var;
/** @type {import('../Attribute.js').default[]} */
/** @type {import('../Attribute.js').default[]} */ attributes;
attributes;
/**
/** * @param {import('../../Component.js').default} component *
* @param {import('../../Component.js').default} component * * @param {Node} parent *
* @param {Node} parent * * @param {any} _scope *
* @param {any} _scope * * @param {import('../../../interfaces.js').TemplateNode} info undefined
* @param {import('../../../interfaces.js').TemplateNode} info undefined */
*/ constructor(component, parent, _scope, info) {
constructor(component, parent, _scope, info) { this.start = info.start;
this.start = info.start; this.end = info.end;
this.end = info.end; this.type = info.type;
this.type = info.type; // this makes properties non-enumerable, which makes logging
// this makes properties non-enumerable, which makes logging // bearable. might have a performance cost. TODO remove in prod?
// bearable. might have a performance cost. TODO remove in prod? Object.defineProperties(this, {
Object.defineProperties(this, { component: {
component: { value: component
value: component },
}, parent: {
parent: { value: parent
value: parent }
} });
}); this.can_use_innerhtml = true;
this.can_use_innerhtml = true; this.is_static_content = true;
this.is_static_content = true; }
} cannot_use_innerhtml() {
cannot_use_innerhtml() { if (this.can_use_innerhtml !== false) {
if (this.can_use_innerhtml !== false) { this.can_use_innerhtml = false;
this.can_use_innerhtml = false; if (this.parent) this.parent.cannot_use_innerhtml();
if (this.parent) }
this.parent.cannot_use_innerhtml(); }
} not_static_content() {
} this.is_static_content = false;
not_static_content() { if (this.parent) this.parent.not_static_content();
this.is_static_content = false; }
if (this.parent)
this.parent.not_static_content(); /** @param {RegExp} selector */
} find_nearest(selector) {
if (selector.test(this.type)) return this;
/** @param {RegExp} selector */ if (this.parent) return this.parent.find_nearest(selector);
find_nearest(selector) { }
if (selector.test(this.type))
return this; /** @param {string} name */
if (this.parent) get_static_attribute_value(name) {
return this.parent.find_nearest(selector); const attribute =
} this.attributes &&
this.attributes.find(
/** @param {string} name */ /** @param {import('../Attribute.js').default} attr */
get_static_attribute_value(name) { (attr) => attr.type === 'Attribute' && attr.name.toLowerCase() === name
const attribute = this.attributes && );
this.attributes.find( if (!attribute) return null;
if (attribute.is_true) return true;
/** @param {import('../Attribute.js').default} attr */ if (attribute.chunks.length === 0) return '';
(attr) => attr.type === 'Attribute' && attr.name.toLowerCase() === name); if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') {
if (!attribute) return /** @type {import('../Text.js').default} */ (attribute.chunks[0]).data;
return null; }
if (attribute.is_true) return null;
return true; }
if (attribute.chunks.length === 0)
return ''; /** @param {string} type */
if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') { has_ancestor(type) {
return ( /** @type {import('../Text.js').default} */(attribute.chunks[0])).data; return this.parent ? this.parent.type === type || this.parent.has_ancestor(type) : false;
} }
return null;
}
/** @param {string} type */
has_ancestor(type) {
return this.parent ? this.parent.type === type || this.parent.has_ancestor(type) : false;
}
} }

Loading…
Cancel
Save