typescript-to-lua 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/CompilerOptions.d.ts +2 -2
  2. package/dist/LuaAST.d.ts +10 -10
  3. package/dist/LuaLib.d.ts +1 -1
  4. package/dist/LuaPrinter.d.ts +2 -2
  5. package/dist/cli/parse.d.ts +1 -1
  6. package/dist/cli/parse.js +1 -1
  7. package/dist/lualib/5.0/Generator.lua +1 -1
  8. package/dist/lualib/5.0/ParseInt.lua +3 -3
  9. package/dist/lualib/5.0/SetDescriptor.lua +1 -2
  10. package/dist/lualib/5.0/SparseArraySpread.lua +1 -1
  11. package/dist/lualib/5.0/Unpack.lua +18 -1
  12. package/dist/lualib/5.0/lualib_bundle.lua +52 -36
  13. package/dist/lualib/5.0/lualib_module_info.json +3 -2
  14. package/dist/lualib/universal/ParseInt.lua +3 -3
  15. package/dist/lualib/universal/SetDescriptor.lua +1 -2
  16. package/dist/lualib/universal/lualib_bundle.lua +20 -21
  17. package/dist/lualib/universal/lualib_module_info.json +0 -1
  18. package/dist/lualib-build/plugin.d.ts +1 -1
  19. package/dist/lualib-build/util.d.ts +2 -2
  20. package/dist/transformation/context/context.js +2 -1
  21. package/dist/transformation/context/visitors.d.ts +8 -7
  22. package/dist/transformation/utils/annotations.d.ts +1 -1
  23. package/dist/transformation/utils/diagnostics.d.ts +0 -9
  24. package/dist/transformation/utils/diagnostics.js +2 -6
  25. package/dist/transformation/utils/export.js +4 -2
  26. package/dist/transformation/utils/lua-ast.d.ts +1 -1
  27. package/dist/transformation/visitors/binary-expression/bit.d.ts +1 -1
  28. package/dist/transformation/visitors/binary-expression/bit.js +3 -0
  29. package/dist/transformation/visitors/binary-expression/compound.d.ts +1 -1
  30. package/dist/transformation/visitors/binary-expression/compound.js +7 -7
  31. package/dist/transformation/visitors/binary-expression/index.d.ts +2 -2
  32. package/dist/transformation/visitors/class/index.js +8 -4
  33. package/dist/transformation/visitors/class/utils.d.ts +1 -1
  34. package/dist/transformation/visitors/class/utils.js +2 -2
  35. package/dist/transformation/visitors/conditional.js +4 -0
  36. package/dist/transformation/visitors/language-extensions/call-extension.d.ts +2 -2
  37. package/dist/transformation/visitors/template.js +2 -2
  38. package/dist/transformation/visitors/typescript.js +1 -0
  39. package/dist/transpilation/resolve.js +4 -0
  40. package/dist/transpilation/utils.d.ts +1 -1
  41. package/dist/utils.d.ts +2 -2
  42. package/package.json +3 -3
@@ -1,5 +1,5 @@
1
1
  import * as ts from "typescript";
