-
-
Notifications
You must be signed in to change notification settings - Fork 180
Tagged template literals support #638
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
Tagged template literals support #638
Conversation
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.
I did a quick test and stumbled on the fact that if the tag function's first argument is not typed as TemplateStringsArray (could be any[], string[], etc...), getResolvedSignature fails and so no context parameter is passed to the function in the resulting lua. I'm not sure off the top of my head how to best handle that, but we'll need to do something or the code breaks at runtime.
|
I did some more tests: Works:
Doesn't work:
So it seems Perhaps we should just require the type of that parameter to be |
|
Turns out |
|
|
|
Is there still anything weird to fix up with the |
|
|
| joinRawResult: "hello \\`", | ||
| }, | ||
| { | ||
| callExpression: "obj.func`hello ${'propertyAccessExpression'}`", |
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.
Looks like it always calls functions with global context:
const obj = {
func(strings: TemplateStringsArray, ...expressions: any[]) {
console.log(this === obj); // `true` in JS, `false` in Lua
},
};
obj.func`hello`;local obj = {func = function(self, strings, ...)
print(self == obj)
end}
obj.func(_G, { -- should be `obj`
"hello",
raw = {"hello"},
})Also there is a case where obj isn't pure:
getObj()["func"]`hello`;In call expressions it's handled like that:
(function()
local ____TS_self = getObj(_G)
return ____TS_self.func(____TS_self, {
"hello",
raw = {"hello"},
})
end)()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.
Good find! Took a bit to understand what to do here, I've added transformContextualCallExpression in an attempt to preserve this left hand side behaviour to call-like expressions which includes these template literals.
Closes #611
Raw strings are usable too.
Equivalent output code does look hard to read.