Skip to content

Commit ba2cc1f

Browse files
committed
Reduce luaEntry option to a string naming a module to export
1 parent d36356d commit ba2cc1f

5 files changed

Lines changed: 18 additions & 37 deletions

File tree

src/CommandLineParser.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ interface CommandLineOptionOfBoolean extends CommandLineOptionBase {
2222
type: "boolean";
2323
}
2424

25-
interface CommandLineOptionOfStringArray extends CommandLineOptionBase {
26-
type: "string[]";
25+
interface CommandLineOptionOfString extends CommandLineOptionBase {
26+
type: "string";
2727
}
2828

29-
type CommandLineOption = CommandLineOptionOfEnum | CommandLineOptionOfBoolean | CommandLineOptionOfStringArray;
29+
type CommandLineOption = CommandLineOptionOfEnum | CommandLineOptionOfBoolean | CommandLineOptionOfString;
3030

3131
const optionDeclarations: CommandLineOption[] = [
3232
{
3333
name: "luaEntry",
34-
description: "Specifies a series of entry points to execute in the resulting output file.",
35-
type: "string[]",
34+
description: "Specifies an entry point that will be executed in the resulting output file.",
35+
type: "string",
3636
},
3737
{
3838
name: "luaLibImport",
@@ -237,18 +237,7 @@ function readValue(option: CommandLineOption, value: unknown): ReadValueResult {
237237
return { value: enumValue };
238238
}
239239

240-
case "string[]": {
241-
if (Array.isArray(value)) {
242-
if (value.some(str => typeof str !== "string")) {
243-
return {
244-
value: undefined,
245-
error: diagnosticFactories.invalidStringArrayForOption(option.name),
246-
};
247-
}
248-
249-
return { value };
250-
}
251-
240+
case "string": {
252241
if (typeof value !== "string") {
253242
return {
254243
value: undefined,

src/CompilerOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface TransformerImport {
2020
export type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & {
2121
noImplicitSelf?: boolean;
2222
noHeader?: boolean;
23-
luaEntry?: string[];
23+
luaEntry?: string;
2424
luaTarget?: LuaTarget;
2525
luaLibImport?: LuaLibImportKind;
2626
noHoisting?: boolean;

src/LuaTransformer.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,15 @@ export class LuaTransformer {
141141
);
142142

143143
if (this.options.luaEntry) {
144-
const requireCalls = this.options.luaEntry.map(entry => {
145-
const sourceFile = this.program.getSourceFile(entry);
146-
if (sourceFile) {
147-
const formattedEntryName = tsHelper.getExportPath(sourceFile.fileName, this.options);
148-
return tstl.createExpressionStatement(
149-
this.createModuleRequire(ts.createStringLiteral(formattedEntryName), false)
150-
);
151-
} else {
152-
throw TSTLErrors.LuaEntryNotFound(entry);
153-
}
154-
});
155-
combinedStatements.push(...requireCalls);
144+
const sourceFile = this.program.getSourceFile(this.options.luaEntry);
145+
if (sourceFile) {
146+
const formattedEntryName = tsHelper.getExportPath(sourceFile.fileName, this.options);
147+
const requireCall = this.createModuleRequire(ts.createStringLiteral(formattedEntryName), false);
148+
const returnStatement = tstl.createReturnStatement([requireCall]);
149+
combinedStatements.push(returnStatement);
150+
} else {
151+
throw TSTLErrors.LuaEntryNotFound(this.options.luaEntry);
152+
}
156153
}
157154

158155
return tstl.createBlock(combinedStatements, bundle);

src/diagnostics.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,3 @@ export const optionBuildMustBeFirstCommandLineArgument = createCommandLineError(
130130
6369,
131131
() => "Option '--build' must be the first command line argument."
132132
);
133-
134-
export const invalidStringArrayForOption = createCommandLineError(
135-
6370,
136-
(name: string) => `Option '${name}' received an invalid array of strings.`
137-
);

test/unit/outFile.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const exportValueSource = "export const value = true;";
77
const reexportValueSource = 'export { value } from "./export";';
88
const validateValueSource = 'if (value !== true) { throw "Failed to import value" }';
99

10-
function outFileOptionsWithEntry(entry: string): CompilerOptions {
11-
return { outFile: "main.lua", noHoisting: true, module: ts.ModuleKind.AMD, luaEntry: [entry] };
10+
function outFileOptionsWithEntry(luaEntry: string): CompilerOptions {
11+
return { outFile: "main.lua", noHoisting: true, module: ts.ModuleKind.AMD, luaEntry };
1212
}
1313

1414
describe("outFile", () => {

0 commit comments

Comments
 (0)