Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
appendNode(getNodesByName(ast, "div"), "test");
// $ExpectType Node[] || AST
appendNodes(ast, [["strong", [], ["div", ["pre", [], []]]], "test"]);
// $ExpectType Node[] || AST
prependNode(getNodesByName(ast, "div"), "test");
// $ExpectType Node[] || AST
prependNodes(ast, [["strong", [], ["div", ["pre", [], []]]], "test"]);
// $ExpectType TreeNode
createNode("div", { prop1: "prop1", prop2: ["expression", "x=2"] }, []);
// $ExpectType Node[]
getChildren(ast[0]);
// $ExpectType void
walkNodes(ast, (n: Node) => {
(n as TreeNode)[0] = "funky-name";
});
// $ExpectType Node[]
findNodes(ast, n => n instanceof Array);
// $ExpectType Node
modifyChildren(ast[0], (n: Node) => {
if (typeof n === "object") {
n[0] = "somename";
}
});
// $ExpectType Node[]
const tNode = node => {
if (getType(node) === 'textnode') return node;
let name = getNodeName(node);
let attrs = getProperties(node);
if (!attrs) {
attrs = {};
}
const children = getChildren(node);
return {
component: name,
...attrConvert(attrs, node),
children: children.map(tNode)
};
};
let name = getNodeName(node);
let attrs = getProperties(node);
if (!attrs) {
attrs = {};
}
const children = getChildren(node);
return {
component: name,
...attrConvert(attrs, node),
children: children.map(tNode)
};
};
return splitAST(getChildren(ast)).elements.map(tNode);
};
return node => {
const type = getType(node);
const props = getProperties(node);
const children = getChildren(node);
if (node.id != 0) {
if (type === 'var') {
state.vars.push(node);
} else if (state[type]) {
state[type].push(node);
} else if (storeElements) {
state.elements.push(node);
}
if (
!children ||
(children.length === 1 && getType(children[0]) === 'textnode')
) {
return;
}
children.forEach(handleNode(false));
}