forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompilerOptions.ts
More file actions
84 lines (72 loc) · 2.33 KB
/
CompilerOptions.ts
File metadata and controls
84 lines (72 loc) · 2.33 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import * as ts from "typescript";
type KnownKeys<T> = { [K in keyof T]: string extends K ? never : number extends K ? never : K } extends {
[_ in keyof T]: infer U;
}
? U
: never;
type OmitIndexSignature<T extends Record<any, any>> = Pick<T, KnownKeys<T>>;
export interface TransformerImport {
transform: string;
import?: string;
after?: boolean;
afterDeclarations?: boolean;
type?: "program" | "config" | "checker" | "raw" | "compilerOptions";
[option: string]: any;
}
export type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & {
noImplicitSelf?: boolean;
noHeader?: boolean;
luaBundle?: string;
luaBundleEntry?: string;
luaTarget?: LuaTarget;
luaLibImport?: LuaLibImportKind;
noHoisting?: boolean;
sourceMapTraceback?: boolean;
plugins?: Array<ts.PluginImport | TransformerImport>;
[option: string]: ts.CompilerOptions[string] | Array<ts.PluginImport | TransformerImport>;
};
export enum LuaLibImportKind {
None = "none",
Always = "always",
Inline = "inline",
Require = "require",
}
export enum LuaTarget {
Lua51 = "5.1",
Lua52 = "5.2",
Lua53 = "5.3",
LuaJIT = "JIT",
}
export function validateOptions(options: CompilerOptions): ts.Diagnostic[] {
const diagnostics: ts.Diagnostic[] = [];
if (options.luaBundle && !options.luaBundleEntry) {
diagnostics.push(configErrorDiagnostic(`'luaBundleEntry' is required when 'luaBundle' is enabled.`));
}
if (options.luaBundle && options.luaLibImport === LuaLibImportKind.Inline) {
diagnostics.push(
configWarningDiagnostic(
`Using 'luaBundle' with 'luaLibImport: "inline"' might generate duplicate code. ` +
`It is recommended to use 'luaLibImport: "require"'`
)
);
}
return diagnostics;
}
const configErrorDiagnostic = (message: string): ts.Diagnostic => ({
file: undefined,
start: undefined,
length: undefined,
category: ts.DiagnosticCategory.Error,
code: 0,
source: "typescript-to-lua",
messageText: message,
});
const configWarningDiagnostic = (message: string): ts.Diagnostic => ({
file: undefined,
start: undefined,
length: undefined,
category: ts.DiagnosticCategory.Warning,
code: 0,
source: "typescript-to-lua",
messageText: message,
});