silphius/app/swcx/evaluators/member.js
2024-06-17 05:20:01 -05:00

17 lines
511 B
JavaScript

import {
isComputed,
} from '@/swcx/types.js';
export default function({object, property, wrapper}, {evaluate, scope}) {
const member = (O, P) => (wrapper?.optional ? O?.[P] : O[P]);
const O = evaluate(object, {scope});
const P = isComputed(property) ? evaluate(property, {scope}) : {value: property.value};
if (O.async || P.async) {
return {
async: true,
value: Promise.all([O.value, P.value]).then(([O, P]) => member(O, P)),
};
}
return {value: member(O.value, P.value)};
}