-
-
Notifications
You must be signed in to change notification settings - Fork 185
Bugfix/anonymous class name #810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
132cf7d
Updated tests to new TestBuilder
Perryvw 67e72a2
Updated classes/classes tests to new TestBuilder
Perryvw 3690477
Fixed exported class super call test
Perryvw 7f4f650
Fixed inconsistency between reflection class names of JS and Lua
Perryvw 1bc474b
Reverted unique default class name change
Perryvw 073049f
Reverted change and changed tests to use testModule instead of setTsH…
Perryvw 3bf5b0c
Merge branch 'master' into bugfix/anonymous-class-name
Perryvw 4fd0e96
Fixed some remaining merge issues
Perryvw 68f8f55
Added gitattributes
Perryvw a44fa5a
Refactored class transformation functions
Perryvw 389819d
Also fixed #584, moved getReflectionName to setup and some other mino…
Perryvw 72aaeb7
Moved getReflectionClassName to setup completely
Perryvw edc9491
Moved tests
Perryvw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * text eol=lf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,9 +7,9 @@ import { | |||||||||
| extensionAndMetaExtensionConflict, | ||||||||||
| extensionCannotExport, | ||||||||||
| extensionCannotExtend, | ||||||||||
| metaExtensionMissingExtends, | ||||||||||
| luaTableMustBeAmbient, | ||||||||||
| luaTableCannotBeExtended, | ||||||||||
| luaTableMustBeAmbient, | ||||||||||
| metaExtensionMissingExtends, | ||||||||||
| } from "../../utils/diagnostics"; | ||||||||||
| import { | ||||||||||
| createDefaultExportIdentifier, | ||||||||||
|
|
@@ -21,7 +21,6 @@ import { | |||||||||
| import { | ||||||||||
| createImmediatelyInvokedFunctionExpression, | ||||||||||
| createSelfIdentifier, | ||||||||||
| OneToManyVisitorResult, | ||||||||||
| unwrapVisitorResult, | ||||||||||
| } from "../../utils/lua-ast"; | ||||||||||
| import { createSafeName, isUnsafeName } from "../../utils/safe-names"; | ||||||||||
|
|
@@ -38,25 +37,29 @@ import { checkForLuaLibType } from "./new"; | |||||||||
| import { createClassSetup } from "./setup"; | ||||||||||
| import { getExtendedNode, getExtendedType, isStaticNode } from "./utils"; | ||||||||||
|
|
||||||||||
| export const transformClassDeclaration: FunctionVisitor<ts.ClassLikeDeclaration> = (declaration, context) => { | ||||||||||
| // If declaration is a default export, transform to export variable assignment instead | ||||||||||
| if (hasDefaultExportModifier(declaration)) { | ||||||||||
| const left = createExportedIdentifier(context, createDefaultExportIdentifier(declaration)); | ||||||||||
| const right = transformClassAsExpression(declaration, context); | ||||||||||
| return [lua.createAssignmentStatement(left, right, declaration)]; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const { statements } = transformClassLikeDeclaration(declaration, context); | ||||||||||
| return statements; | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| export const transformThisExpression: FunctionVisitor<ts.ThisExpression> = node => createSelfIdentifier(node); | ||||||||||
|
|
||||||||||
| export function transformClassAsExpression( | ||||||||||
| expression: ts.ClassLikeDeclaration, | ||||||||||
| context: TransformationContext, | ||||||||||
| isDefaultExport = false | ||||||||||
| context: TransformationContext | ||||||||||
| ): lua.Expression { | ||||||||||
| let className: lua.Identifier; | ||||||||||
| if (expression.name) { | ||||||||||
| className = transformIdentifier(context, expression.name); | ||||||||||
| } else if (isDefaultExport) { | ||||||||||
| className = createDefaultExportIdentifier(expression); | ||||||||||
| } else { | ||||||||||
| className = lua.createAnonymousIdentifier(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| pushScope(context, ScopeType.Function); | ||||||||||
| const classDeclaration = unwrapVisitorResult(transformClassDeclaration(expression, context, className)); | ||||||||||
| const { statements, name } = transformClassLikeDeclaration(expression, context); | ||||||||||
| popScope(context); | ||||||||||
|
|
||||||||||
| return createImmediatelyInvokedFunctionExpression(classDeclaration, className, expression); | ||||||||||
| return createImmediatelyInvokedFunctionExpression(unwrapVisitorResult(statements), name, expression); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const classSuperInfos = new WeakMap<TransformationContext, ClassSuperInfo[]>(); | ||||||||||
|
|
@@ -65,28 +68,19 @@ interface ClassSuperInfo { | |||||||||
| extendedTypeNode?: ts.ExpressionWithTypeArguments; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| export function transformClassDeclaration( | ||||||||||
| function transformClassLikeDeclaration( | ||||||||||
| classDeclaration: ts.ClassLikeDeclaration, | ||||||||||
| context: TransformationContext, | ||||||||||
|
Comment on lines
72
to
73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency:
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually it is consistent right now with transformClassDeclaration and transformClassAsExpression |
||||||||||
| nameOverride?: lua.Identifier | ||||||||||
| ): OneToManyVisitorResult<lua.Statement> { | ||||||||||
| ): { statements: lua.Statement[]; name: lua.Identifier } { | ||||||||||
| let className: lua.Identifier; | ||||||||||
| let classNameText: string; | ||||||||||
| if (nameOverride !== undefined) { | ||||||||||
| className = nameOverride; | ||||||||||
| classNameText = nameOverride.text; | ||||||||||
| } else if (classDeclaration.name !== undefined) { | ||||||||||
| className = transformIdentifier(context, classDeclaration.name); | ||||||||||
| classNameText = classDeclaration.name.text; | ||||||||||
| } else if (hasDefaultExportModifier(classDeclaration)) { | ||||||||||
| const left = createExportedIdentifier(context, createDefaultExportIdentifier(classDeclaration)); | ||||||||||
| const right = transformClassAsExpression(classDeclaration, context, true); | ||||||||||
|
|
||||||||||
| return lua.createAssignmentStatement(left, right, classDeclaration); | ||||||||||
| } else { | ||||||||||
| // TypeScript error | ||||||||||
| className = lua.createAnonymousIdentifier(); | ||||||||||
| classNameText = className.text; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const annotations = getTypeAnnotations(context.checker.getTypeAtLocation(classDeclaration)); | ||||||||||
|
|
@@ -196,9 +190,7 @@ export function transformClassDeclaration( | |||||||||
| } | ||||||||||
|
|
||||||||||
| if (!isExtension && !isMetaExtension) { | ||||||||||
| result.push( | ||||||||||
| ...createClassSetup(context, classDeclaration, className, localClassName, classNameText, extendedType) | ||||||||||
| ); | ||||||||||
| result.push(...createClassSetup(context, classDeclaration, className, localClassName, extendedType)); | ||||||||||
| } else { | ||||||||||
| for (const f of instanceFields) { | ||||||||||
| const fieldName = transformPropertyName(context, f.name); | ||||||||||
|
|
@@ -317,7 +309,7 @@ export function transformClassDeclaration( | |||||||||
|
|
||||||||||
| superInfo.pop(); | ||||||||||
|
|
||||||||||
| return result; | ||||||||||
| return { statements: result, name: className }; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| export const transformSuperExpression: FunctionVisitor<ts.SuperExpression> = (expression, context) => { | ||||||||||
|
|
@@ -345,5 +337,3 @@ export const transformSuperExpression: FunctionVisitor<ts.SuperExpression> = (ex | |||||||||
|
|
||||||||||
| return lua.createTableIndexExpression(baseClassName, lua.createStringLiteral("prototype")); | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| export const transformThisExpression: FunctionVisitor<ts.ThisExpression> = node => createSelfIdentifier(node); | ||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this? Test this.