2
- declare type OmitIndexSignature<T> = {
2
+ type OmitIndexSignature<T> = {
3
3
  [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
4
4
  };
5
5
  export interface TransformerImport {
@@ -33,7 +33,7 @@ export interface TypeScriptToLuaOptions {
33
33
  lua51AllowTryCatchInAsyncAwait?: boolean;
34
34
  measurePerformance?: boolean;
35
35
  }
36
- export declare type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & TypeScriptToLuaOptions & {
36
+ export type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & TypeScriptToLuaOptions & {
37
37
  [option: string]: any;
38
38
  };
39
39
  export declare enum LuaLibImportKind {
package/dist/LuaAST.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as ts from "typescript";
2
- import { LuaLibFeature } from "./transformation/utils/lualib";
2
+ import { LuaLibFeature } from "./LuaLib";
3
3
  export declare enum SyntaxKind {
4
4
  File = 0,
5
5
  Block = 1,
@@ -58,12 +58,12 @@ export declare enum SyntaxKind {
58
58
  BitwiseLeftShiftOperator = 54,
59
59
  BitwiseNotOperator = 55
60
60
  }
61
- export declare type UnaryBitwiseOperator = SyntaxKind.BitwiseNotOperator;
62
- export declare type UnaryOperator = SyntaxKind.NegationOperator | SyntaxKind.LengthOperator | SyntaxKind.NotOperator | UnaryBitwiseOperator;
63
- export declare type BinaryBitwiseOperator = SyntaxKind.BitwiseAndOperator | SyntaxKind.BitwiseOrOperator | SyntaxKind.BitwiseExclusiveOrOperator | SyntaxKind.BitwiseRightShiftOperator | SyntaxKind.BitwiseLeftShiftOperator;
64
- export declare type BinaryOperator = SyntaxKind.AdditionOperator | SyntaxKind.SubtractionOperator | SyntaxKind.MultiplicationOperator | SyntaxKind.DivisionOperator | SyntaxKind.FloorDivisionOperator | SyntaxKind.ModuloOperator | SyntaxKind.PowerOperator | SyntaxKind.ConcatOperator | SyntaxKind.EqualityOperator | SyntaxKind.InequalityOperator | SyntaxKind.LessThanOperator | SyntaxKind.LessEqualOperator | SyntaxKind.GreaterThanOperator | SyntaxKind.GreaterEqualOperator | SyntaxKind.AndOperator | SyntaxKind.OrOperator | BinaryBitwiseOperator;
65
- export declare type Operator = UnaryOperator | BinaryOperator;
66
- export declare type SymbolId = number & {
61
+ export type UnaryBitwiseOperator = SyntaxKind.BitwiseNotOperator;
62
+ export type UnaryOperator = SyntaxKind.NegationOperator | SyntaxKind.LengthOperator | SyntaxKind.NotOperator | UnaryBitwiseOperator;
63
+ export type BinaryBitwiseOperator = SyntaxKind.BitwiseAndOperator | SyntaxKind.BitwiseOrOperator | SyntaxKind.BitwiseExclusiveOrOperator | SyntaxKind.BitwiseRightShiftOperator | SyntaxKind.BitwiseLeftShiftOperator;
64
+ export type BinaryOperator = SyntaxKind.AdditionOperator | SyntaxKind.SubtractionOperator | SyntaxKind.MultiplicationOperator | SyntaxKind.DivisionOperator | SyntaxKind.FloorDivisionOperator | SyntaxKind.ModuloOperator | SyntaxKind.PowerOperator | SyntaxKind.ConcatOperator | SyntaxKind.EqualityOperator | SyntaxKind.InequalityOperator | SyntaxKind.LessThanOperator | SyntaxKind.LessEqualOperator | SyntaxKind.GreaterThanOperator | SyntaxKind.GreaterEqualOperator | SyntaxKind.AndOperator | SyntaxKind.OrOperator | BinaryBitwiseOperator;
65
+ export type Operator = UnaryOperator | BinaryOperator;
66
+ export type SymbolId = number & {
67
67
  _symbolIdBrand: any;
68
68
  };
69
69
  export declare enum NodeFlags {
@@ -300,13 +300,13 @@ export interface TableIndexExpression extends Expression {
300
300
  }
301
301
  export declare function isTableIndexExpression(node: Node): node is TableIndexExpression;
302
302
  export declare function createTableIndexExpression(table: Expression, index: Expression, tsOriginal?: ts.Node): TableIndexExpression;
303
- export declare type AssignmentLeftHandSideExpression = Identifier | TableIndexExpression;
303
+ export type AssignmentLeftHandSideExpression = Identifier | TableIndexExpression;
304
304
  export declare function isAssignmentLeftHandSideExpression(node: Node): node is AssignmentLeftHandSideExpression;
305
- export declare type FunctionDefinition = (VariableDeclarationStatement | AssignmentStatement) & {
305
+ export type FunctionDefinition = (VariableDeclarationStatement | AssignmentStatement) & {
306
306
  right: [FunctionExpression];
307
307
  };
308
308
  export declare function isFunctionDefinition(statement: VariableDeclarationStatement | AssignmentStatement): statement is FunctionDefinition;
309
- export declare type InlineFunctionExpression = FunctionExpression & {
309
+ export type InlineFunctionExpression = FunctionExpression & {
310
310
  body: {
311
311
  statements: [ReturnStatement & {
312
312
  expressions: Expression[];
package/dist/LuaLib.d.ts CHANGED
@@ -107,7 +107,7 @@ export interface LuaLibFeatureInfo {
107
107
  dependencies?: LuaLibFeature[];
108
108
  exports: string[];
109
109
  }
110
- export declare type LuaLibModulesInfo = Record<LuaLibFeature, LuaLibFeatureInfo>;
110
+ export type LuaLibModulesInfo = Record<LuaLibFeature, LuaLibFeatureInfo>;
111
111
  export declare function resolveLuaLibDir(luaTarget: LuaTarget): string;
112
112
  export declare const luaLibModulesInfoFileName = "lualib_module_info.json";
113
113
  export declare function getLuaLibModulesInfo(luaTarget: LuaTarget, emitHost: EmitHost): LuaLibModulesInfo;
@@ -5,8 +5,8 @@ import * as lua from "./LuaAST";
5
5
  import { EmitHost } from "./transpilation";
6
6
  export declare const escapeString: (value: string) => string;
7
7
  export declare const tstlHeader = "--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]\n";
8
- declare type SourceChunk = string | SourceNode;
9
- export declare type Printer = (program: ts.Program, emitHost: EmitHost, fileName: string, file: lua.File) => PrintResult;
8
+ type SourceChunk = string | SourceNode;
9
+ export type Printer = (program: ts.Program, emitHost: EmitHost, fileName: string, file: lua.File) => PrintResult;
10
10
  export interface PrintResult {
11
11
  code: string;
12
12
  sourceMap: string;
@@ -15,7 +15,7 @@ interface CommandLineOptionOfEnum extends CommandLineOptionBase {
15
15
  interface CommandLineOptionOfPrimitive extends CommandLineOptionBase {
16
16
  type: "boolean" | "string" | "json-array-of-objects" | "array";
17
17
  }
18
- declare type CommandLineOption = CommandLineOptionOfEnum | CommandLineOptionOfPrimitive;
18
+ type CommandLineOption = CommandLineOptionOfEnum | CommandLineOptionOfPrimitive;
19
19
  export declare const optionDeclarations: CommandLineOption[];
20
20
  export declare function updateParsedConfigFile(parsedConfigFile: ts.ParsedCommandLine): ParsedCommandLine;
21
21
  export declare function parseCommandLine(args: string[]): ParsedCommandLine;
package/dist/cli/parse.js CHANGED
@@ -125,7 +125,7 @@ function updateParsedCommandLine(parsedCommandLine, args) {
125
125
  if (!args[i].startsWith("-"))
126
126
  continue;
127
127
  const isShorthand = !args[i].startsWith("--");
128
- const argumentName = args[i].substr(isShorthand ? 1 : 2);
128
+ const argumentName = args[i].substring(isShorthand ? 1 : 2);
129
129
  const option = exports.optionDeclarations.find(option => {
130
130
  if (option.name.toLowerCase() === argumentName.toLowerCase())
131
131
  return true;
@@ -25,7 +25,7 @@ do
25
25
  local args = arg
26
26
  local argsLength = __TS__CountVarargs(unpack(arg))
27
27
  return {
28
- ____coroutine = coroutine.create(function() return fn(__TS__Spread(__TS__Unpack(nil, args, 1, argsLength))) end),
28
+ ____coroutine = coroutine.create(function() return fn(__TS__Unpack(args, 1, argsLength)) end),
29
29
  [Symbol.iterator] = generatorIterator,
30
30
  next = generatorNext
31
31
  }
@@ -9,12 +9,12 @@ do
9
9
  base = 16
10
10
  local ____TS__Match_result__0_0
11
11
  if __TS__Match(hexMatch, "-") then
12
- ____TS__Match_result__0_0 = "-" .. __TS__StringSubstr(
12
+ ____TS__Match_result__0_0 = "-" .. __TS__StringSubstring(
13
13
  numberString,
14
14
  string.len(hexMatch)
15
15
  )
16
16
  else
17
- ____TS__Match_result__0_0 = __TS__StringSubstr(
17
+ ____TS__Match_result__0_0 = __TS__StringSubstring(
18
18
  numberString,
19
19
  string.len(hexMatch)
20
20
  )
@@ -29,7 +29,7 @@ do
29
29
  if base <= 10 then
30
30
  ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, base)
31
31
  else
32
- ____temp_1 = __TS__StringSubstr(parseIntBasePattern, 0, 10 + 2 * (base - 10))
32
+ ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
33
33
  end
34
34
  local allowedDigits = ____temp_1
35
35
  local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
@@ -71,8 +71,7 @@ do
71
71
  if not rawget(metatable, "_descriptors") then
72
72
  metatable._descriptors = {}
73
73
  end
74
- local descriptor = __TS__CloneDescriptor(desc)
75
- metatable._descriptors[key] = descriptor
74
+ metatable._descriptors[key] = __TS__CloneDescriptor(desc)
76
75
  metatable.__index = descriptorIndex
77
76
  metatable.__newindex = descriptorNewIndex
78
77
  end
@@ -1,3 +1,3 @@
1
1
  local function __TS__SparseArraySpread(sparseArray)
2
- return unpack(nil, sparseArray, 1, sparseArray.sparseLength)
2
+ return __TS__Unpack(sparseArray, 1, sparseArray.sparseLength)
3
3
  end
@@ -1 +1,18 @@
1
- local __TS__Unpack = unpack
1
+ local function __TS__Unpack(list, i, j)
2
+ if i == 1 and j == nil then
3
+ return unpack(nil, list)
4
+ else
5
+ if j == nil then
6
+ j = table.getn(list)
7
+ end
8
+ local slice = {}
9
+ do
10
+ local n = i
11
+ while n <= j do
12
+ slice[n - i + 1] = list[n]
13
+ n = n + 1
14
+ end
15
+ end
16
+ return unpack(slice)
17
+ end
18
+ end
@@ -971,8 +971,7 @@ do
971
971
  if not rawget(metatable, "_descriptors") then
972
972
  metatable._descriptors = {}
973
973
  end
974
- local descriptor = __TS__CloneDescriptor(desc)
975
- metatable._descriptors[key] = descriptor
974
+ metatable._descriptors[key] = __TS__CloneDescriptor(desc)
976
975
  metatable.__index = descriptorIndex
977
976
  metatable.__newindex = descriptorNewIndex
978
977
  end
@@ -1184,24 +1183,25 @@ local function __TS__DelegatedYield(iterable)
1184
1183
  end
1185
1184
  end
1186
1185
 
1187
- local function __TS__Spread(iterable)
1188
- local arr = {}
1189
- if type(iterable) == "string" then
1190
- for i = 0, string.len(iterable) - 1 do
1191
- arr[i + 1] = __TS__StringAccess(iterable, i)
1192
- end
1186
+ local function __TS__Unpack(list, i, j)
1187
+ if i == 1 and j == nil then
1188
+ return unpack(nil, list)
1193
1189
  else
1194
- local len = 0
1195
- for ____, item in __TS__Iterator(iterable) do
1196
- len = len + 1
1197
- arr[len] = item
1190
+ if j == nil then
1191
+ j = table.getn(list)
1192
+ end
1193
+ local slice = {}
1194
+ do
1195
+ local n = i
1196
+ while n <= j do
1197
+ slice[n - i + 1] = list[n]
1198
+ n = n + 1
1199
+ end
1198
1200
  end
1201
+ return unpack(slice)
1199
1202
  end
1200
- return unpack(arr)
1201
1203
  end
1202
1204
 
1203
- local __TS__Unpack = unpack
1204
-
1205
1205
  local __TS__Generator
1206
1206
  do
1207
1207
  local function generatorIterator(self)
@@ -1229,7 +1229,7 @@ do
1229
1229
  local args = arg
1230
1230
  local argsLength = __TS__CountVarargs(unpack(arg))
1231
1231
  return {
1232
- ____coroutine = coroutine.create(function() return fn(__TS__Spread(__TS__Unpack(nil, args, 1, argsLength))) end),
1232
+ ____coroutine = coroutine.create(function() return fn(__TS__Unpack(args, 1, argsLength)) end),
1233
1233
  [Symbol.iterator] = generatorIterator,
1234
1234
  next = generatorNext
1235
1235
  }
@@ -1672,22 +1672,6 @@ local function __TS__ParseFloat(numberString)
1672
1672
  return ____number_1
1673
1673
  end
1674
1674
 
1675
- local function __TS__StringSubstr(self, from, length)
1676
- if from ~= from then
1677
- from = 0
1678
- end
1679
- if length ~= nil then
1680
- if length ~= length or length <= 0 then
1681
- return ""
1682
- end
1683
- length = length + from
1684
- end
1685
- if from >= 0 then
1686
- from = from + 1
1687
- end
1688
- return string.sub(self, from, length)
1689
- end
1690
-
1691
1675
  local function __TS__StringSubstring(self, start, ____end)
1692
1676
  if ____end ~= ____end then
1693
1677
  ____end = 0
@@ -1717,12 +1701,12 @@ do
1717
1701
  base = 16
1718
1702
  local ____TS__Match_result__0_0
1719
1703
  if __TS__Match(hexMatch, "-") then
1720
- ____TS__Match_result__0_0 = "-" .. __TS__StringSubstr(
1704
+ ____TS__Match_result__0_0 = "-" .. __TS__StringSubstring(
1721
1705
  numberString,
1722
1706
  string.len(hexMatch)
1723
1707
  )
1724
1708
  else
1725
- ____TS__Match_result__0_0 = __TS__StringSubstr(
1709
+ ____TS__Match_result__0_0 = __TS__StringSubstring(
1726
1710
  numberString,
1727
1711
  string.len(hexMatch)
1728
1712
  )
@@ -1737,7 +1721,7 @@ do
1737
1721
  if base <= 10 then
1738
1722
  ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, base)
1739
1723
  else
1740
- ____temp_1 = __TS__StringSubstr(parseIntBasePattern, 0, 10 + 2 * (base - 10))
1724
+ ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
1741
1725
  end
1742
1726
  local allowedDigits = ____temp_1
1743
1727
  local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
@@ -2069,7 +2053,7 @@ local function __TS__SparseArrayPush(sparseArray, ...)
2069
2053
  end
2070
2054
 
2071
2055
  local function __TS__SparseArraySpread(sparseArray)
2072
- return unpack(nil, sparseArray, 1, sparseArray.sparseLength)
2056
+ return __TS__Unpack(sparseArray, 1, sparseArray.sparseLength)
2073
2057
  end
2074
2058
 
2075
2059
  local WeakMap
@@ -2217,6 +2201,22 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
2217
2201
  end
2218
2202
  end
2219
2203
 
2204
+ local function __TS__Spread(iterable)
2205
+ local arr = {}
2206
+ if type(iterable) == "string" then
2207
+ for i = 0, string.len(iterable) - 1 do
2208
+ arr[i + 1] = __TS__StringAccess(iterable, i)
2209
+ end
2210
+ else
2211
+ local len = 0
2212
+ for ____, item in __TS__Iterator(iterable) do
2213
+ len = len + 1
2214
+ arr[len] = item
2215
+ end
2216
+ end
2217
+ return unpack(arr)
2218
+ end
2219
+
2220
2220
  local function __TS__StringCharAt(self, pos)
2221
2221
  if pos ~= pos then
2222
2222
  pos = 0
@@ -2418,6 +2418,22 @@ local function __TS__StringStartsWith(self, searchString, position)
2418
2418
  ) == searchString
2419
2419
  end
2420
2420
 
2421
+ local function __TS__StringSubstr(self, from, length)
2422
+ if from ~= from then
2423
+ from = 0
2424
+ end
2425
+ if length ~= nil then
2426
+ if length ~= length or length <= 0 then
2427
+ return ""
2428
+ end
2429
+ length = length + from
2430
+ end
2431
+ if from >= 0 then
2432
+ from = from + 1
2433
+ end
2434
+ return string.sub(self, from, length)
2435
+ end
2436
+
2421
2437
  local function __TS__StringTrim(self)
2422
2438
  local result = string.gsub(self, "^[%s ]*(.-)[%s ]*$", "%1")
2423
2439
  return result
@@ -254,7 +254,6 @@
254
254
  "__TS__Generator"
255
255
  ],
256
256
  "dependencies": [
257
- "Spread",
258
257
  "Symbol",
259
258
  "CountVarargs",
260
259
  "Unpack"
@@ -420,7 +419,6 @@
420
419
  "__TS__ParseInt"
421
420
  ],
422
421
  "dependencies": [
423
- "StringSubstr",
424
422
  "StringSubstring",
425
423
  "Match"
426
424
  ]
@@ -518,6 +516,9 @@
518
516
  "SparseArraySpread": {
519
517
  "exports": [
520
518
  "__TS__SparseArraySpread"
519
+ ],
520
+ "dependencies": [
521
+ "Unpack"
521
522
  ]
522
523
  },
523
524
  "WeakMap": {
@@ -9,9 +9,9 @@ do
9
9
  base = 16
10
10
  local ____TS__Match_result__0_0
11
11
  if __TS__Match(hexMatch, "-") then
12
- ____TS__Match_result__0_0 = "-" .. __TS__StringSubstr(numberString, #hexMatch)
12
+ ____TS__Match_result__0_0 = "-" .. __TS__StringSubstring(numberString, #hexMatch)
13
13
  else
14
- ____TS__Match_result__0_0 = __TS__StringSubstr(numberString, #hexMatch)
14
+ ____TS__Match_result__0_0 = __TS__StringSubstring(numberString, #hexMatch)
15
15
  end
16
16
  numberString = ____TS__Match_result__0_0
17
17
  end
@@ -23,7 +23,7 @@ do
23
23
  if base <= 10 then
24
24
  ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, base)
25
25
  else
26
- ____temp_1 = __TS__StringSubstr(parseIntBasePattern, 0, 10 + 2 * (base - 10))
26
+ ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
27
27
  end
28
28
  local allowedDigits = ____temp_1
29
29
  local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
@@ -71,8 +71,7 @@ do
71
71
  if not rawget(metatable, "_descriptors") then
72
72
  metatable._descriptors = {}
73
73
  end
74
- local descriptor = __TS__CloneDescriptor(desc)
75
- metatable._descriptors[key] = descriptor
74
+ metatable._descriptors[key] = __TS__CloneDescriptor(desc)
76
75
  metatable.__index = descriptorIndex
77
76
  metatable.__newindex = descriptorNewIndex
78
77
  end
@@ -972,8 +972,7 @@ do
972
972
  if not rawget(metatable, "_descriptors") then
973
973
  metatable._descriptors = {}
974
974
  end
975
- local descriptor = __TS__CloneDescriptor(desc)
976
- metatable._descriptors[key] = descriptor
975
+ metatable._descriptors[key] = __TS__CloneDescriptor(desc)
977
976
  metatable.__index = descriptorIndex
978
977
  metatable.__newindex = descriptorNewIndex
979
978
  end
@@ -1609,22 +1608,6 @@ local function __TS__ParseFloat(numberString)
1609
1608
  return ____number_1
1610
1609
  end
1611
1610
 
1612
- local function __TS__StringSubstr(self, from, length)
1613
- if from ~= from then
1614
- from = 0
1615
- end
1616
- if length ~= nil then
1617
- if length ~= length or length <= 0 then
1618
- return ""
1619
- end
1620
- length = length + from
1621
- end
1622
- if from >= 0 then
1623
- from = from + 1
1624
- end
1625
- return string.sub(self, from, length)
1626
- end
1627
-
1628
1611
  local function __TS__StringSubstring(self, start, ____end)
1629
1612
  if ____end ~= ____end then
1630
1613
  ____end = 0
@@ -1654,9 +1637,9 @@ do
1654
1637
  base = 16
1655
1638
  local ____TS__Match_result__0_0
1656
1639
  if __TS__Match(hexMatch, "-") then
1657
- ____TS__Match_result__0_0 = "-" .. __TS__StringSubstr(numberString, #hexMatch)
1640
+ ____TS__Match_result__0_0 = "-" .. __TS__StringSubstring(numberString, #hexMatch)
1658
1641
  else
1659
- ____TS__Match_result__0_0 = __TS__StringSubstr(numberString, #hexMatch)
1642
+ ____TS__Match_result__0_0 = __TS__StringSubstring(numberString, #hexMatch)
1660
1643
  end
1661
1644
  numberString = ____TS__Match_result__0_0
1662
1645
  end
@@ -1668,7 +1651,7 @@ do
1668
1651
  if base <= 10 then
1669
1652
  ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, base)
1670
1653
  else
1671
- ____temp_1 = __TS__StringSubstr(parseIntBasePattern, 0, 10 + 2 * (base - 10))
1654
+ ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
1672
1655
  end
1673
1656
  local allowedDigits = ____temp_1
1674
1657
  local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
@@ -2378,6 +2361,22 @@ local function __TS__StringStartsWith(self, searchString, position)
2378
2361
  return string.sub(self, position + 1, #searchString + position) == searchString
2379
2362
  end
2380
2363
 
2364
+ local function __TS__StringSubstr(self, from, length)
2365
+ if from ~= from then
2366
+ from = 0
2367
+ end
2368
+ if length ~= nil then
2369
+ if length ~= length or length <= 0 then
2370
+ return ""
2371
+ end
2372
+ length = length + from
2373
+ end
2374
+ if from >= 0 then
2375
+ from = from + 1
2376
+ end
2377
+ return string.sub(self, from, length)
2378
+ end
2379
+
2381
2380
  local function __TS__StringTrim(self)
2382
2381
  local result = string.gsub(self, "^[%s ]*(.-)[%s ]*$", "%1")
2383
2382
  return result
@@ -418,7 +418,6 @@
418
418
  "__TS__ParseInt"
419
419
  ],
420
420
  "dependencies": [
421
- "StringSubstr",
422
421
  "StringSubstring",
423
422
  "Match"
424
423
  ]
@@ -7,7 +7,7 @@ export declare const lualibDiagnostic: ((message: string, file?: ts.SourceFile |
7
7
  };
8
8
  declare class LuaLibPlugin implements tstl.Plugin {
9
9
  visitors: {
10
- 305: (file: ts.SourceFile, context: tstl.TransformationContext) => tstl.File;
10
+ 308: (file: ts.SourceFile, context: tstl.TransformationContext) => tstl.File;
11
11
  };
12
12
  printer: tstl.Printer;
13
13
  afterPrint(program: ts.Program, options: tstl.CompilerOptions, emitHost: EmitHost, result: ProcessedFile[]): ts.Diagnostic[];
@@ -3,14 +3,14 @@ export declare function isExportTableDeclaration(node: tstl.Node): node is tstl.
3
3
  left: [];
4
4
  };
5
5
  export declare function isExportTable(node: tstl.Node): node is tstl.Identifier;
6
- export declare type ExportTableIndex = tstl.TableIndexExpression & {
6
+ export type ExportTableIndex = tstl.TableIndexExpression & {
7
7
  index: tstl.StringLiteral;
8
8
  };
9
9
  export declare function isExportTableIndex(node: tstl.Node): node is ExportTableIndex;
10
10
  export declare function isExportAlias(node: tstl.Node): node is tstl.VariableDeclarationStatement & {
11
11
  right: [ExportTableIndex];
12
12
  };
13
- export declare type ExportAssignment = tstl.AssignmentStatement & {
13
+ export type ExportAssignment = tstl.AssignmentStatement & {
14
14
  left: [ExportTableIndex];
15
15
  };
16
16
  export declare function isExportAssignment(node: tstl.Node): node is ExportAssignment;
@@ -48,7 +48,8 @@ class TransformationContext {
48
48
  transformNodeRaw(node, isExpression) {
49
49
  var _a;
50
50
  // TODO: Move to visitors?
51
- if ((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(modifier => modifier.kind === ts.SyntaxKind.DeclareKeyword)) {
51
+ if (ts.canHaveModifiers(node) &&
52
+ ((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(modifier => modifier.kind === ts.SyntaxKind.DeclareKeyword))) {
52
53
  return [];
53
54
  }
54
55
  const nodeVisitors = this.visitorMap.get(node.kind);
@@ -59,6 +59,7 @@ interface NodesBySyntaxKind {
59
59
  [ts.SyntaxKind.AsExpression]: ts.AsExpression;
60
60
  [ts.SyntaxKind.NonNullExpression]: ts.NonNullExpression;
61
61
  [ts.SyntaxKind.MetaProperty]: ts.MetaProperty;
62
+ [ts.SyntaxKind.SatisfiesExpression]: ts.SatisfiesExpression;
62
63
  [ts.SyntaxKind.TemplateSpan]: ts.TemplateSpan;
63
64
  [ts.SyntaxKind.SemicolonClassElement]: ts.SemicolonClassElement;
64
65
  [ts.SyntaxKind.Block]: ts.Block;
@@ -130,11 +131,11 @@ interface NodesBySyntaxKind {
130
131
  [ts.SyntaxKind.ThisKeyword]: ts.ThisExpression;
131
132
  [ts.SyntaxKind.NotEmittedStatement]: ts.NotEmittedStatement;
132
133
  }
133
- export declare type ExpressionLikeNode = ts.Expression | ts.QualifiedName | ts.ExternalModuleReference;
134
- export declare type StatementLikeNode = ts.Statement;
135
- export declare type VisitorResult<T extends ts.Node> = T extends ExpressionLikeNode ? lua.Expression : T extends StatementLikeNode ? OneToManyVisitorResult<lua.Statement> : T extends ts.SourceFile ? lua.File : OneToManyVisitorResult<lua.Node>;
136
- export declare type Visitor<T extends ts.Node> = FunctionVisitor<T> | ObjectVisitor<T>;
137
- export declare type FunctionVisitor<T extends ts.Node> = (node: T, context: TransformationContext) => VisitorResult<T>;
134
+ export type ExpressionLikeNode = ts.Expression | ts.QualifiedName | ts.ExternalModuleReference;
135
+ export type StatementLikeNode = ts.Statement;
136
+ export type VisitorResult<T extends ts.Node> = T extends ExpressionLikeNode ? lua.Expression : T extends StatementLikeNode ? OneToManyVisitorResult<lua.Statement> : T extends ts.SourceFile ? lua.File : OneToManyVisitorResult<lua.Node>;
137
+ export type Visitor<T extends ts.Node> = FunctionVisitor<T> | ObjectVisitor<T>;
138
+ export type FunctionVisitor<T extends ts.Node> = (node: T, context: TransformationContext) => VisitorResult<T>;
138
139
  export interface ObjectVisitor<T extends ts.Node> {
139
140
  transform: FunctionVisitor<T>;
140
141
  /**
@@ -146,8 +147,8 @@ export interface ObjectVisitor<T extends ts.Node> {
146
147
  */
147
148
  priority?: number;
148
149
  }
149
- export declare type Visitors = {
150
+ export type Visitors = {
150
151
  [P in keyof NodesBySyntaxKind]?: Visitor<NodesBySyntaxKind[P]>;
151
152
  };
152
- export declare type VisitorMap = Map<ts.SyntaxKind, Array<FunctionVisitor<ts.Node>>>;
153
+ export type VisitorMap = Map<ts.SyntaxKind, Array<FunctionVisitor<ts.Node>>>;
153
154
  export {};
@@ -10,7 +10,7 @@ export interface Annotation {
10
10
  kind: AnnotationKind;
11
11
  args: string[];
12
12
  }
13
- export declare type AnnotationsMap = Map<AnnotationKind, Annotation>;
13
+ export type AnnotationsMap = Map<AnnotationKind, Annotation>;
14
14
  export declare function getSymbolAnnotations(symbol: ts.Symbol): AnnotationsMap;
15
15
  export declare function getTypeAnnotations(type: ts.Type): AnnotationsMap;
16
16
  export declare function getNodeAnnotations(node: ts.Node): AnnotationsMap;
@@ -64,21 +64,12 @@ export declare const invalidMultiFunctionUse: ((node: ts.Node, ...args: any[]) =
64
64
  export declare const invalidMultiFunctionReturnType: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
65
65
  code: number;
66
66
  };
67
- export declare const invalidMultiTypeToNonArrayLiteral: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
68
- code: number;
69
- };
70
- export declare const invalidMultiTypeToEmptyPatternOrArrayLiteral: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
71
- code: number;
72
- };
73
67
  export declare const invalidMultiReturnAccess: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
74
68
  code: number;
75
69
  };
76
70
  export declare const invalidCallExtensionUse: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
77
71
  code: number;
78
72
  };
79
- export declare const annotationRemoved: ((node: ts.Node, kind: AnnotationKind) => ts.Diagnostic) & {
80
- code: number;
81
- };
82
73
  export declare const annotationDeprecated: ((node: ts.Node, kind: AnnotationKind) => ts.Diagnostic) & {
83
74
  code: number;
84
75
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.annotationRemoved = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = exports.invalidMultiTypeToNonArrayLiteral = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
3
+ exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
4
4
  const ts = require("typescript");
5
5
  const CompilerOptions_1 = require("../../CompilerOptions");
6
6
  const utils_1 = require("../../utils");
@@ -49,15 +49,11 @@ exports.invalidAmbientIdentifierName = createErrorDiagnosticFactory((text) => `I
49
49
  exports.unsupportedVarDeclaration = createErrorDiagnosticFactory("`var` declarations are not supported. Use `let` or `const` instead.");
50
50
  exports.invalidMultiFunctionUse = createErrorDiagnosticFactory("The $multi function must be called in a return statement.");
51
51
  exports.invalidMultiFunctionReturnType = createErrorDiagnosticFactory("The $multi function cannot be cast to a non-LuaMultiReturn type.");
52
- exports.invalidMultiTypeToNonArrayLiteral = createErrorDiagnosticFactory("Expected an array literal.");
53
- exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = createErrorDiagnosticFactory("There must be one or more elements specified here.");
54
52
  exports.invalidMultiReturnAccess = createErrorDiagnosticFactory("The LuaMultiReturn type can only be accessed via an element access expression of a numeric type.");
55
53
  exports.invalidCallExtensionUse = createErrorDiagnosticFactory("This function must be called directly and cannot be referred to.");
56
- exports.annotationRemoved = createErrorDiagnosticFactory((kind) => `'@${kind}' has been removed and will no longer have any effect.` +
57
- `See https://typescripttolua.github.io/docs/advanced/compiler-annotations#${kind.toLowerCase()} for more information.`);
58
54
  exports.annotationDeprecated = createWarningDiagnosticFactory((kind) => `'@${kind}' is deprecated and will be removed in a future update. Please update your code before upgrading to the next release, otherwise your project will no longer compile. ` +
59
55
  `See https://typescripttolua.github.io/docs/advanced/compiler-annotations#${kind.toLowerCase()} for more information.`);
60
- exports.truthyOnlyConditionalValue = createWarningDiagnosticFactory("Numbers and strings will always evaluate to true in Lua. Explicitly check the value with ===.");
56
+ exports.truthyOnlyConditionalValue = createWarningDiagnosticFactory("Only false and nil evaluate to 'false' in Lua, everything else is considered 'true'. Explicitly compare the value with ===.");
61
57
  exports.notAllowedOptionalAssignment = createErrorDiagnosticFactory("The left-hand side of an assignment expression may not be an optional property access.");
62
58
  exports.awaitMustBeInAsyncFunction = createErrorDiagnosticFactory("Await can only be used inside async functions.");
63
59
  exports.unsupportedBuiltinOptionalCall = createErrorDiagnosticFactory("Optional calls are not supported for builtin or language extension functions.");
@@ -9,12 +9,14 @@ const symbols_1 = require("./symbols");
9
9
  const typescript_1 = require("./typescript");
10
10
  function hasDefaultExportModifier(node) {
11
11
  var _a;
12
- return ((_a = node.modifiers) !== null && _a !== void 0 ? _a : []).some(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword);
12
+ return (ts.canHaveModifiers(node) &&
13
+ ((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword)) === true);
13
14
  }
14
15
  exports.hasDefaultExportModifier = hasDefaultExportModifier;
15
16
  function hasExportModifier(node) {
16
17
  var _a;
17
- return ((_a = node.modifiers) !== null && _a !== void 0 ? _a : []).some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword);
18
+ return (ts.canHaveModifiers(node) &&
19
+ ((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword)) === true);
18
20
  }
19
21
  exports.hasExportModifier = hasExportModifier;
20
22
  const createDefaultExportStringLiteral = (original) => lua.createStringLiteral("default", original);
@@ -1,7 +1,7 @@
1
1
  import * as ts from "typescript";
2
2
  import * as lua from "../../LuaAST";
3
3
  import { TransformationContext } from "../context";
4
- export declare type OneToManyVisitorResult<T extends lua.Node> = T | T[] | undefined;
4
+ export type OneToManyVisitorResult<T extends lua.Node> = T | T[] | undefined;
5
5
  export declare function unwrapVisitorResult<T extends lua.Node>(result: OneToManyVisitorResult<T>): T[];
6
6
  export declare function createSelfIdentifier(tsOriginal?: ts.Node): lua.Identifier;
7
7
  export declare function createExportsIdentifier(): lua.Identifier;
@@ -1,7 +1,7 @@
1
1
  import * as ts from "typescript";
2
2
  import * as lua from "../../../LuaAST";
3
3
  import { TransformationContext } from "../../context";
4
- export declare type BitOperator = ts.ShiftOperator | ts.BitwiseOperator;
4
+ export type BitOperator = ts.ShiftOperator | ts.BitwiseOperator;
5
5
  export declare const isBitOperator: (operator: ts.BinaryOperator) => operator is BitOperator;
6
6
  export declare function transformBinaryBitOperation(context: TransformationContext, node: ts.Node, left: lua.Expression, right: lua.Expression, operator: BitOperator): lua.Expression;
7
7
  export declare function transformUnaryBitOperation(context: TransformationContext, node: ts.Node, expression: lua.Expression, operator: lua.UnaryBitwiseOperator): lua.Expression;
@@ -32,6 +32,7 @@ function transformBitOperatorToLuaOperator(context, node, operator) {
32
32
  return lua.SyntaxKind.BitwiseLeftShiftOperator;
33
33
  case ts.SyntaxKind.GreaterThanGreaterThanToken:
34
34
  context.diagnostics.push((0, diagnostics_1.unsupportedRightShiftOperator)(node));
35
+ return lua.SyntaxKind.BitwiseRightShiftOperator;
35
36
  case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
36
37
  return lua.SyntaxKind.BitwiseRightShiftOperator;
37
38
  }
@@ -42,6 +43,7 @@ function transformBinaryBitOperation(context, node, left, right, operator) {
42
43
  case CompilerOptions_1.LuaTarget.Lua50:
43
44
  case CompilerOptions_1.LuaTarget.Lua51:
44
45
  context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "Bitwise operations", context.luaTarget));
46
+ return transformBinaryBitLibOperation(node, left, right, operator, "bit");
45
47
  case CompilerOptions_1.LuaTarget.LuaJIT:
46
48
  return transformBinaryBitLibOperation(node, left, right, operator, "bit");
47
49
  case CompilerOptions_1.LuaTarget.Lua52:
@@ -69,6 +71,7 @@ function transformUnaryBitOperation(context, node, expression, operator) {
69
71
  case CompilerOptions_1.LuaTarget.Lua50:
70
72
  case CompilerOptions_1.LuaTarget.Lua51:
71
73
  context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "Bitwise operations", context.luaTarget));
74
+ return transformUnaryBitLibOperation(node, expression, operator, "bit");
72
75
  case CompilerOptions_1.LuaTarget.LuaJIT:
73
76
  return transformUnaryBitLibOperation(node, expression, operator, "bit");
74
77
  case CompilerOptions_1.LuaTarget.Lua52:
@@ -1,7 +1,7 @@
1
1
  import * as ts from "typescript";
2
2
  import * as lua from "../../../LuaAST";
3
3
  import { TransformationContext } from "../../context";
4
- declare type CompoundAssignmentToken = ts.SyntaxKind.BarToken | ts.SyntaxKind.PlusToken | ts.SyntaxKind.CaretToken | ts.SyntaxKind.MinusToken | ts.SyntaxKind.SlashToken | ts.SyntaxKind.PercentToken | ts.SyntaxKind.AsteriskToken | ts.SyntaxKind.AmpersandToken | ts.SyntaxKind.AsteriskAsteriskToken | ts.SyntaxKind.LessThanLessThanToken | ts.SyntaxKind.GreaterThanGreaterThanToken | ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken | ts.SyntaxKind.BarBarToken | ts.SyntaxKind.AmpersandAmpersandToken | ts.SyntaxKind.QuestionQuestionToken;
4
+ type CompoundAssignmentToken = ts.SyntaxKind.BarToken | ts.SyntaxKind.PlusToken | ts.SyntaxKind.CaretToken | ts.SyntaxKind.MinusToken | ts.SyntaxKind.SlashToken | ts.SyntaxKind.PercentToken | ts.SyntaxKind.AsteriskToken | ts.SyntaxKind.AmpersandToken | ts.SyntaxKind.AsteriskAsteriskToken | ts.SyntaxKind.LessThanLessThanToken | ts.SyntaxKind.GreaterThanGreaterThanToken | ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken | ts.SyntaxKind.BarBarToken | ts.SyntaxKind.AmpersandAmpersandToken | ts.SyntaxKind.QuestionQuestionToken;
5
5
  export declare const isCompoundAssignmentToken: (token: ts.BinaryOperator) => token is ts.CompoundAssignmentOperator;
6
6
  export declare const unwrapCompoundAssignmentToken: (token: ts.CompoundAssignmentOperator) => CompoundAssignmentToken;
7
7
  export declare function transformCompoundAssignment(context: TransformationContext, expression: ts.Expression, lhs: ts.Expression, rhs: ts.Expression, operator: CompoundAssignmentToken, isPostfix: boolean): {
@@ -5,7 +5,7 @@ const ts = require("typescript");
5
5
  const lua = require("../../../LuaAST");
6
6
  const utils_1 = require("../../../utils");
7
7
  const preceding_statements_1 = require("../../utils/preceding-statements");
8
- const binary_expression_1 = require("../binary-expression");
8
+ const index_1 = require("./index");
9
9
  const assignments_1 = require("./assignments");
10
10
  function isLuaExpressionWithSideEffect(expression) {
11
11
  return !(lua.isLiteral(expression) || lua.isIdentifier(expression));
@@ -52,7 +52,7 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
52
52
  // ____obj[____index] = ____tmp ${replacementOperator} ${right};
53
53
  // return ____tmp
54
54
  const tmpDeclaration = lua.createVariableDeclarationStatement(tmp, accessExpression);
55
- const [precedingStatements, operatorExpression] = (0, binary_expression_1.transformBinaryOperation)(context, tmp, right, rightPrecedingStatements, operator, expression);
55
+ const [precedingStatements, operatorExpression] = (0, index_1.transformBinaryOperation)(context, tmp, right, rightPrecedingStatements, operator, expression);
56
56
  const assignStatement = lua.createAssignmentStatement(accessExpression, operatorExpression);
57
57
  return {
58
58
  statements: [objAndIndexDeclaration, ...precedingStatements, tmpDeclaration, assignStatement],
@@ -72,7 +72,7 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
72
72
  // local ____tmp = ____obj[____index] ${replacementOperator} ${right};
73
73
  // ____obj[____index] = ____tmp;
74
74
  // return ____tmp
75
- const [precedingStatements, operatorExpression] = (0, binary_expression_1.transformBinaryOperation)(context, accessExpression, right, rightPrecedingStatements, operator, expression);
75
+ const [precedingStatements, operatorExpression] = (0, index_1.transformBinaryOperation)(context, accessExpression, right, rightPrecedingStatements, operator, expression);
76
76
  const tmpDeclaration = lua.createVariableDeclarationStatement(tmp, operatorExpression);
77
77
  const assignStatement = lua.createAssignmentStatement(accessExpression, tmp);
78
78
  return {
@@ -88,7 +88,7 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
88
88
  // return ____tmp
89
89
  const tmpIdentifier = context.createTempNameForLuaExpression(left);
90
90
  const tmpDeclaration = lua.createVariableDeclarationStatement(tmpIdentifier, left);
91
- const [precedingStatements, operatorExpression] = (0, binary_expression_1.transformBinaryOperation)(context, tmpIdentifier, right, rightPrecedingStatements, operator, expression);
91
+ const [precedingStatements, operatorExpression] = (0, index_1.transformBinaryOperation)(context, tmpIdentifier, right, rightPrecedingStatements, operator, expression);
92
92
  const assignStatements = (0, assignments_1.transformAssignmentWithRightPrecedingStatements)(context, lhs, operatorExpression, rightPrecedingStatements);
93
93
  return { statements: [tmpDeclaration, ...precedingStatements, ...assignStatements], result: tmpIdentifier };
94
94
  }
@@ -101,7 +101,7 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
101
101
  }
102
102
  // Simple expressions
103
103
  // ${left} = ${left} ${operator} ${right}
104
- const [precedingStatements, operatorExpression] = (0, binary_expression_1.transformBinaryOperation)(context, left, right, rightPrecedingStatements, operator, expression);
104
+ const [precedingStatements, operatorExpression] = (0, index_1.transformBinaryOperation)(context, left, right, rightPrecedingStatements, operator, expression);
105
105
  const statements = (0, assignments_1.transformAssignmentWithRightPrecedingStatements)(context, lhs, operatorExpression, precedingStatements);
106
106
  return { statements, result: left };
107
107
  }
@@ -133,7 +133,7 @@ function transformCompoundAssignmentStatement(context, node, lhs, rhs, operator)
133
133
  ];
134
134
  }
135
135
  let operatorExpression;
136
- [rightPrecedingStatements, operatorExpression] = (0, binary_expression_1.transformBinaryOperation)(context, accessExpression, right, rightPrecedingStatements, operator, node);
136
+ [rightPrecedingStatements, operatorExpression] = (0, index_1.transformBinaryOperation)(context, accessExpression, right, rightPrecedingStatements, operator, node);
137
137
  const assignStatement = lua.createAssignmentStatement(accessExpression, operatorExpression);
138
138
  return [objAndIndexDeclaration, ...rightPrecedingStatements, assignStatement];
139
139
  }
@@ -144,7 +144,7 @@ function transformCompoundAssignmentStatement(context, node, lhs, rhs, operator)
144
144
  // Simple statements
145
145
  // ${left} = ${left} ${replacementOperator} ${right}
146
146
  let operatorExpression;
147
- [rightPrecedingStatements, operatorExpression] = (0, binary_expression_1.transformBinaryOperation)(context, left, right, rightPrecedingStatements, operator, node);
147
+ [rightPrecedingStatements, operatorExpression] = (0, index_1.transformBinaryOperation)(context, left, right, rightPrecedingStatements, operator, node);
148
148
  return (0, assignments_1.transformAssignmentWithRightPrecedingStatements)(context, lhs, operatorExpression, rightPrecedingStatements);
149
149
  }
150
150
  }
@@ -2,8 +2,8 @@ import * as ts from "typescript";
2
2
  import * as lua from "../../../LuaAST";
3
3
  import { FunctionVisitor, TransformationContext } from "../../context";
4
4
  import { BitOperator } from "./bit";
5
- declare type ShortCircuitOperator = ts.SyntaxKind.AmpersandAmpersandToken | ts.SyntaxKind.BarBarToken | ts.SyntaxKind.QuestionQuestionToken;
6
- declare type SimpleOperator = ts.AdditiveOperatorOrHigher | Exclude<ts.RelationalOperator, ts.SyntaxKind.InstanceOfKeyword | ts.SyntaxKind.InKeyword> | ts.EqualityOperator | ts.LogicalOperator;
5
+ type ShortCircuitOperator = ts.SyntaxKind.AmpersandAmpersandToken | ts.SyntaxKind.BarBarToken | ts.SyntaxKind.QuestionQuestionToken;
6
+ type SimpleOperator = ts.AdditiveOperatorOrHigher | Exclude<ts.RelationalOperator, ts.SyntaxKind.InstanceOfKeyword | ts.SyntaxKind.InKeyword> | ts.EqualityOperator | ts.LogicalOperator;
7
7
  export declare function createShortCircuitBinaryExpressionPrecedingStatements(context: TransformationContext, lhs: lua.Expression, rhs: lua.Expression, rightPrecedingStatements: lua.Statement[], operator: ShortCircuitOperator, node?: ts.BinaryExpression): [lua.Statement[], lua.Expression];
8
8
  export declare function transformBinaryOperation(context: TransformationContext, left: lua.Expression, right: lua.Expression, rightPrecedingStatements: lua.Statement[], operator: BitOperator | SimpleOperator | ts.SyntaxKind.QuestionQuestionToken, node: ts.Node): [lua.Statement[], lua.Expression];
9
9
  export declare const transformBinaryExpression: FunctionVisitor<ts.BinaryExpression>;
@@ -15,12 +15,16 @@ const method_1 = require("./members/method");
15
15
  const utils_1 = require("./utils");
16
16
  const setup_1 = require("./setup");
17
17
  const CompilerOptions_1 = require("../../../CompilerOptions");
18
+ const preceding_statements_1 = require("../../utils/preceding-statements");
18
19
  const transformClassDeclaration = (declaration, context) => {
19
20
  // If declaration is a default export, transform to export variable assignment instead
20
21
  if ((0, export_1.hasDefaultExportModifier)(declaration)) {
21
- const left = (0, export_1.createDefaultExportExpression)(declaration);
22
- const right = transformClassAsExpression(declaration, context);
23
- return [lua.createAssignmentStatement(left, right, declaration)];
22
+ // Class declaration including assignment to ____exports.default are in preceding statements
23
+ const [precedingStatements] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => {
24
+ transformClassAsExpression(declaration, context);
25
+ return [];
26
+ });
27
+ return precedingStatements;
24
28
  }
25
29
  const { statements } = transformClassLikeDeclaration(declaration, context);
26
30
  return statements;
@@ -74,7 +78,7 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
74
78
  }
75
79
  else if (!extendedType) {
76
80
  // Generate a constructor if none was defined in a base class
77
- const constructorResult = (0, constructor_1.transformConstructorDeclaration)(context, ts.factory.createConstructorDeclaration([], [], [], ts.factory.createBlock([], true)), localClassName, instanceFields, classDeclaration);
81
+ const constructorResult = (0, constructor_1.transformConstructorDeclaration)(context, ts.factory.createConstructorDeclaration([], [], ts.factory.createBlock([], true)), localClassName, instanceFields, classDeclaration);
78
82
  if (constructorResult)
79
83
  result.push(constructorResult);
80
84
  }
@@ -1,6 +1,6 @@
1
1
  import * as ts from "typescript";
2
2
  import { TransformationContext } from "../../context";
3
- export declare function isStaticNode(node: ts.Node): boolean;
3
+ export declare function isStaticNode(node: ts.HasModifiers): boolean;
4
4
  export declare function getExtendsClause(node: ts.ClassLikeDeclarationBase): ts.HeritageClause | undefined;
5
5
  export declare function getExtendedNode(node: ts.ClassLikeDeclarationBase): ts.ExpressionWithTypeArguments | undefined;
6
6
  export declare function getExtendedType(context: TransformationContext, node: ts.ClassLikeDeclarationBase): ts.Type | undefined;
@@ -4,12 +4,12 @@ exports.getExtendedType = exports.getExtendedNode = exports.getExtendsClause = e
4
4
  const ts = require("typescript");
5
5
  function isStaticNode(node) {
6
6
  var _a;
7
- return ((_a = node.modifiers) !== null && _a !== void 0 ? _a : []).some(m => m.kind === ts.SyntaxKind.StaticKeyword);
7
+ return ((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(m => m.kind === ts.SyntaxKind.StaticKeyword)) === true;
8
8
  }
9
9
  exports.isStaticNode = isStaticNode;
10
10
  function getExtendsClause(node) {
11
11
  var _a;
12
- return ((_a = node.heritageClauses) !== null && _a !== void 0 ? _a : []).find(clause => clause.token === ts.SyntaxKind.ExtendsKeyword);
12
+ return (_a = node.heritageClauses) === null || _a === void 0 ? void 0 : _a.find(clause => clause.token === ts.SyntaxKind.ExtendsKeyword);
13
13
  }
14
14
  exports.getExtendsClause = getExtendsClause;
15
15
  function getExtendedNode(node) {
@@ -76,6 +76,10 @@ function transformIfStatement(statement, context) {
76
76
  }
77
77
  exports.transformIfStatement = transformIfStatement;
78
78
  function checkOnlyTruthyCondition(condition, context) {
79
+ if (context.options.strictNullChecks === false)
80
+ return; // This check is not valid if everything could implicitly be nil
81
+ if (ts.isElementAccessExpression(condition))
82
+ return; // Array index could always implicitly return nil
79
83
  if (!(0, typescript_1.canBeFalsy)(context, context.checker.getTypeAtLocation(condition))) {
80
84
  context.diagnostics.push((0, diagnostics_1.truthyOnlyConditionalValue)(condition));
81
85
  }
@@ -3,8 +3,8 @@ import * as ts from "typescript";
3
3
  import { ExtensionKind } from "../../utils/language-extensions";
4
4
  import * as lua from "../../../LuaAST";
5
5
  export declare const callExtensions: Set<ExtensionKind>;
6
- export declare type LanguageExtensionCallTransformer = (context: TransformationContext, node: ts.CallExpression, extensionKind: ExtensionKind) => lua.Expression;
7
- export declare type LanguageExtensionCallTransformerMap = {
6
+ export type LanguageExtensionCallTransformer = (context: TransformationContext, node: ts.CallExpression, extensionKind: ExtensionKind) => lua.Expression;
7
+ export type LanguageExtensionCallTransformerMap = {
8
8
  [P in ExtensionKind]?: LanguageExtensionCallTransformer;
9
9
  };
10
10
  export declare function transformLanguageExtensionCallExpression(context: TransformationContext, node: ts.CallExpression): lua.Expression | undefined;
@@ -5,7 +5,7 @@ const ts = require("typescript");
5
5
  const lua = require("../../LuaAST");
6
6
  const function_context_1 = require("../utils/function-context");
7
7
  const lua_ast_1 = require("../utils/lua-ast");
8
- const types_1 = require("../utils/typescript/types");
8
+ const typescript_1 = require("../utils/typescript");
9
9
  const call_1 = require("./call");
10
10
  const expression_list_1 = require("./expression-list");
11
11
  // TODO: Source positions
@@ -27,7 +27,7 @@ const transformTemplateExpression = (node, context) => {
27
27
  const span = node.templateSpans[i];
28
28
  const expression = transformedExpressions[i];
29
29
  const spanType = context.checker.getTypeAtLocation(span.expression);
30
- if ((0, types_1.isStringType)(context, spanType)) {
30
+ if ((0, typescript_1.isStringType)(context, spanType)) {
31
31
  parts.push(expression);
32
32
  }
33
33
  else {
@@ -14,6 +14,7 @@ exports.typescriptVisitors = {
14
14
  [ts.SyntaxKind.InterfaceDeclaration]: () => undefined,
15
15
  [ts.SyntaxKind.NonNullExpression]: (node, context) => context.transformExpression(node.expression),
16
16
  [ts.SyntaxKind.ExpressionWithTypeArguments]: (node, context) => context.transformExpression(node.expression),
17
+ [ts.SyntaxKind.SatisfiesExpression]: (node, context) => context.transformExpression(node.expression),
17
18
  [ts.SyntaxKind.AsExpression]: transformAssertionExpression,
18
19
  [ts.SyntaxKind.TypeAssertionExpression]: transformAssertionExpression,
19
20
  [ts.SyntaxKind.NotEmittedStatement]: () => undefined,
@@ -136,6 +136,10 @@ class ResolutionContext {
136
136
  }
137
137
  catch (e) {
138
138
  // resolveSync errors if it fails to resolve
139
+ if (this.options.tstlVerbose && e.details) {
140
+ // Output resolver log
141
+ console.log(e.details);
142
+ }
139
143
  }
140
144
  return undefined;
141
145
  }
@@ -22,7 +22,7 @@ export interface EmitFile extends BaseFile {
22
22
  outputPath: string;
23
23
  }
24
24
  export declare const getConfigDirectory: (options: ts.CompilerOptions) => string;
25
- export declare function resolvePlugin(kind: string, optionName: string, basedir: string, query: string, importName?: string): {
25
+ export declare function resolvePlugin(kind: string, optionName: string, basedir: string, query: unknown, importName?: string): {
26
26
  error?: ts.Diagnostic;
27
27
  result?: unknown;
28
28
  };
package/dist/utils.d.ts CHANGED
@@ -4,7 +4,7 @@ export declare function castArray<T>(value: T | readonly T[]): readonly T[];
4
4
  export declare const intersperse: <T>(values: readonly T[], separator: T) => T[];
5
5
  export declare const union: <T>(...values: Iterable<T>[]) => T[];
6
6
  export declare const intersection: <T>(first: readonly T[], ...rest: (readonly T[])[]) => T[];
7
- declare type DiagnosticFactory = (...args: any) => Partial<ts.Diagnostic> & Pick<ts.Diagnostic, "messageText">;
7
+ type DiagnosticFactory = (...args: any) => Partial<ts.Diagnostic> & Pick<ts.Diagnostic, "messageText">;
8
8
  export declare const createDiagnosticFactoryWithCode: <T extends DiagnosticFactory>(code: number, create: T) => ((...args: Parameters<T>) => ts.Diagnostic) & {
9
9
  code: number;
10
10
  };
@@ -14,7 +14,7 @@ export declare const createSerialDiagnosticFactory: <T extends DiagnosticFactory
14
14
  export declare const normalizeSlashes: (filePath: string) => string;
15
15
  export declare const trimExtension: (filePath: string) => string;
16
16
  export declare function formatPathToLuaPath(filePath: string): string;
17
- declare type NoInfer<T> = [T][T extends any ? 0 : never];
17
+ type NoInfer<T> = [T][T extends any ? 0 : never];
18
18
  export declare function getOrUpdate<K, V>(map: Map<K, V> | (K extends object ? WeakMap<K, V> : never), key: K, getDefaultValue: () => NoInfer<V>): V;
19
19
  export declare function isNonNull<T>(value: T | null | undefined): value is T;
20
20
  export declare function cast<TOriginal, TCast extends TOriginal>(item: TOriginal, cast: (item: TOriginal) => item is TCast): TCast;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
5
5
  "repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
6
6
  "homepage": "https://typescripttolua.github.io/",
@@ -42,7 +42,7 @@
42
42
  "node": ">=16.10.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "typescript": "~4.8.2"
45
+ "typescript": "~4.9.3"
46
46
  },
47
47
  "dependencies": {
48
48
  "@typescript-to-lua/language-extensions": "1.0.0",
@@ -70,6 +70,6 @@
70
70
  "prettier": "^2.3.2",
71
71
  "ts-jest": "^28.0.8",
72
72
  "ts-node": "^10.9.1",
73
- "typescript": "~4.8.2"
73
+ "typescript": "~4.9.3"
74
74
  }
75
75
  }