Improved demo
parent
a89cdbfe4c
commit
429bdf119f
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
})
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue