@vue/shared 3.1.1 → 3.1.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.
@@ -54,11 +54,20 @@ const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
54
54
 
55
55
  const range = 2;
56
56
  function generateCodeFrame(source, start = 0, end = source.length) {
57
- const lines = source.split(/\r?\n/);
57
+ // Split the content into individual lines but capture the newline sequence
58
+ // that separated each line. This is important because the actual sequence is
59
+ // needed to properly take into account the full line length for offset
60
+ // comparison
61
+ let lines = source.split(/(\r?\n)/);
62
+ // Separate the lines and newline sequences into separate arrays for easier referencing
63
+ const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
64
+ lines = lines.filter((_, idx) => idx % 2 === 0);
58
65
  let count = 0;
59
66
  const res = [];
60
67
  for (let i = 0; i < lines.length; i++) {
61
- count += lines[i].length + 1;
68
+ count +=
69
+ lines[i].length +
70
+ ((newlineSequences[i] && newlineSequences[i].length) || 0);
62
71
  if (count >= start) {
63
72
  for (let j = i - range; j <= i + range || end > count; j++) {
64
73
  if (j < 0 || j >= lines.length)
@@ -66,9 +75,10 @@ function generateCodeFrame(source, start = 0, end = source.length) {
66
75
  const line = j + 1;
67
76
  res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
68
77
  const lineLength = lines[j].length;
78
+ const newLineSeqLength = (newlineSequences[j] && newlineSequences[j].length) || 0;
69
79
  if (j === i) {
70
80
  // push underline
71
- const pad = start - (count - lineLength) + 1;
81
+ const pad = start - (count - (lineLength + newLineSeqLength));
72
82
  const length = Math.max(1, end > count ? lineLength - pad : end - start);
73
83
  res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
74
84
  }
@@ -77,7 +87,7 @@ function generateCodeFrame(source, start = 0, end = source.length) {
77
87
  const length = Math.max(Math.min(end - count, lineLength), 1);
78
88
  res.push(` | ` + '^'.repeat(length));
79
89
  }
80
- count += lineLength + 1;
90
+ count += lineLength + newLineSeqLength;
81
91
  }
82
92
  }
83
93
  break;
@@ -54,11 +54,20 @@ const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
54
54
 
55
55
  const range = 2;
56
56
  function generateCodeFrame(source, start = 0, end = source.length) {
57
- const lines = source.split(/\r?\n/);
57
+ // Split the content into individual lines but capture the newline sequence
58
+ // that separated each line. This is important because the actual sequence is
59
+ // needed to properly take into account the full line length for offset
60
+ // comparison
61
+ let lines = source.split(/(\r?\n)/);
62
+ // Separate the lines and newline sequences into separate arrays for easier referencing
63
+ const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
64
+ lines = lines.filter((_, idx) => idx % 2 === 0);
58
65
  let count = 0;
59
66
  const res = [];
60
67
  for (let i = 0; i < lines.length; i++) {
61
- count += lines[i].length + 1;
68
+ count +=
69
+ lines[i].length +
70
+ ((newlineSequences[i] && newlineSequences[i].length) || 0);
62
71
  if (count >= start) {
63
72
  for (let j = i - range; j <= i + range || end > count; j++) {
64
73
  if (j < 0 || j >= lines.length)
@@ -66,9 +75,10 @@ function generateCodeFrame(source, start = 0, end = source.length) {
66
75
  const line = j + 1;
67
76
  res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
68
77
  const lineLength = lines[j].length;
78
+ const newLineSeqLength = (newlineSequences[j] && newlineSequences[j].length) || 0;
69
79
  if (j === i) {
70
80
  // push underline
71
- const pad = start - (count - lineLength) + 1;
81
+ const pad = start - (count - (lineLength + newLineSeqLength));
72
82
  const length = Math.max(1, end > count ? lineLength - pad : end - start);
73
83
  res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
74
84
  }
@@ -77,7 +87,7 @@ function generateCodeFrame(source, start = 0, end = source.length) {
77
87
  const length = Math.max(Math.min(end - count, lineLength), 1);
78
88
  res.push(` | ` + '^'.repeat(length));
79
89
  }
80
- count += lineLength + 1;
90
+ count += lineLength + newLineSeqLength;
81
91
  }
82
92
  }
83
93
  break;
@@ -50,11 +50,20 @@ const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
50
50
 
51
51
  const range = 2;
52
52
  function generateCodeFrame(source, start = 0, end = source.length) {
53
- const lines = source.split(/\r?\n/);
53
+ // Split the content into individual lines but capture the newline sequence
54
+ // that separated each line. This is important because the actual sequence is
55
+ // needed to properly take into account the full line length for offset
56
+ // comparison
57
+ let lines = source.split(/(\r?\n)/);
58
+ // Separate the lines and newline sequences into separate arrays for easier referencing
59
+ const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
60
+ lines = lines.filter((_, idx) => idx % 2 === 0);
54
61
  let count = 0;
55
62
  const res = [];
56
63
  for (let i = 0; i < lines.length; i++) {
57
- count += lines[i].length + 1;
64
+ count +=
65
+ lines[i].length +
66
+ ((newlineSequences[i] && newlineSequences[i].length) || 0);
58
67
  if (count >= start) {
59
68
  for (let j = i - range; j <= i + range || end > count; j++) {
60
69
  if (j < 0 || j >= lines.length)
@@ -62,9 +71,10 @@ function generateCodeFrame(source, start = 0, end = source.length) {
62
71
  const line = j + 1;
63
72
  res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
64
73
  const lineLength = lines[j].length;
74
+ const newLineSeqLength = (newlineSequences[j] && newlineSequences[j].length) || 0;
65
75
  if (j === i) {
66
76
  // push underline
67
- const pad = start - (count - lineLength) + 1;
77
+ const pad = start - (count - (lineLength + newLineSeqLength));
68
78
  const length = Math.max(1, end > count ? lineLength - pad : end - start);
69
79
  res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
70
80
  }
@@ -73,7 +83,7 @@ function generateCodeFrame(source, start = 0, end = source.length) {
73
83
  const length = Math.max(Math.min(end - count, lineLength), 1);
74
84
  res.push(` | ` + '^'.repeat(length));
75
85
  }
76
- count += lineLength + 1;
86
+ count += lineLength + newLineSeqLength;
77
87
  }
78
88
  }
79
89
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/shared",
3
- "version": "3.1.1",
3
+ "version": "3.1.5",
4
4
  "description": "internal utils shared across @vue packages",
5
5
  "main": "index.js",
6
6
  "module": "dist/shared.esm-bundler.js",