mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(prettier): print_method (#1453)
This commit is contained in:
parent
712505bfce
commit
eecf8d3dc6
2 changed files with 37 additions and 3 deletions
|
|
@ -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!(" "));
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue