MCPcopy Index your code
hub / github.com/thx/gogocode

github.com/thx/gogocode @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
547 symbols 1,722 edges 350 files 40 documented · 7% 32 cross-repo links updated 2y ago★ 6,08490 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Code transform has never been easier: GoGoCode

npm version license

GoGoCode 是什么?

English version of README

GoGoCode 是一个基于 AST 的 JavaScript/Typescript/HTML 代码转换工具,但相较于同类,它提供了更符合直觉的 API

  • 一套类 Jquery 的 API 用来查找和处理 AST
  • 一套和正则表达式接近的语法用来匹配和替换代码

GoGoCode.io 了解更多

简介

让我们通过一个简单的例子来看看上述查找和修改代码的 API 是如何使用的

需要转换的代码

const a = 1;
const b = 2;

通过 GoGoCode 来编写转换代码

const $ = require('gogocode');
const script = $(source);
// 按照你的意图,用 $_$ 当通配符能匹配任意位置的 AST 节点
const aAssignment = script.find('const a = $_$');
// 获得我们匹配的 AST 节点的 value
const aValue = aAssignment.match?.[0]?.[0]?.value;
// 就像替换字符串一样去替换代码
// 但可以忽略空格、缩进或者换行的影响
script.replace('const b = $_$', `const b = ${aValue}`);
// 把 ast 节点输出成字符串
const outCode = script.generate();

转换后代码

const a = 1;
const b = 1;

Playground 尝试一下上面的 Demo

相关项目

项目 描述
gogocode-plugin-vue 通过这个 gogocode 插件可以把 vue2 语法的项目转换成 vue3 的
gogocode-cli gogocode 的命令行工具
gogocode-playground 可以在浏览器里尝试 gogocode 转换
gogocode-vscode 在 vscode 中通过此插件用 gogocode 重构你的代码

支持

  • issues
  • 钉钉群:34266233
  • QQ群:735216094

开源协议

MIT

Extension points exported contracts — how you extend this code

GoGoAST (Interface)
(no doc) [1 implementers]
packages/gogocode-core/types/index.d.ts
GoGoOption (Interface)
(no doc)
packages/gogocode-core/types/index.d.ts
FindOption (Interface)
(no doc)
packages/gogocode-core/types/index.d.ts
NodePath (Interface)
(no doc)
packages/gogocode-core/types/index.d.ts
$ (Interface)
(no doc)
packages/gogocode-core/types/index.d.ts

Core symbols most depended-on inside this repo

find
called by 455
packages/gogocode-core/types/index.d.ts
generate
called by 343
packages/gogocode-core/types/index.d.ts
replace
called by 336
packages/gogocode-core/types/index.d.ts
each
called by 150
packages/gogocode-core/types/index.d.ts
match
called by 117
packages/gogocode-core/src/Ast.js
attr
called by 107
packages/gogocode-core/types/index.d.ts
root
called by 88
packages/gogocode-core/types/index.d.ts
has
called by 57
packages/gogocode-core/types/index.d.ts

Shape

Function 457
Method 71
Class 14
Interface 5

Languages

TypeScript100%

Modules by API surface

packages/gogocode-core/src/Ast.js45 symbols
packages/gogocode-core/types/index.d.ts30 symbols
packages/gogocode-core/src/js-core/core.js20 symbols
packages/esbuild-import-plugin/test/fixtures/variable-scope/expected.js14 symbols
packages/gogocode-cli/src/commands/transform.js13 symbols
packages/gogocode-plugin-element/utils/scriptUtils.js12 symbols
packages/esbuild-import-plugin/test/fixtures/variable-scope/actual.jsx11 symbols
packages/gogocode-plugin-vue/utils/scriptUtils.js10 symbols
packages/gogocode-core/src/html-core/core.js9 symbols
packages/transform-project/vue-hackernews-2.0/src/api/index.js8 symbols
packages/gogocode-vue-playground/packages/vue3/src/utils/gogocodeTransfer.js8 symbols
packages/gogocode-element-playground/packages/vue3/src/utils/gogocodeTransfer.js8 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

@babel/core7.7.2 · 1×
@babel/parser7.7.7 · 1×
@babel/plugin-transform-react-jsx7.7.0 · 1×
@babel/preset-env7.7.1 · 1×
@element-plus/icons0.0.11 · 1×
@rollup/plugin-commonjs21.0.2 · 1×
@rollup/plugin-json4.1.0 · 1×
@rollup/plugin-node-resolve13.1.3 · 1×
@types/lodash4.14.170 · 1×
@typescript-eslint/eslint-plugin4.14.1 · 1×
@typescript-eslint/parser4.14.1 · 1×
@vue/cli-plugin-babel4.0.0 · 1×

Datastores touched

BrandCollection · 1 repos

For agents

$ claude mcp add gogocode \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact