How to use the idyll-ast.getProperties 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
// $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");

// $ExpectType Node
setProperty(ast[0], "prop", 9);

// $ExpectType Node
setProperties(ast[1], { prop1: ["expression", "x"], prop2: 3 });

// $ExpectType Node
removeProperty(ast[0], "prop1");
github idyll-lang / idyll / packages / idyll-document / src / utils / index.js View on Github external
const pluck = (acc, val) => {
    const variableType = getType(val);
    const attrs = getProperties(val) || [];

    if (!attrs.name || !attrs.value) return attrs;

    const nameValue = attrs.name.value;
    const valueType = attrs.value.type;
    const valueValue = attrs.value.value;

    switch (valueType) {
      case 'value':
        acc[nameValue] = valueValue;
        break;
      case 'variable':
        if (context.hasOwnProperty(valueValue)) {
          acc[nameValue] = context[valueValue];
        } else {
          acc[nameValue] = evalExpression(context, expr);
github idyll-lang / idyll / packages / idyll-document / src / utils / index.js View on Github external
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)
    };
  };
github idyll-lang / idyll / packages / idyll-document / src / utils / index.js View on Github external
const pluck = (acc, val) => {
    const nameValue = getProperties(val).name.value;
    acc[nameValue] = datasets[nameValue];

    return acc;
  };
github idyll-lang / idyll / packages / idyll-document / src / utils / index.js View on Github external
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));