Fennec/lib/transcompiler.js
2026-03-15 18:36:05 +01:00

83 lines
2.0 KiB
JavaScript

const fs = require("node:fs")
const path = require("node:path")
const acorn = require("acorn")
const source_file = fs.readFileSync(path.join(process.cwd(), "source", "main.js"))
const parsedCode = acorn.parse(source_file)
for (const node of parsedCode.body) {
for (const index in node.declarations) {
const declaration = node.declarations[index]
visitNode(declaration)
}
}
function visitNode(node) {
switch (node.type) {
case "VariableDeclarator":
tranlateVariable(node)
break;
case "CallExpression":
break;
case "Literal":
break;
case "Identifier":
break;
case "ArrowFunctionExpression":
break;
case "FunctionExpression":
break;
case "BinaryExpression":
break;
case "Program":
break;
case "ExpressionStatement":
break;
case "BlockStatement":
break;
default:
console.error("Unsupported declaration type (too complex): " + node.type)
break
}
}
function tranlateVariable(node) {
if (node.init.arguments && node.init.arguments[0] && node.init.arguments[0].value.includes("fennec")) {
return
}
if (!node.init) {
return
}
switch (node.init.type) {
case "NewExpression":
translateNewExpression(node)
break
default:
console.error("Unsupported declaration type (too complex): " + node.type)
break
}
}
function translateNewExpression(nodeInitializer) {
if (nodeInitializer.init.callee) {
switch (nodeInitializer.init.callee.name) {
case "Fennec":
break;
default:
console.error("Unsupported declaration type (too complex): " + node.type)
break;
}
}
}