@parcel/diagnostic 2.0.0-dev.1565 → 2.0.0-dev.1572

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.
Files changed (2) hide show
  1. package/lib/diagnostic.js +10 -16
  2. 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: (_defaultValues$origin = defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.origin) !== null && _defaultValues$origin !== void 0 ? _defaultValues$origin : 'Error',
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: (_ref = (_d$origin = d.origin) !== null && _d$origin !== void 0 ? _d$origin : defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.origin) !== null && _ref !== void 0 ? _ref : 'unknown'
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: (_ref2 = (_ref3 = (_error$filePath = error.filePath) !== null && _error$filePath !== void 0 ? _error$filePath : error.fileName) !== null && _ref3 !== void 0 ? _ref3 : defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.filePath) !== null && _ref2 !== void 0 ? _ref2 : undefined,
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: (_defaultValues$origin2 = defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.origin) !== null && _defaultValues$origin2 !== void 0 ? _defaultValues$origin2 : 'Error',
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 ? (_ref4 = (_error$highlightedCod = error.highlightedCodeFrame) !== null && _error$highlightedCod !== void 0 ? _error$highlightedCod : error.codeFrame) !== null && _ref4 !== void 0 ? _ref4 : error.stack : undefined,
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 = (_diagnostics$0$stack = diagnostics[0].stack) !== null && _diagnostics$0$stack !== void 0 ? _diagnostics$0$stack : super.stack;
126
+ this.stack = diagnostics[0].stack ?? super.stack;
132
127
  // @ts-ignore
133
- this.name = (_diagnostics$0$name = diagnostics[0].name) !== null && _diagnostics$0$name !== void 0 ? _diagnostics$0$name : super.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$mdVerbatim, _param$j;
256
- result.push((_param$j$mdVerbatim = (_param$j = param[j]) === null || _param$j === void 0 ? void 0 : _param$j[mdVerbatim]) !== null && _param$j$mdVerbatim !== void 0 ? _param$j$mdVerbatim : escapeMarkdown(`${param[j]}`));
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
- var _param$mdVerbatim;
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.1565+c422b7ff3",
3
+ "version": "2.0.0-dev.1572+7afdafedd",
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": ">= 12.0.0"
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": "c422b7ff3c383779781ea5169d86191508b01e5b"
31
+ "gitHead": "7afdafedd7f01d82b9868ec004b3966a88006300"
31
32
  }