typescript-to-lua
Advanced tools
Changelog
0.37.0
MultiReturn<>
type and $multi()
helper function as the first language extensions. This is to provide a type-safe alternative to the @tupleReturn
annotation. For more information see the new Language Extensions page on the docs website.tostring
for parameters of template literals (`${}`
) that are already known strings.Changelog
0.36.0
parseInt
and parseFloat
.yield*
for generator functions.Changelog
0.35.0
transpileFiles
and transpileProject
) now write transpiled files by default. This behavior can be changed by providing a writeFile
callback, similarly to TypeScript's program.emit
.transpile
and emitTranspiledFiles
functions have been replaced with the Transpiler
class. See documentation for usage examples.declarationDir
option not being respected.Function.length
is supported now.parseConfigFileWithSystem
to parse tsconfig.json files as part of the tstl API.string.replace
incorrectly escaping some replaceValue
characters (().+-*?[^$
)String.prototype.substr
was evaluated twice.Changelog
0.34.0
Added new "luaTarget"
option value - "universal"
. Choosing this target makes TypeScriptToLua generate code compatible with all supported Lua targets.
"luaTarget": "JIT"
in the tsconfig.json
file.TypeScript has been updated to 3.9. See release notes for details. This update includes some fixes specific to our API usage:
import "./file"
produced a TS2307 error #35973function foo(this: void, x: string) {}
foo(1);
-- Before: with 3.8 (this: void ignored due to signature mismatch)
foo(nil, 1)
-- Now: with 3.9
foo(1)
Reduced memory consumption and optimized performance of generators and iterators
Fixed generator syntax being ignored on methods (*foo() {}
) and function expressions (function*() {}
)
Fixed iteration over generators stopping at first yielded nil
value
Fixed Array.prototype.join
throwing an error when array contains anything other than strings and numbers
Fixed extending a class not keeping toString
implementation from a super class
Fixed issue where CLI arguments were incorrectly removed.
Fixed issue where class accessors threw an error due to a missing dependency.
Under the hood:
Changelog
0.33.0
Added support for nullish coalescing A ?? B
.
Annotation /** @noSelf */
now also works directly on function declarations, not only on classes/interfaces.
Fixed incorrect file paths in source maps.
Fixed unknown node kind throwing an error instead of diagnostic.
Fixed string index with side-effects being evaluated twice.
Added check for node.js version when running tstl.
Fixed some issues with reflection class names.
Fixed incorrectly escaped variable names.
Under the hood:
Changelog
0.32.0
Deprecated: The noHoisting
option has been removed, hoisting will always be done.
TypeScript has been updated to 3.8. See release notes for details.
Fixed class accessors not working when base class is lacking type information (#725)
Class extension code has been extracted to lualib
class A {}
class B extends A {}
A = __TS__Class()
B = __TS__Class()
-B.____super = A
-setmetatable(B, B.____super)
-setmetatable(B.prototype, B.____super.prototype)
+__TS__ClassExtends(A, B)
Generated code for class accessors is more dynamic now
class A {
get a() {
return true;
}
}
A = __TS__Class()
-A.prototype.____getters = {}
-A.prototype.__index = __TS__Index(A.prototype)
-function A.prototype.____getters.a(self)
- return true
-end
+__TS__SetDescriptor(
+ A.prototype,
+ "a",
+ {
+ get = function(self)
+ return true
+ end
+ }
+)
This change simplifies our codebase and opens a path to object accessors implementation
Errors reported during transpilation now are created as TypeScript diagnostics instead of being thrown as JavaScript errors. This makes TypeScriptToLua always try to generate valid code (even in presence of errors) and allows multiple errors to be reported in a single file:
for (var x in []) {
}
$ tstl file.ts
file.ts:1:1 - error TSTL: Iterating over arrays with 'for ... in' is not allowed.
file.ts:1:6 - error TSTL: `var` declarations are not supported. Use `let` or `const` instead.
$ cat file.lua
for x in pairs({}) do
end
Added tstl.luaPlugins
option, allowing to specify plugins in a tsconfig.json
file:
{
"tstl": {
"luaPlugins": [{ "name": "./plugin.ts" }]
}
}
Added support for all valid TS for ... of
loop variable patterns.
Fixed a bug where spread expressions in array literals were not correctly translated:
- [1, ...[2, 3], 4] // --> { 1, 2, 4 }
+ [1, ...[2, 3], 4] // --> { 1, 2, 3, 4 }
- ((...values) => values)(1, ...[2, 3], 4) // --> { 1, 2, 4 }
+ ((...values) => values)(1, ...[2, 3], 4) // --> { 1, 2, 3, 4 }
Fixed Lua error when left hand side of instanceof
was not a table type.
Fixed sourcemapTraceback
function returning a value different from the standard Lua result in 5.1.
Fixed missing LuaLib dependency for Error LuaLib function.
Fixed several issues with exported identifiers breaking for ... in
loops and some default class code.
Fixed overflowing numbers transforming to undefined Infinity, instead they are now transformed to math.huge
.