Skip to content

Commit

Permalink
Remove options argument from LuaTransformer
Browse files Browse the repository at this point in the history
  • Loading branch information
ark120202 committed Apr 22, 2019
1 parent 946f16a commit 4c76457
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
10 changes: 4 additions & 6 deletions src/LuaTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ export class LuaTransformer {
"not", "or", "repeat", "return", "self", "then", "until", "while",
]);

private isStrict = true;
private isStrict: boolean;
private luaTarget: LuaTarget;

private checker: ts.TypeChecker;
protected options: CompilerOptions;
protected program: ts.Program;

private isModule = false;

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

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

public constructor(program: ts.Program, options: CompilerOptions) {
public constructor(protected program: ts.Program) {
this.checker = program.getTypeChecker();
this.options = options;
this.program = program;
this.options = program.getCompilerOptions();
this.isStrict = this.options.alwaysStrict !== undefined
|| (this.options.strict !== undefined && this.options.alwaysStrict !== false)
|| (this.isModule
&& this.options.target !== undefined
&& this.options.target >= ts.ScriptTarget.ES2015);

this.luaTarget = options.luaTarget || LuaTarget.LuaJIT;
this.luaTarget = this.options.luaTarget || LuaTarget.LuaJIT;

this.setupState();
}
Expand Down
9 changes: 4 additions & 5 deletions src/Transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,21 @@ export interface TranspileResult {

export interface TranspileOptions {
program: ts.Program;
customTransformers?: ts.CustomTransformers;
sourceFiles?: ts.SourceFile[];
printer?: LuaPrinter;
customTransformers?: ts.CustomTransformers;
transformer?: LuaTransformer;
printer?: LuaPrinter;
}

export function transpile({
program,
customTransformers = {},
sourceFiles: targetSourceFiles,
customTransformers = {},
transformer = new LuaTransformer(program),
printer,
transformer,
}: TranspileOptions): TranspileResult {
const options = program.getCompilerOptions() as CompilerOptions;
printer = printer || new LuaPrinter(options);
transformer = transformer || new LuaTransformer(program, options);

const diagnostics: ts.Diagnostic[] = [];
const transpiledFiles = new Map<string, TranspiledFile>();
Expand Down
7 changes: 2 additions & 5 deletions test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ export function executeLua(luaStr: string, withLib = true): any {
}

// Get a mock transformer to use for testing
export function makeTestTransformer(
target: tstl.LuaTarget = tstl.LuaTarget.Lua53,
): tstl.LuaTransformer {
const options = { luaTarget: target };
return new tstl.LuaTransformer(ts.createProgram([], options), options);
export function makeTestTransformer(luaTarget = tstl.LuaTarget.Lua53): tstl.LuaTransformer {
return new tstl.LuaTransformer(ts.createProgram([], { luaTarget }));
}

export function transpileAndExecute(
Expand Down

0 comments on commit 4c76457

Please sign in to comment.