Skip to content

Commit

Permalink
fix(es/proposal): Improve resolving of design:returntype (#8303)
Browse files Browse the repository at this point in the history
**Description:**

Emits `'design:returntype'` metadata when using `"decoratorMetadata": true`.

**Related issue:**

 - Closes #3319
  • Loading branch information
ZakisM committed Nov 19, 2023
1 parent cf692e0 commit fab51e1
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 28 deletions.
Expand Up @@ -30,15 +30,17 @@ class AppController {
_ts_decorate._([
(0, _common.Get)(),
_ts_metadata._("design:type", Function),
_ts_metadata._("design:paramtypes", [])
_ts_metadata._("design:paramtypes", []),
_ts_metadata._("design:returntype", Promise)
], AppController.prototype, "getHello", null);
_ts_decorate._([
(0, _common.Post)(),
_ts_param._(0, (0, _common.Body)()),
_ts_metadata._("design:type", Function),
_ts_metadata._("design:paramtypes", [
typeof _CreateUserDto.CreateUserDto === "undefined" ? Object : _CreateUserDto.CreateUserDto
])
]),
_ts_metadata._("design:returntype", Promise)
], AppController.prototype, "create", null);
AppController = _ts_decorate._([
(0, _common.Controller)(),
Expand Down
6 changes: 4 additions & 2 deletions crates/swc/tests/fixture/issues-2xxx/2428/1/output/index.ts
Expand Up @@ -21,7 +21,8 @@ _ts_decorate._([
_ts_metadata._("design:type", Function),
_ts_metadata._("design:paramtypes", [
Boolean
])
]),
_ts_metadata._("design:returntype", Promise)
], Foo.prototype, "fnName1", null);
_ts_decorate._([
_ts_param._(0, Arg("GraphQLArgName", {
Expand All @@ -30,5 +31,6 @@ _ts_decorate._([
_ts_metadata._("design:type", Function),
_ts_metadata._("design:paramtypes", [
Boolean
])
]),
_ts_metadata._("design:returntype", Promise)
], Foo.prototype, "fnName2", null);
@@ -1,5 +1,5 @@
{
"mappings": ";;;AAAA,SAASA,IAAI,EAAEC,UAAU,EAAEC,MAAM,EAAEC,KAAK,EAAEC,GAAG,EAAEC,SAAS,EAAEC,eAAe,QAAQ,iBAAiB;AAElG,SACIC,wBAAwB,EACxBC,uBAAuB,EACvBC,uBAAuB,QACpB,gCAAg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mC;AAChE,SAASC,IAAI,QAAQ,mCAAmC;AACxD,SAASA,QAAQC,QAAQ,QAAQ,kCAAkC;AACnE,SAASC,gBAAgB,QAAQ,uCAAuC;AAIxE,OAAO,MAAMC;IACTC,YAAY,AAAQC,cAA8B,CAAE;aAAhCA,iBAAAA;IAAkC;IAI/CC,cACH,AAAaC,EAAU,EACvB,AAAQC,gBAAkC,EAC1C,AAAQC,IAAc,EACxB;QACE,OAAO,IAAI,CAACJ,cAAc,CAACK,MAAM,CAACH,IAAIC,kBAAkBC,KAAKF,EAAE;IACnE;IAIOI,cAAc,AAAaJ,EAAU,EAAE,AAAQE,IAAc,EAAE;QAClE,OAAO,IAAI,CAACJ,cAAc,CAACO,MAAM,CAACL,IAAIE,KAAKF,EAAE;IACjD;AACJ;;IAfKhB,UAAUQ;IACVT,IAAIK;IAEAN,aAAAA,MAAM;IACNH,aAAAA;IACAc,aAAAA;;;;eADyB,4CAAA;eACZ,oCAAA;;;GARTG;;IAaRZ,UAAUQ;IACVX,OAAOM;IACcL,aAAAA,MAAM;IAAmBW,aAAAA;;;;eAAa,oCAAA;;;GAfnDG;AAAAA;IAFZhB,WAAWM;IACXD,gBAAgBI,mCAAmCC;;;eAEZ,0CAAA;;GAD3BM",
"names": [
"Body",
"Controller",
Expand Down
Expand Up @@ -32,7 +32,8 @@ _ts_decorate([
String,
typeof UpdateCommentDto === "undefined" ? Object : UpdateCommentDto,
typeof UserType === "undefined" ? Object : UserType
])
]),
_ts_metadata("design:returntype", void 0)
], CommentController.prototype, "updateComment", null);
_ts_decorate([
UseGuards(JwtAuthGuard),
Expand All @@ -43,7 +44,8 @@ _ts_decorate([
_ts_metadata("design:paramtypes", [
String,
typeof UserType === "undefined" ? Object : UserType
])
]),
_ts_metadata("design:returntype", void 0)
], CommentController.prototype, "deleteComment", null);
CommentController = _ts_decorate([
Controller(COMMENT_CONTROLLER_ROUTE),
Expand Down
@@ -1,5 +1,5 @@
{
"mappings": ";;;AAAA,SACIA,IAAI,E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A;eAA6B,oCAAA;;;GAf7DK;;IAmBRnB,UAAUa;IACVd,IAAIS;IAEAX,aAAAA,MAAM;IACNJ,aAAAA;IACAqB,aAAAA;;;;eADsB,yCAAA;eACT,oCAAA;;;GAxBTK;;IA6BRnB,UAAUa;IACVlB,OAAOQ;IACWN,aAAAA,MAAM;IAAmBiB,aAAAA;;;;eAAa,oCAAA;;;GA/BhDK;;IAmCRlB,gBAAgBQ,mCAAmCS;IACnDlB,UAAUa;IACVf,KAAKQ;IAEDT,aAAAA,MAAM;IACNJ,aAAAA;IACAqB,aAAAA;;;;eADyB,4CAAA;eACZ,oCAAA;;;GAzCTK;AAAAA;IAFZzB,WAAWQ;IACXD,gBAAgBQ,mCAAmCC;;;eAEf,uCAAA;eAAqC,0CAAA;;GAD7DS",
"names": [
"Body",
"Controller",
Expand Down
18 changes: 12 additions & 6 deletions crates/swc/tests/fixture/sourcemap/013/output/PistController.ts
Expand Up @@ -40,15 +40,17 @@ export class PostController {
_ts_decorate([
Get(POST_GET_ALL_ENDPOINT),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [])
_ts_metadata("design:paramtypes", []),
_ts_metadata("design:returntype", void 0)
], PostController.prototype, "getPosts", null);
_ts_decorate([
Get(POST_GET_ENDPOINT),
_ts_param(0, Param('id')),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
String
])
]),
_ts_metadata("design:returntype", void 0)
], PostController.prototype, "getPost", null);
_ts_decorate([
UseGuards(JwtAuthGuard),
Expand All @@ -59,7 +61,8 @@ _ts_decorate([
_ts_metadata("design:paramtypes", [
typeof CreatePostDto === "undefined" ? Object : CreatePostDto,
typeof UserType === "undefined" ? Object : UserType
])
]),
_ts_metadata("design:returntype", void 0)
], PostController.prototype, "createPost", null);
_ts_decorate([
UseGuards(JwtAuthGuard),
Expand All @@ -72,7 +75,8 @@ _ts_decorate([
String,
typeof CreatePostDto === "undefined" ? Object : CreatePostDto,
typeof UserType === "undefined" ? Object : UserType
])
]),
_ts_metadata("design:returntype", void 0)
], PostController.prototype, "updatePost", null);
_ts_decorate([
UseGuards(JwtAuthGuard),
Expand All @@ -83,7 +87,8 @@ _ts_decorate([
_ts_metadata("design:paramtypes", [
String,
typeof UserType === "undefined" ? Object : UserType
])
]),
_ts_metadata("design:returntype", void 0)
], PostController.prototype, "deletePost", null);
_ts_decorate([
UseInterceptors(MongooseClassSerializerInterceptor(Comment)),
Expand All @@ -97,7 +102,8 @@ _ts_decorate([
String,
typeof CreateCommentDto === "undefined" ? Object : CreateCommentDto,
typeof UserType === "undefined" ? Object : UserType
])
]),
_ts_metadata("design:returntype", void 0)
], PostController.prototype, "createPostComment", null);
PostController = _ts_decorate([
Controller(POST_CONTROLLER_ROUTE),
Expand Down
@@ -1,5 +1,5 @@
{
"mappings": ";;;AAAA,SACIA,UAAU,EACVC,IAAI,EACJC,SAAS,EACTC,IAAI,EACJC,GAAG,EACHC,KAAK,EACLC,kBAAkB,EAClBC,eAAe,QACZ,iBAAiB;AAExB,SACIC,qBAAqB,EACrBC,oBAAoB,EACpBC,oBAAoB,QACjB,gCAAgC;AACvC,SAASC,aAAa,QAAQ,iCAAiC;AAC/D,SAASC,aAAa,QAAQ,iCAAiC;AAC/D,SAASC,YAAY,QAAQ,mCAAmC;AAChE,SAASC,IAAI,QAAQ,mCAAmC;AACxD,SAASA,QAAQC,QAAQ,QAAQ,kCAAkC;AACnE,SAASC,kCAAkC,QAAQ,0DAA0D;AAC7G,SAASC,WAAW,QAAQ,2BAA2B;AAIvD,OAAO,MAAMC;IACTC,YAAY,AAAQC,WAAwB,CAAE;aAA1BA,cAAAA;IAA4B;IAEhD,MACMC,OAAO,AAAQC,aAA4B,EAAE;QAC/C,OAAO,IAAI,CAACF,WAAW,CAACG,MAAM,CAACD;IACnC;IAEA,MAEME,OACF,AAAaC,MAAc,EAC3B,AAAQC,aAA4B,EACpC,AAAQC,IAAc,EACxB;QACE,IAAIA,KAAKC,EAAE,KAAKH,QAAQ;YACpB,MAAM,I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W;IACVT,IAAIM;IAEAL,aAAAA,MAAM;IACNF,aAAAA;IACAW,aAAAA;;;;eADsB,yCAAA;eACT,oCAAA;;;GAbTI;AAAAA;IAFZlB,WAAWQ;IACXD,gBAAgBS,mCAAmCD;;;eAEf,uCAAA;;GADxBG",
"names": [
"Controller",
"Post",
Expand Down
Expand Up @@ -30,7 +30,8 @@ _ts_decorate([
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof CreateUserDto === "undefined" ? Object : CreateUserDto
])
]),
_ts_metadata("design:returntype", Promise)
], UserController.prototype, "signup", null);
_ts_decorate([
UseGuards(JwtAuthGuard),
Expand All @@ -43,7 +44,8 @@ _ts_decorate([
String,
typeof UpdateUserDto === "undefined" ? Object : UpdateUserDto,
typeof UserType === "undefined" ? Object : UserType
])
]),
_ts_metadata("design:returntype", Promise)
], UserController.prototype, "update", null);
UserController = _ts_decorate([
Controller(USER_CONTROLLER_ROUTE),
Expand Down
@@ -0,0 +1,34 @@
import 'reflect-metadata'

let returnType: unknown;

function decorator(target: any, key: string | symbol, descriptor: PropertyDescriptor): void {
returnType = Reflect.getMetadata('design:returntype', target, key);
}

class Foo {
@decorator
public foo(x: string): string {
return 'foo';
}

@decorator
public bar(x: string): number {
return 123;
}

@decorator
public baz(): string | number {
return 'baz';
}

@decorator
public qux() {
return 'qux';
}

@decorator
public async quux() {
return 'quux';
}
}
@@ -0,0 +1,55 @@
import 'reflect-metadata';

let returnType: unknown;

function decorator(target: any, key: string | symbol, descriptor: PropertyDescriptor): void {
returnType = Reflect.getMetadata('design:returntype', target, key);
}

class Foo {
public foo(x: string): string {
return 'foo';
}
public bar(x: string): number {
return 123;
}
public baz(): string | number {
return 'baz';
}
public qux() {
return 'qux';
}
public async quux() {
return 'quux';
}
}
_ts_decorate([
decorator,
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [String]),
_ts_metadata("design:returntype", String)
], Foo.prototype, "foo", null);
_ts_decorate([
decorator,
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [String]),
_ts_metadata("design:returntype", Number)
], Foo.prototype, "bar", null);
_ts_decorate([
decorator,
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", []),
_ts_metadata("design:returntype", Object)
], Foo.prototype, "baz", null);
_ts_decorate([
decorator,
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", []),
_ts_metadata("design:returntype", void 0)
], Foo.prototype, "qux", null);
_ts_decorate([
decorator,
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", []),
_ts_metadata("design:returntype", Promise)
], Foo.prototype, "quux", null);
Expand Up @@ -9,7 +9,8 @@ _ts_decorate([
_ts_metadata("design:paramtypes", [
typeof Inter === "undefined" ? Object : Inter,
typeof InterGen === "undefined" ? Object : InterGen
])
]),
_ts_metadata("design:returntype", void 0)
], MyClass.prototype, "method", null);
MyClass = _ts_decorate([
Decorate,
Expand Down
Expand Up @@ -27,7 +27,8 @@ _ts_decorate([
_ts_decorate([
Get(),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [])
_ts_metadata("design:paramtypes", []),
_ts_metadata("design:returntype", String)
], AppController.prototype, "getHello", null);
_ts_decorate([
Get("/callback"),
Expand All @@ -37,7 +38,8 @@ _ts_decorate([
_ts_metadata("design:paramtypes", [
typeof express === "undefined" || typeof express.Response === "undefined" ? Object : express.Response,
typeof express === "undefined" || typeof express.Express === "undefined" || typeof express.Express.Session === "undefined" ? Object : express.Express.Session
])
]),
_ts_metadata("design:returntype", Promise)
], AppController.prototype, "callback", null);
AppController = _ts_decorate([
Controller(),
Expand Down
Expand Up @@ -21,7 +21,8 @@ _ts_decorate([
_ts_metadata("design:paramtypes", [
String,
void 0
])
]),
_ts_metadata("design:returntype", void 0)
], MyOtherClass.prototype, "methodUndecorated", null);
_ts_decorate([
decorate("named"),
Expand All @@ -31,7 +32,8 @@ _ts_decorate([
_ts_metadata("design:paramtypes", [
typeof Injected === "undefined" ? Object : Injected,
typeof Schema === "undefined" ? Object : Schema
])
]),
_ts_metadata("design:returntype", void 0)
], MyOtherClass.prototype, "method", null);
MyOtherClass = _ts_decorate([
_ts_param(0, inject()),
Expand All @@ -52,7 +54,8 @@ _ts_decorate([
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
String
])
]),
_ts_metadata("design:returntype", void 0)
], DecoratedClass.prototype, "method", null);
DecoratedClass = _ts_decorate([
Decorate,
Expand Down
Expand Up @@ -34,22 +34,25 @@ _ts_decorate([
typeof Object === "undefined" ? Object : Object,
Object,
typeof BigInt === "undefined" ? Object : BigInt
])
]),
_ts_metadata("design:returntype", void 0)
], Sample.prototype, "method", null);
_ts_decorate([
Decorate(),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof Decorate === "undefined" || typeof Decorate.Name === "undefined" ? Object : Decorate.Name,
typeof Decorate === "undefined" || typeof Decorate.Name === "undefined" ? Object : Decorate.Name
])
]),
_ts_metadata("design:returntype", void 0)
], Sample.prototype, "method2", null);
_ts_decorate([
Decorate(),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
String
])
]),
_ts_metadata("design:returntype", void 0)
], Sample.prototype, "assignments", null);
Sample = _ts_decorate([
Decorate(),
Expand Down
Expand Up @@ -9,7 +9,8 @@ _ts_decorate([
_ts_metadata("design:paramtypes", [
String,
String
])
]),
_ts_metadata("design:returntype", void 0)
], Foo.prototype, "foo", null);
_ts_decorate([
_ts_param(0, dec1()),
Expand All @@ -18,5 +19,6 @@ _ts_decorate([
_ts_metadata("design:paramtypes", [
String,
String
])
]),
_ts_metadata("design:returntype", void 0)
], Foo, "bar", null);
Expand Up @@ -161,6 +161,19 @@ impl VisitMut for Metadata<'_> {
);
m.function.decorators.push(dec);
}
{
// Copy tsc behaviour
// https://github.com/microsoft/TypeScript/blob/5e8c261b6ab746213f19ee3501eb8c48a6215dd7/src/compiler/transformers/typeSerializer.ts#L242
let dec = self.create_metadata_design_decorator(
"design:returntype",
if m.function.is_async {
quote_ident!("Promise").as_arg()
} else {
serialize_type(self.class_name, m.function.return_type.as_deref()).as_arg()
},
);
m.function.decorators.push(dec);
}
}

fn visit_mut_class_prop(&mut self, p: &mut ClassProp) {
Expand Down

0 comments on commit fab51e1

Please sign in to comment.