From 871a73afddcccaa314bae767d0bd2936d2f5aa5f Mon Sep 17 00:00:00 2001 From: Boshen Date: Sun, 11 Feb 2024 19:25:38 +0800 Subject: [PATCH] fix(prettier): semi colon after class property (#2387) --- crates/oxc_ast/src/ast/js.rs | 9 +++++++++ crates/oxc_prettier/src/format/class.rs | 1 + tasks/prettier_conformance/prettier.snap.md | 3 +-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 28ee8cffa..fc3378c72 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -2000,6 +2000,15 @@ impl<'a> ClassElement<'a> { } } + pub fn is_property(&self) -> bool { + matches!( + self, + Self::PropertyDefinition(_) + | Self::AccessorProperty(_) + | Self::TSAbstractPropertyDefinition(_) + ) + } + pub fn is_ts_empty_body_function(&self) -> bool { match self { Self::PropertyDefinition(_) diff --git a/crates/oxc_prettier/src/format/class.rs b/crates/oxc_prettier/src/format/class.rs index 4fc066116..7198eea71 100644 --- a/crates/oxc_prettier/src/format/class.rs +++ b/crates/oxc_prettier/src/format/class.rs @@ -35,6 +35,7 @@ pub(super) fn print_class_body<'a>(p: &mut Prettier<'a>, class_body: &ClassBody< parts_inner.push(node.format(p)); if !p.options.semi + && node.is_property() && should_print_semicolon_after_class_property(node, class_body.body.get(i + 1)) { parts_inner.push(ss!(";")); diff --git a/tasks/prettier_conformance/prettier.snap.md b/tasks/prettier_conformance/prettier.snap.md index e3cb41eb0..7e18b244d 100644 --- a/tasks/prettier_conformance/prettier.snap.md +++ b/tasks/prettier_conformance/prettier.snap.md @@ -1,4 +1,4 @@ -Compatibility: 239/562 (42.53%) +Compatibility: 240/562 (42.70%) # Failed @@ -107,7 +107,6 @@ Compatibility: 239/562 (42.53%) * classes/property.js ### classes-private-fields -* classes-private-fields/private_fields.js * classes-private-fields/with_comments.js ### comments