refactor: improve code coverage a little bit

This commit is contained in:
Boshen 2023-08-25 22:59:56 +08:00
parent 3d8ee2567f
commit 12798e075f
No known key found for this signature in database
GPG key ID: 9C7A8C8AB22BEBD1
8 changed files with 31 additions and 31 deletions

View file

@ -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

View file

@ -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!()
}

View file

@ -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,

View file

@ -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!"),
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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