Skip to content

Commit

Permalink
refactor(ast): rename #[estree(always_flatten)] attr to `#[estree(f…
Browse files Browse the repository at this point in the history
…latten)]`
  • Loading branch information
overlookmotel committed Feb 3, 2025
1 parent 2f55d91 commit 0a8303d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_span/src/span/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use super::PointerAlign;
#[ast(visit)]
#[derive(Default, Clone, Copy, Eq, PartialOrd, Ord)]
#[generate_derive(ESTree)]
#[estree(no_type, always_flatten)]
#[estree(no_type, flatten)]
pub struct Span {
/// The zero-based start offset of the span
pub start: u32,
Expand Down
6 changes: 3 additions & 3 deletions tasks/ast_tools/src/derives/estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn parse_estree_attr(location: AttrLocation, part: AttrPart) -> Result<()> {
match location {
// `#[estree]` attr on struct
AttrLocation::Struct(struct_def) => match part {
AttrPart::Tag("always_flatten") => struct_def.estree.always_flatten = true,
AttrPart::Tag("flatten") => struct_def.estree.flatten = true,
AttrPart::Tag("no_type") => struct_def.estree.no_type = true,
AttrPart::Tag("custom_serialize") => struct_def.estree.custom_serialize = true,
AttrPart::String("rename", value) => struct_def.estree.rename = Some(value),
Expand Down Expand Up @@ -266,15 +266,15 @@ pub fn should_add_type_field_to_struct(struct_def: &StructDef) -> bool {
/// Get if should flatten a struct field.
///
/// Returns `true` if either the field has an `#[estree(flatten)]` attr on it,
/// or the type that the field contains has an `#[estree(always_flatten)]` attr.
/// or the type that the field contains has an `#[estree(flatten)]` attr.
///
/// This function also used by Typescript generator.
pub fn should_flatten_field(field: &FieldDef, schema: &Schema) -> bool {
if field.estree.flatten {
true
} else {
let field_type = field.type_def(schema);
matches!(field_type, TypeDef::Struct(field_struct_def) if field_struct_def.estree.always_flatten)
matches!(field_type, TypeDef::Struct(field_struct_def) if field_struct_def.estree.flatten)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tasks/ast_tools/src/schema/extensions/estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub struct ESTreeStruct {
pub rename: Option<String>,
pub via: Option<String>,
pub add_ts: Option<String>,
pub always_flatten: bool,
pub flatten: bool,
pub no_type: bool,
pub custom_serialize: bool,
}
Expand Down

0 comments on commit 0a8303d

Please sign in to comment.