mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor: improve code coverage a little bit
This commit is contained in:
parent
3d8ee2567f
commit
12798e075f
8 changed files with 31 additions and 31 deletions
|
|
@ -145,11 +145,12 @@ impl<'alloc, T> ops::Index<usize> for &'alloc Vec<'alloc, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'alloc, T> ops::IndexMut<usize> for Vec<'alloc, T> {
|
||||
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
|
||||
self.0.index_mut(index)
|
||||
}
|
||||
}
|
||||
// Unused right now.
|
||||
// impl<'alloc, T> ops::IndexMut<usize> for Vec<'alloc, T> {
|
||||
// fn index_mut(&mut self, index: usize) -> &mut Self::Output {
|
||||
// self.0.index_mut(index)
|
||||
// }
|
||||
// }
|
||||
|
||||
impl<'alloc, T> Serialize for Vec<'alloc, T>
|
||||
where
|
||||
|
|
|
|||
|
|
@ -6,20 +6,6 @@ use syn::{
|
|||
Attribute, Error, Ident, Lit, LitStr, Meta, Result, Token,
|
||||
};
|
||||
|
||||
fn parse_attr<const LEN: usize>(path: [&'static str; LEN], attr: &Attribute) -> Option<LitStr> {
|
||||
if let Meta::NameValue(name_value) = attr.parse_meta().ok()? {
|
||||
let path_idents = name_value.path.segments.iter().map(|segment| &segment.ident);
|
||||
|
||||
if itertools::equal(path_idents, path) {
|
||||
if let Lit::Str(lit) = name_value.lit {
|
||||
return Some(lit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub struct LintRuleMeta {
|
||||
name: Ident,
|
||||
category: Ident,
|
||||
|
|
@ -90,3 +76,16 @@ pub fn declare_oxc_lint(metadata: LintRuleMeta) -> TokenStream {
|
|||
|
||||
output
|
||||
}
|
||||
|
||||
fn parse_attr<const LEN: usize>(path: [&'static str; LEN], attr: &Attribute) -> Option<LitStr> {
|
||||
if let Meta::NameValue(name_value) = attr.parse_meta().ok()? {
|
||||
let path_idents = name_value.path.segments.iter().map(|segment| &segment.ident);
|
||||
|
||||
if itertools::equal(path_idents, path) {
|
||||
if let Lit::Str(lit) = name_value.lit {
|
||||
return Some(lit);
|
||||
}
|
||||
}
|
||||
}
|
||||
unreachable!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ type ArrowFunctionHead<'a> = (
|
|||
Span,
|
||||
);
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum IsParenthesizedArrowFunction {
|
||||
True,
|
||||
False,
|
||||
Maybe,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub enum FunctionKind {
|
||||
Declaration { single_statement: bool },
|
||||
Expression,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use oxc_span::Span;
|
|||
|
||||
use super::kind::Kind;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct Token<'a> {
|
||||
/// Token Kind
|
||||
pub kind: Kind,
|
||||
|
|
@ -38,7 +38,7 @@ impl<'a> Token<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TokenValue<'a> {
|
||||
None,
|
||||
Number(f64),
|
||||
|
|
@ -47,7 +47,7 @@ pub enum TokenValue<'a> {
|
|||
RegExp(RegExp<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RegExp<'a> {
|
||||
pub pattern: &'a str,
|
||||
pub flags: RegExpFlags,
|
||||
|
|
@ -63,21 +63,21 @@ impl<'a> TokenValue<'a> {
|
|||
pub fn as_number(&self) -> f64 {
|
||||
match self {
|
||||
Self::Number(s) => *s,
|
||||
_ => panic!("expected number!"),
|
||||
_ => unreachable!("expected number!"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_bigint(&self) -> num_bigint::BigInt {
|
||||
match self {
|
||||
Self::BigInt(s) => s.clone(),
|
||||
_ => panic!("expected bigint!"),
|
||||
_ => unreachable!("expected bigint!"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_regex(&self) -> &RegExp<'a> {
|
||||
match self {
|
||||
Self::RegExp(regex) => regex,
|
||||
_ => panic!("expected regex!"),
|
||||
_ => unreachable!("expected regex!"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ impl<'a> Parser<'a> {
|
|||
span: Span,
|
||||
modifiers: Modifiers<'a>,
|
||||
) -> Result<Declaration<'a>> {
|
||||
self.expect(Kind::Enum)?;
|
||||
self.bump_any(); // bump `enum`
|
||||
|
||||
let id = self.parse_binding_identifier()?;
|
||||
let members = TSEnumMemberList::parse(self)?.members;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ struct IdentityHasher(u64);
|
|||
|
||||
impl Hasher for IdentityHasher {
|
||||
fn write(&mut self, _: &[u8]) {
|
||||
panic!("Invalid use of IdentityHasher")
|
||||
unreachable!("Invalid use of IdentityHasher")
|
||||
}
|
||||
fn write_u64(&mut self, n: u64) {
|
||||
self.0 = n;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ define_index_type! {
|
|||
}
|
||||
|
||||
bitflags! {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct ScopeFlags: u16 {
|
||||
const StrictMode = 1 << 0;
|
||||
const Top = 1 << 1;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ define_index_type! {
|
|||
}
|
||||
|
||||
bitflags! {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct SymbolFlags: u32 {
|
||||
const None = 0;
|
||||
/// Variable (var) or parameter
|
||||
|
|
|
|||
Loading…
Reference in a new issue