X Tutup
Skip to content

Commit 5eeecbd

Browse files
andreiraduPerryvw
authored andcommitted
Casting ambiguous syntax (#181)
* -added fail case * -added ; at the end of statements to avoid ambyguous lua syntax * -updated tests * -removed extra newline from assingments
1 parent 8c6f4ef commit 5eeecbd

24 files changed

+149
-144
lines changed

src/Transpiler.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ export abstract class LuaTranspiler {
263263
case ts.SyntaxKind.FunctionDeclaration:
264264
return this.transpileFunctionDeclaration(node as ts.FunctionDeclaration);
265265
case ts.SyntaxKind.VariableStatement:
266-
return this.indent + this.transpileVariableStatement(node as ts.VariableStatement) + "\n";
266+
return this.indent + this.transpileVariableStatement(node as ts.VariableStatement) + ";\n";
267267
case ts.SyntaxKind.ExpressionStatement:
268-
return this.indent + this.transpileExpression((node as ts.ExpressionStatement).expression) + "\n";
268+
return this.indent + this.transpileExpression((node as ts.ExpressionStatement).expression) + ";\n";
269269
case ts.SyntaxKind.ReturnStatement:
270270
return this.indent + this.transpileReturn(node as ts.ReturnStatement) + "\n";
271271
case ts.SyntaxKind.IfStatement:
@@ -491,7 +491,7 @@ export abstract class LuaTranspiler {
491491
// Add header
492492
let result = "";
493493
for (const variableDeclaration of (node.initializer as ts.VariableDeclarationList).declarations) {
494-
result += this.indent + this.transpileVariableDeclaration(variableDeclaration);
494+
result += this.indent + this.transpileVariableDeclaration(variableDeclaration) + "\n";
495495
}
496496
result += this.indent + `while(${this.transpileExpression(node.condition)}) do\n`;
497497

@@ -1407,9 +1407,9 @@ export abstract class LuaTranspiler {
14071407
const identifierName = this.transpileIdentifier(node.name);
14081408
if (node.initializer) {
14091409
const value = this.transpileExpression(node.initializer);
1410-
return `local ${identifierName} = ${value}\n`;
1410+
return `local ${identifierName} = ${value}`;
14111411
} else {
1412-
return `local ${identifierName} = nil\n`;
1412+
return `local ${identifierName} = nil`;
14131413
}
14141414
} else if (ts.isArrayBindingPattern(node.name)) {
14151415
// Destructuring type
@@ -1423,9 +1423,9 @@ export abstract class LuaTranspiler {
14231423

14241424
// Don't unpack TupleReturn decorated functions
14251425
if (tsHelper.isTupleReturnCall(node.initializer, this.checker)) {
1426-
return `local ${vars}=${this.transpileExpression(node.initializer)}\n`;
1426+
return `local ${vars}=${this.transpileExpression(node.initializer)}`;
14271427
} else {
1428-
return `local ${vars}=${this.transpileDestructingAssignmentValue(node.initializer)}\n`;
1428+
return `local ${vars}=${this.transpileDestructingAssignmentValue(node.initializer)}`;
14291429
}
14301430
} else {
14311431
throw TSTLErrors.UnsupportedKind("variable declaration", node.name.kind, node);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Namespace.myFunction()
1+
Namespace.myFunction();
Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
local quoteInDoubleQuotes = "\' \' \'"
2-
3-
local quoteInTemplateString = "\' \' \'"
4-
5-
local doubleQuoteInQuotes = "\" \" \""
6-
7-
local doubleQuoteInDoubleQuotes = "\" \" \""
8-
9-
local doubleQuoteInTemplateString = "\" \" \""
10-
11-
local escapedCharsInQuotes = "\\ \0 \b \t \n \v \f \" \' \`"
12-
13-
local escapedCharsInDoubleQUotes = "\\ \0 \b \t \n \v \f \" \' \`"
14-
15-
local escapedCharsInTemplateString = "\\ \0 \b \t \n \v \f \" \' \`"
16-
17-
local nonEmptyTemplateString = "Level 0: \n\t "..tostring("Level 1: \n\t\t "..tostring("Level 3: \n\t\t\t "..tostring("Last level \n --").." \n --").." \n --").." \n --"
18-
1+
local quoteInDoubleQuotes = "\' \' \'";
2+
local quoteInTemplateString = "\' \' \'";
3+
local doubleQuoteInQuotes = "\" \" \"";
4+
local doubleQuoteInDoubleQuotes = "\" \" \"";
5+
local doubleQuoteInTemplateString = "\" \" \"";
6+
local escapedCharsInQuotes = "\\ \0 \b \t \n \v \f \" \' \`";
7+
local escapedCharsInDoubleQUotes = "\\ \0 \b \t \n \v \f \" \' \`";
8+
local escapedCharsInTemplateString = "\\ \0 \b \t \n \v \f \" \' \`";
9+
local nonEmptyTemplateString = "Level 0: \n\t "..tostring("Level 1: \n\t\t "..tostring("Level 3: \n\t\t\t "..tostring("Last level \n --").." \n --").." \n --").." \n --";

test/translation/lua/do.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
local e = 10
2-
1+
local e = 10;
32
repeat
43
do
5-
e = (e-1)
4+
e = (e-1);
65
end
76
::__continue0::
87
until not (e>0)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
classInstance:colonMethod()
2-
classInstance.dotMethod()
3-
interfaceInstance:colonMethod()
4-
interfaceInstance.dotMethod()
5-
TestNameSpace.dotMethod()
6-
TestNameSpace.dotMethod2()
1+
classInstance:colonMethod();
2+
classInstance.dotMethod();
3+
interfaceInstance:colonMethod();
4+
interfaceInstance.dotMethod();
5+
TestNameSpace.dotMethod();
6+
TestNameSpace.dotMethod2();

test/translation/lua/enumMembersOnly.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ val1=0
22
val2=2
33
val3=3
44
val4="bye"
5-
local a = val1
5+
local a = val1;

test/translation/lua/getSetAccessors.lua

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ function MyClass.get__field(self)
1111
return self._field+4
1212
end
1313
function MyClass.set__field(self,v)
14-
self._field = (v*2)
14+
self._field = (v*2);
1515
end
16-
local instance = MyClass.new(true)
17-
18-
instance:set__field(4)
19-
local b = instance:get__field()
20-
21-
local c = (4+instance:get__field())*3
16+
local instance = MyClass.new(true);
17+
instance:set__field(4);
18+
local b = instance:get__field();
19+
local c = (4+instance:get__field())*3;
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
local a = {}
2-
3-
a["abc"] = "def"
1+
local a = {};
2+
a["abc"] = "def";
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local exports = exports or {}
2-
local test = nil
3-
4-
test = 1
2+
local test = nil;
3+
test = 1;
54
exports.test = test
65
return exports
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
local exports = exports or {}
2-
local test = "test"
3-
2+
local test = "test";
43
exports.test = test
54
return exports

0 commit comments

Comments
 (0)
X Tutup