Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit e83ade4

Browse files
committed
refactor(compilper): remove filename info in diagnostic message
1 parent dd16c6f commit e83ade4

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

compiler/src/error.rs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,25 @@
33
use std::{fmt, sync::Arc, sync::RwLock};
44
use swc_common::{
55
errors::{Diagnostic, DiagnosticBuilder, Emitter},
6-
FileName, Loc, Span,
6+
Loc, Span,
77
};
88

9+
/// A buffer for collecting errors from the AST parser.
10+
#[derive(Debug, Clone)]
11+
pub struct ErrorBuffer(Arc<RwLock<Vec<Diagnostic>>>);
12+
13+
impl ErrorBuffer {
14+
pub fn new() -> Self {
15+
Self(Arc::new(RwLock::new(Vec::new())))
16+
}
17+
}
18+
19+
impl Emitter for ErrorBuffer {
20+
fn emit(&mut self, diagnostic_builder: &DiagnosticBuilder) {
21+
self.0.write().unwrap().push((**diagnostic_builder).clone());
22+
}
23+
}
24+
925
/// A buffer for collecting diagnostic messages from the AST parser.
1026
#[derive(Debug)]
1127
pub struct DiagnosticBuffer(Vec<String>);
@@ -26,39 +42,14 @@ impl DiagnosticBuffer {
2642
.iter()
2743
.map(|d| {
2844
let mut message = d.message();
29-
3045
if let Some(span) = d.span.primary_span() {
3146
let loc = get_loc(span);
32-
let file_name = match &loc.file.name {
33-
FileName::Real(p) => p.display(),
34-
_ => unreachable!(),
35-
};
36-
message = format!(
37-
"{} at {}:{}:{}",
38-
message, file_name, loc.line, loc.col_display
39-
);
47+
message = format!("{} at {}:{}", message, loc.line, loc.col_display);
4048
}
41-
4249
message
4350
})
4451
.collect();
4552

4653
Self(diagnostics)
4754
}
4855
}
49-
50-
/// A buffer for collecting errors from the AST parser.
51-
#[derive(Debug, Clone)]
52-
pub struct ErrorBuffer(Arc<RwLock<Vec<Diagnostic>>>);
53-
54-
impl ErrorBuffer {
55-
pub fn new() -> Self {
56-
Self(Arc::new(RwLock::new(Vec::new())))
57-
}
58-
}
59-
60-
impl Emitter for ErrorBuffer {
61-
fn emit(&mut self, diagnostic_builder: &DiagnosticBuilder) {
62-
self.0.write().unwrap().push((**diagnostic_builder).clone());
63-
}
64-
}

0 commit comments

Comments
 (0)