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: 23 additions & 0 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,29 @@ impl CallExpression<'_> {
}
}

impl NewExpression<'_> {
/// Returns the span covering **all** arguments in this new call expression.
///
/// The span starts at the beginning of the first argument and ends at the end
/// of the last argument (inclusive).
///
/// # Examples
/// ```ts
/// new Foo(bar, baz);
/// // ^^^^^^^^ <- arguments_span() covers this range
/// ```
///
/// If the new 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<'_> {
/// Returns `true` if this argument is a spread element (like `...foo`).
pub fn is_spread(&self) -> bool {
Expand Down
Loading