macro nullthrows(sourceCodeSnippet) {
return code`
const result = ${sourceCodeSnippet};
if (result === null || result === undefined) {
return result
} else {
throw new Error("Uh oh, this returned null:" + "${sourceCodeSnippet}");
`;
}
The first and the second occurrences of ${sourceCodeSnippet} look the same so I suppose it will just be evaluated twice. You don't want to evaluate the second occurrence, right? The lisp version doesn't have this problem.