Skip to content

Commit

Permalink
fixed same line issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jun 29, 2024
1 parent d2735b2 commit 72efeae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
31 changes: 18 additions & 13 deletions lib/converter/find-original-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ const getAlignPosition = (info, direction) => {
// info.state.textLength.push(gt.length);
// info.state.textLength.push(ot.length);

// const it = {
// gt, ot, gp
// };
// info.state.alignTextList.push(it);

// there is no need to align for long text
const maxLength = 100;
if (gt.length > maxLength || ot.length > maxLength) {
Expand All @@ -198,11 +203,6 @@ const getAlignPosition = (info, direction) => {
// right matched
// only for original first line text

// const it = {
// gt, ot, gp
// };
// info.state.alignTextList.push(it);

// exclusive
const list = alignText(gt, ot, info);
const item = list[gp];
Expand Down Expand Up @@ -438,6 +438,7 @@ const getOriginalText = (m1, m2, cache) => {

const o1 = m1.originalOffset;
const o2 = m2.originalOffset;
const sameLine = m2.originalLine === m1.originalLine;

// o1 < o2: most of time
if (o1 < o2) {
Expand All @@ -452,28 +453,33 @@ const getOriginalText = (m1, m2, cache) => {
// };
// }

if (sameLine) {
return {
originalOffset: o1,
originalText: originalLocator.getSlice(o1, o2)
};
}

// could be multiple lines for original text
return {
originalOffset: o1,
originalText: originalLocator.getSlice(o1, o2)
originalText: originalLocator.getSlice(o1, getOriginalEndOffset(m1, cache))
};
}

// esbuild fixing two mapping have same original
// m1 to end line
if (o1 === o2) {
const originalEndOffset = getOriginalEndOffset(m1, cache);
return {
originalOffset: o1,
originalText: originalLocator.getSlice(o1, originalEndOffset)
originalText: originalLocator.getSlice(o1, getOriginalEndOffset(m1, cache))
};
}

// o1 > o2: should be wrong sourcemap

// just reverse offsets if few cross lines
const crossLines = m1.originalLine - m2.originalLine;
if (crossLines < 2) {
// just reverse offsets if same line
if (sameLine) {
return {
originalOffset: o2,
originalText: originalLocator.getSlice(o2, o1)
Expand All @@ -487,10 +493,9 @@ const getOriginalText = (m1, m2, cache) => {
// }

// should be wrong, ignore m2
const originalEndOffset = getOriginalEndOffset(m1, cache);
return {
originalOffset: o1,
originalText: originalLocator.getSlice(o1, originalEndOffset)
originalText: originalLocator.getSlice(o1, getOriginalEndOffset(m1, cache))
};

};
Expand Down
8 changes: 4 additions & 4 deletions test/snapshot/minify.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"statements": "39.42 %",
"branches": "25.37 %",
"functions": "42.80 %",
"lines": "36.71 %"
"lines": "36.73 %"
},
"files": {
"localhost-8130/demo.js": {
Expand Down Expand Up @@ -244,9 +244,9 @@
"functions": "27.78 %",
"branches": "7.14 %",
"statements": "22.86 %",
"lines": "31.10 %",
"bytes": "26.28 %",
"uncoveredLines": "31-250,254-290,309-347,360,365-367,370-398"
"lines": "31.90 %",
"bytes": "27.04 %",
"uncoveredLines": "31-250,254-290,309-347,360,365-366,372-398"
},
"monocart-v8/packages/v8/src/app.vue/5edf": {
"functions": "",
Expand Down

0 comments on commit 72efeae

Please sign in to comment.