moved to babel

This commit is contained in:
Rolf Martin Glomsrud 2023-10-09 18:26:31 +02:00
parent 0e7a019308
commit ac163abd9d
4 changed files with 54 additions and 2 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -10,6 +10,10 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@babel/generator": "^7.23.0",
"@babel/parser": "^7.23.0",
"@babel/traverse": "^7.23.0",
"babel": "^6.23.0",
"ts-node": "^10.9.1"
}
}

View file

@ -45,7 +45,8 @@ const main = async () => {
const matchStatements = async (module: swc.Script) => {
let fromLocal = from;
let toLocal = to;
let key: "body" = "body";
module[key]
return match(fromLocal, toLocal, module.body);
};
@ -63,7 +64,7 @@ const match = (from: any, to: any, module: swc.Statement[]): any => {
for (const [key, value] of Object.entries(module)){
if (from[key] && key != "span"){
console.log(from[key] + " == " + value);
if (from[key] == value){
if (from[key as any] == value){
console.log("Found valid key with " + key);
let matchRes = match(from[key], to, value);

47
src/index_babel.ts Normal file
View file

@ -0,0 +1,47 @@
import * as babelparser from "@babel/parser";
import traverse from "@babel/traverse";
import generate from "@babel/generator";
const main = () => {
let code_To_Insert = "697 + 457";
let code = "let n = 1 - 1;";
let ast:babelparser.ParseResult<File> = babelparser.parse(code);
console.log(ast);
let insert_ast = babelparser.parse(code);
traverse(ast, {
enter(path:any) {
if (path.isBinaryExpression({operator: "+"})){
}
}
})
traverse(ast, {
enter(path:any){
if (path.isBinaryExpression({operator: "+"})){
path.node.operator="@@@";
}
},
})
console.log(ast)
const output = generate(ast, {}, code);
console.log("input: " + code);
console.log("output: " + output.code);
//let inout = babelparser.parse(output.code);
//console.log(inout);
let awaitex = babelparser.parse("async function a(){let b = await c();}async function c(){return 1; }");
console.log(JSON.stringify(awaitex));
traverse(awaitex, {
})
}
main();