monocart-coverage-reports 2.6.4 → 2.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -97,6 +97,7 @@ const getBlockEndPosition = (originalLineText) => {
97
97
  // generatedPos: 17,
98
98
  // originalText: ' }}</slot>'
99
99
 
100
+ // end marks
100
101
  const list = ['>', '}', ')'];
101
102
  for (const s of list) {
102
103
  const endBlockIndex = originalLineText.lastIndexOf(s);
@@ -116,7 +117,11 @@ const getBlockEndPosition = (originalLineText) => {
116
117
 
117
118
  };
118
119
 
119
- const getComparedPosition = (gt, gp, ot, direction) => {
120
+ const getComparedPosition = (info, direction) => {
121
+
122
+ let gt = info.generatedText;
123
+ const gp = info.generatedPos;
124
+ let ot = info.originalText;
120
125
 
121
126
  // before trim
122
127
  const oLen = ot.length;
@@ -175,45 +180,54 @@ const getComparedPosition = (gt, gp, ot, direction) => {
175
180
 
176
181
  // ============================
177
182
  // right matched
183
+ // only for original first line text
178
184
 
185
+ const olt = info.originalLineText;
179
186
  const right = gt.slice(gp);
180
- if (ot.endsWith(right)) {
187
+ if (olt.endsWith(right)) {
181
188
  return {
182
- pos: ot.length - right.length
189
+ pos: olt.length - right.length
183
190
  };
184
191
  }
185
192
 
186
193
  };
187
194
 
195
+ const initOriginalLineText = (info) => {
196
+ const originalText = info.originalText;
197
+ // never cross line, using first line of original text
198
+ // trim end remove \r\n and \n
199
+ const originalLines = originalText.split(/\n/);
200
+ if (originalLines.length === 1) {
201
+ // already single line
202
+ info.originalLineText = originalText.trimEnd();
203
+ info.originalSingle = true;
204
+ return;
205
+ }
206
+ // multiple liens
207
+ info.originalLineText = originalLines[0].trimEnd();
208
+ };
209
+
188
210
  const getSimilarPosition = (info, direction) => {
189
211
 
190
- const {
191
- generatedText, generatedPos, originalText
192
- } = info;
212
+ initOriginalLineText(info);
193
213
 
194
- const textPos = getComparedPosition(generatedText, generatedPos, originalText, direction);
214
+ const textPos = getComparedPosition(info, direction);
195
215
  if (textPos) {
196
216
  return textPos;
197
217
  }
198
218
 
199
- // never cross line, using first line of original text
200
- // trim end remove \r\n and \n
201
- const originalLines = originalText.split(/\n/);
202
- if (originalLines.length === 1) {
203
- // already single line
204
- info.originalLineText = originalText;
219
+ if (info.originalSingle) {
205
220
  return;
206
221
  }
207
222
 
208
- const originalLineText = originalLines[0].trimEnd();
209
- info.originalLineText = originalLineText;
210
-
223
+ // multiple lines
224
+ const { generatedPos, originalLineText } = info;
211
225
  // generatedPos not in first line
212
226
  if (generatedPos > originalLineText.length) {
213
227
  return;
214
228
  }
215
229
 
216
- const linePos = getComparedPosition(generatedText, generatedPos, originalLineText, direction);
230
+ const linePos = getComparedPosition(info, direction);
217
231
  if (linePos) {
218
232
  return linePos;
219
233
  }
@@ -236,6 +250,7 @@ const getFixedPosition = (info, direction) => {
236
250
  return similarPos.pos;
237
251
  }
238
252
 
253
+
239
254
  // generatedText: never cross lines
240
255
  // originalText: could be multiple lines
241
256
  // originalLineText: single line originalText
@@ -266,7 +281,7 @@ const getOriginalEndOffset = (m, rangeInfo) => {
266
281
  return m.originalEndOffset;
267
282
  };
268
283
 
269
- const getOriginalText = (m1, m2, rangeInfo, direction) => {
284
+ const getOriginalText = (m1, m2, rangeInfo) => {
270
285
  const originalLocator = rangeInfo.originalState.locator;
271
286
 
272
287
  const o1 = m1.originalOffset;
@@ -383,15 +398,17 @@ const getFixedOriginalStart = (start, mappings, state, rangeInfo) => {
383
398
  }
384
399
 
385
400
  const direction = 'start';
386
- const { originalText, originalOffset } = getOriginalText(m1, m2, rangeInfo, direction);
401
+ const { originalText, originalOffset } = getOriginalText(m1, m2, rangeInfo);
387
402
  const { generatedText, generatedPos } = getGeneratedText(m1, m2, state, start);
388
403
 
389
- const originalPos = getFixedPosition({
404
+ const info = {
390
405
  generatedText,
391
406
  generatedPos,
392
407
  originalText,
393
408
  originalState
394
- }, direction);
409
+ };
410
+
411
+ const originalPos = getFixedPosition(info, direction);
395
412
 
396
413
  // if (start === 2660) {
397
414
  // console.log('=====================================================');
@@ -437,7 +454,8 @@ const getFixedOriginalEnd = (end, mappings, state, rangeInfo) => {
437
454
  const gt = state.locator.source[end];
438
455
  const oi = m2.originalOffset - 1;
439
456
  const ot = originalState.locator.source[oi];
440
- if (gt === ot) {
457
+ // it could be ; but it quite far away
458
+ if (gt === ot && [';', ','].includes(gt)) {
441
459
  return {
442
460
  originalEnd: oi
443
461
  };
@@ -456,24 +474,28 @@ const getFixedOriginalEnd = (end, mappings, state, rangeInfo) => {
456
474
  }
457
475
 
458
476
  const direction = 'end';
459
- const { originalText, originalOffset } = getOriginalText(m1, m2, rangeInfo, direction);
477
+ const { originalText, originalOffset } = getOriginalText(m1, m2, rangeInfo);
460
478
  const { generatedText, generatedPos } = getGeneratedText(m1, m2, state, end);
461
479
 
462
- const originalPos = getFixedPosition({
480
+ const info = {
481
+ offset: end,
463
482
  generatedText,
464
483
  generatedPos,
465
484
  originalText,
466
485
  originalState
467
- }, direction);
486
+ };
468
487
 
469
- // if (end === 2858) {
488
+ const originalPos = getFixedPosition(info, direction);
489
+
490
+ // if (end === 1304578) {
470
491
  // console.log('=====================================================');
471
492
  // console.log('fixed end', originalState.sourcePath);
472
493
  // console.log({
473
494
  // generatedText,
474
495
  // generatedPos,
475
496
  // originalText,
476
- // originalPos
497
+ // originalPos,
498
+ // originalLineText: info.originalLineText
477
499
  // });
478
500
  // }
479
501