Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/TSHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class TSHelper {

public static isArrayType(type: ts.Type, checker: ts.TypeChecker): boolean {
const typeNode = checker.typeToTypeNode(type);
return typeNode && typeNode.kind === ts.SyntaxKind.ArrayType;
return typeNode && (typeNode.kind === ts.SyntaxKind.ArrayType || typeNode.kind === ts.SyntaxKind.TupleType);
}

public static isTupleType(type: ts.Type, checker: ts.TypeChecker): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/Transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ export class LuaTranspiler {
const index = this.transpileExpression(node.argumentExpression);

const type = this.checker.getTypeAtLocation(node.expression);
if (tsHelper.isArrayType(type, this.checker) || tsHelper.isTupleType(type, this.checker)) {
if (tsHelper.isArrayType(type, this.checker)) {
return `${element}[${index}+1]`;
} else if (tsHelper.isStringType(type)) {
return `string.sub(${element},${index}+1,${index}+1)`;
Expand Down
8 changes: 8 additions & 0 deletions test/translation/lua/tupleArrayUses.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
for _, value in ipairs(tuple) do
end
TS_forEach(tuple, function(v)
end
)
local num = tuple[1+1]

local len = #tuple
8 changes: 8 additions & 0 deletions test/translation/ts/tupleArrayUses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// test cases where tuples are used as arrays
declare const tuple: [string, number, boolean];

// tslint:disable:no-empty no-unused-expression
for (const value of tuple) {} // for-of loop
tuple.forEach(v => {}); // Array.prototype.forEach
const num = tuple[1]; // array access
const len = tuple.length; // array length