Skip to content

Setup custom name support#1505

Merged
Perryvw merged 22 commits intoTypeScriptToLua:masterfrom
Z3rio:customName-extension
Oct 21, 2023
Merged

Setup custom name support#1505
Perryvw merged 22 commits intoTypeScriptToLua:masterfrom
Z3rio:customName-extension

Conversation

@Z3rio
Copy link
Copy Markdown
Contributor

@Z3rio Z3rio commented Oct 18, 2023

This PR aims to provide a way of renaming the built name of functions, or such.

Resolves issue: #1498

Example usage

/** @customName get_version **/
function GetVersion(this: void) {}

GetVersion();

Lua output from the example

function get_version()
end

get_version()

@Z3rio
Copy link
Copy Markdown
Contributor Author

Z3rio commented Oct 18, 2023

I'll have to add tests to this before it gets merged :)

@Z3rio
Copy link
Copy Markdown
Contributor Author

Z3rio commented Oct 18, 2023

Noticed the reason for the lock files being in the repo, lol
So I added them back again

@Z3rio
Copy link
Copy Markdown
Contributor Author

Z3rio commented Oct 18, 2023

Perhaps further tests should be added, but please take a look at this one first and tell me what you think, aka if it is good or not. If it is, then I'll have a look at adding some more perhaps.

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.

Would also expect tests for renaming classes, variable declarations, namespaces, and also some declared functions that don't exist (ie declare function bla). The tests should execute the generated lua to show that all occurrences have indeed correctly been renamed.

@Z3rio
Copy link
Copy Markdown
Contributor Author

Z3rio commented Oct 19, 2023

There seems to be an issue with renaming the inner names of namespaces.
Aka, the actual namespace name will be changed, but if you have a function inside of that namespace with a custom name, the calling of that function will not receive that customName.

(Hence the error from tests atm)

image

Code for reprod:

/** @customName Test2 **/
namespace Test {
  /** @customName Func2 **/
  export function Func(): string {
    return "hi";
  }
}

export const result = Test.Func();

Seems like the .Func part (last line) isn't being passed through the identifier transformation, hm...

@Perryvw
Copy link
Copy Markdown
Member

Perryvw commented Oct 20, 2023

This code is probably hidden somewhere in the callexpression transformer. I have considered unifying that more with the transformIdentifier code but haven't looked at it into much detail.

@Z3rio
Copy link
Copy Markdown
Contributor Author

Z3rio commented Oct 20, 2023

I'll see if I can find where it is being transformed sometime later today :)
Are the tests looking fair enough though?

@Perryvw
Copy link
Copy Markdown
Member

Perryvw commented Oct 21, 2023

Tests look fine, I'm still missing one where you put the customName on a declare function func() (can't assert execution result on that one ofc).

@Z3rio
Copy link
Copy Markdown
Contributor Author

Z3rio commented Oct 21, 2023

Tests look fine, I'm still missing one where you put the customName on a declare function func() (can't assert execution result on that one ofc).

I added a test for that as well now :)

Could you please have a look at tstl-development in discord? Thank you

@Z3rio
Copy link
Copy Markdown
Contributor Author

Z3rio commented Oct 21, 2023

🎉

@Z3rio Z3rio requested a review from Perryvw October 21, 2023 15:09
Co-authored-by: Perry van Wesel <Perryvw@users.noreply.github.com>
@Perryvw Perryvw merged commit 40e4c22 into TypeScriptToLua:master Oct 21, 2023
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