How to use the idyll-ast.getNodesByName 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
setProperties,
    removeProperty
} from "idyll-ast";

const ast: AST = [
    ["h2", [], []],
    "world",
    ["h1", [], ["child1", ["child2", [], []]]]
];
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]);
github DefinitelyTyped / DefinitelyTyped / types / idyll-ast / idyll-ast-tests.ts View on Github external
// $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[]
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];
github DefinitelyTyped / DefinitelyTyped / types / idyll-ast / idyll-ast-tests.ts View on Github external
"world",
    ["h1", [], ["child1", ["child2", [], []]]]
];
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[]
github idyll-lang / idyll / packages / idyll-cli / src / pipeline / parse.js View on Github external
exports.getHighlightJS = (ast, paths, server) => {
  // load react-syntax-highlighter from idyll's node_modules directory
  const languageMap = {
    js: 'javascript',
    html: 'htmlbars'
  };

  const codeHighlightNodes = getNodesByName(ast, 'CodeHighlight');
  if (!codeHighlightNodes.length) {
    return ' ';
  }

  const languages = codeHighlightNodes.reduce((acc, dataNode) => {
    const language = dataNode.properties.language.value;
    acc[language] = true;
    return acc;
  }, {});

  if (server) {
    const rshPath = slash(
      path.dirname(
        resolve.sync('react-syntax-highlighter', {
          basedir: paths.DEFAULT_COMPONENTS_DIR
        })
github idyll-lang / idyll / packages / idyll-compiler / src / processors / post.js View on Github external
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;
};
github idyll-lang / idyll / packages / idyll-compiler / src / processors / post.js View on Github external
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;
};
github idyll-lang / idyll / packages / idyll-compiler / src / processors / post.js View on Github external
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;
};