From e8de4bde413b5ef3a3022473591a39e0fbcf3350 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Wed, 14 Aug 2024 04:29:17 +0000 Subject: [PATCH] fix(codegen): fix whitespace issue when minifying `x in new Error()` (#4886) --- crates/oxc_codegen/src/gen.rs | 1 + crates/oxc_codegen/tests/integration/unit.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index da6ffa2ef..20a1ab20d 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -2101,6 +2101,7 @@ impl<'a, const MINIFY: bool> GenExpr for NewExpression<'a> { if let Some(comment) = annotate_comment { p.print_comment(comment); } + p.print_space_before_identifier(); p.add_source_mapping(self.span.start); p.print_str("new "); self.callee.gen_expr(p, Precedence::New, Context::FORBID_CALL); diff --git a/crates/oxc_codegen/tests/integration/unit.rs b/crates/oxc_codegen/tests/integration/unit.rs index 5e7372cd9..518bcb849 100644 --- a/crates/oxc_codegen/tests/integration/unit.rs +++ b/crates/oxc_codegen/tests/integration/unit.rs @@ -17,6 +17,7 @@ fn expr() { }", "class Foo {\n\t#test;\n\tbar() {\n\t\tif (!(#test in Foo)) {}\n\t}\n}\n", ); + test_minify("x in new Error()", "x in new Error();"); } #[test]