@parcel/diagnostic 2.4.1 → 2.5.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/lib/diagnostic.d.ts +4 -4
- package/lib/diagnostic.js +22 -17
- package/package.json +3 -3
- package/src/diagnostic.js +15 -12
package/lib/diagnostic.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Mapping } from "json-
|
|
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
3
|
export declare type DiagnosticHighlightLocation = {
|
|
4
4
|
readonly line: number;
|
|
@@ -94,8 +94,8 @@ export default class ThrowableDiagnostic extends Error {
|
|
|
94
94
|
constructor(opts: ThrowableDiagnosticOpts);
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
|
-
* Turns a list of positions in a
|
|
98
|
-
* Uses <a href="https://github.com/
|
|
97
|
+
* Turns a list of positions in a JSON5 file with messages into a list of diagnostics.
|
|
98
|
+
* Uses <a href="https://github.com/mischnic/json-sourcemap">@mischnic/json-sourcemap</a>.
|
|
99
99
|
*
|
|
100
100
|
* @param code the JSON code
|
|
101
101
|
* @param ids A list of JSON keypaths (<code>key: "/some/parent/child"</code>) with corresponding messages, \
|
|
@@ -110,7 +110,7 @@ export declare function generateJSONCodeHighlights(data: string | {
|
|
|
110
110
|
message?: string;
|
|
111
111
|
}>): Array<DiagnosticCodeHighlight>;
|
|
112
112
|
/**
|
|
113
|
-
* Converts entries in <a href="https://github.com/
|
|
113
|
+
* Converts entries in <a href="https://github.com/mischnic/json-sourcemap">@mischnic/json-sourcemap</a>'s
|
|
114
114
|
* <code>result.pointers</code> array.
|
|
115
115
|
*/
|
|
116
116
|
export declare function getJSONSourceLocation(pos: Mapping, type?: ("key" | null | undefined) | "value"): {
|
package/lib/diagnostic.js
CHANGED
|
@@ -32,10 +32,10 @@ function _nullthrows() {
|
|
|
32
32
|
return data;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function
|
|
36
|
-
const data =
|
|
35
|
+
function _jsonSourcemap() {
|
|
36
|
+
const data = require("@mischnic/json-sourcemap");
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
_jsonSourcemap = function () {
|
|
39
39
|
return data;
|
|
40
40
|
};
|
|
41
41
|
|
|
@@ -137,8 +137,8 @@ class ThrowableDiagnostic extends Error {
|
|
|
137
137
|
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
|
-
* Turns a list of positions in a
|
|
141
|
-
* Uses <a href="https://github.com/
|
|
140
|
+
* Turns a list of positions in a JSON5 file with messages into a list of diagnostics.
|
|
141
|
+
* Uses <a href="https://github.com/mischnic/json-sourcemap">@mischnic/json-sourcemap</a>.
|
|
142
142
|
*
|
|
143
143
|
* @param code the JSON code
|
|
144
144
|
* @param ids A list of JSON keypaths (<code>key: "/some/parent/child"</code>) with corresponding messages, \
|
|
@@ -149,8 +149,10 @@ class ThrowableDiagnostic extends Error {
|
|
|
149
149
|
exports.default = ThrowableDiagnostic;
|
|
150
150
|
|
|
151
151
|
function generateJSONCodeHighlights(data, ids) {
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
let map = typeof data == 'string' ? (0, _jsonSourcemap().parse)(data, undefined, {
|
|
153
|
+
dialect: 'JSON5',
|
|
154
|
+
tabWidth: 1
|
|
155
|
+
}) : data;
|
|
154
156
|
return ids.map(({
|
|
155
157
|
key,
|
|
156
158
|
type,
|
|
@@ -163,18 +165,21 @@ function generateJSONCodeHighlights(data, ids) {
|
|
|
163
165
|
});
|
|
164
166
|
}
|
|
165
167
|
/**
|
|
166
|
-
* Converts entries in <a href="https://github.com/
|
|
168
|
+
* Converts entries in <a href="https://github.com/mischnic/json-sourcemap">@mischnic/json-sourcemap</a>'s
|
|
167
169
|
* <code>result.pointers</code> array.
|
|
168
170
|
*/
|
|
169
171
|
|
|
170
172
|
|
|
171
173
|
function getJSONSourceLocation(pos, type) {
|
|
172
|
-
|
|
174
|
+
let key = 'key' in pos ? pos.key : undefined;
|
|
175
|
+
let keyEnd = 'keyEnd' in pos ? pos.keyEnd : undefined;
|
|
176
|
+
|
|
177
|
+
if (!type && key && pos.value) {
|
|
173
178
|
// key and value
|
|
174
179
|
return {
|
|
175
180
|
start: {
|
|
176
|
-
line:
|
|
177
|
-
column:
|
|
181
|
+
line: key.line + 1,
|
|
182
|
+
column: key.column + 1
|
|
178
183
|
},
|
|
179
184
|
end: {
|
|
180
185
|
line: pos.valueEnd.line + 1,
|
|
@@ -182,15 +187,15 @@ function getJSONSourceLocation(pos, type) {
|
|
|
182
187
|
}
|
|
183
188
|
};
|
|
184
189
|
} else if (type == 'key' || !pos.value) {
|
|
185
|
-
(0, _assert().default)(
|
|
190
|
+
(0, _assert().default)(key && keyEnd);
|
|
186
191
|
return {
|
|
187
192
|
start: {
|
|
188
|
-
line:
|
|
189
|
-
column:
|
|
193
|
+
line: key.line + 1,
|
|
194
|
+
column: key.column + 1
|
|
190
195
|
},
|
|
191
196
|
end: {
|
|
192
|
-
line:
|
|
193
|
-
column:
|
|
197
|
+
line: keyEnd.line + 1,
|
|
198
|
+
column: keyEnd.column
|
|
194
199
|
}
|
|
195
200
|
};
|
|
196
201
|
} else {
|
|
@@ -210,7 +215,7 @@ function getJSONSourceLocation(pos, type) {
|
|
|
210
215
|
|
|
211
216
|
|
|
212
217
|
function encodeJSONKeyComponent(component) {
|
|
213
|
-
return component.replace(/\//g, '~1');
|
|
218
|
+
return component.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
214
219
|
}
|
|
215
220
|
|
|
216
221
|
const escapeCharacters = ['\\', '*', '_', '~'];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/diagnostic",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"check-ts": "tsc --noEmit lib/diagnostic.d.ts"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"json-
|
|
27
|
+
"@mischnic/json-sourcemap": "^0.1.0",
|
|
28
28
|
"nullthrows": "^1.1.1"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "5cfb846d742eb86b1232e531be6e0e513551d838"
|
|
31
31
|
}
|
package/src/diagnostic.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import invariant from 'assert';
|
|
4
4
|
import nullthrows from 'nullthrows';
|
|
5
|
-
import
|
|
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
8
|
export type DiagnosticHighlightLocation = {|
|
|
@@ -215,8 +215,8 @@ export default class ThrowableDiagnostic extends Error {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
/**
|
|
218
|
-
* Turns a list of positions in a
|
|
219
|
-
* Uses <a href="https://github.com/
|
|
218
|
+
* Turns a list of positions in a JSON5 file with messages into a list of diagnostics.
|
|
219
|
+
* Uses <a href="https://github.com/mischnic/json-sourcemap">@mischnic/json-sourcemap</a>.
|
|
220
220
|
*
|
|
221
221
|
* @param code the JSON code
|
|
222
222
|
* @param ids A list of JSON keypaths (<code>key: "/some/parent/child"</code>) with corresponding messages, \
|
|
@@ -231,9 +231,10 @@ export function generateJSONCodeHighlights(
|
|
|
231
231
|
|},
|
|
232
232
|
ids: Array<{|key: string, type?: ?'key' | 'value', message?: string|}>,
|
|
233
233
|
): Array<DiagnosticCodeHighlight> {
|
|
234
|
-
// json-source-map doesn't support a tabWidth option (yet)
|
|
235
234
|
let map =
|
|
236
|
-
typeof data == 'string'
|
|
235
|
+
typeof data == 'string'
|
|
236
|
+
? parse(data, undefined, {dialect: 'JSON5', tabWidth: 1})
|
|
237
|
+
: data;
|
|
237
238
|
return ids.map(({key, type, message}) => {
|
|
238
239
|
let pos = nullthrows(map.pointers[key]);
|
|
239
240
|
return {
|
|
@@ -244,7 +245,7 @@ export function generateJSONCodeHighlights(
|
|
|
244
245
|
}
|
|
245
246
|
|
|
246
247
|
/**
|
|
247
|
-
* Converts entries in <a href="https://github.com/
|
|
248
|
+
* Converts entries in <a href="https://github.com/mischnic/json-sourcemap">@mischnic/json-sourcemap</a>'s
|
|
248
249
|
* <code>result.pointers</code> array.
|
|
249
250
|
*/
|
|
250
251
|
export function getJSONSourceLocation(
|
|
@@ -254,17 +255,19 @@ export function getJSONSourceLocation(
|
|
|
254
255
|
start: DiagnosticHighlightLocation,
|
|
255
256
|
end: DiagnosticHighlightLocation,
|
|
256
257
|
|} {
|
|
257
|
-
|
|
258
|
+
let key = 'key' in pos ? pos.key : undefined;
|
|
259
|
+
let keyEnd = 'keyEnd' in pos ? pos.keyEnd : undefined;
|
|
260
|
+
if (!type && key && pos.value) {
|
|
258
261
|
// key and value
|
|
259
262
|
return {
|
|
260
|
-
start: {line:
|
|
263
|
+
start: {line: key.line + 1, column: key.column + 1},
|
|
261
264
|
end: {line: pos.valueEnd.line + 1, column: pos.valueEnd.column},
|
|
262
265
|
};
|
|
263
266
|
} else if (type == 'key' || !pos.value) {
|
|
264
|
-
invariant(
|
|
267
|
+
invariant(key && keyEnd);
|
|
265
268
|
return {
|
|
266
|
-
start: {line:
|
|
267
|
-
end: {line:
|
|
269
|
+
start: {line: key.line + 1, column: key.column + 1},
|
|
270
|
+
end: {line: keyEnd.line + 1, column: keyEnd.column},
|
|
268
271
|
};
|
|
269
272
|
} else {
|
|
270
273
|
return {
|
|
@@ -276,7 +279,7 @@ export function getJSONSourceLocation(
|
|
|
276
279
|
|
|
277
280
|
/** Sanitizes object keys before using them as <code>key</code> in generateJSONCodeHighlights */
|
|
278
281
|
export function encodeJSONKeyComponent(component: string): string {
|
|
279
|
-
return component.replace(/\//g, '~1');
|
|
282
|
+
return component.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
280
283
|
}
|
|
281
284
|
|
|
282
285
|
const escapeCharacters = ['\\', '*', '_', '~'];
|