MCPcopy Create free account
hub / github.com/adobe/react-spectrum / evaluateNode

Function evaluateNode

packages/dev/s2-docs/scripts/generateMarkdownDocs.mjs:1107–1164  ·  view source on GitHub ↗
(node, file)

Source from the content-addressed store, hash-verified

1105}
1106
1107function evaluateNode(node, file) {
1108 if (!node) {
1109 return null;
1110 }
1111
1112 switch (node.type) {
1113 case 'StringLiteral':
1114 return node.value;
1115
1116 case 'NumericLiteral':
1117 return node.value;
1118
1119 case 'BooleanLiteral':
1120 return node.value;
1121
1122 case 'NullLiteral':
1123 return null;
1124
1125 case 'ArrayExpression':
1126 return node.elements.map(el => evaluateNode(el, file)).filter(v => v !== null);
1127
1128 case 'ObjectExpression': {
1129 const obj = {};
1130 for (const prop of node.properties) {
1131 if (prop.type === 'ObjectProperty') {
1132 const key = prop.key.type === 'Identifier' ? prop.key.name : evaluateNode(prop.key, file);
1133 obj[key] = evaluateNode(prop.value, file);
1134 }
1135 }
1136 return obj;
1137 }
1138
1139 case 'Identifier':
1140 // For identifiers, return the name as a string
1141 return node.name;
1142
1143 case 'JSXElement':
1144 case 'JSXFragment': {
1145 // For JSX elements, extract text content
1146 return extractJSXText(node, file);
1147 }
1148
1149 case 'JSXText':
1150 return node.value;
1151
1152 case 'MemberExpression': {
1153 // Handle member expressions like docs.exports.GregorianCalendar.description
1154 const object = evaluateNode(node.object, file);
1155 const property = node.computed
1156 ? evaluateNode(node.property, file)
1157 : node.property.name || node.property.value;
1158 return `${object}.${property}`;
1159 }
1160
1161 default:
1162 return null;
1163 }
1164}

Callers 2

parseExpressionFunction · 0.85
extractJSXTextFunction · 0.85

Calls 2

extractJSXTextFunction · 0.85
filterMethod · 0.65

Tested by

no test coverage detected