@parcel/codeframe 2.9.3 → 2.10.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.9.3",
3
+ "version": "2.10.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -34,5 +34,5 @@
34
34
  "slice-ansi": "^4.0.0",
35
35
  "string-width": "^4.2.0"
36
36
  },
37
- "gitHead": "db3bcae10497fa6a712fd9a135f93f26c5745454"
37
+ "gitHead": "0e235842b5b93301379bdfa626e7a4e2ee42ea98"
38
38
  }
package/src/codeframe.js CHANGED
@@ -260,6 +260,9 @@ export default function codeFrame(
260
260
  characters += startCol - lastCol;
261
261
  }
262
262
 
263
+ // Don't crash (and swallow the original message) if the diagnostic is malformed (end is before start).
264
+ characters = Math.max(1, characters);
265
+
263
266
  // Append the highlight indicators
264
267
  highlightLine += highlighter('^'.repeat(characters));
265
268
 
@@ -796,4 +796,27 @@ describe('codeframe', () => {
796
796
  assert.equal(lines[3], ' 9 | ');
797
797
  assert.equal(lines[4], ' 10 | /**');
798
798
  });
799
+
800
+ it('should still generate a codeframe when end is before start', () => {
801
+ let codeframeString = codeframe(
802
+ 'hello world',
803
+ [
804
+ {
805
+ start: {
806
+ column: 5,
807
+ line: 1,
808
+ },
809
+ end: {
810
+ column: 1,
811
+ line: 1,
812
+ },
813
+ },
814
+ ],
815
+ {useColor: false},
816
+ );
817
+
818
+ let lines = codeframeString.split(LINE_END);
819
+ assert.equal(lines[0], '> 1 | hello world');
820
+ assert.equal(lines[1], '> | ^');
821
+ });
799
822
  });