Skip to content

Commit

Permalink
Revert "fix(common): Do not use adjust_mappings from sourcemap cr…
Browse files Browse the repository at this point in the history
…ate (swc-project#9437)"

This reverts commit 563c162.
  • Loading branch information
kdy1 committed Aug 19, 2024
1 parent d9b6412 commit f57a10b
Show file tree
Hide file tree
Showing 10 changed files with 28,361 additions and 55 deletions.
4 changes: 4 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8789/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"inputSourceMap": true,
"sourceMaps": true
}
40 changes: 40 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8789/input/a.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8789/input/a.js.map

Large diffs are not rendered by default.

24,389 changes: 24,389 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8789/output/a.js

Large diffs are not rendered by default.

3,882 changes: 3,882 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8789/output/a.map

Large diffs are not rendered by default.

18 changes: 8 additions & 10 deletions crates/swc/tests/fixture/sourcemap/004/output/index.map
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
{
"mappings": "AAACA,CAAAA,KAAKC,gBAAmB,GAAGD,KAAKC,gBAAmB,IAAI,EAAE,AAAF,EAAIC,IAAI,CAAC;IAC7D;QACI;KACH;IACD;QACU,MAAY,SAAUC,CAAuB,EAAEC,CAAmB,EAAEC,CAAmB;YACzF;YACA,IAAIC,IAAa,SAAoBC,CAAI;gBACrC,IAAIC,IAAOD,EAAKC,IAAI;gBACpB,OAAqB,AAAC,CAAA,GAAGC,EAA+CC,GAAG,AAAHA,EAAK,OAAO;oBAChFC,UAAUH,EAAKI,GAAG;gBACtB;YACJ;YACAP,EAAoBQ,CAAC,CAACT,IACDC,EAAoBS,CAAC,CAACV,GAAqB;gBACvCW,SAAS;oBAC1B,OAAqBA;gBACzB;gBACqBC,SAAS;oBAC1B,OAAqBV;gBACzB;YACJ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AAAM;wBAEd;UACA,IAAA,SAAA,CAAA,EAAA,CAAA,EAAA,CAAA,EAAA;oBACI,OAAOA,CAAAA,CAAE,EAAA,OAAA,QAAA,IAAA,EAAA,EAAA,IAAA,CAAA;gBACb;gBACH,WAAA;oBACL,OAAA,EAAA;gBACJ;aACSF,CAAC;oBAGF;YACA;IACD,SAAA,CAAA,EAAA;;;;;;mBAGP,EAAA,EAAA,CAAA",
"names": [
"self",
"webpackChunk_N_E",
"push",
"__unused_webpack_module",
"__webpack_exports__",
"__webpack_require__",
"StaticPage",
"_ref",
"n",
"t",
"u",
"r",
"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 @@ -29,7 +27,7 @@
"../../input/index.js"
],
"sourcesContent": [
"(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"
"(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"
],
"version": 3
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mappings": "AAAA,IAAMA,IAAM,cACZC,QAAQC,KAAR,CAAe,KAAY,OAARC,UAEnB,IAAMC,IAAM",
"mappings": "MCAMA,EAAM,CAAA,GAAA,UACZC,GADA,IAAMD,CACEE,KAAK,CAAC,AAAC,KAAY,OAARC,UACnB,IAAMC,IAAM",
"names": [
"xxx",
"console",
Expand All @@ -8,10 +8,12 @@
"bbb"
],
"sources": [
"unknown"
"unknown",
"../../input/index.js"
],
"sourcesContent": [
"const xxx = ', something'\nconsole.error(`❌ ${message}`);\n\nconst bbb = ''\n"
"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"
],
"version": 3
}
14 changes: 8 additions & 6 deletions crates/swc/tests/minify/issue-7475/issue-8372/1/output.map
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"mappings": "AAEAA,IAAAA,EAAQC,CAFEC,IAAA,MAAA,EAASF,QAAAC,GAAA,CAAAE",
"mappings": "YCAYC;IAAK,UAAA,CAAI;AAErBC,QAAQC,GAAG,CAACH",
"names": [
"console",
"log",
"a",
"aób",
"a"
"console",
"log"
],
"sources": [
"input-preprocess.js"
"input-preprocess.js",
"$DIR/tests/minify/issue-7475/issue-8372/1/input.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: 16 additions & 35 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,7 +1268,6 @@ 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 @@ -1300,13 +1299,11 @@ impl SourceMap {
if config.skip(&f.name) {
continue;
}
if orig.is_none() {
src_id = builder.add_source(&config.file_name_to_source(&f.name));
src_id = builder.add_source(&config.file_name_to_source(&f.name));

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));
}
let inline_sources_content = config.inline_sources_content(&f.name);
if inline_sources_content {
builder.set_source_contents(src_id, Some(&f.src));
}

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

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

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 col = chpos - linechpos;
let name = None;

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

let mut map = builder.into_sourcemap();

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

map
}
}

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", "bindings"]
"ignorePaths": ["packages/core/e2e/fixtures"]
}

0 comments on commit f57a10b

Please sign in to comment.