Skip to content

Commit 257df03

Browse files
committed
Replaced numeric loops woth for of and removed useless getRequireKeyword
1 parent a4cf0de commit 257df03

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

src/Transpiler.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,6 @@ export abstract class LuaTranspiler {
174174
return `"${this.pathToLuaRequirePath(relativePath)}"`;
175175
}
176176

177-
public getRequireKeyword(): string {
178-
return "require";
179-
}
180-
181177
public pathToLuaRequirePath(filePath: string): string {
182178
return filePath.replace(new RegExp("\\\\|\/", "g"), ".");
183179
}
@@ -320,18 +316,18 @@ export abstract class LuaTranspiler {
320316

321317
const imports = node.importClause.namedBindings;
322318

323-
const reqKeyword = this.getRequireKeyword();
319+
const requireKeyword = "require";
324320

325321
if (ts.isNamedImports(imports)) {
326322
const fileImportTable = path.basename(importPathWithoutQuotes) + this.importCount;
327323
const resolvedImportPath = this.getImportPath(importPathWithoutQuotes);
328324

329-
let result = `local ${fileImportTable} = ${reqKeyword}(${resolvedImportPath})\n`;
325+
let result = `local ${fileImportTable} = ${requireKeyword}(${resolvedImportPath})\n`;
330326
this.importCount++;
331327

332328
const filteredElements = imports.elements.filter(e => {
333-
const decs = tsHelper.getCustomDecorators(this.checker.getTypeAtLocation(e), this.checker);
334-
return !decs.has(DecoratorKind.Extension) && !decs.has(DecoratorKind.MetaExtension);
329+
const decorators = tsHelper.getCustomDecorators(this.checker.getTypeAtLocation(e), this.checker);
330+
return !decorators.has(DecoratorKind.Extension) && !decorators.has(DecoratorKind.MetaExtension);
335331
});
336332

337333
if (filteredElements.length === 0) {
@@ -351,7 +347,7 @@ export abstract class LuaTranspiler {
351347
return result;
352348
} else if (ts.isNamespaceImport(imports)) {
353349
const resolvedImportPath = this.getImportPath(importPathWithoutQuotes);
354-
return `local ${this.transpileIdentifier(imports.name)} = ${reqKeyword}(${resolvedImportPath})\n`;
350+
return `local ${this.transpileIdentifier(imports.name)} = ${requireKeyword}(${resolvedImportPath})\n`;
355351
} else {
356352
throw TSTLErrors.UnsupportedImportType(imports);
357353
}

src/lualib/ArrayConcat.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
/* tslint:disable */
21
declare function pcall(func: Function): any;
32
declare function type(val: any): string;
43

54
function __TS__ArrayConcat(arr1: any[], ...args: any[]): any[] {
65
const out: any[] = [];
7-
for (let i = 0; i < arr1.length; i++) {
8-
out[out.length] = arr1[i];
6+
for (const val of arr1) {
7+
out[out.length] = val;
98
}
10-
for (let i = 0; i < args.length; i++) {
11-
const arg = args[i];
9+
for (const arg of args) {
1210
// Hack because we don't have an isArray function
1311
if (pcall(() => (arg as any[]).length) && type(arg) !== "string") {
1412
const argAsArray = (arg as any[]);
15-
for (let j = 0; j < argAsArray.length; j++) {
16-
out[out.length] = argAsArray[j];
13+
for (const val of argAsArray) {
14+
out[out.length] = val;
1715
}
1816
} else {
1917
out[out.length] = arg;

src/lualib/ArrayPush.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
function __TS__ArrayPush<T>(arr: T[], ...items: T[]): number {
2-
/* tslint:disable */
3-
for (let i = 0; i < items.length; i++) {
4-
/* tslint:enable */
5-
arr[arr.length] = items[i];
2+
for (const item of items) {
3+
arr[arr.length] = item;
64
}
75
return arr.length;
86
}

0 commit comments

Comments
 (0)