Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/proposal): Improve resolving of
design:returntype
(#8303)
**Description:** Emits `'design:returntype'` metadata when using `"decoratorMetadata": true`. **Related issue:** - Closes #3319
- Loading branch information
Showing
16 changed files
with
155 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
crates/swc/tests/fixture/sourcemap/011/output/CommentControlller.map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
crates/swc/tests/fixture/sourcemap/013/output/PistController.map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
crates/swc/tests/fixture/sourcemap/014/output/UserController.map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
crates/swc_ecma_transforms/tests/fixture/legacy-metadata/issues/3319/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
crates/swc_ecma_transforms/tests/fixture/legacy-metadata/issues/3319/output.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters