mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
feat(ast): allow NONE to be passed to AST builder methods where Option<ArenaVec> is expected (#24629)
`NONE` is used for passing to `AstBuilder` methods which expect an `Option<'a, Box<'a, SomeAstNode<'a>>>`. Extend support to `Option<'a, Vec<'a, SomeAstNode<'a>>>` too. We don't use this currently, but it could be useful in future, and is very little code.
This commit is contained in:
1 parent
18ce449607
commit
94f99b379c
1 file changed
+13
-3
@@ -95,7 +95,7 @@
|
||||
//! `disable_old_builder` Cargo feature is enabled in all Oxc crates which utilize `AstBuilder`.
|
||||
//! Where those crates expose the `AstBuilder` they use to user code, the feature is only enabled in tests.
|
||||
|
||||
use oxc_allocator::{Allocator, ArenaBox, FromIn, GetAllocator};
|
||||
use oxc_allocator::{Allocator, ArenaBox, ArenaVec, FromIn, GetAllocator};
|
||||
use oxc_syntax::node::NodeId;
|
||||
|
||||
mod custom;
|
||||
@@ -185,8 +185,12 @@ impl<'a> GetAstBuilder<'a> for AstBuilder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Type that can be used in any AST builder method call which requires an `IntoIn<'a, Option<Anything<'a>>>`.
|
||||
/// Pass `NONE` instead of `None::<Anything<'a>>`.
|
||||
/// Type that can be used in any AST builder method call which requires either:
|
||||
///
|
||||
/// * `IntoIn<'a, Option<Box<'a, T>>`.
|
||||
/// * `IntoIn<'a, Option<Vec<'a, T>>`.
|
||||
///
|
||||
/// Pass `NONE` instead of `None::<Box<'a, T>>`.
|
||||
#[expect(clippy::upper_case_acronyms)]
|
||||
pub struct NONE;
|
||||
|
||||
@@ -195,3 +199,9 @@ impl<'a, T> FromIn<'a, NONE> for Option<ArenaBox<'a, T>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> FromIn<'a, NONE> for Option<ArenaVec<'a, T>> {
|
||||
fn from_in(_: NONE, _: &'a Allocator) -> Self {
|
||||
None
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user