Skip to content

Commit 29fe5e4

Browse files
tomblindPerryvw
authored andcommitted
Handling modules/namespaces nested via dot in their declaration name (#437)
fixes #434
1 parent 7690be3 commit 29fe5e4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/LuaTransformer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,9 +1322,12 @@ export class LuaTransformer {
13221322
this.currentNamespace = statement;
13231323

13241324
// Transform moduleblock to block and visit it
1325-
if (statement.body && ts.isModuleBlock(statement.body)) {
1325+
if (statement.body && (ts.isModuleBlock(statement.body) || ts.isModuleDeclaration(statement.body))) {
13261326
this.pushScope(ScopeType.Block, statement);
1327-
const statements = this.performHoisting(this.transformStatements(statement.body.statements));
1327+
let statements = ts.isModuleBlock(statement.body)
1328+
? this.transformStatements(statement.body.statements)
1329+
: this.transformModuleDeclaration(statement.body);
1330+
statements = this.performHoisting(statements);
13281331
this.popScope();
13291332
result.push(tstl.createDoStatement(statements));
13301333
}

test/unit/modules.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ export class LuaModuleTests {
5555
// Assert
5656
Expect(lua).toBe(``);
5757
}
58+
59+
@Test("Nested module with dot in name")
60+
public nestedModuleWithDotInName(): void {
61+
const code =
62+
`module a.b {
63+
export const foo = "foo";
64+
}`;
65+
Expect(util.transpileAndExecute("return a.b.foo;", undefined, undefined, code)).toBe("foo");
66+
}
5867
}

0 commit comments

Comments
 (0)