-added support for class expressions#236
Conversation
Perryvw
left a comment
There was a problem hiding this comment.
Added some minor comments, seems like a good implementation.
src/Transpiler.ts
Outdated
| public transpileClass(node: ts.ClassDeclaration): string { | ||
| if (!node.name) { | ||
| public transpileClass(node: ts.ClassLikeDeclarationBase, nameOverride?: string): string { | ||
| let className: string; |
There was a problem hiding this comment.
const className = node.name ? this.transpileIdentifier(node.name) : nameOverride; is much nicer in my opinion.
| case ts.SyntaxKind.NonNullExpression: | ||
| return this.transpileExpression((node as ts.NonNullExpression).expression); | ||
| case ts.SyntaxKind.ClassExpression: | ||
| this.namespace.push(""); |
There was a problem hiding this comment.
Any specific reason for this line?
There was a problem hiding this comment.
It scopes the class declaration. Otherwise the class would be in global scope. Not sure if this is the best approach - I see it as sort of an anonymous namespace in C++.
There was a problem hiding this comment.
Could you provide an input/ouput example?
There was a problem hiding this comment.
let f = function() { let a = class{} }
would generate
local f; f = function() local a = (function() --[[ should be local ]] _ = _ or {} _.__index = _ function _.new(construct, ...) local self = setmetatable({}, _) if construct and _.constructor then _.constructor(self, ...) end return self end function _.constructor(self) end ; return _ end)(); end ;
This is mostly for the sake of completion. I ran into it while trying to implement class decorators