mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 11:13:43 +03:00
fix(es/codegen): Fix sourcemaps of multi line block comments (#1511)
swc_ecma_codegen: - Fix sourcemaps of multiline block comments. Co-authored-by: 강동윤 <kdy1997.dev@gmail.com>
This commit is contained in:
parent
99f4f0f280
commit
393808a8f6
@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_codegen"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.49.0"
|
||||
version = "0.49.1"
|
||||
|
||||
[dependencies]
|
||||
bitflags = "1"
|
||||
|
@ -23,7 +23,7 @@ macro_rules! write_comments {
|
||||
$e.wr.write_comment(cmt.span, " ")?;
|
||||
}
|
||||
$e.wr.write_comment(cmt.span, "/*")?;
|
||||
$e.wr.write_comment(cmt.span, &cmt.text)?;
|
||||
$e.wr.write_lit(cmt.span, &cmt.text)?;
|
||||
$e.wr.write_comment(cmt.span, "*/")?;
|
||||
$e.wr.write_space()?;
|
||||
}
|
||||
|
@ -163,13 +163,20 @@ impl<'a, W: Write> WriteJs for JsWriter<'a, W> {
|
||||
|
||||
fn write_lit(&mut self, span: Span, s: &str) -> Result {
|
||||
if !s.is_empty() {
|
||||
self.write(Some(span), s)?;
|
||||
if !span.is_dummy() {
|
||||
self.srcmap(span.lo())
|
||||
}
|
||||
|
||||
self.write(None, 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 =
|
||||
self.written_bytes - s.len() + line_start_of_s.last().cloned().unwrap_or(0);
|
||||
self.line_pos = s.len() - line_start_of_s.last().cloned().unwrap_or(0);
|
||||
}
|
||||
|
||||
if !span.is_dummy() {
|
||||
self.srcmap(span.hi())
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,8 +230,7 @@ fn compute_line_starts(s: &str) -> Vec<usize> {
|
||||
|
||||
'\n' => {
|
||||
res.push(line_start);
|
||||
line_start = pos;
|
||||
break;
|
||||
line_start = pos + 1;
|
||||
}
|
||||
|
||||
_ => {}
|
||||
|
Loading…
Reference in New Issue
Block a user