fix(prettier): print_method (#1453)

This commit is contained in:
magic-akari 2023-11-20 20:41:36 +08:00 committed by GitHub
parent 712505bfce
commit eecf8d3dc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 3 deletions

View file

@ -50,7 +50,42 @@ pub(super) fn print_function<'a>(
pub(super) fn print_method<'a>(p: &mut Prettier<'a>, method: &MethodDefinition<'a>) -> Doc<'a> {
let mut parts = p.vec();
parts.push(method.key.format(p));
if method.r#static {
parts.push(ss!("static "));
}
match method.kind {
MethodDefinitionKind::Constructor | MethodDefinitionKind::Method => {}
MethodDefinitionKind::Get => {
parts.push(ss!("get "));
}
MethodDefinitionKind::Set => {
parts.push(ss!("set "));
}
}
if method.value.r#async {
parts.push(ss!("async "));
}
if method.value.generator {
parts.push(ss!("*"));
}
if method.computed {
parts.push(ss!("["));
let key = match &method.key {
PropertyKey::Identifier(ident) => ident.format(p),
PropertyKey::PrivateIdentifier(ident) => ident.format(p),
PropertyKey::Expression(expr) => expr.format(p),
};
parts.push(key);
parts.push(ss!("]"));
} else {
parts.push(method.key.format(p));
}
parts.push(method.value.params.format(p));
if let Some(body) = &method.value.body {
parts.push(ss!(" "));

View file

@ -1,4 +1,4 @@
Compatibility: 118/601 (19.63%)
Compatibility: 119/601 (19.80%)
# Failed
@ -88,7 +88,6 @@ Compatibility: 118/601 (19.63%)
* assignment-comments/string.js
### async
* async/async-iteration.js
* async/await-parse.js
* async/conditional-expression.js
* async/exponentiation.js