Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(common): Do not use adjust_mappings from sourcemap crate #9437

Merged
merged 6 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/poor-guests-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
swc_common: patch
---

fix(common): Do not use `adjust_mappings`
5,073 changes: 3,741 additions & 1,332 deletions crates/swc/tests/fixture/issues-8xxx/8789/output/a.map

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions crates/swc/tests/fixture/sourcemap/004/output/index.map
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
{
"mappings": "AAACA,MAAKC,gBAAmBD,AAAH,GAAGA,EAAKC,GAAAA,aAAgB,GAAK,CAAD,CAAIC,EAAAA,EAAAA,AAAI,CAAC,CAAA,IAAA,CAAA;IACvD;QACI;KACH;IACD;QACU,MAAYE,CAAC,EAAEC,AAANF,CAAO,AAAN,KAAM,CAAA,EAAA,CAAA,EAAA,CAAA,EAAA;YAClB;YACA,IAAIG,IAAI,AAASH,CAAC,QAAA,CAAA,EAAA;gBACd,IAAIC,IAAMG,AAAFJ,EAAEI,AAAI,CAAA,GAAA;gBACd,OAAO,AAAC,AAAU,CAAV,AAAU,GAAPC,AAAc,EAAZC,AAAY,GAAA,AAAV,AAAU,AAAT,EAAE,AAAO,OAAA;oBACrBC,UAAUN,EAAEO,AAAG,GAAA;gBACnB;YACJ;YACAN,EAAEC,AAAa,CAAZ,AAAY,CAAXF,AAAW,IAAPC,AACK,EADHO,AACG,CADF,AACE,CAAA,AADDR,GACC,AADE;gBAEAU,SAAAA,WAAAA;oBACX,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AC,CAAC,GAAG;YAC9B;YACA;YACA;SACH,EAAE;YACC,OAPOf,EAAoBA,EAAoBgB,CAAC,GAOxB;QAC5B,IAESC,OAD0BjB,EAAoBe,CAAC;IAGhE;CACC",
"names": [
"self",
"webpackChunk_N_E",
"push",
"n",
"t",
"u",
"r",
"__unused_webpack_module",
"__webpack_exports__",
"__webpack_require__",
"StaticPage",
"_ref",
"data",
"_",
"react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__",
"jsx",
"children",
"foo",
"r",
"d",
"__N_SSG",
"i",
"default",
"__unused_webpack_exports",
"window",
"__NEXT_P",
"O",
Expand All @@ -27,7 +29,7 @@
"../../input/index.js"
],
"sourcesContent": [
"(self.webpackChunk_N_E = self.webpackChunk_N_E || []).push([\n [\n 158\n ],\n {\n 2943: function(n, t, u) {\n \"use strict\";\n var r = function(n) {\n var t = n.data;\n return (0, _.jsx)(\"div\", {\n children: t.foo\n });\n };\n u.r(t), u.d(t, {\n __N_SSG: function() {\n return i;\n },\n default: function() {\n return r;\n }\n });\n var _ = u(4512), i = !0;\n },\n 7139: function(n, t, u) {\n (window.__NEXT_P = window.__NEXT_P || []).push([\n \"/static\",\n function() {\n return u(2943);\n }\n ]);\n }\n },\n function(n) {\n n.O(0, [\n 774,\n 888,\n 179\n ], function() {\n return n(n.s = 7139);\n }), _N_E = n.O();\n }\n]);\n"
"(self[\"webpackChunk_N_E\"] = self[\"webpackChunk_N_E\"] || []).push([\n [\n 158\n ],\n {\n /***/ 2943: /***/ function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {\n \"use strict\";\n var StaticPage = function StaticPage(_ref) {\n var data = _ref.data;\n return /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(\"div\", {\n children: data.foo\n });\n };\n __webpack_require__.r(__webpack_exports__);\n /* harmony export */ __webpack_require__.d(__webpack_exports__, {\n /* harmony export */ __N_SSG: function __N_SSG1() {\n return /* binding */ __N_SSG;\n },\n /* harmony export */ default: function _default() {\n return /* binding */ StaticPage;\n }\n });\n /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4512);\n var __N_SSG = true;\n /***/\n},\n /***/ 7139: /***/ function (__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {\n (window.__NEXT_P = window.__NEXT_P || []).push([\n \"/static\",\n function () {\n return __webpack_require__(2943);\n }\n ]);\n if (false) { }\n /***/\n}\n },\n /******/ function (__webpack_require__) {\n // webpackRuntimeModules\n /******/ var __webpack_exec__ = function __webpack_exec__(moduleId) {\n return __webpack_require__(__webpack_require__.s = moduleId);\n };\n /******/ __webpack_require__.O(0, [\n 774,\n 888,\n 179\n ], function () {\n return __webpack_exec__(7139);\n });\n /******/ var __webpack_exports__ = __webpack_require__.O();\n /******/ _N_E = __webpack_exports__;\n /******/\n}\n]);\n"
],
"version": 3
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mappings": "MCAMA,EAAM,CAAA,GAAA,UACZC,GADA,IAAMD,CACEE,KAAK,CAAC,AAAC,KAAY,OAARC,UACnB,IAAMC,IAAM",
"mappings": "AAAA,IAAMA,IAAM,cACZC,QAAQC,KAAR,CAAe,KAAY,OAARC,UAEnB,IAAMC,IAAM",
"names": [
"xxx",
"console",
Expand All @@ -8,12 +8,10 @@
"bbb"
],
"sources": [
"unknown",
"../../input/index.js"
"unknown"
],
"sourcesContent": [
"const xxx = ', something'\nconsole.error(`❌ ${message}`);\n\nconst bbb = ''\n",
"const xxx = ', something';\nconsole.error(`❌ ${message}`);\nconst bbb = '';\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJ4eHgiLCJjb25zb2xlIiwiZXJyb3IiLCJtZXNzYWdlIiwiYmJiIl0sInNvdXJjZXMiOlsidW5rbm93biJdLCJzb3VyY2VzQ29udGVudCI6WyJjb25zdCB4eHggPSAnLCBzb21ldGhpbmcnXG5jb25zb2xlLmVycm9yKGDinYwgJHttZXNzYWdlfWApO1xuXG5jb25zdCBiYmIgPSAnJ1xuIl0sIm1hcHBpbmdzIjoiQUFBQSxNQUFNQSxHQUFHLEdBQUcsYUFBWjtBQUNBQyxPQUFPLENBQUNDLEtBQVIsQ0FBZSxLQUFJQyxPQUFRLEVBQTNCO0FBRUEsTUFBTUMsR0FBRyxHQUFHLEVBQVoifQ==\n"
"const xxx = ', something'\nconsole.error(`❌ ${message}`);\n\nconst bbb = ''\n"
],
"version": 3
}
14 changes: 6 additions & 8 deletions crates/swc/tests/minify/issue-7475/issue-8372/1/output.map
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{
"mappings": "YCAYC;IAAK,UAAA,CAAI;AAErBC,QAAQC,GAAG,CAACH",
"mappings": "AAEAA,IAAAA,EAAQC,CAFEC,IAAA,MAAA,EAASF,QAAAC,GAAA,CAAAE",
"names": [
"a",
"aób",
"console",
"log"
"log",
"aób",
"a"
],
"sources": [
"input-preprocess.js",
"$DIR/tests/minify/issue-7475/issue-8372/1/input.js"
"input-preprocess.js"
],
"sourcesContent": [
"const a = {aób: 'ó'}\n\nconsole.log(a)",
"const a = { aób: 'ó' }\n\nconsole.log(a)"
"const a = {aób: 'ó'}\n\nconsole.log(a)"
],
"version": 3
}
51 changes: 35 additions & 16 deletions crates/swc_common/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ impl SourceMap {

let mut src_id = 0u32;

if let Some(orig) = &orig {
if let Some(orig) = orig {
for src in orig.sources() {
let id = builder.add_source(src);
src_id = id;
Expand All @@ -1268,6 +1268,7 @@ impl SourceMap {

let mut prev_dst_line = u32::MAX;

let mut inline_sources_content = false;
let mut ch_state = ByteToCharPosState::default();
let mut line_state = ByteToCharPosState::default();

Expand Down Expand Up @@ -1299,11 +1300,13 @@ impl SourceMap {
if config.skip(&f.name) {
continue;
}
src_id = builder.add_source(&config.file_name_to_source(&f.name));
if orig.is_none() {
src_id = builder.add_source(&config.file_name_to_source(&f.name));

let inline_sources_content = config.inline_sources_content(&f.name);
if inline_sources_content {
builder.set_source_contents(src_id, Some(&f.src));
inline_sources_content = config.inline_sources_content(&f.name);
if inline_sources_content && orig.is_none() {
builder.set_source_contents(src_id, Some(&f.src));
}
}

ch_state = ByteToCharPosState::default();
Expand All @@ -1323,7 +1326,7 @@ impl SourceMap {
continue;
}

let line = match f.lookup_line(pos) {
let mut line = match f.lookup_line(pos) {
Some(line) => line as u32,
None => continue,
};
Expand All @@ -1349,8 +1352,31 @@ impl SourceMap {
linechpos,
);

let col = chpos - linechpos;
let name = None;
let mut col = chpos - linechpos;
let mut name = None;
if let Some(orig) = &orig {
if let Some(token) = orig
.lookup_token(line, col)
.filter(|t| t.get_dst_line() == line)
{
line = token.get_src_line();
col = token.get_src_col();
if token.has_name() {
name = token.get_name();
}
if token.get_source().is_some() {
// When we have the original source map, we use the source ids from it
src_id = token.get_raw_token().src_id;
if inline_sources_content && !builder.has_source_contents(src_id) {
if let Some(contents) = token.get_source_view() {
builder.set_source_contents(src_id, Some(contents.source()));
}
}
}
} else {
continue;
}
}

let name_idx = name
.or_else(|| config.name_for_bytepos(pos))
Expand All @@ -1359,14 +1385,7 @@ impl SourceMap {
builder.add_raw(lc.line, lc.col, line, col, Some(src_id), name_idx, false);
prev_dst_line = lc.line;
}

let mut map = builder.into_sourcemap();

if let Some(orig) = orig {
map.adjust_mappings(orig)
}

map
builder.into_sourcemap()
}
}

Expand Down
2 changes: 1 addition & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
"automerge": true
}
],
"ignorePaths": ["packages/core/e2e/fixtures"]
"ignorePaths": ["packages/core/e2e/fixtures", "bindings"]
}
Loading