Improved demo

master
Sir Robert Burbridge 2023-04-07 21:49:43 -04:00
parent a89cdbfe4c
commit 429bdf119f
2 changed files with 44 additions and 8 deletions

View File

@ -1,4 +1,9 @@
<loom-module define="Component">
<span>component</span>
</loom-module>
<div>
<h1>Title</h1>
<span class="foo" id="bar">testing</span>
<Component/>
</div>

View File

@ -14,19 +14,50 @@ async function showAst () {
return tree;
}
async function extractModules (ast) {
const modules = [];
visit(
ast,
node => {
if (!node?.children?.length) {
return false;
}
for (var i = 0; i < node.children.length; i++) {
if (node.children[i].tagName === 'loom-module') {
return true;
}
}
},
node => {
node.children = node.children.reduce(
(list,item) => {
if (item.tagName === 'loom-module') {
console.log("foo")
modules.push(item);
} else {
list.push(item);
}
return list;
},
[]
);
}
);
return {modules, ast};
}
showAst()
.then(ast => {
//console.log(JSON.stringify(ast ,undefined,2))
return ast;
})
.then(ast => {
visit(ast, node => node.tagName === 'span', node => {
node.tagName = "div";
});
return ast;
})
.then(ast => {
.then(extractModules)
.then(({ast,modules}) => {
console.log(ast);
console.log(toHtml(ast))
console.log(modules);
})