mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(prettier): add print_call_expression for CallExpression and NewExpression (#1340)
This commit is contained in:
parent
cf3318c609
commit
187299bd8f
3 changed files with 27 additions and 10 deletions
22
crates/oxc_prettier/src/format/call_expression.rs
Normal file
22
crates/oxc_prettier/src/format/call_expression.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use oxc_allocator::{Box, Vec};
|
||||
#[allow(clippy::wildcard_imports)]
|
||||
use oxc_ast::ast::*;
|
||||
|
||||
use crate::{doc::Doc, ss, Format, Prettier};
|
||||
|
||||
impl<'a> Prettier<'a> {
|
||||
pub(super) fn print_call_expression(
|
||||
&mut self,
|
||||
callee: &Expression<'a>,
|
||||
arguments: &Vec<'a, Argument<'a>>,
|
||||
optional: bool, // for optional chaining
|
||||
type_parameters: &Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
|
||||
) -> Doc<'a> {
|
||||
let mut parts = self.vec();
|
||||
parts.push(callee.format(self));
|
||||
parts.push(ss!("("));
|
||||
parts.extend(arguments.iter().map(|arg| arg.format(self)));
|
||||
parts.push(ss!(")"));
|
||||
Doc::Array(parts)
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ use oxc_ast::ast::*;
|
|||
|
||||
mod binaryish;
|
||||
mod block;
|
||||
mod call_expression;
|
||||
mod statement;
|
||||
mod ternary;
|
||||
|
||||
|
|
@ -737,13 +738,7 @@ impl<'a> Format<'a> for PrivateFieldExpression<'a> {
|
|||
|
||||
impl<'a> Format<'a> for CallExpression<'a> {
|
||||
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
|
||||
let mut parts = p.vec();
|
||||
parts.push(self.callee.format(p));
|
||||
parts.push(ss!("("));
|
||||
parts.extend(self.arguments.iter().map(|arg| arg.format(p)));
|
||||
parts.push(ss!(")"));
|
||||
|
||||
Doc::Array(parts)
|
||||
p.print_call_expression(&self.callee, &self.arguments, self.optional, &self.type_parameters)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1072,7 +1067,7 @@ impl<'a> Format<'a> for ChainElement<'a> {
|
|||
|
||||
impl<'a> Format<'a> for NewExpression<'a> {
|
||||
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
|
||||
Doc::Line
|
||||
p.print_call_expression(&self.callee, &self.arguments, false, &self.type_parameters)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#[allow(clippy::wildcard_imports)]
|
||||
use crate::{doc::Doc, Prettier};
|
||||
use oxc_allocator::Vec;
|
||||
|
||||
use crate::{doc::Doc, Prettier};
|
||||
|
||||
use super::Format;
|
||||
|
||||
impl<'a> Prettier<'a> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue