Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renameTo doesn't rename annotations in type parameters #199

Closed
steveluscher opened this issue May 26, 2017 · 2 comments
Closed

renameTo doesn't rename annotations in type parameters #199

steveluscher opened this issue May 26, 2017 · 2 comments

Comments

@steveluscher
Copy link

I expected this to rename the type annotation in the type parameter, but it didn't.

/**
 * const A = require('ModuleA');
 * 
 * class Foo<A> {
 *  render(foo: A): A {
 *    return A;
 *   }
 * }
 */
export default function transformer(file, api) {
  const j = api.jscodeshift;
  return j(file.source)
    .find(j.VariableDeclarator, {id: {name: 'A'}})
    .forEach(path => { j(path).renameTo('B'); })
    .toSource();
}

Repro: http://astexplorer.net/#/gist/02d7f52e10dd9c7d803f433635931369/abc53a869b55bc61aa1ded6062d166d655b7c2cc

@steveluscher
Copy link
Author

steveluscher commented May 26, 2017

This is because a TypeParameter is not an Identifier. #goodfirstbug

.find(types.Identifier, {name: oldName})

@bgw
Copy link

bgw commented Mar 7, 2018

In case anyone runs into this, it's actually because TypeParameter wasn't being traversed. It does have an Identifier child. It's fixed by benjamn/ast-types#253, so #239 (a version bump) should fix this in jscodeshift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants