{"id":13483284,"url":"https://github.com/thx/gogocode","last_synced_at":"2025-05-13T20:22:24.380Z","repository":{"id":37463004,"uuid":"344026346","full_name":"thx/gogocode","owner":"thx","description":"GoGoCode is a transformer for JavaScript/Typescript/HTML based on AST but providing a more intuitive API.","archived":false,"fork":false,"pushed_at":"2024-04-11T02:24:33.000Z","size":4104,"stargazers_count":5907,"open_issues_count":92,"forks_count":461,"subscribers_count":52,"default_branch":"main","last_synced_at":"2025-05-05T14:09:19.243Z","etag":null,"topics":["ast","babel","jscodeshift","recast","vue"],"latest_commit_sha":null,"homepage":"","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/thx.png","metadata":{"files":{"readme":"README-cn.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-03-03T06:32:37.000Z","updated_at":"2025-05-05T08:23:56.000Z","dependencies_parsed_at":"2022-07-08T01:35:20.192Z","dependency_job_id":"8742bb17-0792-4567-8856-ff2b42a55260","html_url":"https://github.com/thx/gogocode","commit_stats":{"total_commits":362,"total_committers":18,"mean_commits":20.11111111111111,"dds":0.781767955801105,"last_synced_commit":"026f75c9b5ad7448283a80976665428104a1eaa9"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thx%2Fgogocode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thx%2Fgogocode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thx%2Fgogocode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thx%2Fgogocode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thx","download_url":"https://codeload.github.com/thx/gogocode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253851073,"owners_count":21973674,"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":["ast","babel","jscodeshift","recast","vue"],"created_at":"2024-07-31T17:01:09.693Z","updated_at":"2025-05-13T20:22:24.339Z","avatar_url":"https://github.com/thx.png","language":"JavaScript","readme":"[![Code transform has never been easier: GoGoCode](https://img.alicdn.com/imgextra/i3/O1CN01mosd7H1tHiOY3uxB2_!!6000000005877-2-tps-1949-552.png)](https://gogocode.io)\n\n[![npm version](https://img.shields.io/npm/v/gogocode.svg)](https://www.npmjs.com/package/gogocode) [![license](https://img.shields.io/npm/l/gogocode.svg)](LICENSE)\n\n## GoGoCode 是什么？\n\n[English version of README](README.md)\n\nGoGoCode 是一个基于 AST 的 JavaScript/Typescript/HTML 代码转换工具，但相较于同类，它提供了更符合直觉的 API\n\n-   一套类 Jquery 的 API 用来查找和处理 AST\n-   一套和正则表达式接近的语法用来匹配和替换代码\n\n来 [GoGoCode.io](https://gogocode.io) 了解更多\n\n## 简介\n\n让我们通过一个简单的例子来看看上述查找和修改代码的 API 是如何使用的\n\n### 需要转换的代码\n\n```javascript\nconst a = 1;\nconst b = 2;\n```\n\n### 通过 GoGoCode 来编写转换代码\n\n```javascript\nconst $ = require('gogocode');\nconst script = $(source);\n// 按照你的意图，用 $_$ 当通配符能匹配任意位置的 AST 节点\nconst aAssignment = script.find('const a = $_$');\n// 获得我们匹配的 AST 节点的 value\nconst aValue = aAssignment.match?.[0]?.[0]?.value;\n// 就像替换字符串一样去替换代码\n// 但可以忽略空格、缩进或者换行的影响\nscript.replace('const b = $_$', `const b = ${aValue}`);\n// 把 ast 节点输出成字符串\nconst outCode = script.generate();\n```\n\n### 转换后代码\n\n```javascript\nconst a = 1;\nconst b = 1;\n```\n\n在 [Playground](https://play.gogocode.io/#code/N4IglgdgDgrgLgYQPYBMCmIBcIDGSIDOcABAIbEC8xAjADoR6EkBGlxATPSADQgDuSAE4BrZOiwgAZjAZww+YnEGlCkoQFsAFJLAAbNAEkIa7mShhTSKHPwEAlMWD1ixRkWIASNqXMA6AOZIgXjozq62JARIMII4aGw6+kZqvlExcfRhbpE4gmDWbB6aabFodmEA9BXEMATxHgD6XqQEZMR8eig4pIIoikjE6qRwOAAWxACCAMoAKsRo+upoECTDZBAAnsRQSARgNhDEG9HtKnBZEWQTBHv+EEsrbAS5+XC+OhAomgDk2W1UjQ833Kh2IVWI-jQJDgo3iQxGsL60zmCzQDxIADdSLoYGgLkwyAA1bG47zXW73ZZveFjAD8vgA2gAGAC69OZbN8WJxeNB4MEaCgulIcUmszIrQIpCWEuIAqFIvi5CIeQg-mIzHgxDAdyE8Rh8RC8TUgnhxGKUEVgEAGSDoR5CYi6SBoZgC0jCEEuZ55ay+eXCuI-P6sAFNb6mAAGwcKwFIxJ5AF8I56wdVIRA0Mo4Er3HABirIP4wgK4DFDt7XgFlpnhmhNCCE1xeJBYHAADIqfwSOAbKBoCvWHggUYtAAKJbkmawSlxvDw6ktAoA8vBW9PBLiE0A) 尝试一下上面的 Demo\n\n## 相关项目\n\n| 项目                  | 描述                                                       |\n| --------------------- | ---------------------------------------------------------- |\n| [gogocode-plugin-vue] | 通过这个 gogocode 插件可以把 vue2 语法的项目转换成 vue3 的 |\n| [gogocode-cli]        | gogocode 的命令行工具                                      |\n| [gogocode-playground] | 可以在浏览器里尝试 gogocode 转换                           |\n| [gogocode-vscode]     | 在 vscode 中通过此插件用 gogocode 重构你的代码             |\n\n[gogocode-plugin-vue]: https://github.com/thx/gogocode/tree/main/packages/gogocode-plugin-vue\n[gogocode-cli]: https://github.com/thx/gogocode/tree/main/packages/gogocode-cli\n[gogocode-playground]: https://play.gogocode.io\n[gogocode-vscode]: https://marketplace.visualstudio.com/items?itemName=mmfe.vscode-gogocode\n\n## 支持\n\n-   [issues](https://github.com/thx/gogocode/issues)\n-   钉钉群：34266233\n-   QQ群：735216094\n\n## 开源协议\n\n[MIT](LICENSE)\n","funding_links":[],"categories":["JavaScript","Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthx%2Fgogocode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthx%2Fgogocode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthx%2Fgogocode/lists"}