Skip to content

-added support for class expressions#236

Merged
Perryvw merged 3 commits intoTypeScriptToLua:masterfrom
andreiradu:class_statement
Oct 13, 2018
Merged

-added support for class expressions#236
Perryvw merged 3 commits intoTypeScriptToLua:masterfrom
andreiradu:class_statement

Conversation

@andreiradu
Copy link
Copy Markdown
Contributor

This is mostly for the sake of completion. I ran into it while trying to implement class decorators

Copy link
Copy Markdown
Member

@Perryvw Perryvw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some minor comments, seems like a good implementation.

public transpileClass(node: ts.ClassDeclaration): string {
if (!node.name) {
public transpileClass(node: ts.ClassLikeDeclarationBase, nameOverride?: string): string {
let className: string;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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("");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason for this line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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++.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide an input/ouput example?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ;

@Perryvw Perryvw merged commit c6159e1 into TypeScriptToLua:master Oct 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants