Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions compiler/apps/playground/lib/stores/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,34 @@
*/

export enum MessageSource {
Babel,
Forget,
Playground,
Babel = 'Babel',
Forget = 'Forget',
Playground = 'Playground',
}

export enum MessageLevel {
Info,
Warning,
Error,
Info = 'info',
Warning = 'warning',
Error = 'error',
}

export interface Message {
title: string;
level: MessageLevel;
source: MessageSource; // Can be used to further style messages differently.
codeframe: string | undefined;
readonly title: string;
readonly level: MessageLevel;
readonly source: MessageSource; // Can be used to further style messages differently.
readonly codeframe?: string;
}

export function createMessage(
message: string,
level: MessageLevel,
source: MessageSource,
): Message {
const [title, ...body] = message.split('\n');
const codeframe = body.length > 0 ? body.join('\n') : undefined;
const normalized = message.replace(/\r\n/g, '\n').trimEnd();
const [titleRaw, ...body] = normalized.split('\n');
const title = titleRaw.trim();
const codeframeRaw = body.join('\n').trim();
const codeframe = codeframeRaw === '' ? undefined : codeframeRaw;

return {
source,
Expand Down