mirror of
https://github.com/bendtherules/not-a-js-engine.git
synced 2026-08-18 13:52:36 +00:00
evaluate.ts - Add comments for handlers
This commit is contained in:
@@ -18,15 +18,20 @@ import { throwUnknownNode } from './throwUnknownNode';
|
||||
|
||||
export function Evaluate(node: Node): CompletionRecord {
|
||||
if (isProgram(node)) {
|
||||
// Handle root program node
|
||||
const completions = node.body.map(tmp => Evaluate(tmp));
|
||||
return completions[completions.length - 1];
|
||||
} else if (isExpressionStatement(node)) {
|
||||
// Handle ExpressionStatement
|
||||
return Evaluate(node.expression);
|
||||
} else if (isNumericLiteral(node)) {
|
||||
// Handle NumberLiteral
|
||||
return NormalCompletion(new NumberValue(node.value));
|
||||
} else if (isStringLiteral(node)) {
|
||||
// Handle StringLiteral
|
||||
return NormalCompletion(new StringValue(node.value));
|
||||
} else {
|
||||
// If not handled, throw error
|
||||
throwUnknownNode(node);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user