GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||
GeezerVison is showing github.com — Tagged template literals support by hazzard993 · Pull Request #638 · TypeScriptToLua/TypeScriptToLua Conversation
Contributor
Closes #611 Raw strings are usable too. Equivalent output code does look hard to read. function func(strings: TemplateStringsArray, ...expressions: any[]) {} func`\u00A9 ${4}`; --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]] function func(self, strings, ...) end func(_G, { "© ", "", raw = { "\\u00A9 ", "", }, }, 4)
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
tomblind
requested changes
|
|
I did some more tests: Works:
Doesn't work:
So it seems Perhaps we should just require the type of that parameter to be |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Turns out |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Is there still anything weird to fix up with the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| joinRawResult: "hello \\`", | ||
| }, | ||
| { | ||
| callExpression: "obj.func`hello ${'propertyAccessExpression'}`", |
There was a problem 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)()
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Feature request: Tagged template literals
There was an error while loading. Please reload this page.