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

Remove AstPath(aka FastPath) #10785

Open
fisker opened this issue Apr 29, 2021 · 6 comments
Open

Remove AstPath(aka FastPath) #10785

fisker opened this issue Apr 29, 2021 · 6 comments
Labels
status:needs discussion Issues needing discussion and a decision to be made before action can be taken type:refactor Issues about tackling technical debt

Comments

@fisker
Copy link
Member

fisker commented Apr 29, 2021

It's hard to access ancestors, why can't we use .parent like ESLint do?

And it's a state machine, remove it so maybe we can print node in parallel, by worker?

@fisker fisker added status:needs discussion Issues needing discussion and a decision to be made before action can be taken type:refactor Issues about tackling technical debt labels Apr 29, 2021
@sosukesuzuki
Copy link
Member

pros and cons I think other than what fisker gives:

Pros

  • Easy to understand to usage of AST especially for first-time contributors.

Cons

  • It's a refactoring with a lot of changes. So it may not be cost effective.
  • Flexible operations may be lost? (e.g. path.match)

@fisker
Copy link
Member Author

fisker commented Apr 29, 2021

Flexible operations may be lost? (e.g. path.match)

I think similar function for node not hard to implement.

@fisker
Copy link
Member Author

fisker commented Apr 29, 2021

The FastPath history benjamn/recast#139

@siefkenj
Copy link
Contributor

As a plugin author, I find AstPath an endless source of frustration. I often want to reparse or modify the AST on-the-fly to add metadata/etc during printing. I haven't found an easy way to do that because AstPath is locked to the initial AST. At a minimum, it should be exported so plugins can create new AstPath objects...

@fisker
Copy link
Member Author

fisker commented Aug 30, 2021

it should be exported so plugins can create new AstPath objects

const AstPath = path.constructor

Not recommanded, but possible :)

@thorn0
Copy link
Member

thorn0 commented Aug 8, 2022

It's hard to access ancestors

Seriously?

why can't we use .parent like ESLint do?

Use it where it's available. Nothing stops you.

remove it so maybe we can print node in parallel, by worker

Clone it if needed. Essentially it's just an array. It doesn't have to be a singleton. print doesn't have to be bound to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:needs discussion Issues needing discussion and a decision to be made before action can be taken type:refactor Issues about tackling technical debt
Projects
None yet
Development

No branches or pull requests

4 participants