fix(es/codegen): Fix sourcemap bug related to multi-line comments (#3023)

swc_ecma_codegen:
 - Compute line starts in multi-line comments.
This commit is contained in:
Donny/강동윤 2021-12-13 09:21:22 +09:00 committed by GitHub
parent f86c077a37
commit c415487bb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -184,6 +184,13 @@ impl<'a, W: Write> WriteJs for JsWriter<'a, W> {
fn write_comment(&mut self, span: Span, s: &str) -> Result {
self.write(Some(span), s)?;
{
let line_start_of_s = compute_line_starts(s);
if line_start_of_s.len() > 1 {
self.line_count = self.line_count + line_start_of_s.len() - 1;
self.line_pos = s.len() - line_start_of_s.last().cloned().unwrap_or(0);
}
}
Ok(())
}