Skip to content
Open
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/major-potatoes-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/acorn-typescript': patch
---

fix: support decorators on abstract classes
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ export function tsPlugin(options?: {
}

canHaveLeadingDecorator(): boolean {
return this.match(tt._class);
return this.match(tt._class) || this.isAbstractClass();
}

eatContextual(name: string) {
Expand Down
100 changes: 100 additions & 0 deletions test/decorators_class_abstract/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"type": "Program",
"start": 0,
"end": 42,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 0
}
},
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 30
}
},
"abstract": true,
"decorators": [
{
"type": "Decorator",
"start": 0,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 10
}
},
"expression": {
"type": "Identifier",
"start": 1,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 10
}
},
"name": "decorator"
}
}
],
"id": {
"type": "Identifier",
"start": 26,
"end": 38,
"loc": {
"start": {
"line": 2,
"column": 15
},
"end": {
"line": 2,
"column": 27
}
},
"name": "ExampleClass"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 39,
"end": 41,
"loc": {
"start": {
"line": 2,
"column": 28
},
"end": {
"line": 2,
"column": 30
}
},
"body": []
}
}
],
"sourceType": "module"
}
2 changes: 2 additions & 0 deletions test/decorators_class_abstract/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@decorator
abstract class ExampleClass {}
118 changes: 118 additions & 0 deletions test/decorators_class_abstract_export/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"type": "Program",
"start": 0,
"end": 49,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 0
}
},
"body": [
{
"type": "ExportNamedDeclaration",
"start": 11,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 37
}
},
"exportKind": "value",
"declaration": {
"type": "ClassDeclaration",
"start": 0,
"end": 48,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 37
}
},
"abstract": true,
"decorators": [
{
"type": "Decorator",
"start": 0,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 10
}
},
"expression": {
"type": "Identifier",
"start": 1,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 10
}
},
"name": "decorator"
}
}
],
"id": {
"type": "Identifier",
"start": 33,
"end": 45,
"loc": {
"start": {
"line": 2,
"column": 22
},
"end": {
"line": 2,
"column": 34
}
},
"name": "ExampleClass"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 46,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 35
},
"end": {
"line": 2,
"column": 37
}
},
"body": []
}
},
"specifiers": [],
"source": null
}
],
"sourceType": "module"
}
2 changes: 2 additions & 0 deletions test/decorators_class_abstract_export/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@decorator
export abstract class ExampleClass {}