Skip to content

Commit 44c03be

Browse files
tomblindlolleko
authored andcommitted
Fixing remaining tests (#350)
* Fixing remaining tests - Fixed exporting enum members - Fixed exporting namespace members in a non-module - (Re)Fixed recursive functions - Updated transformation tests with aesthetic changes * corrected class export transform tests (which re-breaks them right now)
1 parent 82b84cd commit 44c03be

11 files changed

+67
-64
lines changed

src/LuaTransformer.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,10 @@ export class LuaTransformer {
853853
));
854854
}
855855
} else {
856-
const table = this.transformIdentifier(enumDeclaration.name);
856+
let table: tstl.Identifier | tstl.TableIndexExpression = this.transformIdentifier(enumDeclaration.name);
857+
if (this.isIdentifierExported(enumDeclaration.name.text)) {
858+
table = this.createExportedIdentifier(table);
859+
}
857860
const property = tstl.createTableIndexExpression(table, memberName, undefined);
858861
result.push(tstl.createAssignmentStatement(property, enumMember.value, undefined, enumMember.original));
859862
}
@@ -2987,7 +2990,7 @@ export class LuaTransformer {
29872990
}
29882991

29892992
public isIdentifierExported(identifierName: string | ts.__String): boolean {
2990-
if (!this.isModule) {
2993+
if (!this.isModule && !this.currentNamespace) {
29912994
return false;
29922995
}
29932996
const currentScope = this.currentNamespace ? this.currentNamespace : this.currentSourceFile;
@@ -3136,7 +3139,9 @@ export class LuaTransformer {
31363139
statements.push(
31373140
tstl.createAssignmentStatement(lhs.map(i => this.createExportedIdentifier(i)), rhs, parent));
31383141
} else {
3139-
statements.push(tstl.createVariableDeclarationStatement(lhs, rhs, parent));
3142+
// Separate declaration from assignment to allow for recursion
3143+
statements.push(tstl.createVariableDeclarationStatement(lhs, undefined, parent));
3144+
statements.push(tstl.createAssignmentStatement(lhs, rhs, parent));
31403145
}
31413146
} else {
31423147
statements.push(tstl.createAssignmentStatement(lhs, rhs, parent, tsOriginal));
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
local exports = exports or {}
2-
local TestClass = TestClass or {}
3-
TestClass.__index = TestClass
4-
function TestClass.new(construct, ...)
5-
local self = setmetatable({}, TestClass)
6-
if construct and TestClass.constructor then TestClass.constructor(self, ...) end
7-
return self
8-
end
9-
function TestClass.constructor(self)
10-
end
11-
exports.TestClass = TestClass
12-
return exports
1+
local exports = exports or {};
2+
exports.TestClass = exports.TestClass or {};
3+
exports.TestClass.__index = exports.TestClass;
4+
exports.TestClass.new = function(construct, ...)
5+
local self = setmetatable({}, exports.TestClass);
6+
if construct and exports.TestClass.constructor then
7+
exports.TestClass.constructor(self, ...);
8+
end
9+
return self;
10+
end;
11+
exports.TestClass.constructor = function(self)
12+
end;
13+
return exports;
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
local exports = exports or {}
2-
local TestClass = TestClass or {}
3-
TestClass.__index = TestClass
4-
function TestClass.new(construct, ...)
5-
local self = setmetatable({}, TestClass)
6-
if construct and TestClass.constructor then TestClass.constructor(self, ...) end
7-
return self
8-
end
9-
function TestClass.constructor(self)
10-
end
11-
function TestClass.memberFunc(self)
12-
end
13-
exports.TestClass = TestClass
14-
return exports
1+
local exports = exports or {};
2+
exports.TestClass = exports.TestClass or {};
3+
exports.TestClass.__index = exports.TestClass;
4+
exports.TestClass.new = function(construct, ...)
5+
local self = setmetatable({}, exports.TestClass);
6+
if construct and exports.TestClass.constructor then
7+
exports.TestClass.constructor(self, ...);
8+
end
9+
return self;
10+
end;
11+
exports.TestClass.constructor = function(self)
12+
end;
13+
exports.TestClass.memberFunc = function(self)
14+
end;
15+
return exports;
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
local exports = exports or {}
2-
local function publicFunc()
3-
end
4-
exports.publicFunc = publicFunc
5-
return exports
1+
local exports = exports or {};
2+
exports.publicFunc = function()
3+
end;
4+
return exports;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local exports = exports or {};
22
exports.TestSpace = exports.TestSpace or {};
3+
local TestSpace = exports.TestSpace;
34
do
45
end
5-
return exports;
6+
return exports;
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
local exports = exports or {}
2-
local test = exports.test or test or {}
1+
local exports = exports or {};
2+
exports.test = exports.test or {};
3+
local test = exports.test;
34
do
4-
local TestEnum={}
5-
TestEnum.foo="foo"
6-
TestEnum.bar="bar"
7-
test.TestEnum = TestEnum
5+
test.TestEnum = {};
6+
test.TestEnum.foo = "foo";
7+
test.TestEnum.bar = "bar";
88
end
9-
exports.test = test
10-
return exports
9+
return exports;
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
local exports = exports or {}
2-
local TestSpace = exports.TestSpace or TestSpace or {}
1+
local exports = exports or {};
2+
exports.TestSpace = exports.TestSpace or {};
3+
local TestSpace = exports.TestSpace;
34
do
4-
local TestNestedSpace = TestNestedSpace or {}
5+
TestSpace.TestNestedSpace = TestSpace.TestNestedSpace or {};
6+
local TestNestedSpace = TestSpace.TestNestedSpace;
57
do
6-
local function innerFunc()
7-
end
8-
TestNestedSpace.innerFunc = innerFunc
8+
TestNestedSpace.innerFunc = function()
9+
end;
910
end
10-
TestSpace.TestNestedSpace = TestNestedSpace
1111
end
12-
exports.TestSpace = TestSpace
13-
return exports
12+
return exports;
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
local exports = exports or {}
2-
local TestSpace = exports.TestSpace or TestSpace or {}
1+
local exports = exports or {};
2+
exports.TestSpace = exports.TestSpace or {};
3+
local TestSpace = exports.TestSpace;
34
do
4-
local function innerFunc()
5-
end
6-
TestSpace.innerFunc = innerFunc
5+
TestSpace.innerFunc = function()
6+
end;
77
end
8-
exports.TestSpace = TestSpace
9-
return exports
8+
return exports;

test/translation/lua/modulesNamespaceWithMemberNoExport.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ do
66
innerFunc = function()
77
end;
88
end
9-
return exports;
9+
return exports;

test/translation/lua/namespace.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ do
33
local nsMember;
44
nsMember = function()
55
end;
6-
end
6+
end

0 commit comments

Comments
 (0)