Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const prop: Property = ["className", ["value", "hello"]];
// $ExpectType Node[] || AST
appendNode(ast, "hello");
// $ExpectType Node[] || AST
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
const hoistVariables = (ast) => {
const vars = getNodesByName(ast, 'var');
const derived = getNodesByName(ast, 'derived');
const data = getNodesByName(ast, 'data');
ast = removeNodesByName(ast, 'var');
ast = removeNodesByName(ast, 'derived');
ast = removeNodesByName(ast, 'data');
ast = prependNodes(ast, derived);
ast = prependNodes(ast, data);
ast = prependNodes(ast, vars);
return ast;
};
const hoistVariables = (ast) => {
const vars = getNodesByName(ast, 'var');
const derived = getNodesByName(ast, 'derived');
const data = getNodesByName(ast, 'data');
ast = removeNodesByName(ast, 'var');
ast = removeNodesByName(ast, 'derived');
ast = removeNodesByName(ast, 'data');
ast = prependNodes(ast, derived);
ast = prependNodes(ast, data);
ast = prependNodes(ast, vars);
return ast;
};
const hoistVariables = (ast) => {
const vars = getNodesByName(ast, 'var');
const derived = getNodesByName(ast, 'derived');
const data = getNodesByName(ast, 'data');
ast = removeNodesByName(ast, 'var');
ast = removeNodesByName(ast, 'derived');
ast = removeNodesByName(ast, 'data');
ast = prependNodes(ast, derived);
ast = prependNodes(ast, data);
ast = prependNodes(ast, vars);
return ast;
};