From ab187d1e22392d5ee78df54c4293387a0889965a Mon Sep 17 00:00:00 2001 From: DonIsaac <22823424+DonIsaac@users.noreply.github.com> Date: Sat, 28 Sep 2024 14:33:42 +0000 Subject: [PATCH] refactor(codegen): restrict visibility of internal methods (#6145) add `pub(crate)` to `Codegen` methods that should only be used within `oxc_codegen` --- crates/oxc_codegen/src/binary_expr_visitor.rs | 2 +- crates/oxc_codegen/src/comment.rs | 12 ++++++------ crates/oxc_codegen/src/operator.rs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/oxc_codegen/src/binary_expr_visitor.rs b/crates/oxc_codegen/src/binary_expr_visitor.rs index 87fa28205..852699f46 100644 --- a/crates/oxc_codegen/src/binary_expr_visitor.rs +++ b/crates/oxc_codegen/src/binary_expr_visitor.rs @@ -12,7 +12,7 @@ use oxc_syntax::{ use crate::{gen::GenExpr, Codegen, Context, Operator}; #[derive(Clone, Copy)] -pub enum Binaryish<'a> { +pub(crate) enum Binaryish<'a> { Binary(&'a BinaryExpression<'a>), Logical(&'a LogicalExpression<'a>), } diff --git a/crates/oxc_codegen/src/comment.rs b/crates/oxc_codegen/src/comment.rs index b4f48090c..29bf12f48 100644 --- a/crates/oxc_codegen/src/comment.rs +++ b/crates/oxc_codegen/src/comment.rs @@ -7,16 +7,16 @@ use oxc_syntax::identifier::is_line_terminator; use crate::Codegen; -pub static ANNOTATION_MATCHER: Lazy> = Lazy::new(|| { +static ANNOTATION_MATCHER: Lazy> = Lazy::new(|| { let patterns = vec!["#__NO_SIDE_EFFECTS__", "@__NO_SIDE_EFFECTS__", "@__PURE__", "#__PURE__"]; DoubleArrayAhoCorasick::new(patterns).unwrap() }); -pub type CommentsMap = FxHashMap>; +pub(crate) type CommentsMap = FxHashMap>; impl<'a> Codegen<'a> { - pub fn preserve_annotate_comments(&self) -> bool { + pub(crate) fn preserve_annotate_comments(&self) -> bool { self.comment_options.preserve_annotate_comments && !self.options.minify } @@ -26,11 +26,11 @@ impl<'a> Codegen<'a> { } } - pub fn has_comment(&self, start: u32) -> bool { + pub(crate) fn has_comment(&self, start: u32) -> bool { self.comments.contains_key(&start) } - pub fn has_annotation_comment(&self, start: u32) -> bool { + pub(crate) fn has_annotation_comment(&self, start: u32) -> bool { if !self.preserve_annotate_comments() { return false; } @@ -40,7 +40,7 @@ impl<'a> Codegen<'a> { }) } - pub fn has_non_annotation_comment(&self, start: u32) -> bool { + pub(crate) fn has_non_annotation_comment(&self, start: u32) -> bool { if !self.preserve_annotate_comments() { return self.has_comment(start); } diff --git a/crates/oxc_codegen/src/operator.rs b/crates/oxc_codegen/src/operator.rs index 8c5fb8089..d30f36dde 100644 --- a/crates/oxc_codegen/src/operator.rs +++ b/crates/oxc_codegen/src/operator.rs @@ -1,7 +1,7 @@ use oxc_syntax::operator::{BinaryOperator, UnaryOperator, UpdateOperator}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum Operator { +pub(crate) enum Operator { Binary(BinaryOperator), Unary(UnaryOperator), Update(UpdateOperator),