Skip to content

Bugfix/anonymous class name#810

Merged
Perryvw merged 13 commits intomasterfrom
bugfix/anonymous-class-name
Apr 5, 2020
Merged

Bugfix/anonymous class name#810
Perryvw merged 13 commits intomasterfrom
bugfix/anonymous-class-name

Conversation

@Perryvw
Copy link
Copy Markdown
Member

@Perryvw Perryvw commented Jan 19, 2020

As discovered in #802, the class name property on anonymous classes did not match the class names in JS.

Not entirely sure about the modules.spec test, since it depends on the logic of the unique variable generation staying the same. Maybe we can come up with a better way to test that.

@Perryvw Perryvw requested a review from ark120202 January 27, 2020 20:02
context: TransformationContext,
isDefaultExport = false
): lua.Expression {
let className: lua.Identifier;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Revert this? Test this.

Perryvw added 4 commits March 28, 2020 17:44
# Conflicts:
#	src/transformation/visitors/class/index.ts
#	test/unit/functions/validation/invalidFunctionAssignments.spec.ts
@Perryvw Perryvw requested a review from ark120202 April 4, 2020 15:20
classDeclaration,
className,
localClassName,
getReflectionClassName(classDeclaration),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we move getReflectionClassName implementation to setup instead of passing it as a parameter? Unrelated, buy maybe extendedType too?

lua.createAssignmentStatement(
lua.createTableIndexExpression(lua.cloneIdentifier(localClassName), lua.createStringLiteral("name")),
lua.createStringLiteral(classNameText),
reflectionClassName,
Copy link
Copy Markdown
Contributor

@ark120202 ark120202 Apr 5, 2020

Choose a reason for hiding this comment

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

Suggested change
reflectionClassName,
getReflectionClassName(context, statement, localClassName),

Comment on lines +83 to +87
export function getReflectionClassName(
declaration: ts.ClassLikeDeclaration,
className: lua.Identifier,
context: TransformationContext
): lua.Expression {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
export function getReflectionClassName(
declaration: ts.ClassLikeDeclaration,
className: lua.Identifier,
context: TransformationContext
): lua.Expression {
export function getReflectionClassName(
context: TransformationContext,
declaration: ts.ClassLikeDeclaration,
className: lua.Identifier
): lua.Expression {

Comment on lines +774 to +783
function Numbers(...message_type_args: number[]) {
return <T extends new(...args: any[]) => {}>(constructor: T) => {
return class extends constructor {
protected numbers = message_type_args;
};
};
}

@Numbers(10, 20)
class MyClass {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
function Numbers(...message_type_args: number[]) {
return <T extends new(...args: any[]) => {}>(constructor: T) => {
return class extends constructor {
protected numbers = message_type_args;
};
};
}
@Numbers(10, 20)
class MyClass {}
const decorator = <T extends new (...args: any[]) => any>(constructor: T) => class extends constructor {};
@decorator
class MyClass {}

},
"value"
);
test("default exported name class has correct name property", () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think these would be better with other class tests

Comment on lines 72 to 73
classDeclaration: ts.ClassLikeDeclaration,
context: TransformationContext,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For consistency:

Suggested change
classDeclaration: ts.ClassLikeDeclaration,
context: TransformationContext,
context: TransformationContext,
classDeclaration: ts.ClassLikeDeclaration,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually it is consistent right now with transformClassDeclaration and transformClassAsExpression

@Perryvw Perryvw merged commit 282da23 into master Apr 5, 2020
@Perryvw Perryvw deleted the bugfix/anonymous-class-name branch April 5, 2020 19:20
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