@parcel/diagnostic 2.0.0-canary.1543 → 2.0.0-dev.1424

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.
@@ -1,9 +1,9 @@
1
1
  import type { Mapping } from "@mischnic/json-sourcemap";
2
2
  /** These positions are 1-based (so <code>1</code> is the first line/column) */
3
- export type DiagnosticHighlightLocation = {
3
+ export interface DiagnosticHighlightLocation {
4
4
  readonly line: number;
5
5
  readonly column: number;
6
- };
6
+ }
7
7
  export type DiagnosticSeverity = "error" | "warn" | "info";
8
8
  /**
9
9
  * Note: A tab character is always counted as a single character
@@ -37,8 +37,6 @@ export type DiagnosticCodeFrame = {
37
37
  language?: string;
38
38
  codeHighlights: Array<DiagnosticCodeHighlight>;
39
39
  };
40
- /** A JSON object (as in "map") */
41
- type JSONObject = Record<string, any>;
42
40
  /**
43
41
  * A style agnostic way of emitting errors, warnings and info.
44
42
  * Reporters are responsible for rendering the message, codeframes, hints, ...
@@ -60,8 +58,6 @@ export type Diagnostic = {
60
58
  skipFormatting?: boolean;
61
59
  /** A URL to documentation to learn more about the diagnostic. */
62
60
  documentationURL?: string;
63
- /** Diagnostic specific metadata (optional) */
64
- meta?: JSONObject;
65
61
  };
