17 lines
522 B
JavaScript
17 lines
522 B
JavaScript
export default function(node, {evaluate, scope}) {
|
|
const {computed, object, optional, property} = node;
|
|
const member = (O, P) => (optional ? O?.[P] : O[P]);
|
|
const O = evaluate(object, {scope});
|
|
const P = computed
|
|
? evaluate(property, {scope})
|
|
// Otherwise, identifier
|
|
: {value: property.name};
|
|
if (O.async || P.async) {
|
|
return {
|
|
async: true,
|
|
value: Promise.all([O.value, P.value]).then(([O, P]) => member(O, P)),
|
|
};
|
|
}
|
|
return {async: false, value: member(O.value, P.value)};
|
|
}
|