mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +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> {
|
// Unused right now.
|
||||||
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
|
// impl<'alloc, T> ops::IndexMut<usize> for Vec<'alloc, T> {
|
||||||
self.0.index_mut(index)
|
// fn index_mut(&mut self, index: usize) -> &mut Self::Output {
|
||||||
}
|
// self.0.index_mut(index)
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
impl<'alloc, T> Serialize for Vec<'alloc, T>
|
impl<'alloc, T> Serialize for Vec<'alloc, T>
|
||||||
where
|
where
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,6 @@ use syn::{
|
||||||
Attribute, Error, Ident, Lit, LitStr, Meta, Result, Token,
|
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 {
|
pub struct LintRuleMeta {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
category: Ident,
|
category: Ident,
|
||||||
|
|
@ -90,3 +76,16 @@ pub fn declare_oxc_lint(metadata: LintRuleMeta) -> TokenStream {
|
||||||
|
|
||||||
output
|
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,
|
Span,
|
||||||
);
|
);
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum IsParenthesizedArrowFunction {
|
pub enum IsParenthesizedArrowFunction {
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
Maybe,
|
Maybe,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||||
pub enum FunctionKind {
|
pub enum FunctionKind {
|
||||||
Declaration { single_statement: bool },
|
Declaration { single_statement: bool },
|
||||||
Expression,
|
Expression,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use oxc_span::Span;
|
||||||
|
|
||||||
use super::kind::Kind;
|
use super::kind::Kind;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Token<'a> {
|
pub struct Token<'a> {
|
||||||
/// Token Kind
|
/// Token Kind
|
||||||
pub kind: Kind,
|
pub kind: Kind,
|
||||||
|
|
@ -38,7 +38,7 @@ impl<'a> Token<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum TokenValue<'a> {
|
pub enum TokenValue<'a> {
|
||||||
None,
|
None,
|
||||||
Number(f64),
|
Number(f64),
|
||||||
|
|
@ -47,7 +47,7 @@ pub enum TokenValue<'a> {
|
||||||
RegExp(RegExp<'a>),
|
RegExp(RegExp<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct RegExp<'a> {
|
pub struct RegExp<'a> {
|
||||||
pub pattern: &'a str,
|
pub pattern: &'a str,
|
||||||
pub flags: RegExpFlags,
|
pub flags: RegExpFlags,
|
||||||
|
|
@ -63,21 +63,21 @@ impl<'a> TokenValue<'a> {
|
||||||
pub fn as_number(&self) -> f64 {
|
pub fn as_number(&self) -> f64 {
|
||||||
match self {
|
match self {
|
||||||
Self::Number(s) => *s,
|
Self::Number(s) => *s,
|
||||||
_ => panic!("expected number!"),
|
_ => unreachable!("expected number!"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_bigint(&self) -> num_bigint::BigInt {
|
pub fn as_bigint(&self) -> num_bigint::BigInt {
|
||||||
match self {
|
match self {
|
||||||
Self::BigInt(s) => s.clone(),
|
Self::BigInt(s) => s.clone(),
|
||||||
_ => panic!("expected bigint!"),
|
_ => unreachable!("expected bigint!"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_regex(&self) -> &RegExp<'a> {
|
pub fn as_regex(&self) -> &RegExp<'a> {
|
||||||
match self {
|
match self {
|
||||||
Self::RegExp(regex) => regex,
|
Self::RegExp(regex) => regex,
|
||||||
_ => panic!("expected regex!"),
|
_ => unreachable!("expected regex!"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ impl<'a> Parser<'a> {
|
||||||
span: Span,
|
span: Span,
|
||||||
modifiers: Modifiers<'a>,
|
modifiers: Modifiers<'a>,
|
||||||
) -> Result<Declaration<'a>> {
|
) -> Result<Declaration<'a>> {
|
||||||
self.expect(Kind::Enum)?;
|
self.bump_any(); // bump `enum`
|
||||||
|
|
||||||
let id = self.parse_binding_identifier()?;
|
let id = self.parse_binding_identifier()?;
|
||||||
let members = TSEnumMemberList::parse(self)?.members;
|
let members = TSEnumMemberList::parse(self)?.members;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ struct IdentityHasher(u64);
|
||||||
|
|
||||||
impl Hasher for IdentityHasher {
|
impl Hasher for IdentityHasher {
|
||||||
fn write(&mut self, _: &[u8]) {
|
fn write(&mut self, _: &[u8]) {
|
||||||
panic!("Invalid use of IdentityHasher")
|
unreachable!("Invalid use of IdentityHasher")
|
||||||
}
|
}
|
||||||
fn write_u64(&mut self, n: u64) {
|
fn write_u64(&mut self, n: u64) {
|
||||||
self.0 = n;
|
self.0 = n;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ define_index_type! {
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct ScopeFlags: u16 {
|
pub struct ScopeFlags: u16 {
|
||||||
const StrictMode = 1 << 0;
|
const StrictMode = 1 << 0;
|
||||||
const Top = 1 << 1;
|
const Top = 1 << 1;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ define_index_type! {
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct SymbolFlags: u32 {
|
pub struct SymbolFlags: u32 {
|
||||||
const None = 0;
|
const None = 0;
|
||||||
/// Variable (var) or parameter
|
/// Variable (var) or parameter
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue