feat(ast): add visit_span to Visit and VisitMut (#7816)

Add `Visit::visit_span` and `VisitMut::visit_span` methods, to facilitate #7811.

Both are no-ops by default, and marked `#[inline]`, so this produces no performance impact.
This commit is contained in:
overlookmotel 2024-12-12 13:33:12 +00:00
parent d14d360061
commit 8991f33fc7
5 changed files with 416 additions and 5 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -56,7 +56,7 @@ use oxc_estree::ESTree;
///
/// [`expand`]: Span::expand
/// [`shrink`]: Span::shrink
#[ast]
#[ast(visit)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[generate_derive(ESTree)]
#[non_exhaustive] // Disallow struct expression constructor `Span {}`

View file

@ -17,6 +17,8 @@ use crate::{
use super::define_generator;
pub const BLACK_LIST: [&str; 1] = ["Span"];
pub struct AstBuilderGenerator;
define_generator!(AstBuilderGenerator);
@ -26,7 +28,11 @@ impl Generator for AstBuilderGenerator {
let fns = schema
.defs
.iter()
.filter(|it| it.is_visitable())
.filter(|def| {
let is_visitable = def.is_visitable();
let is_blacklisted = BLACK_LIST.contains(&def.name());
is_visitable && !is_blacklisted
})
.map(|it| generate_builder_fn(it, schema))
.collect_vec();

View file

@ -15,7 +15,8 @@ pub struct AstKindGenerator;
define_generator!(AstKindGenerator);
pub const BLACK_LIST: [&str; 61] = [
pub const BLACK_LIST: [&str; 62] = [
"Span",
"Expression",
"ObjectPropertyKind",
"TemplateElement",