Skip to content

Commit b0f04e7

Browse files
committed
Fixed comments && more tests
1 parent 5974e27 commit b0f04e7

File tree

9 files changed

+37
-15
lines changed

9 files changed

+37
-15
lines changed

src/TSHelper.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,13 @@ export class TSHelper {
101101
}
102102

103103
public static hasCustomDecorator(type: ts.Type, checker: ts.TypeChecker, decorator: string): boolean {
104-
const comment = type.symbol.getDocumentationComment(checker);
105-
const decorators =
106-
comment.filter((_) => _.kind === "text").map((_) => _.text.trim()).filter((_) => _[0] === "!");
107-
return decorators.indexOf(decorator) > -1;
104+
if (type.symbol) {
105+
const comment = type.symbol.getDocumentationComment(checker);
106+
const decorators =
107+
comment.filter((_) => _.kind === "text").map((_) => _.text.trim()).filter((_) => _[0] === "!");
108+
return decorators.indexOf(decorator) > -1;
109+
}
110+
return false;
108111
}
109112

110113
// Search up until finding a node satisfying the callback

src/Transpiler.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,21 +361,17 @@ export class LuaTranspiler {
361361
}
362362

363363
public transpileFor(node: ts.ForStatement): string {
364-
// Get iterator variable
365-
const variableDeclaration = (node.initializer as ts.VariableDeclarationList).declarations[0];
366-
const variable = this.transpileVariableDeclaration(variableDeclaration);
367-
const condition = this.transpileExpression(node.condition);
368-
const incrementor = this.transpileExpression(node.incrementor);
369-
370364
// Add header
371-
let result = `--for(${variable.trim()}; ${condition}; ${incrementor};)\n`;
372-
result += this.indent + variable;
365+
let result = "";
366+
for (const variableDeclaration of (node.initializer as ts.VariableDeclarationList).declarations) {
367+
result += this.transpileVariableDeclaration(variableDeclaration);
368+
}
373369
result += this.indent + `while(${this.transpileExpression(node.condition)}) do\n`;
374370

375371
// Add body
376372
this.pushIndent();
377373
result += this.transpileStatement(node.statement);
378-
result += this.indent + incrementor + "\n";
374+
result += this.indent + this.transpileExpression(node.incrementor) + "\n";
379375
this.popIndent();
380376

381377
result += this.indent + "end\n";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
function TestClass.myFunction(self)
2+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
MyClass = MyClass or {}
2+
MyClass.__index = MyClass
3+
function MyClass.new(construct, ...)
4+
local instance = setmetatable({}, MyClass)
5+
if construct and MyClass.constructor then MyClass.constructor(instance, ...) end
6+
return instance
7+
end
8+
MyClass.test = 0
9+
function MyClass.constructor(self)
10+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** !Extension */
2+
class TestClass {
3+
}
4+
5+
6+
/** !Extension */
7+
class MyClass extends TestClass {
8+
myFunction() {}
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class MyClass {
2+
public static test = 0;
3+
}

test/unit/loops.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ export class LuaLoopTests {
102102
@TestCase([0, 1, 2, 3], [1, 2, 3, 4], "let i = 0; arrTest.length > i; i++")
103103
@TestCase([0, 1, 2, 3], [1, 2, 3, 4], "let i = 0; arrTest.length - 1 >= i; i++")
104104
@TestCase([0, 1, 2, 3], [1, 1, 3, 3], "let i = 0; i < arrTest.length; i += 2")
105-
// @TestCase([0, 1, 2, 3], [1, 2, 3, 4], "let i = arrTest.length - 1; i <= 0; i--")
106-
// @TestCase([0, 1, 2, 3], [0, 2, 2, 4], "let i = arrTest.length - 1; i <= 0; i -= 2")
105+
@TestCase([0, 1, 2, 3], [1, 2, 3, 4 ], "let i = arrTest.length - 1; i >= 0; i--")
107106
@TestCase([0, 1, 2, 3], [0, 2, 2, 4], "let i = arrTest.length - 1; i >= 0; i -= 2")
108107
@TestCase([0, 1, 2, 3], [0, 2, 2, 4], "let i = arrTest.length - 1; i > 0; i -= 2")
109108
@Test("forheader")

0 commit comments

Comments
 (0)