Skip to content

thx/gogocode

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

fix: 指令生命周期中,卸载的钩子名称是"unmounted",不是“unMounted”。
026f75c

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
May 21, 2021 09:53
June 25, 2021 15:05
February 21, 2022 21:11
June 30, 2021 14:55
July 5, 2021 15:25
July 6, 2021 17:47
March 3, 2021 14:32
October 29, 2021 15:45
March 1, 2022 16:54
February 22, 2022 10:50
March 3, 2021 14:42
February 21, 2022 21:11

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:

  • A jQuery-like API to select and transform AST.
  • A Regex-like syntax to match and replace code.

Learn more at GoGoCode.io and GoGoCode: Yet Another Automated Refactor Tool for Web Developers

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;

Try this demo out at our Playground.

Related Project

Project Description
gogocode-plugin-vue transform a project from vue2 to vue3
gogocode-plugin-element transform a project from ElementUI to ElementPlus
gogocode-cli command-line tool for gogocode
gogocode-playground test gogocode at browser instantly
gogocode-vscode refactor your project with gogocode in vscode

Support

  • issues
  • Ding Group:34266233
  • QQ Group:735216094

License

MIT

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages