diff --git a/bun.lockb b/bun.lockb index c229411..fed73d6 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 1ee2c78..9400ff7 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/index.ts b/src/index.ts index 1611098..df3e3d4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); diff --git a/src/index_babel.ts b/src/index_babel.ts new file mode 100644 index 0000000..edcd88b --- /dev/null +++ b/src/index_babel.ts @@ -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 = 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();