Home

Awesome

Code transform has never been easier: GoGoCode

npm version license

详细文档点击这里

What is GoGoCode?

中文 README

GoGoCode is a transformer for JavaScript/Typescript/HTML based on AST but providing an intuitive API:

Learn more at GoGoCode Document

Intro

Let's show you how to select and modify code with our API

In

const a = 1;
const b = 2;

Transform With GoGoCode

const $ = require('gogocode');
const script = $(source);
// use $_$ as a wildcard to match AST element at any position you want
const aAssignment = script.find('const a = $_$');
// get matched AST element value
const aValue = aAssignment.match?.[0]?.[0]?.value;
// replace AST as same as replace a string
// but ignore code format (space、indent or linebreak)
script.replace('const b = $_$', `const b = ${aValue}`);
// generate ast to string
const outCode = script.generate();

Out

const a = 1;
const b = 1;

Related Project

ProjectDescription
gogocode-plugin-vuetransform a project from vue2 to vue3
gogocode-plugin-elementtransform a project from ElementUI to ElementPlus
gogocode-clicommand-line tool for gogocode
gogocode-playgroundtest gogocode at browser instantly
gogocode-vscoderefactor your project with gogocode in vscode

Support

License

MIT