@parcel/diagnostic 2.0.0-beta.3.1 → 2.0.0-nightly.1002

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.
@@ -0,0 +1,131 @@
1
+ import type { Mapping } from "json-source-map";
2
+ /** These positions are 1-based (so <code>1</code> is the first line/column) */
3
+ export declare type DiagnosticHighlightLocation = {
4
+ readonly line: number;
5
+ readonly column: number;
6
+ };
7
+ export declare type DiagnosticSeverity = "error" | "warn" | "info";
8
+ /**
9
+ * Note: A tab character is always counted as a single character
10
+ * This is to prevent any mismatch of highlighting across machines
11
+ */
12
+ export declare type DiagnosticCodeHighlight = {
13
+ /** Location of the first character that should get highlighted for this highlight. */
14
+ start: DiagnosticHighlightLocation;
15
+ /** Location of the last character that should get highlighted for this highlight. */
16
+ end: DiagnosticHighlightLocation;
17
+ /** A message that should be displayed at this location in the code (optional). */
18
+ message?: string;
19
+ };
20
+ /**
21
+ * Describes how to format a code frame.
22
+ * A code frame is a visualization of a piece of code with a certain amount of
23
+ * code highlights that point to certain chunk(s) inside the code.
24
+ */
25
+ export declare type DiagnosticCodeFrame = {
26
+ /**
27
+ * The contents of the source file.
28
+ *
29
+ * If no code is passed, it will be read in from filePath, remember that
30
+ * the asset's current code could be different from the input contents.
31
+ *
32
+ */
33
+ code?: string;
34
+ /** Path to the file this code frame is about (optional, absolute or relative to the project root) */
35
+ filePath?: string;
36
+ /** Language of the file this code frame is about (optional) */
37
+ language?: string;
38
+ codeHighlights: Array<DiagnosticCodeHighlight>;
39
+ };
40
+ /**
41
+ * A style agnostic way of emitting errors, warnings and info.
42
+ * Reporters are responsible for rendering the message, codeframes, hints, ...
43
+ */
44
+ export declare type Diagnostic = {
45
+ /** This is the message you want to log. */
46
+ message: string;
47
+ /** Name of plugin or file that threw this error */
48
+ origin?: string;
49
+ /** A stacktrace of the error (optional) */
50
+ stack?: string;
51
+ /** Name of the error (optional) */
52
+ name?: string;
53
+ /** A code frame points to a certain location(s) in the file this diagnostic is linked to (optional) */
54
+ codeFrames?: Array<DiagnosticCodeFrame> | null | undefined;
55
+ /** An optional list of strings that suggest ways to resolve this issue */
56
+ hints?: Array<string>;
57
+ /** @private */
58
+ skipFormatting?: boolean;
59
+ /** A URL to documentation to learn more about the diagnostic. */
60
+ documentationURL?: string;
61
+ };
62
+ export interface PrintableError extends Error {
63
+ fileName?: string;
64
+ filePath?: string;
65
+ codeFrame?: string;
66
+ highlightedCodeFrame?: string;
67
+ loc?: {
68
+ column: number;
69
+ line: number;
70
+ } | null | undefined;
71
+ source?: string;
72
+ }
73
+ export declare type DiagnosticWithoutOrigin = Diagnostic & {
74
+ origin?: string;
75
+ };
76
+ /** Something that can be turned into a diagnostic. */
77
+ export declare type Diagnostifiable = Diagnostic | Array<Diagnostic> | ThrowableDiagnostic | PrintableError | Error | string;
78
+ /** Normalize the given value into a diagnostic. */
79
+ export declare function anyToDiagnostic(input: Diagnostifiable): Array<Diagnostic>;
80
+ /** Normalize the given error into a diagnostic. */
81
+ export declare function errorToDiagnostic(error: ThrowableDiagnostic | PrintableError | string, defaultValues?: {
82
+ origin?: string | null | undefined;
83
+ filePath?: string | null | undefined;
84
+ }): Array<Diagnostic>;
85
+ declare type ThrowableDiagnosticOpts = {
86
+ diagnostic: Diagnostic | Array<Diagnostic>;
87
+ };
88
+ /**
89
+ * An error wrapper around a diagnostic that can be <code>throw</code>n (e.g. to signal a
90
+ * build error).
91
+ */
92
+ export default class ThrowableDiagnostic extends Error {
93
+ diagnostics: Array<Diagnostic>;
94
+ constructor(opts: ThrowableDiagnosticOpts);
95
+ }
96
+ /**
97
+ * Turns a list of positions in a JSON file with messages into a list of diagnostics.
98
+ * Uses <a href="https://github.com/epoberezkin/json-source-map">epoberezkin/json-source-map</a>.
99
+ *
100
+ * @param code the JSON code
101
+ * @param ids A list of JSON keypaths (<code>key: "/some/parent/child"</code>) with corresponding messages, \
102
+ * <code>type</code> signifies whether the key of the value in a JSON object should be highlighted.
103
+ */
104
+ export declare function generateJSONCodeHighlights(data: string | {
105
+ data: unknown;
106
+ pointers: Record<string, Mapping>;
107
+ }, ids: Array<{
108
+ key: string;
109
+ type?: ("key" | null | undefined) | "value";
110
+ message?: string;
111
+ }>): Array<DiagnosticCodeHighlight>;
112
+ /**
113
+ * Converts entries in <a href="https://github.com/epoberezkin/json-source-map">epoberezkin/json-source-map</a>'s
114
+ * <code>result.pointers</code> array.
115
+ */
116
+ export declare function getJSONSourceLocation(pos: Mapping, type?: ("key" | null | undefined) | "value"): {
117
+ start: DiagnosticHighlightLocation;
118
+ end: DiagnosticHighlightLocation;
119
+ };
120
+ /** Sanitizes object keys before using them as <code>key</code> in generateJSONCodeHighlights */
121
+ export declare function encodeJSONKeyComponent(component: string): string;
122
+ export declare function escapeMarkdown(s: string): string;
123
+ declare type TemplateInput = any;
124
+ export declare function md(strings: Array<string>, ...params: Array<TemplateInput>): string;
125
+ export declare namespace md {
126
+ var bold: (s: any) => any;
127
+ var italic: (s: any) => any;
128
+ var underline: (s: any) => any;
129
+ var strikethrough: (s: any) => any;
130
+ }
131
+ export {};
package/lib/diagnostic.js CHANGED
@@ -4,13 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.anyToDiagnostic = anyToDiagnostic;
7
+ exports.default = void 0;
8
+ exports.encodeJSONKeyComponent = encodeJSONKeyComponent;
7
9
  exports.errorToDiagnostic = errorToDiagnostic;
