How to use the idyll-ast.setProperty 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
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-compiler / src / processors / post.js View on Github external
let match;                           
  let hyperLinkIndex = 0;              
  let substringIndex = 0; 
  let newChildNodes = [];           
  while(hyperLinkIndex < hyperlinks.length) {
    let regexURL = new RegExp(hyperlinks[hyperLinkIndex], "g"); 
    match = regexURL.exec(textnode.substring(substringIndex));
    if(match) {
      let linkEndIndex = regexURL.lastIndex;
      let linkStartIndex = linkEndIndex - hyperlinks[hyperLinkIndex].length;
      let textNodeValue = textnode.substring(substringIndex, linkStartIndex); 
      if(textNodeValue !== "") {
        newChildNodes.push(createTextNode(textnode.substring(substringIndex, linkStartIndex)));
      }
      let anchorElement = createNode("a", [], [hyperlinks[hyperLinkIndex]]); 
      setProperty(anchorElement, "href", hyperlinks[hyperLinkIndex]);
      newChildNodes.push(anchorElement); 
      textnode = textnode.substring(linkEndIndex);
      substringIndex = 0;   
    }
    hyperLinkIndex++;
  }
  if(textnode != "") {
    newChildNodes.push(createTextNode(textnode)); 
  }
  return createNode("span", [], newChildNodes); 
}
github idyll-lang / idyll / packages / idyll-compiler / src / processors / post.js View on Github external
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']);
        }
      } else {
        child = removeProperty(child, 'fullWidth');
      }

      if (currentTextContainer.length) {
        acc = acc.concat([['TextContainer', [], currentTextContainer], child]);
      } else {
        acc = acc.concat([child]);
      }
      currentTextContainer = [];
    } else {
      currentTextContainer.push(child);
    }
    return acc;
  }, []);