|
1 | 1 | import * as ts from "typescript"; |
2 | 2 |
|
3 | | -export const toLoadTransformerItShouldBeTranspiled = (transform: string): ts.Diagnostic => ({ |
| 3 | +const createDiagnosticFactory = <TArgs extends any[]>(getMessage: (...args: TArgs) => string) => ( |
| 4 | + ...args: TArgs |
| 5 | +): ts.Diagnostic => ({ |
4 | 6 | file: undefined, |
5 | 7 | start: undefined, |
6 | 8 | length: undefined, |
7 | 9 | category: ts.DiagnosticCategory.Error, |
8 | 10 | code: 0, |
9 | 11 | source: "typescript-to-lua", |
10 | | - messageText: `To load "${transform}" transformer it should be transpiled or "ts-node" should be installed`, |
| 12 | + messageText: getMessage(...args), |
11 | 13 | }); |
12 | 14 |
|
13 | | -export const couldNotResolveTransformerFrom = (transform: string, base: string): ts.Diagnostic => ({ |
14 | | - file: undefined, |
15 | | - start: undefined, |
16 | | - length: undefined, |
17 | | - category: ts.DiagnosticCategory.Error, |
18 | | - code: 0, |
19 | | - source: "typescript-to-lua", |
20 | | - messageText: `Could not resolve "${transform}" transformer from "${base}".`, |
21 | | -}); |
| 15 | +export const toLoadTransformerItShouldBeTranspiled = createDiagnosticFactory( |
| 16 | + (transform: string) => |
| 17 | + `To load "${transform}" transformer it should be transpiled or "ts-node" should be installed.` |
| 18 | +); |
22 | 19 |
|
23 | | -export const transformerShouldHaveAExport = (transform: string, importName: string): ts.Diagnostic => ({ |
24 | | - file: undefined, |
25 | | - start: undefined, |
26 | | - length: undefined, |
27 | | - category: ts.DiagnosticCategory.Error, |
28 | | - code: 0, |
29 | | - source: "typescript-to-lua", |
30 | | - messageText: `"${transform}" transformer should have a "${importName}" export`, |
31 | | -}); |
| 20 | +export const couldNotResolveTransformerFrom = createDiagnosticFactory( |
| 21 | + (transform: string, base: string) => `Could not resolve "${transform}" transformer from "${base}".` |
| 22 | +); |
32 | 23 |
|
33 | | -export const transformerShouldBeATsTransformerFactory = (transform: string): ts.Diagnostic => ({ |
34 | | - file: undefined, |
35 | | - start: undefined, |
36 | | - length: undefined, |
37 | | - category: ts.DiagnosticCategory.Error, |
38 | | - code: 0, |
39 | | - source: "typescript-to-lua", |
40 | | - messageText: `"${transform}" transformer should be a ts.TransformerFactory or an object with ts.TransformerFactory values`, |
41 | | -}); |
| 24 | +export const transformerShouldHaveAExport = createDiagnosticFactory( |
| 25 | + (transform: string, importName: string) => `"${transform}" transformer should have a "${importName}" export.` |
| 26 | +); |
42 | 27 |
|
43 | | -export const couldNotFindBundleEntryPoint = (entryPoint: string): ts.Diagnostic => ({ |
44 | | - file: undefined, |
45 | | - start: undefined, |
46 | | - length: undefined, |
47 | | - category: ts.DiagnosticCategory.Error, |
48 | | - code: 0, |
49 | | - source: "typescript-to-lua", |
50 | | - messageText: `Could not find bundle entry point '${entryPoint}'. It should be a file in the project.`, |
51 | | -}); |
| 28 | +export const transformerShouldBeATsTransformerFactory = createDiagnosticFactory( |
| 29 | + (transform: string) => |
| 30 | + `"${transform}" transformer should be a ts.TransformerFactory or an object with ts.TransformerFactory values.` |
| 31 | +); |
| 32 | + |
| 33 | +export const couldNotFindBundleEntryPoint = createDiagnosticFactory( |
| 34 | + (entryPoint: string) => `Could not find bundle entry point '${entryPoint}'. It should be a file in the project.` |
| 35 | +); |
0 commit comments