GithubHelp home page GithubHelp logo

Comments (2)

benjamn avatar benjamn commented on May 8, 2024

Does it work if you do something like this?

while (path.name > 0) {
  path.parentPath.shift();
}

When path.parentPath.value is an array, path.name is the index of path.value in the array, and that index/name will be decremented by 1 each time you call path.parentPath.shift() (which removes the first element from the array).

I'm not saying this is the ideal interface for removing elements, but I think it should work currently. I'm tempted to implement Path.prototype.splice, a la Array.prototype.splice, so you could just do: path.parentPath.splice(0, path.name) to remove earlier siblings, or path.parentPath.splice(path.name + 1) to remove later siblings.

from ast-types.

eurekaa avatar eurekaa commented on May 8, 2024

Thanks for your kind response.
The problem is that when path.node is an AssignmentExpression path.parentPath or path.parent is an Expression node, which is not an array.
I got an error also with path.parent.parentPath.shift() and with path.parent.parent.parentPath.shift() too.
I tried so many combination i can't remember exactly :)

It seems that when a node extends another one, his parent is the super class, may it be?

Anyway i found a solution (coffeescripted):

node_index = path.parent.name
parents = path.parent.parentPath.value
siblings = _.rest parents, node_index + 1
while parents.length > (node_index + 1) then parents.pop()

this way it works!

I can't understand why

parents = _.initial parents, node_index

doesn't work, it seems that direct assignments are not allowed.

If think your ideas are very nice, really a great work, i'm so near to implement a cps transformation with so few code!

Thank you very much!

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.