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

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.

1 participant