fix(es/codegen): Fix sourcemap of multiline comments (#5299)

This commit is contained in:
Donny/강동윤 2022-07-26 13:02:50 +09:00 committed by GitHub
parent 0ddeb749f6
commit 3100bf8c62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 112 additions and 15 deletions

View File

@ -1,5 +1,5 @@
{
"mappings": "AAAAA,CAAC,EAAE,CAAC,6BAA6B,CAA9B,CAA+B",
"mappings": "AAAAA,CAAC,EAAE,CAAC,2BAA2B,GAA5B,CAA+B",
"names": [
"a"
],

View File

@ -1,5 +1,5 @@
{
"mappings": "AAAAA,CAAC,EAAE,CAAC,6BAA6B,CAA9B,CAA+B",
"mappings": "AAAAA,CAAC,EAAE,CAAC,2BAA2B,GAA5B,CAA+B",
"names": [
"a"
],

View File

@ -1,5 +1,5 @@
{
"mappings": "AAAAA,CAAC,EAAE,CAAC,CAAC,KAAK;AAEVA,CAAC,EAAE,CAAC,CAAC,GAAG;AAERA,CAAC,EAAE,CAAC,CAAC,KAAK;AAEVA,CAAC,EAAE,CAAC,CAAC,GAAG",
"mappings": "AAAAA,CAAC,EAAE,CAAC,CAAC,GAAG;AAERA,CAAC,EAAE,CAAC,CAAC,GAAG;AAERA,CAAC,EAAE,CAAC,CAAC,GAAG;AAERA,CAAC,EAAE,CAAC,CAAC,GAAG",
"names": [
"a"
],

View File

@ -0,0 +1,3 @@
{
"sourceMaps": true
}

View File

@ -0,0 +1,11 @@
/*!
something v5.1.0
more
else
*/
// a
console.log(1);
// b

View File

@ -0,0 +1,9 @@
/*!
something v5.1.0
more
else
*/ // a
console.log(1); // b

View File

@ -0,0 +1,14 @@
{
"mappings": "AAAA;;;;;;;AAOA,GACA,IAAI;AACJA,OAAO,CAACC,GAAG,CAAC,CAAC,CAAC,CAAC,CACf,IAAI",
"names": [
"console",
"log"
],
"sources": [
"../../input/index.js"
],
"sourcesContent": [
"/*!\n\n something v5.1.0\n\nmore\n\nelse\n*/\n// a\nconsole.log(1);\n// b"
],
"version": 3
}

View File

@ -1,5 +1,5 @@
{
"mappings": "AAAA;;GAEG,CACH,OAAO,IAAMA,WAAW,GAAG,SAACC,IAAI,EAAK;IACjCC,OAAO,CAACC,GAAG,CAACF,IAAI,CAAC,CAAC;IAClBC,OAAO,CAACC,GAAG,CAACF,IAAI,CAAC,CAAC;IAClBC,OAAO,CAACC,GAAG,CAACF,IAAI,CAAC,CAAC;IAClBC,OAAO,CAACC,GAAG,CAACF,IAAI,CAAC,CAAC;CACrB,CAAC",
"mappings": "AAAA;;CAEC,GACD,OAAO,IAAMA,WAAW,GAAG,SAACC,IAAI,EAAK;IACjCC,OAAO,CAACC,GAAG,CAACF,IAAI,CAAC,CAAC;IAClBC,OAAO,CAACC,GAAG,CAACF,IAAI,CAAC,CAAC;IAClBC,OAAO,CAACC,GAAG,CAACF,IAAI,CAAC,CAAC;IAClBC,OAAO,CAACC,GAAG,CAACF,IAAI,CAAC,CAAC;CACrB,CAAC",
"names": [
"LogSomeText",
"text",

View File

@ -1,5 +1,5 @@
{
"mappings": "AAAAA;AAAAA,QAAQ,CAAC,oBAAoB,EAAE,IAAM;IACjCC,EAAE,CAAC,OAAO,EAAE,IAAM;QACdC,MAAM,CAAC,KAAK,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC5B,CAAC,CAAC;IAEHF,EAAE,CAAC,OAAO,EAAE,IAAM;QACd,IAAI,CACJC,MAAM,CAAC,KAAK,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC5B,CAAC,CAAC;IAEHF,EAAE,CAAC,OAAO,EAAE,IAAM;QACd;;WAEG,CACHC,MAAM,CAAC,KAAK,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC5B,CAAC,CAAC;IAEHF,EAAE,CAAC,OAAO,EAAE,IAAM;QACdC,MAAM,CAAC,KAAK,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC5B,CAAC,CAAC;CACN,CAAC,CAAC",
"mappings": "AAAAA;AAAAA,QAAQ,CAAC,oBAAoB,EAAE,IAAM;IACjCC,EAAE,CAAC,OAAO,EAAE,IAAM;QACdC,MAAM,CAAC,KAAK,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC5B,CAAC,CAAC;IAEHF,EAAE,CAAC,OAAO,EAAE,IAAM;QACd,EAAE,GACFC,MAAM,CAAC,KAAK,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC5B,CAAC,CAAC;IAEHF,EAAE,CAAC,OAAO,EAAE,IAAM;QACd;;SAEC,GACDC,MAAM,CAAC,KAAK,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC5B,CAAC,CAAC;IAEHF,EAAE,CAAC,OAAO,EAAE,IAAM;QACdC,MAAM,CAAC,KAAK,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC5B,CAAC,CAAC;CACN,CAAC,CAAC",
"names": [
"describe",
"it",

View File

@ -1,5 +1,5 @@
{
"mappings": "AAAA;;;;;GAKG,CACHA;AAAAA,OAAO,CAACC,GAAG,CAAC,IAAIC,KAAK,EAAE,CAACC,KAAK,CAAC,CAAC",
"mappings": "AAAA;;;;;CAKC,GACDA;AAAAA,OAAO,CAACC,GAAG,CAAC,IAAIC,KAAK,EAAE,CAACC,KAAK,CAAC,CAAC",
"names": [
"console",
"log",

View File

@ -1,5 +1,5 @@
{
"mappings": "AAAAA,CAAC,EAAE,CAAC,CAAC,KAAK",
"mappings": "AAAAA,CAAC,EAAE,CAAC,CAAC,GAAG",
"names": [
"a"
],

View File

@ -29,10 +29,16 @@ macro_rules! write_comments {
srcmap!($e, cmt, true);
$e.wr.write_comment("/*")?;
$e.wr.write_lit(DUMMY_SP, &cmt.text)?;
$e.wr.write_comment(&cmt.text)?;
{
let hi = cmt.span_hi();
if !hi.is_dummy() && hi.0 > 2 {
$e.wr.add_srcmap(hi - swc_common::BytePos(2))?;
}
}
$e.wr.write_comment("*/")?;
srcmap!($e, cmt, false);
$e.wr.write_space()?;
}
}

View File

@ -0,0 +1,11 @@
/*!
something v5.1.0
more
else
*/
// a
console.log(1);
// b

View File

@ -0,0 +1,34 @@
> Leading (lo)
Error:
> !
|
| something v5.1.0
|
| more
|
| else
|
,-[$DIR/tests/comments/issue-4876/input.js:10:1]
10 | console.log(1);
: ^
`----
> Leading (lo)
Error:
> a
,-[$DIR/tests/comments/issue-4876/input.js:10:1]
10 | console.log(1);
: ^
`----
> Trailing (hi)
Error:
> b
,-[$DIR/tests/comments/issue-4876/input.js:10:1]
10 | console.log(1);
: ^
`----

View File

@ -4,13 +4,22 @@ set -u
export UPDATE=1
export DIFF=0
function up(){
cargo test -p swc -p swc_ecma_codegen -p swc_ecma_parser -p swc_bundler -p swc_node_bundler --no-fail-fast
function crate() {
until cargo test -p $1 --no-fail-fast
do
git add -A
git commit -m 'Update test refs'
done
git add -A
git commit -m 'Update test refs'
}
up
crate swc
crate swc_ecma_codegen
crate swc_ecma_parser
crate swc_bundler
crate swc_node_bundler
crate swc_ecma_transforms_react
git add -A
git commit -m 'Update test refs'
git push -u origin "$(git rev-parse --abbrev-ref HEAD)" --no-verify