Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ast): rename #[estree(always_flatten)] attr to #[estree(flatten)] #8871

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading