https://github.com/catc/jscodeshift-debug
Debug utilities for jscodeshift
https://github.com/catc/jscodeshift-debug
Last synced: 12 months ago
JSON representation
Debug utilities for jscodeshift
- Host: GitHub
- URL: https://github.com/catc/jscodeshift-debug
- Owner: catc
- License: mit
- Created: 2022-02-24T18:20:40.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-31T22:10:39.000Z (about 4 years ago)
- Last Synced: 2025-05-31T20:54:10.108Z (about 1 year ago)
- Language: TypeScript
- Size: 94.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## jscodeshift-debug
Debug utilities for jscodeshift
#### Usage:
Install
```sh
yarn add --dev jscodeshift-debug
```
And use
```ts
import debug from 'jscodeshift-debug
debug(node) // or debug(nodepath)
```
#### Example
```js
// someFileToTransform.js
import sinon from 'sinon-sandbox'
sinon.stub(I18n, 'extend');
```
```ts
import core, { API, FileInfo } from 'jscodeshift'
// basic jscodeshift transformer
export default function transformer(fileInfo: FileInfo, api: API, options) {
const j = api.jscodeshift
const ast = j(fileInfo.source)
ast
.find(j.CallExpression, {
callee: {
type: 'MemberExpression',
property: {
type: 'Identifier',
name: 'stub',
},
object: {
type: 'Identifier',
name: 'sinon',
},
},
})
.forEach((nodepath) => {
// usage:
debug(np)
})
}
```
Will log:
```
Node tree is:
{
"type": "CallExpression",
"callee": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "sinon"
},
"property": {
"type": "Identifier",
"name": "stub"
}
},
"arguments": [
{
"type": "Identifier",
"name": "I18n"
},
{
"type": "Literal",
"value": "extend"
}
]
}
Node to source:
sinon.stub(I18n, 'extend');
```