@parcel/diagnostic 2.0.0-dev.1565 → 2.0.0-dev.1573
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.js +10 -16
- package/package.json +4 -3
package/lib/diagnostic.js
CHANGED
|
@@ -73,28 +73,24 @@ function anyToDiagnostic(input) {
|
|
|
73
73
|
|
|
74
74
|
/** Normalize the given error into a diagnostic. */
|
|
75
75
|
function errorToDiagnostic(error, defaultValues) {
|
|
76
|
-
var _defaultValues$origin2, _ref4, _error$highlightedCod;
|
|
77
76
|
let codeFrames = undefined;
|
|
78
77
|
if (typeof error === 'string') {
|
|
79
|
-
var _defaultValues$origin;
|
|
80
78
|
return [{
|
|
81
|
-
origin: (
|
|
79
|
+
origin: (defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.origin) ?? 'Error',
|
|
82
80
|
message: escapeMarkdown(error)
|
|
83
81
|
}];
|
|
84
82
|
}
|
|
85
83
|
if (error instanceof ThrowableDiagnostic) {
|
|
86
84
|
return error.diagnostics.map(d => {
|
|
87
|
-
var _ref, _d$origin;
|
|
88
85
|
return {
|
|
89
86
|
...d,
|
|
90
|
-
origin:
|
|
87
|
+
origin: d.origin ?? (defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.origin) ?? 'unknown'
|
|
91
88
|
};
|
|
92
89
|
});
|
|
93
90
|
}
|
|
94
91
|
if (error.loc && error.source != null) {
|
|
95
|
-
var _ref2, _ref3, _error$filePath;
|
|
96
92
|
codeFrames = [{
|
|
97
|
-
filePath:
|
|
93
|
+
filePath: error.filePath ?? error.fileName ?? (defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.filePath) ?? undefined,
|
|
98
94
|
code: error.source,
|
|
99
95
|
codeHighlights: [{
|
|
100
96
|
start: {
|
|
@@ -109,10 +105,10 @@ function errorToDiagnostic(error, defaultValues) {
|
|
|
109
105
|
}];
|
|
110
106
|
}
|
|
111
107
|
return [{
|
|
112
|
-
origin: (
|
|
108
|
+
origin: (defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.origin) ?? 'Error',
|
|
113
109
|
message: escapeMarkdown(error.message),
|
|
114
110
|
name: error.name,
|
|
115
|
-
stack: codeFrames == null ?
|
|
111
|
+
stack: codeFrames == null ? error.highlightedCodeFrame ?? error.codeFrame ?? error.stack : undefined,
|
|
116
112
|
codeFrames
|
|
117
113
|
}];
|
|
118
114
|
}
|
|
@@ -122,15 +118,14 @@ function errorToDiagnostic(error, defaultValues) {
|
|
|
122
118
|
*/
|
|
123
119
|
class ThrowableDiagnostic extends Error {
|
|
124
120
|
constructor(opts) {
|
|
125
|
-
var _diagnostics$0$stack, _diagnostics$0$name;
|
|
126
121
|
let diagnostics = Array.isArray(opts.diagnostic) ? opts.diagnostic : [opts.diagnostic];
|
|
127
122
|
|
|
128
123
|
// Construct error from diagnostics
|
|
129
124
|
super(diagnostics[0].message);
|
|
130
125
|
// @ts-ignore
|
|
131
|
-
this.stack =
|
|
126
|
+
this.stack = diagnostics[0].stack ?? super.stack;
|
|
132
127
|
// @ts-ignore
|
|
133
|
-
this.name =
|
|
128
|
+
this.name = diagnostics[0].name ?? super.name;
|
|
134
129
|
this.diagnostics = diagnostics;
|
|
135
130
|
}
|
|
136
131
|
}
|
|
@@ -252,15 +247,14 @@ function md(strings, ...params) {
|
|
|
252
247
|
let param = params[i];
|
|
253
248
|
if (Array.isArray(param)) {
|
|
254
249
|
for (let j = 0; j < param.length; j++) {
|
|
255
|
-
var _param$j
|
|
256
|
-
result.push((
|
|
250
|
+
var _param$j;
|
|
251
|
+
result.push(((_param$j = param[j]) === null || _param$j === void 0 ? void 0 : _param$j[mdVerbatim]) ?? escapeMarkdown(`${param[j]}`));
|
|
257
252
|
if (j < param.length - 1) {
|
|
258
253
|
result.push(', ');
|
|
259
254
|
}
|
|
260
255
|
}
|
|
261
256
|
} else {
|
|
262
|
-
|
|
263
|
-
result.push((_param$mdVerbatim = param === null || param === void 0 ? void 0 : param[mdVerbatim]) !== null && _param$mdVerbatim !== void 0 ? _param$mdVerbatim : escapeMarkdown(`${param}`));
|
|
257
|
+
result.push((param === null || param === void 0 ? void 0 : param[mdVerbatim]) ?? escapeMarkdown(`${param}`));
|
|
264
258
|
}
|
|
265
259
|
}
|
|
266
260
|
return result.join('') + strings[strings.length - 1];
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/diagnostic",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.1573+c9a0ab031",
|
|
4
|
+
"description": "Types and utilities for printing source-code located errors, warning and information messages.",
|
|
4
5
|
"license": "MIT",
|
|
5
6
|
"publishConfig": {
|
|
6
7
|
"access": "public"
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
"source": "src/diagnostic.js",
|
|
18
19
|
"types": "lib/diagnostic.d.ts",
|
|
19
20
|
"engines": {
|
|
20
|
-
"node": ">=
|
|
21
|
+
"node": ">= 16.0.0"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
23
24
|
"build-ts": "flow-to-ts src/*.js --write && tsc --emitDeclarationOnly --declaration --esModuleInterop src/*.ts && mkdir -p lib && mv src/*.d.ts lib/. && rm src/*.ts",
|
|
@@ -27,5 +28,5 @@
|
|
|
27
28
|
"@mischnic/json-sourcemap": "^0.1.0",
|
|
28
29
|
"nullthrows": "^1.1.1"
|
|
29
30
|
},
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "c9a0ab031986a896a5991de16420b12988d013cd"
|
|
31
32
|
}
|