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 {
|
export function Evaluate(node: Node): CompletionRecord {
|
||||||
if (isProgram(node)) {
|
if (isProgram(node)) {
|
||||||
|
// Handle root program node
|
||||||
const completions = node.body.map(tmp => Evaluate(tmp));
|
const completions = node.body.map(tmp => Evaluate(tmp));
|
||||||
return completions[completions.length - 1];
|
return completions[completions.length - 1];
|
||||||
} else if (isExpressionStatement(node)) {
|
} else if (isExpressionStatement(node)) {
|
||||||
|
// Handle ExpressionStatement
|
||||||
return Evaluate(node.expression);
|
return Evaluate(node.expression);
|
||||||
} else if (isNumericLiteral(node)) {
|
} else if (isNumericLiteral(node)) {
|
||||||
|
// Handle NumberLiteral
|
||||||
return NormalCompletion(new NumberValue(node.value));
|
return NormalCompletion(new NumberValue(node.value));
|
||||||
} else if (isStringLiteral(node)) {
|
} else if (isStringLiteral(node)) {
|
||||||
|
// Handle StringLiteral
|
||||||
return NormalCompletion(new StringValue(node.value));
|
return NormalCompletion(new StringValue(node.value));
|
||||||
} else {
|
} else {
|
||||||
|
// If not handled, throw error
|
||||||
throwUnknownNode(node);
|
throwUnknownNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user