{"id":13837698,"url":"https://github.com/rajasegar/ast-node-builder","last_synced_at":"2025-07-10T19:30:22.433Z","repository":{"id":36242309,"uuid":"222682504","full_name":"rajasegar/ast-node-builder","owner":"rajasegar","description":"AST Node building api for jscodeshift","archived":true,"fork":false,"pushed_at":"2022-05-17T09:16:07.000Z","size":715,"stargazers_count":14,"open_issues_count":12,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-14T22:44:11.103Z","etag":null,"topics":["abstract-syntax-tree","ast","codemod","codemods","jscodeshiift"],"latest_commit_sha":null,"homepage":"https://rajasegar.github.io/ast-builder/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rajasegar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-19T11:40:52.000Z","updated_at":"2023-01-28T00:44:37.000Z","dependencies_parsed_at":"2022-08-08T13:46:55.440Z","dependency_job_id":null,"html_url":"https://github.com/rajasegar/ast-node-builder","commit_stats":null,"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"purl":"pkg:github/rajasegar/ast-node-builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fast-node-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fast-node-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fast-node-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fast-node-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rajasegar","download_url":"https://codeload.github.com/rajasegar/ast-node-builder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fast-node-builder/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264639832,"owners_count":23642313,"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":["abstract-syntax-tree","ast","codemod","codemods","jscodeshiift"],"created_at":"2024-08-04T15:01:21.000Z","updated_at":"2025-07-10T19:30:21.964Z","avatar_url":"https://github.com/rajasegar.png","language":"JavaScript","readme":"# ast-node-builder\n\nWARNING: This package is moved here\nhttps://github.com/rajasegar/ast-tooling/tree/master/packages/ast-node-builder\n\nCheckout the api in this [Playground](https://rajasegar.github.io/ast-builder/)\n\nRead the [introductory blog post](https://dev.to/rajasegar/building-ast-nodes-from-source-code-3p49) to know more about the tool.\n\nBuild your Abstract Syntax Trees (AST) directly from code. \nYou give the input in the form of code and get the builder API in [jscodeshift](https://github.com/facebook/jscodeshift).\n\n## Usage\n```js\nconst { buildAST } = require('ast-node-builder');\nconst { parse }  = require('recast');\nconst code = `\nclass MyComponent extends ReactComponent {\n  constructor(a, b) {\n    this.a = a;\n    this.b = b;\n  }\n\n  hello(x, y) {\n    console.log(x, y);\n  }\n}\n`;\n\nlet ast = parse(code);\n\nlet pseudoAst =  buildAST(ast);\nconsole.log(pseudoAst);\n```\n\n### Output\n```js\nj.classDeclaration(\n  j.identifier('MyComponent'),\n  j.classBody([j.methodDefinition(\n    'constructor',\n    j.identifier('constructor'),\n    j.functionExpression(\n      null,\n      [j.identifier('a'),j.identifier('b')],\n      j.blockStatement([j.expressionStatement(j.assignmentExpression(\n        '=',\n        j.memberExpression(\n          j.thisExpression(),\n          j.identifier('a'),\n          false\n        ),\n        j.identifier('a')\n      )),j.expressionStatement(j.assignmentExpression(\n        '=',\n        j.memberExpression(\n          j.thisExpression(),\n          j.identifier('b'),\n          false\n        ),\n        j.identifier('b')\n      ))])\n    ),\n    false\n  ),j.methodDefinition(\n    'method',\n    j.identifier('hello'),\n    j.functionExpression(\n      null,\n      [j.identifier('x'),j.identifier('y')],\n      j.blockStatement([j.expressionStatement(j.callExpression(\n        j.memberExpression(\n          j.identifier('console'),\n          j.identifier('log'),\n          false\n        ),\n        [j.identifier('x'),j.identifier('y')]\n      ))])\n    ),\n    false\n  )]),\n  j.identifier('ReactComponent')\n)\n\n```\n\n## Debugging\nPlace `debugger` statements in the code in appropriate places and run:\n\n```\n$ npm run debug\n```\n\nThis will start mocha tests in debug mode and you can use Chrome Dev Tools to view the debugger.\n\n\n\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajasegar%2Fast-node-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frajasegar%2Fast-node-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajasegar%2Fast-node-builder/lists"}