@parcel/codeframe 2.6.2 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/codeframe",
3
- "version": "2.6.2",
3
+ "version": "2.8.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": "e10fcfc1e8b71222da90978fb87f1b68e207473e"
38
+ "gitHead": "c3bbe0a6160186f496ca2f9e9bead9376c0522f1"
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
  }