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

feat!: use js-tokens instead of acorn #6

Merged
merged 9 commits into from Dec 29, 2023

Conversation

sheremet-va
Copy link
Sponsor Contributor

Description

This PR replaces acorn with js-tokens. All tests are passing (I did update Vitest that changed snapshots, but I did it before running tests, so this is legitimate). I am opening this PR before I am fully ready (I didn't try updating createIsLiteralPositionAcorn yet) to also discuss some potential API changes:

  1. js-tokens never throws an error, so do we need still the regexp version?
  2. Tokens don't have any information about start/end - is it needed somewhere?
  3. Do we maybe want to have a separate entry point like strip-iteral/acorn with the previous implementation, and specify acorn in peerDependencies?
  4. I am also open to any review

Linked Issues

Additional context

@sheremet-va
Copy link
Sponsor Contributor Author

@antfu what do you think?

src/js-tokens.ts Outdated Show resolved Hide resolved
@antfu
Copy link
Owner

antfu commented Dec 29, 2023

Looks solid! It seems that regex mode is never used now. Could we find a counter-example, or maybe we could just remove the regex mode and always use js-tokens?

@antfu
Copy link
Owner

antfu commented Dec 29, 2023

For createIsLiteralPositionAcorn, I searched the entire GH https://github.com/search?q=createIsLiteralPositionAcorn&type=code and it seems no one is using it. I kind of forgot why I introduced it at the beginning, but I am ok with a big breaking change on the internal change. The expected behavior is not affected anyway :)

For strip-iteral/acorn, I think it's fine to remove it. People who absolutely need it can use the old version

@antfu
Copy link
Owner

antfu commented Dec 29, 2023

Did the bench:
image

To my surprise the regex is the slowest. I am ok with js-tokens being a bit slower than acorn for the better error tolerance (otherwise we are fallback to regex often)

@sheremet-va
Copy link
Sponsor Contributor Author

sheremet-va commented Dec 29, 2023

Do you have this benchmark somewhere? I can try optimizing the new implementation a bit more (using if instead of factory might be faster, but I don't know how fast)

@sheremet-va
Copy link
Sponsor Contributor Author

sheremet-va commented Dec 29, 2023

Do you have this benchmark somewhere? I can try optimizing the new implementation a bit more (using if instead of factory might be faster, but I don't know how fast)

I see now you already pushed it :D

Could we find a counter-example, or maybe we could just remove the regex mode and always use js-tokens?

As I said in the issue description, it never throws an error. I am fine with removing the regexp implementation.

But does anyone use tokens from the detailed version?

@sheremet-va sheremet-va changed the title feat: use js-tokens instead of acorn feat!: use js-tokens instead of acorn Dec 29, 2023
@sheremet-va sheremet-va marked this pull request as ready for review December 29, 2023 08:48
@sheremet-va
Copy link
Sponsor Contributor Author

sheremet-va commented Dec 29, 2023

@antfu acorn and regexp are removed now, ready for a review. I removed factory with restructuring, so it's a little bit faster now

@antfu antfu merged commit bad0e6f into antfu:main Dec 29, 2023
8 checks passed
@sheremet-va sheremet-va deleted the feat/use-js-tokens branch December 29, 2023 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants