Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
filterNodes(ast, n => (n instanceof Object ? n[0] === "h1" : false));
// $ExpectType Node[] || AST
modifyNodesByName(ast, "h2", n => {
typeof n === "object" ? (n[1] = []) : undefined;
});
// $ExpectType [PropType, PropData] | null || PropValue | null
getProperty(ast[1], "someProp");
// $ExpectType [string, [PropType, PropData]] || Property
getProperties(ast[1])[0];
// $ExpectType [string, [PropType, PropData]][] || Property[]
getPropertiesByType(["h1", [], []], "variable");
// $ExpectType Node[] || AST
removeNodesByName(ast, "h1");
// $ExpectType Node
setProperty(ast[0], "prop", 9);
// $ExpectType Node
setProperties(ast[1], { prop1: ["expression", "x"], prop2: 3 });
// $ExpectType Node
removeProperty(ast[0], "prop1");
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;
};
export const filterASTForDocument = ast => {
return removeNodesByName(ast, 'meta');
};
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;
};