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

closest's second argument doesn't appear to work #41

Closed
aaronjensen opened this issue Aug 18, 2015 · 3 comments
Closed

closest's second argument doesn't appear to work #41

aaronjensen opened this issue Aug 18, 2015 · 3 comments
Labels

Comments

@aaronjensen
Copy link

Here's an example: http://felix-kling.de/esprima_ast_explorer/#/WhIlcdMzwh/1

function foo() {
  function bar() {
    return 3;
  }
}
module.exports = function(file, api) {
  var j = api.jscodeshift;

  return j(file.source)
    .find(j.Literal)
    .forEach(function(path) { console.log(path.value) })
    .closest(j.FunctionDeclaration, { id: { name: "foo" } })
    .forEach(function(path) { 
      console.log(path.value);
      path.value.id.name = 'renamed'; })
    .toSource();
};

I'd expect this to work like find does, using the 2nd parameter as a filter. Unfortunately, adding the 2nd parameter causes it to find the ReturnStatement instead of the top level Foo function

@fkling fkling added the bug label Aug 18, 2015
@fkling fkling closed this as completed in a1be267 Aug 20, 2015
@aaronjensen
Copy link
Author

Nice, thanks!

@fkling
Copy link
Contributor

fkling commented Aug 20, 2015

I'm trying to tackle another bug first before I release a new version. I will definitely make a new release tomorrow though.

@fkling
Copy link
Contributor

fkling commented Aug 21, 2015

Just released v0.3.6 with the fix.

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

No branches or pull requests

2 participants