@parcel/codeframe 2.6.0 → 2.7.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/codeframe",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -35,5 +35,5 @@
35
35
  "string-width": "^4.2.0",
36
36
  "strip-ansi": "^6.0.0"
37
37
  },
38
- "gitHead": "f2d0a3a27d6e493b23ddc2edbc8a4c0053ff34ab"
38
+ "gitHead": "9e5d05586577e89991ccf90400f2c741dca11aa3"
39
39
  }
package/src/codeframe.js CHANGED
@@ -84,6 +84,7 @@ export default function codeFrame(
84
84
  };
85
85
 
86
86
  // Make columns/lines start at 1
87
+ let originalHighlights = highlights;
87
88
  highlights = highlights.map(h => {
88
89
  return {
89
90
  start: {
@@ -112,10 +113,17 @@ export default function codeFrame(
112
113
  let startLine = firstHighlight.start.line - opts.padding.before;
113
114
  startLine = startLine < 0 ? 0 : startLine;
114
115
  let endLineIndex = lastHighlight.end.line + opts.padding.after;
115
- endLineIndex =
116
- endLineIndex - startLine > opts.maxLines
117
- ? startLine + opts.maxLines - 1
118
- : endLineIndex;
116
+ let tail;
117
+ if (endLineIndex - startLine > opts.maxLines) {
118
+ let maxLine = startLine + opts.maxLines - 1;
119
+ highlights = highlights.filter(h => h.start.line < maxLine);
120
+ lastHighlight = highlights[0];
121
+ endLineIndex = Math.min(
122
+ maxLine,
123
+ lastHighlight.end.line + opts.padding.after,
124
+ );
125
+ tail = originalHighlights.filter(h => h.start.line > endLineIndex);
126
+ }
119
127
 
120
128
  let lineNumberLength = (endLineIndex + 1).toString(10).length;
121
129
 
@@ -281,5 +289,11 @@ export default function codeFrame(
281
289
  }
282
290
  }
283
291
 
284
- return resultLines.join('\n');
292
+ let result = resultLines.join('\n');
293
+
294
+ if (tail && tail.length > 0) {
295
+ result += '\n\n' + codeFrame(code, tail, inputOpts);
296
+ }
297
+
298
+ return result;
285
299
  }