-
-
Notifications
You must be signed in to change notification settings - Fork 185
Expand file tree
/
Copy pathCompilerOptions.ts
More file actions
107 lines (88 loc) · 2.9 KB
/
CompilerOptions.ts
File metadata and controls
107 lines (88 loc) · 2.9 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import * as ts from "typescript";
import { JsxEmit } from "typescript";
import * as diagnosticFactories from "./transpilation/diagnostics";
import { Plugin } from "./transpilation/plugins";
type OmitIndexSignature<T> = {
[K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
};
export interface TransformerImport {
transform: string;
import?: string;
after?: boolean;
afterDeclarations?: boolean;
type?: "program" | "config" | "checker" | "raw" | "compilerOptions";
[option: string]: any;
}
export interface LuaPluginImport {
name: string;
import?: string;
[option: string]: any;
}
export interface InMemoryLuaPlugin {
plugin: Plugin | ((options: Record<string, any>) => Plugin);
[option: string]: any;
}
export interface TypeScriptToLuaOptions {
buildMode?: BuildMode;
extension?: string;
luaBundle?: string;
luaBundleEntry?: string;
luaTarget?: LuaTarget;
luaLibImport?: LuaLibImportKind;
luaPlugins?: Array<LuaPluginImport | InMemoryLuaPlugin>;
noImplicitGlobalVariables?: boolean;
noImplicitSelf?: boolean;
noHeader?: boolean;
noResolvePaths?: string[];
plugins?: Array<ts.PluginImport | TransformerImport>;
sourceMapTraceback?: boolean;
tstlVerbose?: boolean;
lua51AllowTryCatchInAsyncAwait?: boolean;
measurePerformance?: boolean;
}
export type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> &
TypeScriptToLuaOptions & {
[option: string]: any;
};
export enum LuaLibImportKind {
None = "none",
Inline = "inline",
Require = "require",
RequireMinimal = "require-minimal",
}
export enum LuaTarget {
Universal = "universal",
Lua50 = "5.0",
Lua51 = "5.1",
Lua52 = "5.2",
Lua53 = "5.3",
Lua54 = "5.4",
Lua55 = "5.5",
LuaJIT = "JIT",
Luau = "Luau",
}
export enum BuildMode {
Default = "default",
Library = "library",
}
export const isBundleEnabled = (options: CompilerOptions) =>
options.luaBundle !== undefined && options.luaBundleEntry !== undefined;
export function validateOptions(options: CompilerOptions): ts.Diagnostic[] {
const diagnostics: ts.Diagnostic[] = [];
if (options.luaBundle && !options.luaBundleEntry) {
diagnostics.push(diagnosticFactories.luaBundleEntryIsRequired());
}
if (options.luaBundle && options.luaLibImport === LuaLibImportKind.Inline) {
diagnostics.push(diagnosticFactories.usingLuaBundleWithInlineMightGenerateDuplicateCode());
}
if (options.luaBundle && options.buildMode === BuildMode.Library) {
diagnostics.push(diagnosticFactories.cannotBundleLibrary());
}
if (options.jsx && options.jsx !== JsxEmit.React) {
diagnostics.push(diagnosticFactories.unsupportedJsxEmit());
}
if (options.paths && !options.baseUrl) {
diagnostics.push(diagnosticFactories.pathsWithoutBaseUrl());
}
return diagnostics;
}