Thanks to visit codestin.com
Credit goes to github.com

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/nervous-gifts-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'esrap': patch
---

fix: support typescript class decorator
6 changes: 6 additions & 0 deletions src/languages/ts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,12 @@ export default (options = {}) => {
* @param {Context} context
*/
'ClassDeclaration|ClassExpression': (node, context) => {
if (node.decorators) {
for (const decorator of node.decorators) {
context.visit(decorator);
}
}

if (node.declare) {
context.write('declare ');
}
Expand Down
11 changes: 11 additions & 0 deletions test/samples/ts-decorators-class/expected.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Entity {
constructor(
private readonly name: string,
private readonly info: boolean
) {}
}

@Entity('users', { info: true })
class User {}

const u = new User(); // will print "random uuid..."
11 changes: 11 additions & 0 deletions test/samples/ts-decorators-class/expected.ts.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": 3,
"names": [],
"sources": [
"input.js"
],
"sourcesContent": [
"class Entity {\n\tconstructor(\n\t\tprivate readonly name: string,\n\t\tprivate readonly info: boolean\n\t) {}\n}\n\n@Entity('users', { info: true })\nclass User {}\n\nconst u = new User(); // will print \"random uuid...\"\n"
],
"mappings": "MAAM,MAAM,CAAC,CAAC;CACb,WAAW;mBACO,IAAY,EAAN,MAAM;mBACZ,IAAa,EAAP,OAAO;GAC7B,CAAC,AAAA,CAAC;AACL,CAAC;;CAEA,MAAM,CAAC,OAAO,IAAI,IAAI,EAAE,IAAI;MACvB,IAAI,CAAC,CAAC,AAAA,CAAC;;MAEP,CAAC,OAAO,IAAI"
}
11 changes: 11 additions & 0 deletions test/samples/ts-decorators-class/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Entity {
constructor(
private readonly name: string,
private readonly info: boolean
) {}
}

@Entity('users', { info: true })
class User {}

const u = new User(); // will print "random uuid..."
Loading