How to use the idyll-ast.filterNodes function in idyll-ast

To help you get started, we’ve selected a few idyll-ast examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / idyll-ast / idyll-ast-tests.ts View on Github external
findNodes(ast, n => n instanceof Array);

// $ExpectType Node
modifyChildren(ast[0], (n: Node) => {
    if (typeof n === "object") {
        n[0] = "somename";
    }
});
// $ExpectType Node[]
getNodesByName(ast, "h1");

// $ExpectType Node
filterChildren(ast[1], n => n === "world");

// $ExpectType Node[] || AST
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");
github idyll-lang / idyll / packages / idyll-cli / src / pipeline / parse.js View on Github external
exports.getComponentNodes = ast => {
  const ignoreTypes = new Set(['var', 'data', 'meta', 'derived']);
  let filter = filterNodes(ast, node => {
    if (node.type === 'textnode') {
      return false;
    }
    return !ignoreTypes.has(getType(node).toLowerCase());
  });
  return filter;
};