Skip to content

Conversation

@Chakroun-Anas
Copy link

@Chakroun-Anas Chakroun-Anas commented Oct 30, 2025

Issue: #20

Problem:

The parser crashes with Unexpected character '@' when a decorator appears immediately after an interface or type declaration, which is common in Angular and NestJS codebases.

Example:

interface User {
  id: number;
  name: string;
}

@Injectable()
export class UserService {
  getUser() { return null; }
}

Root cause

After parsing the interface closing }, the parser calls next() to advance to the @ character while still in type parsing mode. The getTokenFromCodeInType method didn't handle @ , causing it to fall through to the base parser which doesn't recognise decorators.

Solution

Added @ character handling in getTokenFromCodeInType method moving the position of the cursor and finishing by calling finishToken with the token type @

Testing

  • All 188 tests pass (187 existing + 1 new)
  • No breaking changes

@changeset-bot
Copy link

changeset-bot bot commented Oct 30, 2025

🦋 Changeset detected

Latest commit: e9ce73d

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/acorn-typescript 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

@baseballyama
Copy link
Member

@Chakroun-Anas Hi! Thank you for your PR! Can you add a changeset?

@Chakroun-Anas Chakroun-Anas force-pushed the fix/decorator-after-type-declaration branch from d80ccbd to e9ce73d Compare November 17, 2025 06:12
@Chakroun-Anas
Copy link
Author

Hello @baseballyama,

changeset added, thank you!

Copy link
Member

@baseballyama baseballyama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

Since @ (64) does not appear in type declarations, I believe handling this issue in getTokenFromCodeInType is not appropriate.

I’ve submitted an alternative PR: #26

@manuel3108
Copy link
Member

Closed in favor of #26

@manuel3108 manuel3108 closed this Nov 29, 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.

3 participants