From bc302f4f8bbc893c0c69f61d59a43d8e4ccc5db2 Mon Sep 17 00:00:00 2001 From: Boshen Date: Thu, 16 Nov 2023 19:04:12 +0800 Subject: [PATCH] feat(prettier): print big int with lowercase (#1351) --- crates/oxc_prettier/src/format/mod.rs | 8 +++++++- tasks/prettier_conformance/prettier.snap.md | 3 +-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/oxc_prettier/src/format/mod.rs b/crates/oxc_prettier/src/format/mod.rs index b055a4a9b..c0902766f 100644 --- a/crates/oxc_prettier/src/format/mod.rs +++ b/crates/oxc_prettier/src/format/mod.rs @@ -613,7 +613,13 @@ impl<'a> Format<'a> for NumberLiteral<'a> { impl<'a> Format<'a> for BigintLiteral { fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> { - Doc::Str(self.span.source_text(p.source_text)) + let text = self.span.source_text(p.source_text); + // Perf: avoid a memory allocation from `to_ascii_lowercase`. + if text.contains(|c: char| c.is_lowercase()) { + p.str(&text.to_ascii_lowercase()) + } else { + Doc::Str(text) + } } } diff --git a/tasks/prettier_conformance/prettier.snap.md b/tasks/prettier_conformance/prettier.snap.md index 4fd61cb61..2d239d538 100644 --- a/tasks/prettier_conformance/prettier.snap.md +++ b/tasks/prettier_conformance/prettier.snap.md @@ -1,4 +1,4 @@ -Compatibility: 8/173 (4.62%) +Compatibility: 9/173 (5.20%) # Failed @@ -13,7 +13,6 @@ Compatibility: 8/173 (4.62%) * async * async-do-expressions * babel-plugins -* big-int * binary-expressions * binary_math * bind-expressions