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

Uncaught Error: toAST() expects a succesfull MatchResult as first parameter, but the MatchResult is successful #363

Closed
nailuj29 opened this issue Feb 11, 2022 · 6 comments

Comments

@nailuj29
Copy link

I am creating an app that uses Ohm, and when trying to get an AST with the toAST function. However, I get an error stating toAST() expects a succesfull MatchResult as first parameter, but the MatchResult is successful I believe this is an error with the instanceof in the code, because semanticsForToAST fails similarly, and the MatchResult is successful

@pdubroy
Copy link
Contributor

pdubroy commented Feb 16, 2022

I wasn't able to reproduce this. Can you give me some more details about how are importing Ohm (e.g., require or import), and how you are running and/or bundling it?

It sounds like the problem is that there are two different instances of the module.

@nailuj29
Copy link
Author

I am importing it using import and running it in a Vite with typescript.

@pdubroy
Copy link
Contributor

pdubroy commented Feb 16, 2022

@nailuj29 Can you show me exactly how you are importing and using it? If you give me the code it's much easier for me to try to reproduce.

Also, what does your tsconfig look like? That could make a difference.

@pdubroy
Copy link
Contributor

pdubroy commented Feb 17, 2022

Ok, I was able to reproduce the problem as follows:

  1. Set up a new Vite project with npm create vite@latest, and chose "vanilla-ts" as the project type.
  2. npm install -D ohm-js
  3. Put the following code into main.ts:
    import ohm from 'ohm-js';
    import extras from 'ohm-js/extras';
    
    extras.toAST(ohm.grammar('G { start = }').match(''))
    

@nailuj29, is this similar to how you are using it?

@nailuj29
Copy link
Author

Yes, that is what I am doing

@pdubroy
Copy link
Contributor

pdubroy commented Feb 28, 2022

@nailuj29 The issue is fixed now, and I've just published the fix in v16.3.1.

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