Skip to content

Commit 0cf96b0

Browse files
authored
Merge pull request #115 from apemanzilla/fix/tuple-array-type
Update isArrayType to include tuples
2 parents 6da78c5 + b3775fc commit 0cf96b0

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/TSHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class TSHelper {
4747

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

5353
public static isTupleType(type: ts.Type, checker: ts.TypeChecker): boolean {

src/Transpiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ export class LuaTranspiler {
11631163
const index = this.transpileExpression(node.argumentExpression);
11641164

11651165
const type = this.checker.getTypeAtLocation(node.expression);
1166-
if (tsHelper.isArrayType(type, this.checker) || tsHelper.isTupleType(type, this.checker)) {
1166+
if (tsHelper.isArrayType(type, this.checker)) {
11671167
return `${element}[${index}+1]`;
11681168
} else if (tsHelper.isStringType(type)) {
11691169
return `string.sub(${element},${index}+1,${index}+1)`;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
for _, value in ipairs(tuple) do
2+
end
3+
TS_forEach(tuple, function(v)
4+
end
5+
)
6+
local num = tuple[1+1]
7+
8+
local len = #tuple
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// test cases where tuples are used as arrays
2+
declare const tuple: [string, number, boolean];
3+
4+
// tslint:disable:no-empty no-unused-expression
5+
for (const value of tuple) {} // for-of loop
6+
tuple.forEach(v => {}); // Array.prototype.forEach
7+
const num = tuple[1]; // array access
8+
const len = tuple.length; // array length

0 commit comments

Comments
 (0)