Code Monkey home page Code Monkey logo

Comments (6)

benjamn avatar benjamn commented on May 14, 2024

Yeah, this story is pretty broken. I originally didn't want to force replacement nodes to be traversed, but that seems to be what one almost always wants.

You can technically call

types.traverse(
  this.replace(functionExpressionNode)[0],
  arguments.callee
);

but that's admittedly pretty ugly.

from ast-types.

benjamn avatar benjamn commented on May 14, 2024

One case where you don't want automatic traversal is when you pass multiple arguments to this.replace and one of the arguments is the current node:

types.traverse(ast, function addLogging(node) {
  if (n.Statement.check(node)) {
    this.replace(
      makeConsoleLogStatementFor(node),
      node // Don't want to traverse this node again!
    );
  }
});

Without some sort of additional check, automatic traversal would result in this traversal never terminating.

from ast-types.

fabiomcosta avatar fabiomcosta commented on May 14, 2024

It seems like having both methods would be the best then.
Add replaceAndTraverse() and keep replace()?

from ast-types.

fabiomcosta avatar fabiomcosta commented on May 14, 2024

Hi @benjamn just to let you know

types.traverse(
  this.replace(functionExpressionNode)[0],
  arguments.callee
);

Worked well for me, thank you! :)

I was doing:

this.replace(functionExpressionNode);
types.traverse(
  functionExpressionNode,
  arguments.callee
);

Which was making me lose all the parent context of functionExpressionNode.

from ast-types.

benjamn avatar benjamn commented on May 14, 2024

Fixed by c6fa69d and 92a64f9. You should no longer have to explicitly traverse the new path objects returned from path.replace.

from ast-types.

fabiomcosta avatar fabiomcosta commented on May 14, 2024

👍

On Tuesday, July 8, 2014, Ben Newman [email protected] wrote:

Closed #25 #25.


Reply to this email directly or view it on GitHub
#25 (comment).

Fabio Miranda Costa
twitter: @fabioMiranda
github: fabiomcosta

from ast-types.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.