fix(error-reporters): Store diagnostics in TransformOutput#10027
fix(error-reporters): Store diagnostics in TransformOutput#10027kdy1 merged 12 commits intoswc-project:mainfrom
TransformOutput#10027Conversation
|
CodSpeed Performance ReportMerging #10027 will degrade performances by 5.92%Comparing Summary
Benchmarks breakdown
|
kdy1
left a comment
There was a problem hiding this comment.
This PR is inevitably breaking change, so I think it's overly complicated.
|
According to
pub trait DiagnosticEmitter {
emit(&mut self, d: Diagnostic);
}
pub fn try_with_handler<F, Ret>(
cm: Lrc<SourceMap>,
config: HandlerOpts,
op: F,
) -> Result<Ret, Error>
where
Ret: DiagnosticEmitter,
F: FnOnce(&Handler) -> Result<Ret, Error>,
{
let emitter = PrettyEmitter::new(
cm,
wr.clone(),
to_miette_reporter(config.color),
PrettyEmitterConfig {
skip_filename: config.skip_filename,
},
);
.......
for d in emitter.take_diagnostics {
ret.emit(d);
}
}
transformOutput.diagnostic = handler.take_diagnostics();
impl Handler {
pub fn take_diagnostics(&self) {
self.emitter.take_diagnositc.
}
} |
kdy1
left a comment
There was a problem hiding this comment.
Thank you so much for the effort! I think this PR is fine to be merged, but please tell me if you want to add json support to this PR.
| } | ||
| } | ||
|
|
||
| pub fn take_diagnostics(&self) -> Vec<String> { |
There was a problem hiding this comment.
Great, you can merge it at any time.
Can we have an option to set the formatting of error messages?
About option to set the formatting of error messages, i can implement in another PR.
TransformOutput
Description:
SWC will return a
Result<Error>to js, then js console message then throw error, when swc apply pass occur errors.But SWC would not print warning message if
emit_handlerwas only had warning message. So we print warning message in rust.In the future, It might be more appropriate to let rust print the information and let the js side end the process
BREAKING CHANGE:
Related issue (if exists):
#9887