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
11 changes: 8 additions & 3 deletions src/LuaTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,10 @@ export class LuaTransformer {
));
}
} else {
const table = this.transformIdentifier(enumDeclaration.name);
let table: tstl.Identifier | tstl.TableIndexExpression = this.transformIdentifier(enumDeclaration.name);
if (this.isIdentifierExported(enumDeclaration.name.text)) {
table = this.createExportedIdentifier(table);
}
const property = tstl.createTableIndexExpression(table, memberName, undefined);
result.push(tstl.createAssignmentStatement(property, enumMember.value, undefined, enumMember.original));
}
Expand Down Expand Up @@ -2987,7 +2990,7 @@ export class LuaTransformer {
}

public isIdentifierExported(identifierName: string | ts.__String): boolean {
if (!this.isModule) {
if (!this.isModule && !this.currentNamespace) {
return false;
}
const currentScope = this.currentNamespace ? this.currentNamespace : this.currentSourceFile;
Expand Down Expand Up @@ -3136,7 +3139,9 @@ export class LuaTransformer {
statements.push(
tstl.createAssignmentStatement(lhs.map(i => this.createExportedIdentifier(i)), rhs, parent));
} else {
statements.push(tstl.createVariableDeclarationStatement(lhs, rhs, parent));
// Separate declaration from assignment to allow for recursion
statements.push(tstl.createVariableDeclarationStatement(lhs, undefined, parent));
statements.push(tstl.createAssignmentStatement(lhs, rhs, parent));
}
} else {
statements.push(tstl.createAssignmentStatement(lhs, rhs, parent, tsOriginal));
Expand Down
25 changes: 13 additions & 12 deletions test/translation/lua/modulesClassExport.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
local exports = exports or {}
local TestClass = TestClass or {}
TestClass.__index = TestClass
function TestClass.new(construct, ...)
local self = setmetatable({}, TestClass)
if construct and TestClass.constructor then TestClass.constructor(self, ...) end
return self
end
function TestClass.constructor(self)
end
exports.TestClass = TestClass
return exports
local exports = exports or {};
exports.TestClass = exports.TestClass or {};
exports.TestClass.__index = exports.TestClass;
exports.TestClass.new = function(construct, ...)
local self = setmetatable({}, exports.TestClass);
if construct and exports.TestClass.constructor then
exports.TestClass.constructor(self, ...);
end
return self;
end;
exports.TestClass.constructor = function(self)
end;
return exports;
29 changes: 15 additions & 14 deletions test/translation/lua/modulesClassWithMemberExport.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
local exports = exports or {}
local TestClass = TestClass or {}
TestClass.__index = TestClass
function TestClass.new(construct, ...)
local self = setmetatable({}, TestClass)
if construct and TestClass.constructor then TestClass.constructor(self, ...) end
return self
end
function TestClass.constructor(self)
end
function TestClass.memberFunc(self)
end
exports.TestClass = TestClass
return exports
local exports = exports or {};
exports.TestClass = exports.TestClass or {};
exports.TestClass.__index = exports.TestClass;
exports.TestClass.new = function(construct, ...)
local self = setmetatable({}, exports.TestClass);
if construct and exports.TestClass.constructor then
exports.TestClass.constructor(self, ...);
end
return self;
end;
exports.TestClass.constructor = function(self)
end;
exports.TestClass.memberFunc = function(self)
end;
return exports;
9 changes: 4 additions & 5 deletions test/translation/lua/modulesFunctionExport.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local exports = exports or {}
local function publicFunc()
end
exports.publicFunc = publicFunc
return exports
local exports = exports or {};
exports.publicFunc = function()
end;
return exports;
3 changes: 2 additions & 1 deletion test/translation/lua/modulesNamespaceExport.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local exports = exports or {};
exports.TestSpace = exports.TestSpace or {};
local TestSpace = exports.TestSpace;
do
end
return exports;
return exports;
15 changes: 7 additions & 8 deletions test/translation/lua/modulesNamespaceExportEnum.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
local exports = exports or {}
local test = exports.test or test or {}
local exports = exports or {};
exports.test = exports.test or {};
local test = exports.test;
do
local TestEnum={}
TestEnum.foo="foo"
TestEnum.bar="bar"
test.TestEnum = TestEnum
test.TestEnum = {};
test.TestEnum.foo = "foo";
test.TestEnum.bar = "bar";
end
exports.test = test
return exports
return exports;
17 changes: 8 additions & 9 deletions test/translation/lua/modulesNamespaceNestedWithMemberExport.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
local exports = exports or {}
local TestSpace = exports.TestSpace or TestSpace or {}
local exports = exports or {};
exports.TestSpace = exports.TestSpace or {};
local TestSpace = exports.TestSpace;
do
local TestNestedSpace = TestNestedSpace or {}
TestSpace.TestNestedSpace = TestSpace.TestNestedSpace or {};
local TestNestedSpace = TestSpace.TestNestedSpace;
do
local function innerFunc()
end
TestNestedSpace.innerFunc = innerFunc
TestNestedSpace.innerFunc = function()
end;
end
TestSpace.TestNestedSpace = TestNestedSpace
end
exports.TestSpace = TestSpace
return exports
return exports;
13 changes: 6 additions & 7 deletions test/translation/lua/modulesNamespaceWithMemberExport.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
local exports = exports or {}
local TestSpace = exports.TestSpace or TestSpace or {}
local exports = exports or {};
exports.TestSpace = exports.TestSpace or {};
local TestSpace = exports.TestSpace;
do
local function innerFunc()
end
TestSpace.innerFunc = innerFunc
TestSpace.innerFunc = function()
end;
end
exports.TestSpace = TestSpace
return exports
return exports;
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ do
innerFunc = function()
end;
end
return exports;
return exports;
2 changes: 1 addition & 1 deletion test/translation/lua/namespace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ do
local nsMember;
nsMember = function()
end;
end
end
5 changes: 2 additions & 3 deletions test/translation/lua/namespaceMerge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ MergedClass.methodB = function(self)
end;
MergedClass = MergedClass or {};
do
local namespaceFunc;
namespaceFunc = function()
MergedClass.namespaceFunc = function()
end;
end
local mergedClass = MergedClass.new(true);
mergedClass:methodB();
mergedClass:propertyFunc();
MergedClass:staticMethodB();
MergedClass.namespaceFunc();
MergedClass.namespaceFunc();