Skip to content

Commit 1ef66d1

Browse files
tomblindPerryvw
authored andcommitted
support for class expressions (#345)
1 parent e42c5be commit 1ef66d1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/LuaTransformer.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@ export class LuaTransformer {
229229
}
230230
}
231231

232-
public transformClassDeclaration(statement: ts.ClassDeclaration, nameOverride?: tstl.Identifier): tstl.Statement[] {
232+
public transformClassDeclaration(
233+
statement: ts.ClassLikeDeclaration,
234+
nameOverride?: tstl.Identifier
235+
): tstl.Statement[] {
233236
let className = statement.name ? this.transformIdentifier(statement.name) : nameOverride;
234237
if (!className) {
235238
throw TSTLErrors.MissingClassName(statement);
@@ -1496,11 +1499,9 @@ export class LuaTransformer {
14961499
// TODO move to extra function (consistency)
14971500
return undefined;
14981501
case ts.SyntaxKind.ClassExpression:
1499-
/*this.namespace.push("");
1500-
const classDeclaration = this.transformClassDeclaration(node as ts.ClassExpression, "_");
1501-
this.namespace.pop();
1502-
return `(function() ${classDeclaration}; return _ end)()`;*/
1503-
throw new Error("Not yet implemented");
1502+
const className = tstl.createIdentifier("____");
1503+
const classDeclaration = this.transformClassDeclaration(expression as ts.ClassExpression, className);
1504+
return this.createImmediatelyInvokedFunctionExpression(classDeclaration, className, expression);
15041505
default:
15051506
throw TSTLErrors.UnsupportedKind("expression", expression.kind, expression);
15061507
}

0 commit comments

Comments
 (0)