fix(es/codegen): Fix codegen of async methods with decorators (#8575)

**Related issue:**

 - Closes #4311
This commit is contained in:
Donny/강동윤 2024-01-31 17:48:30 +09:00 committed by GitHub
parent d006482bd9
commit 8c322250b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,22 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"tsx": false,
"keepClassNames": true
},
"target": "es2020",
"preserveAllComments": true,
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "commonjs"
},
"minify": false,
"isModule": true
}

View File

@ -0,0 +1,24 @@
const printMemberName = (target: any, memberName: string) => {
console.log(memberName);
};
class TestClass {
// moving the decorator below the comment works as expected
@printMemberName
/**
* some tsdoc comments
*
* Some more comments
* over
* multiple
* lines
*/
async run(): Promise<boolean> {
return await Promise.resolve(true);
}
}
export { TestClass };

View File

@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "TestClass", {
enumerable: true,
get: function() {
return TestClass;
}
});
const _ts_decorate = require("@swc/helpers/_/_ts_decorate");
const printMemberName = (target, memberName)=>{
console.log(memberName);
};
class TestClass {
// moving the decorator below the comment works as expected
/**
* some tsdoc comments
*
* Some more comments
* over
* multiple
* lines
*/ async run() {
return await Promise.resolve(true);
}
}
_ts_decorate._([
printMemberName
], TestClass.prototype, "run", null);

View File

@ -1474,6 +1474,8 @@ where
fn emit_class_method(&mut self, n: &ClassMethod) -> Result { fn emit_class_method(&mut self, n: &ClassMethod) -> Result {
self.emit_leading_comments_of_span(n.span(), false)?; self.emit_leading_comments_of_span(n.span(), false)?;
self.emit_leading_comments_of_span(n.key.span(), false)?;
srcmap!(n, true); srcmap!(n, true);
for d in &n.function.decorators { for d in &n.function.decorators {