From df70da0c04511526f931181a6853240dedbd4348 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Fri, 26 Sep 2025 00:53:26 -0700 Subject: [PATCH] Refactor: Convert transpiler to an ES Module --- transpiler.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 transpiler.js diff --git a/transpiler.js b/transpiler.js new file mode 100644 index 0000000..12f17b2 --- /dev/null +++ b/transpiler.js @@ -0,0 +1,17 @@ +/** + * Transpiles a string of Hi source code into JavaScript. + * @param {string} sourceCode The Hi source code. + * @returns {string} The equivalent JavaScript code. + */ +export function hi2js(sourceCode) { + // This will be replaced by a proper AST-based generator. + return sourceCode + // Comments: // ... + .replace(/^\s*\/\/.*/gm, (match) => match) + // Declaration: name: value -> let name = value; + .replace(/^(?!.*\/\/.*)([\w$]+)\s*:\s*(.*)/gm, 'let $1 = $2;') + // Assignment: name = value -> name = value; + .replace(/^(?!.*\/\/.*)([\w$]+)\s*=\s*([^:;].*)/gm, '$1 = $2;') + // Global output: _(...) -> console.log(...); + .replace(/^(?!.*\/\/.*)\s*_\((.*)\)/gm, 'console.log($1);'); +}