How to use the idyll-ast.appendNode 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
getPropertiesByType,
    removeNodesByName,
    setProperty,
    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"] }, []);
github idyll-lang / idyll-studio / src / render / idyll-display / components / deploy.js View on Github external
compile('[meta /]').then(metaAST => {
            let ast = this.context.ast;
            let lastChild = ast.children[ast.children.length - 1];

            // reset ids
            metaAST.children[0].id = getRandomId(); // TextContainer
            this.setState({ metaNode: metaAST.children[0].children[0] }); // meta
            this.state.metaNode.id = getRandomId();

            if (lastChild.name === 'TextContainer') {
              // push just meta tag
              lastChild.children.push(metaAST.children[0].children[0]);
            } else {
              // push text container
              ast = idyllAST.appendNode(ast, metaAST.children[0]);
            }
            this.context.setAst(this.context.ast);
          });
        }
github idyll-lang / idyll-studio / src / components / idyll-document / src / runtime.js View on Github external
console.log('mod block')
          found = true;
          return newNode;
          
        }
    
        node = IdyllAST.modifyChildren(node, handleNode);
        return node;
      }
    
      ast = ast.map((node) => {
        return handleNode(node);
      });
      if (found === false) {
        console.log('append block')
        ast = IdyllAST.appendNode(ast,newNode);
      }
      return ast;
    };
github idyll-lang / idyll-studio / src / render / idyll-display / components / variable-view.js View on Github external
const valueOfVar = newID;
    const newVarNode = {
      id: newID,
      type: 'var',
      properties: {
        name: {
          type: 'value',
          value: nameOfVar
        },
        value: {
          type: 'value',
          value: valueOfVar
        }
      }
    };
    const updatedAST = IdyllAST.appendNode(ast, newVarNode);
    this.context.setAst(updatedAST);
  }