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

pull/8569/head
Simon Holthausen 3 years ago
parent 9886954315
commit ca30dff13d

@ -22,50 +22,50 @@ import { push_array } from '../../../utils/push_array.js';
/** @param {any} type */ /** @param {any} type */
function get_constructor(type) { function get_constructor(type) {
switch (type) { switch (type) {
case 'AwaitBlock': case 'AwaitBlock':
return AwaitBlock; return AwaitBlock;
case 'Body': case 'Body':
return Body; return Body;
case 'Comment': case 'Comment':
return Comment; return Comment;
case 'ConstTag': case 'ConstTag':
return ConstTag; return ConstTag;
case 'Document': case 'Document':
return Document; return Document;
case 'EachBlock': case 'EachBlock':
return EachBlock; return EachBlock;
case 'Element': case 'Element':
return Element; return Element;
case 'Head': case 'Head':
return Head; return Head;
case 'IfBlock': case 'IfBlock':
return IfBlock; return IfBlock;
case 'InlineComponent': case 'InlineComponent':
return InlineComponent; return InlineComponent;
case 'KeyBlock': case 'KeyBlock':
return KeyBlock; return KeyBlock;
case 'MustacheTag': case 'MustacheTag':
return MustacheTag; return MustacheTag;
case 'Options': case 'Options':
return Options; return Options;
case 'RawMustacheTag': case 'RawMustacheTag':
return RawMustacheTag; return RawMustacheTag;
case 'DebugTag': case 'DebugTag':
return DebugTag; return DebugTag;
case 'Slot': case 'Slot':
return Slot; return Slot;
case 'SlotTemplate': case 'SlotTemplate':
return SlotTemplate; return SlotTemplate;
case 'Text': case 'Text':
return Text; return Text;
case 'Title': case 'Title':
return Title; return Title;
case 'Window': case 'Window':
return Window; return Window;
default: default:
throw new Error(`Not implemented: ${type}`); throw new Error(`Not implemented: ${type}`);
} }
} }
/** /**
@ -75,27 +75,24 @@ function get_constructor(type) {
* @param {import('../../../interfaces.js').TemplateNode[]} children * @param {import('../../../interfaces.js').TemplateNode[]} children
*/ */
export default function map_children(component, parent, scope, children) { export default function map_children(component, parent, scope, children) {
let last = null; let last = null;
let ignores = []; let ignores = [];
return children.map(/** @param {any} child */ (child) => { return children.map(
const constructor = get_constructor(child.type); /** @param {any} child */ (child) => {
const use_ignores = child.type !== 'Text' && child.type !== 'Comment' && ignores.length; const constructor = get_constructor(child.type);
if (use_ignores) const use_ignores = child.type !== 'Text' && child.type !== 'Comment' && ignores.length;
component.push_ignores(ignores); if (use_ignores) component.push_ignores(ignores);
const node = new constructor(component, parent, scope, child); const node = new constructor(component, parent, scope, child);
if (use_ignores) if (use_ignores) component.pop_ignores(), (ignores = []);
component.pop_ignores(), (ignores = []); if (node.type === 'Comment' && node.ignores.length) {
if (node.type === 'Comment' && node.ignores.length) { push_array(ignores, node.ignores);
push_array(ignores, node.ignores); }
} if (last) last.next = node;
if (last) node.prev = last;
last.next = node; last = node;
node.prev = last; return node;
last = node; }
return node; );
});
} }
/** @typedef {Class<map_children>>} Children */ /** @typedef {Class<map_children>>} Children */

Loading…
Cancel
Save