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

Sync method #10

Closed
brettz9 opened this issue Jun 22, 2024 · 9 comments · Fixed by #11
Closed

Sync method #10

brettz9 opened this issue Jun 22, 2024 · 9 comments · Fixed by #11

Comments

@brettz9
Copy link

brettz9 commented Jun 22, 2024

Hi,

I'm working with eslint-plugin-jsdoc and we have a need for parsing import statements (for use within @import tags). However, ESLint does not allow asynchronous rules.

I know that es-module-lexer mentions using async to be safe, but when I tested it within eslint, it seems enough time has passed for Wasm to load such that I could successfully get results using its parse method synchronously.

I am wondering if you could expose a sync version of parseImports (that presupposes it is called with enough time for Wasm to load)?

@TomerAberbach
Copy link
Owner

What you observed does make sense given that the WASM apparently takes only 5ms to boot!

I think a parseImportsSync method could make sense. Maybe I would also expose an wasmBootPromise that people can await if they want (even if you personally wouldn't be depending on that). Will probably be able to get to this soon. Thanks for filing :)

@TomerAberbach
Copy link
Owner

One thing I will mention is that jsdoc isn't valid JavaScript if you consider only the content within the comment and exclude the comment delimiters. I do wonder whether es-module-lexer always parses jsdoc imports correctly (given that there's an @ before import). I'll assume you've already looked into that

@brettz9
Copy link
Author

brettz9 commented Jun 22, 2024

That's right, I'd be supplying my own well-formed import statements based on the comments content, but not including the @. (TS suggests these comments are otherwise just well-formed imports.)

@TomerAberbach
Copy link
Owner

Got it. Makes sense!

@TomerAberbach
Copy link
Owner

@brettz9 are you able to confirm whether #11 does what you need?

Will need to be breaking change since I'm swapping the async method from a default import to a named import

@brettz9
Copy link
Author

brettz9 commented Jun 22, 2024

LGTM, thanks!

@TomerAberbach
Copy link
Owner

Published in v2.0.0!

@brettz9
Copy link
Author

brettz9 commented Jun 23, 2024

Awesome, appears to be working great too, thanks!

@TomerAberbach
Copy link
Owner

No problem! Glad it's working 😁

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 a pull request may close this issue.

2 participants