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

Can only remove recursive type definitions on union types not "TypeReference" #119

Open
fefrei opened this issue Oct 12, 2023 · 6 comments

Comments

@fefrei
Copy link

fefrei commented Oct 12, 2023

Starting with version 4.0.0, ts-pegjs fails to handle recursive rules like this:

start = "(" e: start ")" { return e; }

Peggy itself has no issue with this, but ts-pegjs struggles computing the types:

Error: Can only remove recursive type definitions on union types not "TypeReference"
    at getInfoFromDiagnostic (C:\Users\felix\git\pseuco-ccs-interpreter\node_modules\ts-pegjs\dist\tspegjs.js:339:11)
    at C:\Users\felix\git\pseuco-ccs-interpreter\node_modules\ts-pegjs\dist\tspegjs.js:304:41
    at Array.map (<anonymous>)
    at pruneCircularReferences (C:\Users\felix\git\pseuco-ccs-interpreter\node_modules\ts-pegjs\dist\tspegjs.js:304:30)
    at TypeExtractor.getTypes (C:\Users\felix\git\pseuco-ccs-interpreter\node_modules\ts-pegjs\dist\tspegjs.js:482:5)
    at generateParser (C:\Users\felix\git\pseuco-ccs-interpreter\node_modules\ts-pegjs\dist\tspegjs.js:779:35)
    at C:\Users\felix\git\pseuco-ccs-interpreter\node_modules\peggy\lib\compiler\index.js:119:9
    at Array.forEach (<anonymous>)
    at C:\Users\felix\git\pseuco-ccs-interpreter\node_modules\peggy\lib\compiler\index.js:116:21
    at Array.forEach (<anonymous>)

Version 3.1.0 could still handle this.

@iccicci
Copy link
Contributor

iccicci commented Jan 2, 2024

+1

@iccicci
Copy link
Contributor

iccicci commented Feb 23, 2024

Sorry @pjmolina , are you still supporting this package?

@pjmolina
Copy link
Contributor

Sorry @pjmolina , are you still supporting this package?

Yes! We still need to review the latest changes in Peggy. We accept insights, and PR ;-)

@iccicci
Copy link
Contributor

iccicci commented Feb 23, 2024

Thank you for your quick and kind answer!

Unfortunately I'm not able to do none of them 😞 I trust on you.

@iccicci
Copy link
Contributor

iccicci commented Nov 4, 2024

Simply commenting out the check in my node_modules directoy, everithing seems to work fine...
I can't understand neither the meaning of getInfoFromDiagnostic function nor its last check (the one I tried to comment out)... which is the meaning of the check?

  if (!typeBodyNode.isKind(ts.SyntaxKind.UnionType)) {
    throw new Error(
      `Can only remove recursive type definitions on union types not "${typeBodyNode.getKindName()}"`
    );
  }

@iccicci
Copy link
Contributor

iccicci commented Nov 4, 2024

As a quick workaround: adding skipTypeComputation: true to tspegjs in options to peggy.generate call, makes the check throwing this error to be skipped and the error not being thrown.

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

3 participants