Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
fmt::{self, Display},
};

use oxc_span::{Atom, Span};
use oxc_span::{Atom, GetSpan, Span};
use oxc_syntax::{operator::UnaryOperator, scope::ScopeFlags};

use crate::ast::*;
Expand Down Expand Up @@ -786,6 +786,27 @@ impl CallExpression<'_> {
_ => None,
}
}

/// Returns the span covering **all** arguments in this call expression.
///
/// The span starts at the beginning of the first argument and ends at the end
/// of the last argument (inclusive).
///
/// # Examples
/// ```ts
/// foo(bar, baz);
/// // ^^^^^^^^ <- arguments_span() covers this range
/// ```
///
/// If the call expression has no arguments, [`None`] is returned.
pub fn arguments_span(&self) -> Option<Span> {
self.arguments.first().map(|first| {
// The below will never panic since the len of `self.arguments` must be >= 1
#[expect(clippy::missing_panics_doc)]
let last = self.arguments.last().unwrap();
Span::new(first.span().start, last.span().end)
})
}
}

impl Argument<'_> {
Expand Down
Loading