Skip to content
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
7 changes: 3 additions & 4 deletions crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_minifier/src/peephole/remove_unused_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 6 additions & 1 deletion crates/oxc_parser/src/js/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading