From 37be46ca87c6d8457c6e3009e2dc7618f41441a0 Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Thu, 17 Jul 2025 14:57:38 +0000 Subject: [PATCH] feat(ast): introduce `NewExpression::arguments_span` (#12368) follow on from #12321 --- crates/oxc_ast/src/ast_impl/js.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/oxc_ast/src/ast_impl/js.rs b/crates/oxc_ast/src/ast_impl/js.rs index f9766c0471b70..b9e15efd7ac48 100644 --- a/crates/oxc_ast/src/ast_impl/js.rs +++ b/crates/oxc_ast/src/ast_impl/js.rs @@ -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 { + 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 {