diff --git a/crates/oxc_codegen/tests/integration/unit.rs b/crates/oxc_codegen/tests/integration/unit.rs index 7527ca66cc9df..db7cbb3ab11cf 100644 --- a/crates/oxc_codegen/tests/integration/unit.rs +++ b/crates/oxc_codegen/tests/integration/unit.rs @@ -379,17 +379,16 @@ fn pure_comment() { test_same("/* @__PURE__ */ a.b().c.d();\n"); test("/* @__PURE__ */ a().b;", "a().b;\n"); // INVALID, it does not end with a call test_same("(/* @__PURE__ */ a()).b;\n"); -} -#[test] -fn pure_comment_additional() { + // More test_same("/* @__PURE__ */ a() || b;\n"); test_same("/* @__PURE__ */ a() && b;\n"); test_same("/* @__PURE__ */ a() ?? b;\n"); test_same("/* @__PURE__ */ a() ? b : c;\n"); test_same("/* @__PURE__ */ a.b();\n"); test_same("/* @__PURE__ */ a?.b();\n"); - test_same("/* @__PURE__ */ a.b?.();\n"); + test_same("true && /* @__PURE__ */ noEffect();\n"); + test_same("false || /* @__PURE__ */ noEffect();\n"); } // followup from https://github.com/oxc-project/oxc/pull/6422 diff --git a/crates/oxc_minifier/src/peephole/remove_unused_expression.rs b/crates/oxc_minifier/src/peephole/remove_unused_expression.rs index c4221251ef084..62a5da05978f1 100644 --- a/crates/oxc_minifier/src/peephole/remove_unused_expression.rs +++ b/crates/oxc_minifier/src/peephole/remove_unused_expression.rs @@ -867,6 +867,8 @@ mod test { test("/* @__PURE__ */ foo(...'a')", ""); test("/* @__PURE__ */ new Foo()", ""); test("/* @__PURE__ */ new Foo(a)", "a"); + test("true && /* @__PURE__ */ noEffect()", ""); + test("false || /* @__PURE__ */ noEffect()", ""); } #[test] diff --git a/crates/oxc_parser/src/js/expression.rs b/crates/oxc_parser/src/js/expression.rs index d1a9488e33bbd..56f860376175d 100644 --- a/crates/oxc_parser/src/js/expression.rs +++ b/crates/oxc_parser/src/js/expression.rs @@ -1021,7 +1021,12 @@ impl<'a> ParserImpl<'a> { } self.ast.expression_private_in(self.end_span(lhs_span), left, right) } else { - self.parse_unary_expression_or_higher(lhs_span)? + let has_pure_comment = self.lexer.trivia_builder.previous_token_has_pure_comment(); + let mut expr = self.parse_unary_expression_or_higher(lhs_span)?; + if has_pure_comment { + Self::set_pure_on_call_or_new_expr(&mut expr); + } + expr }; self.parse_binary_expression_rest(lhs_span, lhs, lhs_precedence)