jscodeshift-debug
v1.1.1
Published
Debug utilities for jscodeshift
Downloads
18
Maintainers
Readme
jscodeshift-debug
Debug utilities for jscodeshift
Usage:
Install
yarn add --dev jscodeshift-debug
And use
import debug from 'jscodeshift-debug
debug(node) // or debug(nodepath)
Example
// someFileToTransform.js
import sinon from 'sinon-sandbox'
sinon.stub(I18n, 'extend');
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');