mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 14:16:12 +03:00
fix(es): Fix sourcemap (#1548)
swc_ecma_codegen: - Consider indentions while calculating starting point of source map entries. (denoland/deno#10014)
This commit is contained in:
parent
228429c7bb
commit
62d0cbcabb
@ -76,16 +76,17 @@ impl<'a, W: Write> JsWriter<'a, W> {
|
|||||||
let mut cnt = 0;
|
let mut cnt = 0;
|
||||||
|
|
||||||
if !data.is_empty() {
|
if !data.is_empty() {
|
||||||
|
if self.line_start {
|
||||||
|
cnt += self.write_indent_string()?;
|
||||||
|
self.line_start = false;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(span) = span {
|
if let Some(span) = span {
|
||||||
if !span.is_dummy() {
|
if !span.is_dummy() {
|
||||||
self.srcmap(span.lo())
|
self.srcmap(span.lo())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.line_start {
|
|
||||||
cnt += self.write_indent_string()?;
|
|
||||||
self.line_start = false;
|
|
||||||
}
|
|
||||||
cnt += self.raw_write(data.as_bytes())?;
|
cnt += self.raw_write(data.as_bytes())?;
|
||||||
|
|
||||||
if let Some(span) = span {
|
if let Some(span) = span {
|
||||||
|
3
tests/fixture/deno-10014/case1/input/.swcrc
Normal file
3
tests/fixture/deno-10014/case1/input/.swcrc
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"sourceMaps": true
|
||||||
|
}
|
14
tests/fixture/deno-10014/case1/input/index.ts
Normal file
14
tests/fixture/deno-10014/case1/input/index.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import "./errors.ts";
|
||||||
|
|
||||||
|
function a() {
|
||||||
|
t();
|
||||||
|
}
|
||||||
|
|
||||||
|
function t(x = false) {
|
||||||
|
if (x) {
|
||||||
|
throw new Error("Hello");
|
||||||
|
}
|
||||||
|
t(!0);
|
||||||
|
}
|
||||||
|
|
||||||
|
a();
|
11
tests/fixture/deno-10014/case1/output/index.map
Normal file
11
tests/fixture/deno-10014/case1/output/index.map
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"mappings": "UAAO,WAAa;SAEX,CAAC;IACN,CAAC;;SAGI,CAAC,CAAC,KAAS;QAAT,CAAC,GAAD,KAAS,cAAL,KAAK,GAAT,KAAS;QACZ,CAAC;kBACS,KAAK,EAAC,KAAO;;IAE3B,CAAC,EAAE,CAAC;;AAGR,CAAC",
|
||||||
|
"names": [],
|
||||||
|
"sources": [
|
||||||
|
"$DIR/tests/fixture/deno-10014/case1/input/index.ts"
|
||||||
|
],
|
||||||
|
"sourcesContent": [
|
||||||
|
"import \"./errors.ts\";\n\nfunction a() {\n t();\n}\n\nfunction t(x = false) {\n if (x) {\n throw new Error(\"Hello\");\n }\n t(!0);\n}\n\na();"
|
||||||
|
],
|
||||||
|
"version": 3
|
||||||
|
}
|
12
tests/fixture/deno-10014/case1/output/index.ts
Normal file
12
tests/fixture/deno-10014/case1/output/index.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import "./errors.ts";
|
||||||
|
function a() {
|
||||||
|
t();
|
||||||
|
}
|
||||||
|
function t(param) {
|
||||||
|
var x = param === void 0 ? false : param;
|
||||||
|
if (x) {
|
||||||
|
throw new Error("Hello");
|
||||||
|
}
|
||||||
|
t(!0);
|
||||||
|
}
|
||||||
|
a();
|
@ -1 +1,11 @@
|
|||||||
{"version":3,"sources":["$DIR/tests/fixture/issue-1309/case1/input/index.ts"],"sourcesContent":["/n/nexport const foo = 1;"],"names":[],"mappings":";;;;;MAEa,GAAG,GAAG,CAAC;QAAP,GAAG,GAAH,GAAG"}
|
{
|
||||||
|
"mappings": ";;;;;MAEa,GAAG,GAAG,CAAC;QAAP,GAAG,GAAH,GAAG",
|
||||||
|
"names": [],
|
||||||
|
"sources": [
|
||||||
|
"$DIR/tests/fixture/issue-1309/case1/input/index.ts"
|
||||||
|
],
|
||||||
|
"sourcesContent": [
|
||||||
|
"\n\nexport const foo = 1;"
|
||||||
|
],
|
||||||
|
"version": 3
|
||||||
|
}
|
||||||
|
@ -611,7 +611,12 @@ fn tests(dir: PathBuf) {
|
|||||||
.compare_to_file(output.join(entry.file_name()))
|
.compare_to_file(output.join(entry.file_name()))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
NormalizedOutput::from(v.map.unwrap_or_default())
|
let map = v.map.map(|json| {
|
||||||
|
let json: serde_json::Value = serde_json::from_str(&json).unwrap();
|
||||||
|
serde_json::to_string_pretty(&json).unwrap()
|
||||||
|
});
|
||||||
|
|
||||||
|
NormalizedOutput::from(map.unwrap_or_default())
|
||||||
.compare_to_file(
|
.compare_to_file(
|
||||||
output
|
output
|
||||||
.join(entry.path().with_extension("map").file_name().unwrap()),
|
.join(entry.path().with_extension("map").file_name().unwrap()),
|
||||||
|
Loading…
Reference in New Issue
Block a user