fix(cli): Use the source-file-name and source-root options#6973
fix(cli): Use the source-file-name and source-root options#6973kdy1 merged 8 commits intoswc-project:mainfrom
Conversation
|
CI fails due to an unrelated error |
|
I pinned the version of the sourcemap crate to 6.2 globally. |
|
After updating the sourcemap crate for - "mappings": "AAACA,CAAAA,KAAKC,gBAAmB,GAAGD,KAAKC,gBAAmB,IAAI,EAAC,AAAD,EAAIC,IAAI,CAAC;IAC7D;QACI;KACH;IACD;QACU,MAAY,SAAUC,CAAuB,EAAEC,CAAmB,EAAEC,CAAmB,EAAE;YAC3F;YACA,IAAIC,IAAa,SAAoBC,CAAI,EAAE;gBACvC,IAAIC,IAAOD,EAAKC,IAAI;gBACpB,OAAsB,CAAA,GAAGC,EAA+CC,GAAE,AAAFA,EAAK,OAAO;oBAChFC,UAAUH,EAAKI,GAAG;gBACtB;YACJ;YACAP,EAAoBQ,CAAC,CAACT,IACDC,EAAoBS,CAAC,CAACV,GAAqB;gBACvCW,SAAS,WAAoB;oBAC9C,OAAqBA;gBACzB;gBACqBC,SAAS,WAAoB;oBAC9C,OAAqBV;gBACzB;YACJ,EAAA;YACqB,IAAIG,IAAiDJ,EAAoB,OAC1FU,IAAU,CAAA;QAE1B;QACc,MAAY,SAAUZ,CAAuB,EAAEc,CAAwB,EAAEZ,CAAmB,EAAE;YAC/Fa,CAAAA,OAAOC,QAAQ,GAAGD,OAAOC,QAAQ,IAAI,EAAC,AAAD,EAAIjB,IAAI,CAAC;gBAC3C;gBACA,WAAY;oBACR,OAAOG,EAAoB;gBAC/B;aACH;QAGb;IACI;IACS,SAAUA,CAAmB,EAAE;QAK3BA,EAAoBe,CAAC,CAAC,GAAG;YAC9B;YACA;YACA;SACH,EAAE,WAAY;YACX,OAPOf,EAAoBA,EAAoBgB,CAAC,GAOxB;QAC5B,IAESC,OAD0BjB,EAAoBe,CAAC,EAAA;IAGhE;CACC",
+ "mappings": "AAACA,CAAAA,KAAKC,gBAAmB,GAAGD,KAAKC,gBAAmB,IAAI,EAAC,AAAD,EAAIC,IAAI,CAAC;IAC7D;QACI;KACH;IACD;QACU,MAAY,SAAUC,CAAuB,EAAEC,CAAmB,EAAEC,CAAmB,EAAE;YAC3F;YACA,IAAIC,IAAa,SAAoBC,CAAI,EAAE;gBACvC,IAAIC,IAAOD,EAAKC,IAAI;gBACpB,OAAqB,AAAC,CAAA,GAAGC,EAA+CC,GAAE,AAAFA,EAAK,OAAO;oBAChFC,UAAUH,EAAKI,GAAG;gBACtB;YACJ;YACAP,EAAoBQ,CAAC,CAACT,IACDC,EAAoBS,CAAC,CAACV,GAAqB;gBACvCW,SAAS,WAAoB;oBAC9C,OAAqBA;gBACzB;gBACqBC,SAAS,WAAoB;oBAC9C,OAAqBV;gBACzB;YACJ,EAAA;YACqB,IAAIG,IAAiDJ,EAAoB,OAC1FU,IAAU,CAAA;QAE1B;QACc,MAAY,SAAUZ,CAAuB,EAAEc,CAAwB,EAAEZ,CAAmB,EAAE;YAC/Fa,CAAAA,OAAOC,QAAQ,GAAGD,OAAOC,QAAQ,IAAI,EAAC,AAAD,EAAIjB,IAAI,CAAC;gBAC3C;gBACA,WAAY;oBACR,OAAOG,EAAoB;gBAC/B;aACH;QAGb;IACI;IACS,SAAUA,CAAmB,EAAE;QAK3BA,EAAoBe,CAAC,CAAC,GAAG;YAC9B;YACA;YACA;SACH,EAAE,WAAY;YACX,OAPOf,EAAoBA,EAAoBgB,CAAC,GAOxB;QAC5B,IAESC,OAD0BjB,EAAoBe,CAAC,EAAA;IAGhE;CACC",Should I revert the update of the sourcemap crate for |
|
The snapshot itself should be updated in this case. The diff is adding an additional |
|
I updated the fixture test. Thank you @kamilogorek. |
|
Blocked by servo/string-cache#271 |
a37e850 to
2123530
Compare
|
Some tests fail. GitHub actions is unable to run the git checkout step: HTTP status 429. I will retry tomorrow. |
swc-bot
left a comment
There was a problem hiding this comment.
Automated review comment generated by auto-rebase script
|
The tests basically compare the generated source maps from the sourcemap crate with the generated source maps from the Node.js terser package @kdy1 Is this a requirement to have parity with terser? The reason why the tests fail seems to be related to getsentry/rust-sourcemap#53 as mentioned by @kamilogorek in #6973 (comment). Terser uses the Node.js @jridgewell/gen-mapping package to generate source maps. Was this issue in getsentry/rust-sourcemap#53 fixed in Node.js too? Line 7266 in 447c1da Ping @jridgewell short summary: this PR updates the sourcemap crate to a version that includes your PR getsentry/rust-sourcemap#53. However, some tests are failing (see above). |
|
It does not have to be same as @jridgewell Do you have any idea? |
|
So the sourcemap itself hasn't changed: Notice those last two tokens. They have the same generated location ( In getsentry/rust-sourcemap#54, we switched from a manual greatest-lower-bound binary search to one using Rust's I think this is a bug in sourcemap, caused because I didn't really look up the binary search behavior when it was suggested we switch to the stdlib impl. For reference, my |
When we switched to Rust's `binary_search_by_key`, we accidentally changed the behavior when a token matches exactly. Before, we were guaranteed to always return the lowest index because we didn't stop iterating when we found a match. Now, we exit as soon as we find a match, which can be any matching based on the size of the slice. Fixes swc-project/swc#6973
When we switched to Rust's `binary_search_by_key`, we accidentally changed the behavior when a token matches exactly. Before, we were guaranteed to always return the lowest index because we didn't stop iterating when we found a match. Now, we exit as soon as we find a match, which can be any matching based on the size of the slice. Fixes swc-project/swc#6973
|
|
|
Ah god, I think I read it in the wrong direction. The test was failing because we received @kamilogorek: We could revert |
|
I think it's better to align with js ecosystem, so we may inline source maps for those tests. But I think it should be done in a separate PR |
|
@Swatinem what do you think? |
|
I’m not sure I fully understand the problem at hand.
I believe this might be the solution. We shouldn’t even get to the situation where there is more than one token matching (and picking the lowest or higher match). What would that even mean in sourcemaps that you have more than one token for one minified source position? |
kdy1
left a comment
There was a problem hiding this comment.
Please revert the top level Cargo.lock
|
There were no changes in the main Cargo.lock file, the git history differed. |
Adds the
--source-file-nameand--source-rootoptions to allow the user to set the source file URL to the original source file and the URL root from which all sources are relative respectively.The implementation follows the Node.js @swc/cli
https://github.com/swc-project/cli/blob/461231917181133fd2e98b954fce07b599711502/src/swc/compile.ts#L20
https://github.com/swc-project/cli/blob/461231917181133fd2e98b954fce07b599711502/src/swc/util.ts#L58-L59
Example
The
source_rootfeature was added to the sourcemap crate in v6.2.0 (kudos @kamilogorek).Related
compileto feature parity to @swc/cli #4017