From f0b7b1ba98921c352987fe9e85db2da6d64c56fa Mon Sep 17 00:00:00 2001 From: polsevev Date: Wed, 11 Oct 2023 16:28:24 +0200 Subject: [PATCH] LESSGOOOO Finally i added some stupid custom syntax :) --- .vscode/launch.json | 53 +++++++++++++++++++++++++++++++++++++++++++ .vscode/settings.json | 10 ++++++++ src/index.js | 49 ++++++++++++++++++--------------------- 3 files changed, 85 insertions(+), 27 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..478c336 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,53 @@ +{ + "version": "0.2.0", + "configurations": [ + + { + "type": "bun", + "request": "launch", + "name": "Debug Bun", + + // The path to a JavaScript or TypeScript file to run. + "program": "src/index.js", + + // The arguments to pass to the program, if any. + "args": [], + + // The working directory of the program. + "cwd": "${workspaceFolder}", + + // The environment variables to pass to the program. + "env": {}, + + // If the environment variables should not be inherited from the parent process. + "strictEnv": false, + + // If the program should be run in watch mode. + // This is equivalent to passing `--watch` to the `bun` executable. + // You can also set this to "hot" to enable hot reloading using `--hot`. + "watchMode": false, + + // If the debugger should stop on the first line of the program. + "stopOnEntry": false, + + // If the debugger should be disabled. (for example, breakpoints will not be hit) + "noDebug": false, + + // The path to the `bun` executable, defaults to your `PATH` environment variable. + "runtime": "bun", + + // The arguments to pass to the `bun` executable, if any. + // Unlike `args`, these are passed to the executable itself, not the program. + "runtimeArgs": [], + }, + { + "type": "bun", + "request": "attach", + "name": "Attach to Bun", + + // The URL of the WebSocket inspector to attach to. + // This value can be retrieved by using `bun --inspect`. + "url": "ws://localhost:6499/", + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b396049 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + // The path to the `bun` executable. + "bun.runtime": "/home/rolfmg/.bun/bin/bun", + + // If support for Bun should be added to the default "JavaScript Debug Terminal". + "bun.debugTerminal.enabled": true, + + // If the debugger should stop on the first line of the program. + "bun.debugTerminal.stopOnEntry": true, +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 0dd5177..3cbe795 100644 --- a/src/index.js +++ b/src/index.js @@ -1,35 +1,30 @@ import * as babelparser from "../babel/packages/babel-parser/lib"; -import traverse from "@babel/traverse"; -import generate from "@babel/generator"; +import traverse from "../babel/packages/babel-traverse/lib"; +import generate from "../babel/packages/babel-generator/lib"; const main = () => { - - let code_To_Insert = "697 + 457"; + let code_To_Insert = "697 + 457"; - let code = "1 + 1;"; - let ast = babelparser.parse(code); - console.log(ast); - let insert_ast = babelparser.parse(code); + let code = "1 + 1;"; + let ast = babelparser.parse(code); + console.log(ast); + let insert_ast = babelparser.parse(code); + traverse(ast, { + enter(path) { + if (path.isBinaryExpression({ operator: "+" })) { + path.node.operator = "@@@"; + } + }, + }); - traverse(ast, { - enter(path){ - if (path.isBinaryExpression({operator: "+"})){ - path.node.operator="@@@"; - } - }, - }) - - console.log(JSON.stringify(ast, null, 4)); - const out = generate(ast, {}, code); - console.log("input: " + code); - console.log("output: " + out.code); - let inout = babelparser.parse(out.code); - console.log(inout); - console.log(generate(inout, {}, code)); - - -} - + console.log(JSON.stringify(ast, null, 4)); + const out = generate(ast, {}, code); + console.log("input: " + code); + console.log("output: " + out.code); + let inout = babelparser.parse(out.code); + console.log(inout); + console.log(generate(inout, {}, code)); +}; main();