Skip to content

Commit 8c32225

Browse files
authoredJan 31, 2024
fix(es/codegen): Fix codegen of async methods with decorators (#8575)
**Related issue:** - Closes #4311
1 parent d006482 commit 8c32225

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "typescript",
5+
"decorators": true,
6+
"tsx": false,
7+
"keepClassNames": true
8+
},
9+
"target": "es2020",
10+
"preserveAllComments": true,
11+
"loose": false,
12+
"minify": {
13+
"compress": false,
14+
"mangle": false
15+
}
16+
},
17+
"module": {
18+
"type": "commonjs"
19+
},
20+
"minify": false,
21+
"isModule": true
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const printMemberName = (target: any, memberName: string) => {
2+
console.log(memberName);
3+
};
4+
5+
class TestClass {
6+
7+
8+
// moving the decorator below the comment works as expected
9+
10+
@printMemberName
11+
/**
12+
* some tsdoc comments
13+
*
14+
* Some more comments
15+
* over
16+
* multiple
17+
* lines
18+
*/
19+
async run(): Promise<boolean> {
20+
return await Promise.resolve(true);
21+
}
22+
}
23+
24+
export { TestClass };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", {
3+
value: true
4+
});
5+
Object.defineProperty(exports, "TestClass", {
6+
enumerable: true,
7+
get: function() {
8+
return TestClass;
9+
}
10+
});
11+
const _ts_decorate = require("@swc/helpers/_/_ts_decorate");
12+
const printMemberName = (target, memberName)=>{
13+
console.log(memberName);
14+
};
15+
class TestClass {
16+
// moving the decorator below the comment works as expected
17+
/**
18+
* some tsdoc comments
19+
*
20+
* Some more comments
21+
* over
22+
* multiple
23+
* lines
24+
*/ async run() {
25+
return await Promise.resolve(true);
26+
}
27+
}
28+
_ts_decorate._([
29+
printMemberName
30+
], TestClass.prototype, "run", null);

‎crates/swc_ecma_codegen/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,8 @@ where
14741474
fn emit_class_method(&mut self, n: &ClassMethod) -> Result {
14751475
self.emit_leading_comments_of_span(n.span(), false)?;
14761476

1477+
self.emit_leading_comments_of_span(n.key.span(), false)?;
1478+
14771479
srcmap!(n, true);
14781480

14791481
for d in &n.function.decorators {

0 commit comments

Comments
 (0)
Please sign in to comment.