typescript-to-lua 1.29.0 → 1.30.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.
@@ -1,4 +1,5 @@
1
1
  import * as ts from "typescript";
2
+ import { Plugin } from "./transpilation/plugins";
2
3
  type OmitIndexSignature<T> = {
3
4
  [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
4
5
  };
@@ -15,6 +16,10 @@ export interface LuaPluginImport {
15
16
  import?: string;
16
17
  [option: string]: any;
17
18
  }
19
+ export interface InMemoryLuaPlugin {
20
+ plugin: Plugin | ((options: Record<string, any>) => Plugin);
21
+ [option: string]: any;
22
+ }
18
23
  export interface TypeScriptToLuaOptions {
19
24
  buildMode?: BuildMode;
20
25
  extension?: string;
@@ -22,7 +27,7 @@ export interface TypeScriptToLuaOptions {
22
27
  luaBundleEntry?: string;
23
28
  luaTarget?: LuaTarget;
24
29
  luaLibImport?: LuaLibImportKind;
25
- luaPlugins?: LuaPluginImport[];
30
+ luaPlugins?: Array<LuaPluginImport | InMemoryLuaPlugin>;
26
31
  noImplicitGlobalVariables?: boolean;
27
32
  noImplicitSelf?: boolean;
28
33
  noHeader?: boolean;
@@ -17,6 +17,11 @@ do
17
17
  end
18
18
  if __TS__StringIncludes(_VERSION, "Lua 5.0") then
19
19
  return debug.traceback(("[Level " .. tostring(level)) .. "]")
20
+ elseif _VERSION == "Lua 5.1" then
21
+ return string.sub(
22
+ debug.traceback("", level),
23
+ 2
24
+ )
20
25
  else
21
26
  return debug.traceback(nil, level)
22
27
  end
@@ -25,7 +30,7 @@ do
25
30
  return function(self)
26
31
  local description = getDescription(self)
27
32
  local caller = debug.getinfo(3, "f")
28
- local isClassicLua = __TS__StringIncludes(_VERSION, "Lua 5.0") or _VERSION == "Lua 5.1"
33
+ local isClassicLua = __TS__StringIncludes(_VERSION, "Lua 5.0")
29
34
  if isClassicLua or caller and caller.func ~= error then
30
35
  return description
31
36
  else
@@ -49,7 +54,7 @@ do
49
54
  end
50
55
  self.message = message
51
56
  self.name = "Error"
52
- self.stack = getErrorStack(nil, self.constructor.new)
57
+ self.stack = getErrorStack(nil, __TS__New)
53
58
  local metatable = getmetatable(self)
54
59
  if metatable and not metatable.__errorToStringPatched then
55
60
  metatable.__errorToStringPatched = true
@@ -1098,6 +1098,11 @@ do
1098
1098
  end
1099
1099
  if __TS__StringIncludes(_VERSION, "Lua 5.0") then
1100
1100
  return debug.traceback(("[Level " .. tostring(level)) .. "]")
1101
+ elseif _VERSION == "Lua 5.1" then
1102
+ return string.sub(
1103
+ debug.traceback("", level),
1104
+ 2
1105
+ )
1101
1106
  else
1102
1107
  return debug.traceback(nil, level)
1103
1108
  end
@@ -1106,7 +1111,7 @@ do
1106
1111
  return function(self)
1107
1112
  local description = getDescription(self)
1108
1113
  local caller = debug.getinfo(3, "f")
1109
- local isClassicLua = __TS__StringIncludes(_VERSION, "Lua 5.0") or _VERSION == "Lua 5.1"
1114
+ local isClassicLua = __TS__StringIncludes(_VERSION, "Lua 5.0")
1110
1115
  if isClassicLua or caller and caller.func ~= error then
1111
1116
  return description
1112
1117
  else
@@ -1130,7 +1135,7 @@ do
1130
1135
  end
1131
1136
  self.message = message
1132
1137
  self.name = "Error"
1133
- self.stack = getErrorStack(nil, self.constructor.new)
1138
+ self.stack = getErrorStack(nil, __TS__New)
1134
1139
  local metatable = getmetatable(self)
1135
1140
  if metatable and not metatable.__errorToStringPatched then
1136
1141
  metatable.__errorToStringPatched = true
@@ -17,6 +17,11 @@ do
17
17
  end
18
18
  if __TS__StringIncludes(_VERSION, "Lua 5.0") then
19
19
  return debug.traceback(("[Level " .. tostring(level)) .. "]")
20
+ elseif _VERSION == "Lua 5.1" then
21
+ return string.sub(
22
+ debug.traceback("", level),
23
+ 2
24
+ )
20
25
  else
21
26
  return debug.traceback(nil, level)
22
27
  end
@@ -25,7 +30,7 @@ do
25
30
  return function(self)
26
31
  local description = getDescription(self)
27
32
  local caller = debug.getinfo(3, "f")
28
- local isClassicLua = __TS__StringIncludes(_VERSION, "Lua 5.0") or _VERSION == "Lua 5.1"
33
+ local isClassicLua = __TS__StringIncludes(_VERSION, "Lua 5.0")
29
34
  if isClassicLua or caller and caller.func ~= error then
30
35
  return description
31
36
  else
@@ -49,7 +54,7 @@ do
49
54
  end
50
55
  self.message = message
51
56
  self.name = "Error"
52
- self.stack = getErrorStack(nil, self.constructor.new)
57
+ self.stack = getErrorStack(nil, __TS__New)
53
58
  local metatable = getmetatable(self)
54
59
  if metatable and not metatable.__errorToStringPatched then
55
60
  metatable.__errorToStringPatched = true
@@ -1094,6 +1094,11 @@ do
1094
1094
  end
1095
1095
  if __TS__StringIncludes(_VERSION, "Lua 5.0") then
1096
1096
  return debug.traceback(("[Level " .. tostring(level)) .. "]")
1097
+ elseif _VERSION == "Lua 5.1" then
1098
+ return string.sub(
1099
+ debug.traceback("", level),
1100
+ 2
1101
+ )
1097
1102
  else
1098
1103
  return debug.traceback(nil, level)
1099
1104
  end
@@ -1102,7 +1107,7 @@ do
1102
1107
  return function(self)
1103
1108
  local description = getDescription(self)
1104
1109
  local caller = debug.getinfo(3, "f")
1105
- local isClassicLua = __TS__StringIncludes(_VERSION, "Lua 5.0") or _VERSION == "Lua 5.1"
1110
+ local isClassicLua = __TS__StringIncludes(_VERSION, "Lua 5.0")
1106
1111
  if isClassicLua or caller and caller.func ~= error then
1107
1112
  return description
1108
1113
  else
@@ -1126,7 +1131,7 @@ do
1126
1131
  end
1127
1132
  self.message = message
1128
1133
  self.name = "Error"
1129
- self.stack = getErrorStack(nil, self.constructor.new)
1134
+ self.stack = getErrorStack(nil, __TS__New)
1130
1135
  local metatable = getmetatable(self)
1131
1136
  if metatable and not metatable.__errorToStringPatched then
1132
1137
  metatable.__errorToStringPatched = true
@@ -11,9 +11,17 @@ function getPlugins(program) {
11
11
  const options = program.getCompilerOptions();
12
12
  for (const [index, pluginOption] of ((_a = options.luaPlugins) !== null && _a !== void 0 ? _a : []).entries()) {
13
13
  const optionName = `tstl.luaPlugins[${index}]`;
14
- const { error: resolveError, result: factory } = (0, utils_1.resolvePlugin)("plugin", `${optionName}.name`, (0, utils_1.getConfigDirectory)(options), pluginOption.name, pluginOption.import);
15
- if (resolveError)
16
- diagnostics.push(resolveError);
14
+ const factory = (() => {
15
+ if ("plugin" in pluginOption) {
16
+ return pluginOption.plugin;
17
+ }
18
+ else {
19
+ const { error: resolveError, result: factory } = (0, utils_1.resolvePlugin)("plugin", `${optionName}.name`, (0, utils_1.getConfigDirectory)(options), pluginOption.name, pluginOption.import);
20
+ if (resolveError)
21
+ diagnostics.push(resolveError);
22
+ return factory;
23
+ }
24
+ })();
17
25
  if (factory === undefined)
18
26
  continue;
19
27
  const plugin = typeof factory === "function" ? factory(pluginOption) : factory;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.29.0",
3
+ "version": "1.30.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/",