Closed
Description
export function interpret(expr: ast.Expression): number {
switch (expr.kind) {
case "BinaryExpression":
const { left, right } = expr;
return interpret(left) + interpret(right);
}
}
Extract the entire function body out into its own function.
Expected:
export function interpret(expr): number {
return newFunction(expr);
}
function newFunction(expr: any) {
switch (expr.kind) {
case "BinaryExpression":
const { left, right } = expr;
return interpret(left) + interpret(right);
}
}
Actual:
export function interpret(expr): number {
return newFunction();
function newFunction() {
switch(expr.kind) {
case "BinaryExpression":
const { left, right } = expr;
return interpret(left) + interpret(right);
}
}
}