Skip to content

Commit 5a51be3

Browse files
committed
feat: add BindingPattern as an edge case.
1 parent e00ab6c commit 5a51be3

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

crates/oxc_ast/src/generated/span.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -925,13 +925,6 @@ impl GetSpan for DebuggerStatement {
925925
}
926926
}
927927

928-
impl<'a> GetSpan for BindingPattern<'a> {
929-
#[inline]
930-
fn span(&self) -> Span {
931-
self.span
932-
}
933-
}
934-
935928
impl<'a> GetSpan for BindingPatternKind<'a> {
936929
fn span(&self) -> Span {
937930
match self {
@@ -2174,3 +2167,9 @@ impl<'a> GetSpan for JSXText<'a> {
21742167
self.span
21752168
}
21762169
}
2170+
2171+
impl<'a> GetSpan for BindingPattern<'a> {
2172+
fn span(&self) -> Span {
2173+
self.kind.span()
2174+
}
2175+
}

tasks/ast_codegen/src/generators/impl_get_span.rs

+33-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
use std::collections::HashMap;
2+
13
use itertools::Itertools;
4+
use lazy_static::lazy_static;
25
use proc_macro2::TokenStream;
36
use quote::quote;
47
use syn::{parse_quote, Attribute, Variant};
@@ -12,6 +15,23 @@ use super::generated_header;
1215

1316
pub struct ImplGetSpanGenerator;
1417

18+
const EDGE_CASES: [&str; 1] = ["BindingPattern"];
19+
20+
fn edge_case(it: &std::cell::Ref<RType>) -> bool {
21+
!it.ident().is_some_and(|it| EDGE_CASES.contains(&it.to_string().as_str()))
22+
}
23+
24+
fn edge_case_impls() -> TokenStream {
25+
quote! {
26+
endl!();
27+
impl<'a> GetSpan for BindingPattern<'a> {
28+
fn span(&self) -> Span {
29+
self.kind.span()
30+
}
31+
}
32+
}
33+
}
34+
1535
impl Generator for ImplGetSpanGenerator {
1636
fn name(&self) -> &'static str {
1737
"ImplGetSpanGenerator"
@@ -21,14 +41,19 @@ impl Generator for ImplGetSpanGenerator {
2141
let impls: Vec<TokenStream> = ctx
2242
.ty_table
2343
.iter()
24-
.filter(|it| it.borrow().visitable())
25-
.filter_map(|maybe_kind| match &*maybe_kind.borrow() {
26-
RType::Enum(it) => Some(impl_enum(it)),
27-
RType::Struct(it) => Some(impl_struct(it)),
28-
_ => None,
44+
.map(|it| it.borrow())
45+
.filter(|it| it.visitable())
46+
.filter(|it| matches!(&**it, RType::Enum(_) | RType::Struct(_)))
47+
.filter(edge_case)
48+
.map(|kind| match &*kind {
49+
RType::Enum(it) => impl_enum(it),
50+
RType::Struct(it) => impl_struct(it),
51+
_ => unreachable!("already filtered out!"),
2952
})
3053
.collect();
3154

55+
let edge_impls = edge_case_impls();
56+
3257
let header = generated_header!();
3358

3459
GeneratorOutput::One(quote! {
@@ -40,6 +65,9 @@ impl Generator for ImplGetSpanGenerator {
4065
use oxc_span::{GetSpan, Span};
4166

4267
#(#impls)*
68+
69+
#edge_impls
70+
4371
})
4472
}
4573
}

tasks/ast_codegen/src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
205205
span_file.write_all(span_content.as_bytes())?;
206206
}
207207

208-
209208
// NOTE: Print AstKind
210209
// println!(
211210
// "{}",

0 commit comments

Comments
 (0)