refactor(syntax): move number related functions to number module (#3130)

This commit is contained in:
Boshen 2024-04-29 18:54:35 +08:00 committed by GitHub
parent 843318cdbe
commit a8af5de8f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 45 additions and 41 deletions

View file

@ -10,7 +10,7 @@ use std::{
use bitflags::bitflags;
use oxc_span::{Atom, Span};
use oxc_syntax::{BigintBase, NumberBase};
use oxc_syntax::number::{BigintBase, NumberBase};
#[cfg(feature = "serialize")]
use serde::Serialize;
#[cfg(feature = "serialize")]

View file

@ -10,10 +10,10 @@ use std::mem;
use oxc_allocator::{Allocator, Box, String, Vec};
use oxc_span::{Atom, GetSpan, SourceType, Span, SPAN};
use oxc_syntax::{
number::{BigintBase, NumberBase},
operator::{
AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator, UpdateOperator,
},
BigintBase, NumberBase,
};
#[allow(clippy::wildcard_imports)]

View file

@ -5,9 +5,9 @@ use oxc_span::GetSpan;
use oxc_syntax::{
identifier::{LS, PS},
keyword::is_keyword,
number::NumberBase,
operator::{BinaryOperator, UnaryOperator},
precedence::{GetPrecedence, Precedence},
NumberBase,
};
use super::{Codegen, Context, Operator, Separator};

View file

@ -152,18 +152,18 @@ impl Rule for NumericSeparatorsStyle {
impl NumericSeparatorsStyle {
fn format_number(&self, number: &NumericLiteral) -> String {
use oxc_syntax::NumberBase;
use oxc_syntax::number::NumberBase;
match number.base {
NumberBase::Binary => self.format_binary(number.raw),
NumberBase::Decimal | oxc_syntax::NumberBase::Float => self.format_decimal(number.raw),
NumberBase::Decimal | NumberBase::Float => self.format_decimal(number.raw),
NumberBase::Hex => self.format_hex(number.raw),
NumberBase::Octal => self.format_octal(number.raw),
}
}
fn format_bigint(&self, number: &BigIntLiteral, raw: &str) -> String {
use oxc_syntax::BigintBase;
use oxc_syntax::number::BigintBase;
let raw_without_bigint_n_suffix = &raw[..raw.len() - 1];
let mut formatted = match number.base {

View file

@ -9,8 +9,8 @@ use num_bigint::BigInt;
use oxc_ast::ast::*;
use oxc_span::{Atom, GetSpan, Span};
use oxc_syntax::{
number::NumberBase,
operator::{BinaryOperator, LogicalOperator, UnaryOperator},
NumberBase,
};
use super::ast_util::{

View file

@ -15,9 +15,9 @@ use oxc_ast::visit::walk_mut::{
use oxc_ast::{ast::*, AstBuilder, VisitMut};
use oxc_span::Span;
use oxc_syntax::{
number::NumberBase,
operator::{BinaryOperator, UnaryOperator},
precedence::GetPrecedence,
NumberBase,
};
pub use self::options::CompressOptions;

View file

@ -4,7 +4,11 @@ use oxc_allocator::Box;
use oxc_ast::ast::*;
use oxc_diagnostics::Result;
use oxc_span::{Atom, Span};
use oxc_syntax::{operator::BinaryOperator, precedence::Precedence, BigintBase, NumberBase};
use oxc_syntax::{
number::{BigintBase, NumberBase},
operator::BinaryOperator,
precedence::Precedence,
};
use super::{
function::IsParenthesizedArrowFunction,

View file

@ -11,8 +11,8 @@ use oxc_diagnostics::{
use oxc_span::{Atom, CompactStr, GetSpan, ModuleKind, Span};
use oxc_syntax::{
module_record::ExportLocalName,
number::NumberBase,
operator::{AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator},
NumberBase,
};
use phf::{phf_set, Set};
use rustc_hash::FxHashMap;

View file

@ -6,38 +6,10 @@ pub mod keyword;
pub mod module_graph_visitor;
pub mod module_record;
pub mod node;
pub mod number;
pub mod operator;
pub mod precedence;
pub mod reference;
pub mod scope;
pub mod symbol;
pub mod xml_entities;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum NumberBase {
Float,
Decimal,
Binary,
Octal,
Hex,
}
impl NumberBase {
pub fn is_base_10(&self) -> bool {
matches!(self, Self::Float | Self::Decimal)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BigintBase {
Decimal,
Binary,
Octal,
Hex,
}
impl BigintBase {
pub fn is_base_10(&self) -> bool {
self == &Self::Decimal
}
}

View file

@ -0,0 +1,28 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum NumberBase {
Float,
Decimal,
Binary,
Octal,
Hex,
}
impl NumberBase {
pub fn is_base_10(&self) -> bool {
matches!(self, Self::Float | Self::Decimal)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BigintBase {
Decimal,
Binary,
Octal,
Hex,
}
impl BigintBase {
pub fn is_base_10(&self) -> bool {
self == &Self::Decimal
}
}

View file

@ -4,7 +4,7 @@ use std::rc::Rc;
use oxc_ast::ast::*;
use oxc_span::{Span, SPAN};
use oxc_syntax::NumberBase;
use oxc_syntax::number::NumberBase;
use crate::context::Ctx;

View file

@ -4,8 +4,8 @@ use oxc_allocator::{Box, Vec};
use oxc_ast::{ast::*, visit::walk_mut, VisitMut};
use oxc_span::{Atom, SPAN};
use oxc_syntax::{
number::NumberBase,
operator::{AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator},
NumberBase,
};
use rustc_hash::FxHashMap;
use ryu_js::Buffer;