66
62
  export interface PrintableError extends Error {
67
63
  fileName?: string;
@@ -123,27 +119,16 @@ export declare function getJSONHighlightLocation(pos: Mapping, type?: ("key" | n
123
119
  };
124
120
  /** Result is 1-based, but end is exclusive */
125
121
  export declare function getJSONSourceLocation(pos: Mapping, type?: ("key" | null | undefined) | "value"): {
126
- start: {
127
- readonly line: number;
128
- readonly column: number;
129
- };
130
- end: {
131
- readonly line: number;
132
- readonly column: number;
133
- };
122
+ start: DiagnosticHighlightLocation;
123
+ end: DiagnosticHighlightLocation;
134
124
  };
135
- export declare function convertSourceLocationToHighlight<Location extends {
125
+ interface Location {
136
126
  /** 1-based, inclusive */
137
- readonly start: {
138
- readonly line: number;
139
- readonly column: number;
140
- };
127
+ readonly start: DiagnosticHighlightLocation;
141
128
  /** 1-based, exclusive */
142
- readonly end: {
143
- readonly line: number;
144
- readonly column: number;
145
- };
146
- }>({ start, end }: Location, message?: string): DiagnosticCodeHighlight;
129
+ readonly end: DiagnosticHighlightLocation;
130
+ }
131
+ export declare function convertSourceLocationToHighlight({ start, end }: Location, message?: string): DiagnosticCodeHighlight;
147
132
  /** Sanitizes object keys before using them as <code>key</code> in generateJSONCodeHighlights */
148
133
  export declare function encodeJSONKeyComponent(component: string): string;
149
134
  export declare function escapeMarkdown(s: string): string;
package/lib/diagnostic.js CHANGED
@@ -45,7 +45,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
45
45
  * A code frame is a visualization of a piece of code with a certain amount of
46
46
  * code highlights that point to certain chunk(s) inside the code.
47
47
  */
48
- /** A JSON object (as in "map") */
49
48
  /**
50
49
  * A style agnostic way of emitting errors, warnings and info.
51
50
  * Reporters are responsible for rendering the message, codeframes, hints, ...
@@ -224,7 +223,10 @@ function convertSourceLocationToHighlight({
224
223
  }, message) {
225
224
  return {
226
225
  message,
227
- start,
226
+ start: {
227
+ line: start.line,
228
+ column: start.column
229
+ },
228
230
  end: {
229
231
  line: end.line,
230
232
  column: end.column - 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/diagnostic",
3
- "version": "2.0.0-canary.1543+ec3f4a5fb",
3
+ "version": "2.0.0-dev.1424+7f6b4dbbc",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -27,5 +27,5 @@
27
27
  "@mischnic/json-sourcemap": "^0.1.0",
28
28
  "nullthrows": "^1.1.1"
29
29
  },
30
- "gitHead": "ec3f4a5fbfad05bd3b645e02b90ff9c5abc738dc"
30
+ "gitHead": "7f6b4dbbc56a203e0fce8794856c03598c4f6708"
31
31
  }
package/src/diagnostic.js CHANGED
@@ -5,10 +5,10 @@ import nullthrows from 'nullthrows';
5
5
  import {parse, type Mapping} from '@mischnic/json-sourcemap';
6
6
 
7
7
  /** These positions are 1-based (so <code>1</code> is the first line/column) */
8
- export type DiagnosticHighlightLocation = {|
9
- +line: number,
10
- +column: number,
11
- |};
8
+ export interface DiagnosticHighlightLocation {
9
+ +line: number;
10
+ +column: number;
11
+ }
12
12
 
13
13
  export type DiagnosticSeverity = 'error' | 'warn' | 'info';
14
14
 
@@ -46,12 +46,6 @@ export type DiagnosticCodeFrame = {|
46
46
  codeHighlights: Array<DiagnosticCodeHighlight>,
47
47
  |};
48
48
 
49
- /** A JSON object (as in "map") */
50
- type JSONObject = {
51
- // $FlowFixMe
52
- [key: string]: any,
53
- };
54
-
55
49
  /**
56
50
  * A style agnostic way of emitting errors, warnings and info.
57
51
  * Reporters are responsible for rendering the message, codeframes, hints, ...
@@ -78,9 +72,6 @@ export type Diagnostic = {|
78
72
 
79
73
  /** A URL to documentation to learn more about the diagnostic. */
80
74
  documentationURL?: string,
81
-
82
- /** Diagnostic specific metadata (optional) */
83
- meta?: JSONObject,
84
75
  |};
85
76
 
86
77
  // This type should represent all error formats Parcel can encounter...
@@ -291,35 +282,29 @@ export function getJSONSourceLocation(
291
282
  pos: Mapping,
292
283
  type?: ?'key' | 'value',
293
284
  ): {|
294
- start: {|
295
- +line: number,
296
- +column: number,
297
- |},
298
- end: {|
299
- +line: number,
300
- +column: number,
301
- |},
285
+ start: DiagnosticHighlightLocation,
286
+ end: DiagnosticHighlightLocation,
302
287
  |} {
303
288
  let v = getJSONHighlightLocation(pos, type);
304
289
  return {start: v.start, end: {line: v.end.line, column: v.end.column + 1}};
305
290
  }
306
291
 
307
- export function convertSourceLocationToHighlight<
308
- Location: {
309
- /** 1-based, inclusive */
310
- +start: {|
311
- +line: number,
312
- +column: number,
313
- |},
314
- /** 1-based, exclusive */
315
- +end: {|
316
- +line: number,
317
- +column: number,
318
- |},
319
- ...
320
- },
321
- >({start, end}: Location, message?: string): DiagnosticCodeHighlight {
322
- return {message, start, end: {line: end.line, column: end.column - 1}};
292
+ interface Location {
293
+ /** 1-based, inclusive */
294
+ +start: DiagnosticHighlightLocation;
295
+ /** 1-based, exclusive */
296
+ +end: DiagnosticHighlightLocation;
297
+ }
298
+
299
+ export function convertSourceLocationToHighlight(
300
+ {start, end}: Location,
301
+ message?: string,
302
+ ): DiagnosticCodeHighlight {
303
+ return {
304
+ message,
305
+ start: {line: start.line, column: start.column},
306
+ end: {line: end.line, column: end.column - 1},
307
+ };
323
308
  }
324
309
 
325
310
  /** Sanitizes object keys before using them as <code>key</code> in generateJSONCodeHighlights */