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

Loading…
Cancel
Save