From faff18a8fc56d4ee15555b8380fca0e8edc27115 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Fri, 5 Jun 2026 01:29:24 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E8=87=AA=E5=8A=A8=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_parser/src/error.rs | 2 +- crates/oxide_parser/src/lib.rs | 5 ++++- crates/oxide_parser/tests/parse_smoke.rs | 20 +++++++++++++------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/crates/oxide_parser/src/error.rs b/crates/oxide_parser/src/error.rs index 52acb081..14d71e96 100644 --- a/crates/oxide_parser/src/error.rs +++ b/crates/oxide_parser/src/error.rs @@ -19,7 +19,7 @@ impl From for OxideError { let span = diag .labels .clone() - .and_then(|labels| labels.first().map(|l| (l.offset() as usize, (l.offset() + l.len()) as usize))) + .and_then(|labels| labels.first().map(|l| (l.offset(), l.offset() + l.len()))) .unwrap_or((0, 0)); OxideError { diff --git a/crates/oxide_parser/src/lib.rs b/crates/oxide_parser/src/lib.rs index 89f347c3..381fb12e 100644 --- a/crates/oxide_parser/src/lib.rs +++ b/crates/oxide_parser/src/lib.rs @@ -7,7 +7,10 @@ pub use oxc_allocator::Allocator; pub use oxc_ast::ast::*; pub use oxc_span::Span; -pub fn parse<'a>(allocator: &'a Allocator, source: &'a str) -> Result, Vec> { +pub fn parse<'a>( + allocator: &'a Allocator, + source: &'a str, +) -> Result, Vec> { use oxc_parser::Parser; use oxc_span::SourceType; diff --git a/crates/oxide_parser/tests/parse_smoke.rs b/crates/oxide_parser/tests/parse_smoke.rs index 47cc7006..b55817db 100644 --- a/crates/oxide_parser/tests/parse_smoke.rs +++ b/crates/oxide_parser/tests/parse_smoke.rs @@ -13,7 +13,10 @@ fn parse_empty_string() { let result = oxide_parser::parse(&allocator, ""); assert!(result.is_ok(), "empty string should parse"); let program = result.unwrap(); - assert!(program.body.is_empty(), "empty program should have empty body"); + assert!( + program.body.is_empty(), + "empty program should have empty body" + ); } #[test] @@ -22,7 +25,10 @@ fn parse_function_declaration() { let result = oxide_parser::parse(&allocator, "function foo() { return 42; }"); assert!(result.is_ok(), "function declaration should parse"); let program = result.unwrap(); - assert!(!program.body.is_empty(), "program with function should not be empty"); + assert!( + !program.body.is_empty(), + "program with function should not be empty" + ); } #[test] @@ -31,7 +37,10 @@ fn parse_syntax_error() { let result = oxide_parser::parse(&allocator, "function("); assert!(result.is_err(), "syntax error should return Err"); let errors = result.unwrap_err(); - assert!(!errors.is_empty(), "syntax error should produce at least one error"); + assert!( + !errors.is_empty(), + "syntax error should produce at least one error" + ); } #[test] @@ -44,10 +53,7 @@ fn parse_variable_declaration() { #[test] fn parse_multiple_statements() { let allocator = Allocator::default(); - let result = oxide_parser::parse( - &allocator, - "var a = 1; var b = 2; var c = a + b;", - ); + let result = oxide_parser::parse(&allocator, "var a = 1; var b = 2; var c = a + b;"); assert!(result.is_ok(), "multiple statements should parse"); let program = result.unwrap(); assert_eq!(program.body.len(), 3, "should have 3 statements");