Skip to content

Commit 4c76457

Browse files
committed
Remove options argument from LuaTransformer
1 parent 946f16a commit 4c76457

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

src/LuaTransformer.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ export class LuaTransformer {
4343
"not", "or", "repeat", "return", "self", "then", "until", "while",
4444
]);
4545

46-
private isStrict = true;
46+
private isStrict: boolean;
4747
private luaTarget: LuaTarget;
4848

4949
private checker: ts.TypeChecker;
5050
protected options: CompilerOptions;
51-
protected program: ts.Program;
5251

5352
private isModule = false;
5453

@@ -69,17 +68,16 @@ export class LuaTransformer {
6968

7069
private readonly typeValidationCache: Map<ts.Type, Set<ts.Type>> = new Map<ts.Type, Set<ts.Type>>();
7170

72-
public constructor(program: ts.Program, options: CompilerOptions) {
71+
public constructor(protected program: ts.Program) {
7372
this.checker = program.getTypeChecker();
74-
this.options = options;
75-
this.program = program;
73+
this.options = program.getCompilerOptions();
7674
this.isStrict = this.options.alwaysStrict !== undefined
7775
|| (this.options.strict !== undefined && this.options.alwaysStrict !== false)
7876
|| (this.isModule
7977
&& this.options.target !== undefined
8078
&& this.options.target >= ts.ScriptTarget.ES2015);
8179

82-
this.luaTarget = options.luaTarget || LuaTarget.LuaJIT;
80+
this.luaTarget = this.options.luaTarget || LuaTarget.LuaJIT;
8381

8482
this.setupState();
8583
}

src/Transpile.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,21 @@ export interface TranspileResult {
4848

4949
export interface TranspileOptions {
5050
program: ts.Program;
51-
customTransformers?: ts.CustomTransformers;
5251
sourceFiles?: ts.SourceFile[];
53-
printer?: LuaPrinter;
52+
customTransformers?: ts.CustomTransformers;
5453
transformer?: LuaTransformer;
54+
printer?: LuaPrinter;
5555
}
5656

5757
export function transpile({
5858
program,
59-
customTransformers = {},
6059
sourceFiles: targetSourceFiles,
60+
customTransformers = {},
61+
transformer = new LuaTransformer(program),
6162
printer,
62-
transformer,
6363
}: TranspileOptions): TranspileResult {
6464
const options = program.getCompilerOptions() as CompilerOptions;
6565
printer = printer || new LuaPrinter(options);
66-
transformer = transformer || new LuaTransformer(program, options);
6766

6867
const diagnostics: ts.Diagnostic[] = [];
6968
const transpiledFiles = new Map<string, TranspiledFile>();

test/util.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,8 @@ export function executeLua(luaStr: string, withLib = true): any {
9393
}
9494

9595
// Get a mock transformer to use for testing
96-
export function makeTestTransformer(
97-
target: tstl.LuaTarget = tstl.LuaTarget.Lua53,
98-
): tstl.LuaTransformer {
99-
const options = { luaTarget: target };
100-
return new tstl.LuaTransformer(ts.createProgram([], options), options);
96+
export function makeTestTransformer(luaTarget = tstl.LuaTarget.Lua53): tstl.LuaTransformer {
97+
return new tstl.LuaTransformer(ts.createProgram([], { luaTarget }));
10198
}
10299

103100
export function transpileAndExecute(

0 commit comments

Comments
 (0)