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

Types for LooseParser constructor are wrong #1249

Closed
connor4312 opened this issue Sep 29, 2023 · 2 comments
Closed

Types for LooseParser constructor are wrong #1249

connor4312 opened this issue Sep 29, 2023 · 2 comments

Comments

@connor4312
Copy link

connor4312 commented Sep 29, 2023

The types say that LooseParser is just a Parser

export const LooseParser: typeof acorn.Parser

...which orders is arguments as options, input...

constructor(options: Options, input: string, startPos?: number)

...but LooseParser actually takes the arguments in reverse order:

constructor(input, options = {}) {

@marijnh
Copy link
Member

marijnh commented Sep 30, 2023

The constructors aren't really part of the public interface. In what situation are you calling them?

@connor4312
Copy link
Author

I was extending the parser class, adding an additional property that I want to read after calling parse(), so my usage was const p = new MyParser(...); const ast = p.parse(); doSomethingElseWith(p.prop). (This is a little sketchy, and I eventually went a different route for another reason.)

If the parser constructor is not meant to be public API, perhaps it should be marked as protected in the types to avoid external callers?

@marijnh marijnh closed this as completed in 520547b Oct 1, 2023
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

No branches or pull requests

2 participants