在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:thx/gogocode开源软件地址:https://github.com/thx/gogocode开源编程语言:JavaScript 75.9%开源软件介绍:What is GoGoCode?GoGoCode is a transformer for JavaScript/Typescript/HTML based on AST but providing an intuitive API:
Learn more at GoGoCode.io and GoGoCode: Yet Another Automated Refactor Tool for Web Developers IntroLet's show you how to select and modify code with our API Inconst a = 1;
const b = 2; Transform With GoGoCodeconst $ = 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(); Outconst a = 1;
const b = 1; Try this demo out at our Playground. Related Project
Support
License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论