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

Function evaluateNode

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

Source from the content-addressed store, hash-verified

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

Callers 2

parseExpressionFunction · 0.85
extractJSXTextFunction · 0.85

Calls 2

extractJSXTextFunction · 0.85
filterMethod · 0.65

Tested by

no test coverage detected