lovelang
Version:
🖤 LoveLang: A romantic wrapper language over TypeScript/TSX
31 lines (30 loc) • 782 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.emit = emit;
function emit(nodes) {
let out = "";
for (const n of nodes) {
switch (n.type) {
case "VarDecl":
out += `let ${n.name} = ${emitExpr(n.expr)};\n`;
break;
case "PrintStmt":
out += `console.log(${emitExpr(n.expr)});\n`;
break;
// … handle other statements
}
}
return out;
}
function emitExpr(e) {
switch (e.type) {
case "StringLiteral":
return JSON.stringify(e.value);
case "NumberLiteral":
return e.value;
case "Identifier":
return e.value;
default:
return "";
}
}