{"id":21492720,"url":"https://github.com/nerodesu017/babel-traverse-nero","last_synced_at":"2025-03-17T11:27:28.644Z","repository":{"id":148340193,"uuid":"414992470","full_name":"nerodesu017/babel-traverse-nero","owner":"nerodesu017","description":null,"archived":false,"fork":false,"pushed_at":"2021-10-08T13:32:17.000Z","size":42,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T21:17:26.820Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nerodesu017.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-08T13:13:24.000Z","updated_at":"2024-12-16T01:55:44.000Z","dependencies_parsed_at":"2023-04-10T21:47:17.615Z","dependency_job_id":null,"html_url":"https://github.com/nerodesu017/babel-traverse-nero","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nerodesu017%2Fbabel-traverse-nero","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nerodesu017%2Fbabel-traverse-nero/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nerodesu017%2Fbabel-traverse-nero/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nerodesu017%2Fbabel-traverse-nero/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nerodesu017","download_url":"https://codeload.github.com/nerodesu017/babel-traverse-nero/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244024077,"owners_count":20385372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-23T15:31:34.615Z","updated_at":"2025-03-17T11:27:28.619Z","avatar_url":"https://github.com/nerodesu017.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @babel/traverse\n\n\u003e The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes\n\n\u003e A single line of code patched by nerodesu017 to offer overall skip of certain nodes\n\n\nSee our website [@babel/traverse](https://babeljs.io/docs/en/babel-traverse) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93\u0026q=is%3Aissue+label%3A%22pkg%3A%20traverse%22+is%3Aopen) associated with this package.\n\n## Install\n\nUsing npm:\n\n```sh\nnpm install https://github.com/nerodesu017/babel-traverse-nero\n```\n\nor using yarn:\n\n```\nLMFAOOOOO SIKE YOU THOUGHT\n\njk i acc dunno how to make u download this on yarn\n\nuse git u freak\n```\n\n## How to use?\n\n### 1. Find the Node you want to skip (skip itself and, thus, inner Nodes)\n### 2. Set its \"nero_skip\" property to true\n### 3. That's it\n\n\u003cbr\u003e\u003cbr\u003e\n\n### **Transform.js**\n\n```js\nconst fs = require(\"fs\");\nconst t = require(\"@babel/types\");\nconst traverse = require(\"@babel/traverse\").default;\nconst parse = require(\"@babel/parser\").parse;\nconst generate = require(\"@babel/generator\").default;\n\nlet fileName = \"in\";\nlet file = fs.readFileSync(fileName + \".js\", {\"encoding\": \"utf-8\"})\n\nconst AST = parse(file);\n\nfunction genCode(node){\n  return generate(node, ...Array.from(arguments).slice(1)).code;\n}\n\n// The function we care about most\ntraverse(AST, {\n  FunctionDeclaration(path){\n    if(path.node.id.name === \"b\"){\n      path.node.nero_skip = true;\n    }\n  }\n})\n// The function we care about most\n\ntraverse(AST, {\n  Identifier(path){\n    // It will only change the first occurence in your case\n    if(path.node.name === \"a\"){\n      path.scope.rename(\"a\", \"renamed\");\n    }\n\n    // We won't get to our only \"b\" identifier occurence\n    if(path.node.name === \"b\"){\n      path.scope.rename(\"b\", \"thisWillNotBeRenamed\");\n    }\n  }\n})\n\nfs.writeFileSync(fileName + \"_out.js\", genCode(AST));\n```\n\n### **in.js**\n\n```js\nlet a = 3;\n\nfunction b() {\n  let a = 4;\n  function c() {\n    let a = 5;\n  }\n}\n```\n\n### **in_out.js**\n\n```js\nlet renamed = 3;\n\nfunction b() {\n  let a = 4;\n\n  function c() {\n    let a = 5;\n  }\n}\n```\n\n## Downsides\n\n### I'm not sure how you'd unset the nero_skip property\n### I guess you can only generate and parse again, good for my use case\n### Submit pull reqs and I'll try and review them\n\n### Oh, and don't forget, this also f*#ks up the scope renaming and all that","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnerodesu017%2Fbabel-traverse-nero","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnerodesu017%2Fbabel-traverse-nero","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnerodesu017%2Fbabel-traverse-nero/lists"}