Skip to content

Commit 5dd2e09

Browse files
authored
fix (#26)
1 parent 5961df5 commit 5dd2e09

File tree

4 files changed

+438
-1
lines changed

4 files changed

+438
-1
lines changed

.changeset/real-corners-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/acorn-typescript': patch
3+
---
4+
5+
fix: handle decorators after type declarations

src/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2459,11 +2459,25 @@ export function tsPlugin(options?: {
24592459
node.extends = this.tsParseHeritageClause('extends');
24602460
}
24612461
const body = this.startNode();
2462-
body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
2462+
body.body = this.tsParseInterfaceBody();
24632463
node.body = this.finishNode(body, 'TSInterfaceBody');
24642464
return this.finishNode(node, 'TSInterfaceDeclaration');
24652465
}
24662466

2467+
/**
2468+
* Parse interface body, ensuring the closing brace is read outside of type context
2469+
* so that decorators following the interface are properly tokenized.
2470+
*/
2471+
tsParseInterfaceBody(): Array<Node> {
2472+
this.expect(tt.braceL);
2473+
const oldInType = this.inType;
2474+
this.inType = true;
2475+
let members = this.tsParseList('TypeMembers', this.tsParseTypeMember.bind(this));
2476+
this.inType = oldInType;
2477+
this.expect(tt.braceR);
2478+
return members;
2479+
}
2480+
24672481
tsParseAbstractDeclaration(node: any): any | undefined | null {
24682482
if (this.match(tt._class)) {
24692483
node.abstract = true;

0 commit comments

Comments
 (0)