Support transpiling class methods as named functions#1548
Support transpiling class methods as named functions#1548luis-j-soares merged 9 commits intomasterfrom
Conversation
TwitchBronBron
left a comment
There was a problem hiding this comment.
To keep the diff a little smaller, it might be good to keep any existing functions in their current locations rather than moving them around. Good example is getTranspiledBuilder, it seems like it moved? This'll make the merge into v1 a lot easier as well.
src/parser/Statement.ts
Outdated
| ); | ||
| } | ||
|
|
||
| private getBuilderName(className: string) { |
There was a problem hiding this comment.
Should probably rename this param to transpiledClassName since that's what you're expecting. Same with the getMethodIdentifier function.
There was a problem hiding this comment.
Renamed for consistency. Thanks!
Good point. I didn't exactly move I've now moved those new methods below the builder, and the diff seems easier to parse. |
TwitchBronBron
left a comment
There was a problem hiding this comment.
Just thought of an edge case. What happens if you have a method called builder?
class Person
sub builder()
end sub
end class
I think the current implementation will result in two __Person_builder functions. We probably need a way to differentiate (without back-compat breaks) the actual builder, and methods with the name builder. So maybe another underscore for methods? or "method" or something in the name. Thoughts?
As discussed offline, renamed the hoisted methods to |
Fixes #1544
This PR changes the transpiled output of classes from this:
To this:
Notes:
__[ClassName]_[methodName])__[ClassName]_builder)[ClassName])MethodStatement::transpileto allow for a custom name to be passed in. Which in this case, this is used to pass the method name concatenated to the class prefix.transpile, as we need to reuse that body for both the methods and the builder functions.