Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const parseMeta = ast => {
// there should only be one meta node
const metaNodes = getNodesByType(ast, 'meta');
let metaProperties = {};
if (metaNodes.length > 1) {
console.warn('There are more than 1 meta nodes');
} else if (metaNodes.length === 1) {
getPropertyKeys(metaNodes[0]).forEach(key => {
metaProperties[key] = getProperty(metaNodes[0], key).value;
});
}
return metaProperties;
};
componentDidMount() {
// Grab meta node
let node = idyllAST.getNodesByType(this.context.ast, 'meta')[0];
this.setState(
{
metaNode: node
},
() => {
if (!this.state.metaNode) {
// if doesn't exist insert into tree
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();
getAllVariables() {
return AST.getNodesByType(this.context.ast, 'var').map(variable => {
const props = variable.properties;
const name = props.name.value;
const value = props.value.value;
return (
<div>
<li>
{name}, whose current value is {value}
</li>
</div>
);
});
}
exports.getDataNodes = ast => {
const nodes = getNodesByType(ast, 'data');
return nodes.map(node => {
return {
node,
name: getProperty(node, 'name'),
source: getProperty(node, 'source')
};
});
};