unjs/unimport

AST Parsing Mode

Closed this issue · 1 comments

Describe the feature

RegExp is fast, but there would be so many edge cases that can't be solved properly. I think we could introduce an optional AST parsing mode to have the most accurate result, for ppl who willing to sacrifice a bit of performance to opt-in.

Additional information

  • Would you be willing to help implement this feature?

Here's an example of a piece of code where the auto-import suddenly stoped working for us, and I didn't find the time to figure out why (naming was abstracted for purpose of illustration):

const items = parentItem.items.filter(isSuitableItem)

I then had to replace the code with this version for the auto-import of isSuitableItem() to work again:

const items = parentItem.items.filter(item => isSuitableItem(item))