main
ts 41 lines 790 Bytes
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 export enum MessageSource {
9 Babel,
10 Forget,
11 Playground,
12 }
13
14 export enum MessageLevel {
15 Info,
16 Warning,
17 Error,
18 }
19
20 export interface Message {
21 title: string;
22 level: MessageLevel;
23 source: MessageSource; // Can be used to further style messages differently.
24 codeframe: string | undefined;
25 }
26
27 export function createMessage(
28 message: string,
29 level: MessageLevel,
30 source: MessageSource,
31 ): Message {
32 const [title, ...body] = message.split('\n');
33 const codeframe = body.length > 0 ? body.join('\n') : undefined;
34
35 return {
36 source,
37 level,
38 title,
39 codeframe,
40 };
41 }