forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
38 lines (30 loc) · 869 Bytes
/
index.ts
File metadata and controls
38 lines (30 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { TranspiledModule } from '../typings/codesandbox';
const transformers: Check[] = [];
export type SuggestionAction = (module: TranspiledModule, modules: TranspiledModule[]) => boolean;
export interface Suggestion {
title: string;
action: SuggestionAction;
}
export type Check = (
error: Error,
module: TranspiledModule,
modules: TranspiledModule[]
) => {
name: string | undefined;
message: string;
suggestions: Suggestion[];
} | null;
export function transformError(
error: Error,
module: TranspiledModule,
modules: TranspiledModule[]
) {
const transformedErrors = transformers.map(c => c(error, module, modules)).filter(x => x != null);
return transformedErrors[0];
}
export function clearErrorTransformers() {
transformers.length = 0;
}
export function registerErrorTransformer(check: Check) {
transformers.push(check);
}