First commit
This commit is contained in:
83
lib/transcompiler.js
Normal file
83
lib/transcompiler.js
Normal file
@@ -0,0 +1,83 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user