10
+ exports.escapeMarkdown = escapeMarkdown;
8
11
  exports.generateJSONCodeHighlights = generateJSONCodeHighlights;
9
12
  exports.getJSONSourceLocation = getJSONSourceLocation;
10
- exports.encodeJSONKeyComponent = encodeJSONKeyComponent;
11
- exports.escapeMarkdown = escapeMarkdown;
12
13
  exports.md = md;
13
- exports.default = void 0;
14
14
 
15
15
  function _assert() {
16
16
  const data = _interopRequireDefault(require("assert"));
@@ -44,37 +44,38 @@ function _jsonSourceMap() {
44
44
 
45
45
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
46
46
 
47
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
48
-
49
47
  /** Normalize the given value into a diagnostic. */
50
48
  function anyToDiagnostic(input) {
51
- // $FlowFixMe
52
- let diagnostic = input;
53
-
54
- if (input instanceof ThrowableDiagnostic) {
55
- diagnostic = input.diagnostics;
49
+ if (Array.isArray(input)) {
50
+ return input;
51
+ } else if (input instanceof ThrowableDiagnostic) {
52
+ return input.diagnostics;
56
53
  } else if (input instanceof Error) {
57
- diagnostic = errorToDiagnostic(input);
54
+ return errorToDiagnostic(input);
55
+ } else if (typeof input === 'string') {
56
+ return [{
57
+ message: input
58
+ }];
59
+ } else if (typeof input === 'object') {
60
+ return [input];
61
+ } else {
62
+ return errorToDiagnostic(input);
58
63
  }
59
-
60
- return Array.isArray(diagnostic) ? diagnostic : [diagnostic];
61
64
  }
62
65
  /** Normalize the given error into a diagnostic. */
63
66
 
64
67
 
65
- function errorToDiagnostic(error, defaultValues = { ...null
66
- }) {
67
- var _defaultValues$origin2, _ref2, _ref3, _error$filePath, _ref4, _error$highlightedCod;
68
+ function errorToDiagnostic(error, defaultValues) {
69
+ var _defaultValues$origin2, _ref4, _error$highlightedCod;
68
70
 
69
- let codeFrame = undefined;
71
+ let codeFrames = undefined;
70
72
 
71
73
  if (typeof error === 'string') {
72
74
  var _defaultValues$origin;
73
75
 
74
76
  return [{
75
77
  origin: (_defaultValues$origin = defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.origin) !== null && _defaultValues$origin !== void 0 ? _defaultValues$origin : 'Error',
76
- message: escapeMarkdown(error),
77
- codeFrame
78
+ message: escapeMarkdown(error)
78
79
  }];
79
80
  }
80
81
 
@@ -89,7 +90,10 @@ function errorToDiagnostic(error, defaultValues = { ...null
89
90
  }
90
91
 
91
92
  if (error.loc && error.source != null) {
92
- codeFrame = {
93
+ var _ref2, _ref3, _error$filePath;
94
+
95
+ codeFrames = [{
96
+ 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
97
  code: error.source,
94
98
  codeHighlights: [{
95
99
  start: {
@@ -101,16 +105,15 @@ function errorToDiagnostic(error, defaultValues = { ...null
101
105
  column: error.loc.column
102
106
  }
103
107
  }]
104
- };
108
+ }];
105
109
  }
106
110
 
107
111
  return [{
108
112
  origin: (_defaultValues$origin2 = defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.origin) !== null && _defaultValues$origin2 !== void 0 ? _defaultValues$origin2 : 'Error',
109
113
  message: escapeMarkdown(error.message),
110
114
  name: error.name,
111
- 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,
112
- stack: (_ref4 = (_error$highlightedCod = error.highlightedCodeFrame) !== null && _error$highlightedCod !== void 0 ? _error$highlightedCod : error.codeFrame) !== null && _ref4 !== void 0 ? _ref4 : error.stack,
113
- codeFrame
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,
116
+ codeFrames
114
117
  }];
115
118
  }
116
119
 
@@ -124,11 +127,10 @@ class ThrowableDiagnostic extends Error {
124
127
 
125
128
  let diagnostics = Array.isArray(opts.diagnostic) ? opts.diagnostic : [opts.diagnostic]; // Construct error from diagnostics
126
129
 
127
- super(diagnostics[0].message);
130
+ super(diagnostics[0].message); // @ts-ignore
128
131
 
129
- _defineProperty(this, "diagnostics", void 0);
132
+ this.stack = (_diagnostics$0$stack = diagnostics[0].stack) !== null && _diagnostics$0$stack !== void 0 ? _diagnostics$0$stack : super.stack; // @ts-ignore
130
133
 
131
- this.stack = (_diagnostics$0$stack = diagnostics[0].stack) !== null && _diagnostics$0$stack !== void 0 ? _diagnostics$0$stack : super.stack;
132
134
  this.name = (_diagnostics$0$name = diagnostics[0].name) !== null && _diagnostics$0$name !== void 0 ? _diagnostics$0$name : super.name;
133
135
  this.diagnostics = diagnostics;
134
136
  }
@@ -221,8 +223,7 @@ function escapeMarkdown(s) {
221
223
  }
222
224
 
223
225
  return result;
224
- } // $FlowFixMe[unclear-type]
225
-
226
+ }
226
227
 
227
228
  const mdVerbatim = Symbol();
228
229
 
@@ -230,8 +231,24 @@ function md(strings, ...params) {
230
231
  let result = [];
231
232
 
232
233
  for (let i = 0; i < params.length; i++) {
234
+ result.push(strings[i]);
233
235
  let param = params[i];
234
- result.push(strings[i], param !== null && param !== void 0 && param[mdVerbatim] ? param.value : escapeMarkdown(`${param}`));
236
+
237
+ if (Array.isArray(param)) {
238
+ for (let j = 0; j < param.length; j++) {
239
+ var _param$j$mdVerbatim, _param$j;
240
+
241
+ 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]}`));
242
+
243
+ if (j < param.length - 1) {
244
+ result.push(', ');
245
+ }
246
+ }
247
+ } else {
248
+ var _param$mdVerbatim;
249
+
250
+ result.push((_param$mdVerbatim = param === null || param === void 0 ? void 0 : param[mdVerbatim]) !== null && _param$mdVerbatim !== void 0 ? _param$mdVerbatim : escapeMarkdown(`${param}`));
251
+ }
235
252
  }
236
253
 
237
254
  return result.join('') + strings[strings.length - 1];
@@ -240,31 +257,27 @@ function md(strings, ...params) {
240
257
  md.bold = function (s) {
241
258
  // $FlowFixMe[invalid-computed-prop]
242
259
  return {
243
- [mdVerbatim]: true,
244
- value: '**' + escapeMarkdown(`${s}`) + '**'
260
+ [mdVerbatim]: '**' + escapeMarkdown(`${s}`) + '**'
245
261
  };
246
262
  };
247
263
 
248
264
  md.italic = function (s) {
249
265
  // $FlowFixMe[invalid-computed-prop]
250
266
  return {
251
- [mdVerbatim]: true,
252
- value: '_' + escapeMarkdown(`${s}`) + '_'
267
+ [mdVerbatim]: '_' + escapeMarkdown(`${s}`) + '_'
253
268
  };
254
269
  };
255
270
 
256
271
  md.underline = function (s) {
257
272
  // $FlowFixMe[invalid-computed-prop]
258
273
  return {
259
- [mdVerbatim]: true,
260
- value: '__' + escapeMarkdown(`${s}`) + '__'
274
+ [mdVerbatim]: '__' + escapeMarkdown(`${s}`) + '__'
261
275
  };
262
276
  };
263
277
 
264
278
  md.strikethrough = function (s) {
265
279
  // $FlowFixMe[invalid-computed-prop]
266
280
  return {
267
- [mdVerbatim]: true,
268
- value: '~~' + escapeMarkdown(`${s}`) + '~~'
281
+ [mdVerbatim]: '~~' + escapeMarkdown(`${s}`) + '~~'
269
282
  };
270
283
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/diagnostic",
3
- "version": "2.0.0-beta.3.1",
3
+ "version": "2.0.0-nightly.1002+5530a6ef",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,12 +15,17 @@
15
15
  },
16
16
  "main": "lib/diagnostic.js",
17
17
  "source": "src/diagnostic.js",
18
+ "types": "lib/diagnostic.d.ts",
18
19
  "engines": {
19
20
  "node": ">= 12.0.0"
20
21
  },
22
+ "scripts": {
23
+ "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",
24
+ "check-ts": "tsc --noEmit lib/diagnostic.d.ts"
25
+ },
21
26
  "dependencies": {
22
27
  "json-source-map": "^0.6.1",
23
28
  "nullthrows": "^1.1.1"
24
29
  },
25
- "gitHead": "daece49d003ba804bbdaa3a7ed3d6aaf446f166d"
30
+ "gitHead": "5530a6eff8b619873353baeb0457ae4ec591e9fa"
26
31
  }
package/src/diagnostic.js CHANGED
@@ -1,5 +1,4 @@
1
1
  // @flow strict-local
2
- import type {FilePath} from '@parcel/types';
3
2
 
4
3
  import invariant from 'assert';
5
4
  import nullthrows from 'nullthrows';
@@ -35,11 +34,15 @@ export type DiagnosticCodeFrame = {|
35
34
  /**
36
35
  * The contents of the source file.
37
36
  *
38
- * If no code is passed, it will be read in from Diagnostic#filePath, remember that
37
+ * If no code is passed, it will be read in from filePath, remember that
39
38
  * the asset's current code could be different from the input contents.
40
39
  *
41
40
  */
42
41
  code?: string,
42
+ /** Path to the file this code frame is about (optional, absolute or relative to the project root) */
43
+ filePath?: string,
44
+ /** Language of the file this code frame is about (optional) */
45
+ language?: string,
43
46
  codeHighlights: Array<DiagnosticCodeHighlight>,
44
47
  |};
45
48
 
@@ -58,35 +61,32 @@ export type Diagnostic = {|
58
61
  /** Name of the error (optional) */
59
62
  name?: string,
60
63
 
61
- /** Path to the file this diagnostic is about (optional, absolute or relative to the project root) */
62
- filePath?: FilePath,
63
- /** Language of the file this diagnostic is about (optional) */
64
- language?: string,
65
-
66
64
  /** A code frame points to a certain location(s) in the file this diagnostic is linked to (optional) */
67
- codeFrame?: DiagnosticCodeFrame,
65
+ codeFrames?: ?Array<DiagnosticCodeFrame>,
68
66
 
69
67
  /** An optional list of strings that suggest ways to resolve this issue */
70
68
  hints?: Array<string>,
71
69
 
72
70
  /** @private */
73
71
  skipFormatting?: boolean,
72
+
73
+ /** A URL to documentation to learn more about the diagnostic. */
74
+ documentationURL?: string,
74
75
  |};
75
76
 
76
77
  // This type should represent all error formats Parcel can encounter...
77
- export type PrintableError = Error & {
78
- fileName?: string,
79
- filePath?: string,
80
- codeFrame?: string,
81
- highlightedCodeFrame?: string,
78
+ export interface PrintableError extends Error {
79
+ fileName?: string;
80
+ filePath?: string;
81
+ codeFrame?: string;
82
+ highlightedCodeFrame?: string;
82
83
  loc?: ?{
83
84
  column: number,
84
85
  line: number,
85
86
  ...
86
- },
87
- source?: string,
88
- ...
89
- };
87
+ };
88
+ source?: string;
89
+ }
90
90
 
91
91
  export type DiagnosticWithoutOrigin = {|
92
92
  ...Diagnostic,
@@ -99,38 +99,41 @@ export type Diagnostifiable =
99
99
  | Array<Diagnostic>
100
100
  | ThrowableDiagnostic
101
101
  | PrintableError
102
+ | Error
102
103
  | string;
103
104
 
104
105
  /** Normalize the given value into a diagnostic. */
105
106
  export function anyToDiagnostic(input: Diagnostifiable): Array<Diagnostic> {
106
- // $FlowFixMe
107
- let diagnostic: Array<Diagnostic> = input;
108
-
109
- if (input instanceof ThrowableDiagnostic) {
110
- diagnostic = input.diagnostics;
107
+ if (Array.isArray(input)) {
108
+ return input;
109
+ } else if (input instanceof ThrowableDiagnostic) {
110
+ return input.diagnostics;
111
111
  } else if (input instanceof Error) {
112
- diagnostic = errorToDiagnostic(input);
112
+ return errorToDiagnostic(input);
113
+ } else if (typeof input === 'string') {
114
+ return [{message: input}];
115
+ } else if (typeof input === 'object') {
116
+ return [input];
117
+ } else {
118
+ return errorToDiagnostic(input);
113
119
  }
114
-
115
- return Array.isArray(diagnostic) ? diagnostic : [diagnostic];
116
120
  }
117
121
 
118
122
  /** Normalize the given error into a diagnostic. */
119
123
  export function errorToDiagnostic(
120
124
  error: ThrowableDiagnostic | PrintableError | string,
121
- defaultValues: {|
125
+ defaultValues?: {|
122
126
  origin?: ?string,
123
127
  filePath?: ?string,
124
- |} = {...null},
128
+ |},
125
129
  ): Array<Diagnostic> {
126
- let codeFrame: DiagnosticCodeFrame | void = undefined;
130
+ let codeFrames: ?Array<DiagnosticCodeFrame> = undefined;
127
131
 
128
132
  if (typeof error === 'string') {
129
133
  return [
130
134
  {
131
135
  origin: defaultValues?.origin ?? 'Error',
132
136
  message: escapeMarkdown(error),
133
- codeFrame,
134
137
  },
135
138
  ];
136
139
  }
@@ -145,21 +148,28 @@ export function errorToDiagnostic(
145
148
  }
146
149
 
147
150
  if (error.loc && error.source != null) {
148
- codeFrame = {
149
- code: error.source,
150
- codeHighlights: [
151
- {
152
- start: {
153
- line: error.loc.line,
154
- column: error.loc.column,
155
- },
156
- end: {
157
- line: error.loc.line,
158
- column: error.loc.column,
151
+ codeFrames = [
152
+ {
153
+ filePath:
154
+ error.filePath ??
155
+ error.fileName ??
156
+ defaultValues?.filePath ??
157
+ undefined,
158
+ code: error.source,
159
+ codeHighlights: [
160
+ {
161
+ start: {
162
+ line: error.loc.line,
163
+ column: error.loc.column,
164
+ },
165
+ end: {
166
+ line: error.loc.line,
167
+ column: error.loc.column,
168
+ },
159
169
  },
160
- },
161
- ],
162
- };
170
+ ],
171
+ },
172
+ ];
163
173
  }
164
174
 
165
175
  return [
@@ -167,13 +177,11 @@ export function errorToDiagnostic(
167
177
  origin: defaultValues?.origin ?? 'Error',
168
178
  message: escapeMarkdown(error.message),
169
179
  name: error.name,
170
- filePath:
171
- error.filePath ??
172
- error.fileName ??
173
- defaultValues?.filePath ??
174
- undefined,
175
- stack: error.highlightedCodeFrame ?? error.codeFrame ?? error.stack,
176
- codeFrame,
180
+ stack:
181
+ codeFrames == null
182
+ ? error.highlightedCodeFrame ?? error.codeFrame ?? error.stack
183
+ : undefined,
184
+ codeFrames,
177
185
  },
178
186
  ];
179
187
  }
@@ -197,7 +205,9 @@ export default class ThrowableDiagnostic extends Error {
197
205
 
198
206
  // Construct error from diagnostics
199
207
  super(diagnostics[0].message);
208
+ // @ts-ignore
200
209
  this.stack = diagnostics[0].stack ?? super.stack;
210
+ // @ts-ignore
201
211
  this.name = diagnostics[0].name ?? super.name;
202
212
 
203
213
  this.diagnostics = diagnostics;
@@ -280,8 +290,7 @@ export function escapeMarkdown(s: string): string {
280
290
  return result;
281
291
  }
282
292
 
283
- // $FlowFixMe[unclear-type]
284
- type TemplateInput = any;
293
+ type TemplateInput = $FlowFixMe;
285
294
 
286
295
  const mdVerbatim = Symbol();
287
296
  export function md(
@@ -290,31 +299,39 @@ export function md(
290
299
  ): string {
291
300
  let result = [];
292
301
  for (let i = 0; i < params.length; i++) {
302
+ result.push(strings[i]);
303
+
293
304
  let param = params[i];
294
- result.push(
295
- strings[i],
296
- param?.[mdVerbatim] ? param.value : escapeMarkdown(`${param}`),
297
- );
305
+ if (Array.isArray(param)) {
306
+ for (let j = 0; j < param.length; j++) {
307
+ result.push(param[j]?.[mdVerbatim] ?? escapeMarkdown(`${param[j]}`));
308
+ if (j < param.length - 1) {
309
+ result.push(', ');
310
+ }
311
+ }
312
+ } else {
313
+ result.push(param?.[mdVerbatim] ?? escapeMarkdown(`${param}`));
314
+ }
298
315
  }
299
316
  return result.join('') + strings[strings.length - 1];
300
317
  }
301
318
 
302
- md.bold = function(s: TemplateInput): {|value: string|} {
319
+ md.bold = function (s: TemplateInput): TemplateInput {
303
320
  // $FlowFixMe[invalid-computed-prop]
304
- return {[mdVerbatim]: true, value: '**' + escapeMarkdown(`${s}`) + '**'};
321
+ return {[mdVerbatim]: '**' + escapeMarkdown(`${s}`) + '**'};
305
322
  };
306
323
 
307
- md.italic = function(s: TemplateInput): {|value: string|} {
324
+ md.italic = function (s: TemplateInput): TemplateInput {
308
325
  // $FlowFixMe[invalid-computed-prop]
309
- return {[mdVerbatim]: true, value: '_' + escapeMarkdown(`${s}`) + '_'};
326
+ return {[mdVerbatim]: '_' + escapeMarkdown(`${s}`) + '_'};
310
327
  };
311
328
 
312
- md.underline = function(s: TemplateInput): {|value: string|} {
329
+ md.underline = function (s: TemplateInput): TemplateInput {
313
330
  // $FlowFixMe[invalid-computed-prop]
314
- return {[mdVerbatim]: true, value: '__' + escapeMarkdown(`${s}`) + '__'};
331
+ return {[mdVerbatim]: '__' + escapeMarkdown(`${s}`) + '__'};
315
332
  };
316
333
 
317
- md.strikethrough = function(s: TemplateInput): {|value: string|} {
334
+ md.strikethrough = function (s: TemplateInput): TemplateInput {
318
335
  // $FlowFixMe[invalid-computed-prop]
319
- return {[mdVerbatim]: true, value: '~~' + escapeMarkdown(`${s}`) + '~~'};
336
+ return {[mdVerbatim]: '~~' + escapeMarkdown(`${s}`) + '~~'};
320
337
  };