Skip to content

Conversation

LukasBombach
Copy link

When printing a TypeScript interface parsed with Oxc, esrap will add a random extends keyword and create a syntax error

interface Props {
  value?: string;
  className?: string;
}

// becomes

interface Props extends { value?: string; className?: string }
//                    ^^^
//                       syntax error  

This is because Oxc parser creates a slightly different AST for TSInterfaceDeclarations from what esrap expects. When parsing this interface with Acorn, it will create an AST node like this

{
  "type": "TSInterfaceDeclaration",
  "id": { /* snip */ },
  "body": { /* snip */ },
}

the interface does not extend any other interface so there is no extends property in the AST. Oxc will create an empty array here

{
  "type": "TSInterfaceDeclaration",
  "id": { /* snip */ },
  "body": { /* snip */ },
  "extends": [],
}

This PR fixes that, by adding a check for an empty array on the extends property.

Copy link

changeset-bot bot commented Sep 1, 2025

🦋 Changeset detected

Latest commit: f8132c6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
esrap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@LukasBombach
Copy link
Author

Hey folks, I'd love to write a test for this, but there is no setup another parser than Acorn. If there is any direction I can take here, I'd happily go there if you have any suggestions

@jycouet
Copy link
Contributor

jycouet commented Sep 12, 2025

It's actually already done in this PR: https://github.com/sveltejs/esrap/pull/70/files#diff-7c3ad21f697e100eaf9b40c3c6e608b0bf6fdd7d66714fdd322df0853b3be8c6R1948

With a setup to have tests with oxc-parser

I'll have a look at the other PR to see what needs to be done to move foward.

Thank you for your push 💪

@jycouet jycouet closed this Sep 12, 2025
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.

2 participants