Skip to content

Commit e23b1d6

Browse files
committed
Factorize transpilation diagnostics
1 parent be9bb93 commit e23b1d6

File tree

2 files changed

+22
-42
lines changed

2 files changed

+22
-42
lines changed

src/transformation/utils/diagnostics.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ export const luaIteratorForbiddenUsage = createDiagnosticFactory(
9797
"the '@tupleReturn' annotation."
9898
);
9999

100-
export const unsupportedSyntaxKind = createDiagnosticFactory(
101-
(description: string, kind: ts.SyntaxKind) => `Unsupported ${description} kind: ${ts.SyntaxKind[kind]}`
102-
);
103-
104100
export const unsupportedNullishCoalescing = createDiagnosticFactory("Nullish coalescing is not supported.");
105101

106102
export const unsupportedAccessorInObjectLiteral = createDiagnosticFactory(

src/transpilation/diagnostics.ts

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,35 @@
11
import * as ts from "typescript";
22

3-
export const toLoadTransformerItShouldBeTranspiled = (transform: string): ts.Diagnostic => ({
3+
const createDiagnosticFactory = <TArgs extends any[]>(getMessage: (...args: TArgs) => string) => (
4+
...args: TArgs
5+
): ts.Diagnostic => ({
46
file: undefined,
57
start: undefined,
68
length: undefined,
79
category: ts.DiagnosticCategory.Error,
810
code: 0,
911
source: "typescript-to-lua",
10-
messageText: `To load "${transform}" transformer it should be transpiled or "ts-node" should be installed`,
12+
messageText: getMessage(...args),
1113
});
1214

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+
);
2219

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+
);
3223

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+
);
4227

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

Comments
 (0)