jscodeshift
jscodeshift copied to clipboard
.find doesn't traverse "typeParameters" in TypeScript
Description
jscodeshift(file.source).find
doesn't find anything in a generic.
Example
~~Code sandbox: https://codesandbox.io/s/unruffled-goodall-b5qkn~~
Edit: ASTExplorer: https://astexplorer.net/#/gist/191f77988f260ee6bef6ec402331ac0e/808e05a888e206dacc16f8dac85609a7ac09eeab
Input
const [state, setState] = React.useState<Enum.A | Enum.B | null>(null);
Traverse
root.find("TSQualifiedName")
// []
And it should match 2 things : Enum.A
and Enum.B
AST
{
"type": "Program",
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "ArrayPattern",
"elements": [
{
"type": "Identifier",
"name": "state"
},
{
"type": "Identifier",
"name": "setState"
}
]
},
"init": {
"type": "CallExpression",
"callee": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "React"
},
"computed": false,
"property": {
"type": "Identifier",
"name": "useState"
}
},
"arguments": [
{
"type": "NullLiteral"
}
],
"typeParameters": {
"type": "TSTypeParameterInstantiation",
"params": [
{
"type": "TSUnionType",
"types": [
{
"type": "TSTypeReference",
"typeName": {
"type": "TSQualifiedName",
"left": {
"type": "Identifier",
"name": "Enum"
},
"right": {
"type": "Identifier",
"name": "A"
}
}
},
{
"type": "TSTypeReference",
"typeName": {
"type": "TSQualifiedName",
"left": {
"type": "Identifier",
"name": "Enum"
},
"right": {
"type": "Identifier",
"name": "B"
}
}
},
{
"type": "TSNullKeyword"
}
]
}
]
}
}
}
],
"kind": "const"
}
],
"directives": []
}
Versions
- jscodeshift: 0.11.0
- recast: 0.20.3
- ast-types: 0.14.1
- esprima: 4.0.1
- tslib: 2.0.1