How to use the idyll-ast.getProperty 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[]
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");

// $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-studio / src / components / idyll-document / src / runtime.js View on Github external
addBlock(ast){
    console.log('addBlock',ast,'to',this.ast );
    if(ast === undefined) return;
    console.log('ast[0]',ast[0])
    const id = IdyllAST.getProperty(ast[0], 'id');
    const key = id[1];
    console.log('key',key);

    const modifyNodeByKey = function(ast, key, newNode) {
      var found = false;
      var handleNode = (node) => {
        if (typeof node === 'string') {
          return node;
        }
        var id = IdyllAST.getProperty(node, 'id');
        if(id === undefined) {
          return node;
        }
        var compare = id[1] === key
        // console.log('id[1]',id[1],'key',key,compare)
        if( compare ) {
github idyll-lang / idyll-studio / src / components / idyll-document / src / runtime.js View on Github external
var handleNode = (node) => {
        if (typeof node === 'string') {
          return node;
        }
        var id = IdyllAST.getProperty(node, 'id');
        if(id === undefined) {
          return node;
        }
        var compare = id[1] === key
        // console.log('id[1]',id[1],'key',key,compare)
        if( compare ) {
          console.log('mod block')
          found = true;
          return newNode;
          
        }
    
        node = IdyllAST.modifyChildren(node, handleNode);
        return node;
      }
github idyll-lang / idyll / packages / idyll-compiler / src / processors / post.js View on Github external
const reduced = (ast || []).reduce((acc, child) => {
    if (typeof child === 'string') {
      currentTextContainer.push(child);
      return acc;
    }
    const attrs = attrConvert(child[1] || []);
    const childName = child[0].toLowerCase();
    if (['derived', 'var', 'data', 'fullwidth', 'scroller'].indexOf(childName) > -1 || attrs.fullWidth) {
      if (childName === 'fullwidth') {
        child[0] = 'div';
        const className = getProperty(child, 'className');
        if (className) {
          switch (className[0]) {
            case 'value':
              child = setProperty(child, 'className', ['value', 'fullWidth ' + className[1]]);
              break;
            case 'expression':
              child = setProperty(child, 'className', ['expression', `"fullWidth " + (${className[1]})`]);
              break;
            case 'variable':
              child = setProperty(child, 'className', ['expression', `"fullWidth " + (${className[1]})`]);
              break;
            default:
              child = setProperty(child, 'className', ['value', 'fullWidth']);
          }
        } else {
          child = setProperty(child, 'className', ['value', 'fullWidth']);
github idyll-lang / idyll / packages / idyll-cli / src / pipeline / parse.js View on Github external
return nodes.map(node => {
    return {
      node,
      name: getProperty(node, 'name'),
      source: getProperty(node, 'source')
    };
  });
};
github idyll-lang / idyll / packages / idyll-cli / src / pipeline / parse.js View on Github external
return nodes.map(node => {
    return {
      node,
      name: getProperty(node, 'name'),
      source: getProperty(node, 'source')
    };
  });
};
github idyll-lang / idyll / packages / idyll-cli / src / pipeline / parse.js View on Github external
getPropertyKeys(metaNodes[0]).forEach(key => {
      metaProperties[key] = getProperty(metaNodes[0], key).value;
    });
  }