function getPromiseValue(cell) {
const value = getProperty(cell, "value").value;
const inputs = getInputs(cell).map(name => ({type: "Identifier", name}));
return {
type: "CallExpression",
callee: {
type: "MemberExpression",
object: inputs.length === 0
? {
type: "CallExpression",
callee: {
type: "MemberExpression",
object: {
type: "Identifier",
name: "Promise"
},
property: {
type: "Identifier",
name: "resolve"
}
},
arguments: []
}
: inputs.length === 1 ? inputs[0]
: {
type: "CallExpression",
callee: {
type: "MemberExpression",
object: {
type: "Identifier",
name: "Promise"
},
property: {
type: "Identifier",
name: "all"
}
},
arguments: [
{
type: "ArrayExpression",
elements: inputs
}
]
},
property: {
type: "Identifier",
name: "then"
}
},
arguments: [
{
...value,
params: inputs.length > 1
? [{type: "ArrayPattern", elements: value.params}]
: value.params
}
]
};
}