fix(es/codegen): Fix sourcemap (#3003)

swc_ecma_codegen:
 - Handle source map of multi-line template literals. (Closes #2185, Closes #2362, Closes #2900)
This commit is contained in:
Donny/강동윤 2021-12-10 19:57:39 +09:00 committed by GitHub
parent 57f512c262
commit a3bd6aea54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 78 additions and 7 deletions

4
Cargo.lock generated
View File

@ -2695,7 +2695,7 @@ dependencies = [
[[package]]
name = "swc_ecma_codegen"
version = "0.83.0"
version = "0.83.1"
dependencies = [
"bitflags",
"memchr",
@ -3826,7 +3826,7 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasm"
version = "1.2.118"
version = "1.2.119"
dependencies = [
"anyhow",
"console_error_panic_hook",

View File

@ -1,5 +1,5 @@
{
"mappings": "CEACA,IAAI,CAAC,gBAAkB,GAAIA,IAAI,CAAC,gBAAkB,IAAK,CAAC,CAAC,EAAEC,IAAI,CAAC,CAAC;IAAA,CAAC;QAAA,GAAG;IAAA,CAAC;IAAE,CAAC;QAEhE,IAAI,EACH,QAAQ,CAAEC,CAAuB,EAAEC,CAAmB,EAAEC,CAAmB,EAAE,CAAC;YAE7E,CAAY;gBFJtBC,CAAO,GAAP,QAAA,CAAOC,CAAA,EAAA,CAAA;gBAAM,GAAK,CAAAC,CAAA,GAAAD,CAAA,CAAAC,IAAA;gBAAlB,MAAA,KAAAC,CAAA,CAAAC,GAAA,EAAA,CAAA,MAAA,CAAA;oBACDC,QAAA,EAAAH,CAAA,CAAAI,GAAA;gBAAA,CAAA;YAAA,CAAA;YAIWP,CAAmB,CAACQ,CAAC,CAACT,CAAmB,GAC5BC,CAAmB,CAACS,CAAC,CAACV,CAAmB,EAAE,CAAC;gBAC1C,CAAS,UAAE,QAAQ,GAAI,CAAC;oBAAC,MAAM,CAAeW,CAAO;gBAAE,CAAC;gBACxD,CAAS,UAAE,QAAQ,GAAI,CAAC;oBAAC,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AmB,CAACQ,CAAC,CAACT,CAAmB,GAC5BC,CAAmB,CAACS,CAAC,CAACV,CAAmB,EAAE,CAAC;gBAC1C,CAAS,UAAE,QAAQ,GAAI,CAAC;oBAAC,MAAM,CAAeW,CAAO;gBAAE,CAAC;gBACxD,CAAS,UAAE,QAAQ,GAAI,CAAC;oBAAC,MAAM,CAAeT,CAAU;gBAAE,CAAC;YAE1E,CAAC;YACY,GAAG,CAACG,CAA8C,GAAGJ,CAAmB,CAAC,IAAI,GAZzDU,CAAA,IAAA,CAAA;QAE5C,CAAA;AAAA,YAAA,ECDD,QAAA,CAAAZ,CAAA,EAAAa,CAAA,EAAAX,CAAA,EAAA,CAAA;aAGAY,MAAe,CAAAC,QAAA,GAAAD,MAAQ,CAAAC,QAA8B,IAAA,CAAA,CAAA,EAAAhB,IAAA,CAAA,CAAA;gBACrD,CAAA;gBACA,QAAA,GAAA,CAAA;oBAKK,MAAA,CAAAG,CAAA,CAAA,IAAA;gBACL,CAAA;YAAA,CAAA;QAAA,CAAA;IAAA,CAAA;IAAA,QAAA,CAAAA,CAAA,EAAA,CAAA;QAAAA,CAAA,CAAAc,CAAA,CAAA,CAAA,EAAA,CAAA;AAAA,eAAA;AAAA,eAAA;AAAA,eAAA;QAAA,CAAA,EAAA,QAAA,GAAA,CAAA;YAAA,MAAA,CAAAd,CAAA,CAAAA,CAAA,CAAAe,CAAA,GAAA,IAAA;QAAA,CAAA,GAAAC,IAAA,GAAAhB,CAAA,CAAAc,CAAA;IAAA,CAAA;AAAA,CAAA",
"names": [
"self",
"push",

View File

@ -0,0 +1,6 @@
{
"sourceMaps": true,
"jsc": {
"target": "es2015"
}
}

View File

@ -0,0 +1,17 @@
describe("foo", () => {
it("test1", () => {
expect(false).toBe(true);
});
it("test2", () => {
const str = `
bar
`;
expect(false).toBe(true);
});
it("test3", () => {
expect(false).toBe(true);
});
});

View File

@ -0,0 +1,14 @@
describe("foo", ()=>{
it("test1", ()=>{
expect(false).toBe(true);
});
it("test2", ()=>{
const str = `
bar
`;
expect(false).toBe(true);
});
it("test3", ()=>{
expect(false).toBe(true);
});
});

View File

@ -0,0 +1,17 @@
{
"mappings": "AAAAA,QAAQ,CAAC,CAAK,UAAQ,CAAC;IACnBC,EAAE,CAAC,CAAO,YAAQ,CAAC;QACfC,MAAM,CAAC,KAAK,EAAEC,IAAI,CAAC,IAAI;IAC3B,CAAC;IAEDF,EAAE,CAAC,CAAO,YAAQ,CAAC;QACf,KAAK,CAACG,GAAG,IAAI;;MAEf;QAEEF,MAAM,CAAC,KAAK,EAAEC,IAAI,CAAC,IAAI;IAC3B,CAAC;IAEDF,EAAE,CAAC,CAAO,YAAQ,CAAC;QACfC,MAAM,CAAC,KAAK,EAAEC,IAAI,CAAC,IAAI;IAC3B,CAAC;AACL,CAAC",
"names": [
"describe",
"it",
"expect",
"toBe",
"str"
],
"sources": [
"../../input/index.js"
],
"sourcesContent": [
"describe(\"foo\", () => {\n it(\"test1\", () => {\n expect(false).toBe(true);\n });\n\n it(\"test2\", () => {\n const str = `\n bar\n `;\n\n expect(false).toBe(true);\n });\n\n it(\"test3\", () => {\n expect(false).toBe(true);\n });\n});"
],
"version": 3
}

View File

@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0"
name = "swc_ecma_codegen"
repository = "https://github.com/swc-project/swc.git"
version = "0.83.0"
version = "0.83.1"
[dependencies]
bitflags = "1"

View File

@ -188,7 +188,24 @@ impl<'a, W: Write> WriteJs for JsWriter<'a, W> {
}
fn write_str_lit(&mut self, span: Span, s: &str) -> Result {
self.write(Some(span), s)?;
if !s.is_empty() {
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 = s.len() - line_start_of_s.last().cloned().unwrap_or(0);
}
if !span.is_dummy() {
self.srcmap(span.hi())
}
}
Ok(())
}

View File

@ -6,7 +6,7 @@ license = "Apache-2.0"
name = "wasm"
publish = false
repository = "https://github.com/swc-project/swc.git"
version = "1.2.118"
version = "1.2.119"
[lib]
crate-type = ["cdylib"]

View File

@ -1,6 +1,6 @@
{
"name": "@swc/core",
"version": "1.2.118",
"version": "1.2.119",
"description": "Super-fast alternative for babel",
"homepage": "https://swc.rs",
"main": "./index.js",