Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/real-corners-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/acorn-typescript': patch
---

fix: handle decorators after type declarations
16 changes: 15 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2459,11 +2459,25 @@ export function tsPlugin(options?: {
node.extends = this.tsParseHeritageClause('extends');
}
const body = this.startNode();
body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
body.body = this.tsParseInterfaceBody();
node.body = this.finishNode(body, 'TSInterfaceBody');
return this.finishNode(node, 'TSInterfaceDeclaration');
}

/**
* Parse interface body, ensuring the closing brace is read outside of type context
* so that decorators following the interface are properly tokenized.
*/
tsParseInterfaceBody(): Array<Node> {
this.expect(tt.braceL);
const oldInType = this.inType;
this.inType = true;
let members = this.tsParseList('TypeMembers', this.tsParseTypeMember.bind(this));
this.inType = oldInType;
this.expect(tt.braceR);
return members;
}

tsParseAbstractDeclaration(node: any): any | undefined | null {
if (this.match(tt._class)) {
node.abstract = true;
Expand Down
Loading