typescript-to-lua 1.4.3 → 1.6.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 (45) hide show
  1. package/dist/CompilerOptions.d.ts +1 -0
  2. package/dist/cli/parse.js +5 -0
  3. package/dist/lualib/Await.lua +21 -34
  4. package/dist/lualib/SourceMapTraceBack.lua +14 -1
  5. package/dist/lualib/lualib_bundle.lua +35 -35
  6. package/dist/lualib-build/plugin.d.ts +1 -1
  7. package/dist/transformation/builtins/array.d.ts +2 -3
  8. package/dist/transformation/builtins/array.js +8 -10
  9. package/dist/transformation/builtins/console.d.ts +2 -2
  10. package/dist/transformation/builtins/console.js +8 -9
  11. package/dist/transformation/builtins/function.d.ts +1 -2
  12. package/dist/transformation/builtins/function.js +5 -6
  13. package/dist/transformation/builtins/index.js +22 -23
  14. package/dist/transformation/builtins/math.d.ts +1 -2
  15. package/dist/transformation/builtins/math.js +3 -4
  16. package/dist/transformation/builtins/number.d.ts +3 -3
  17. package/dist/transformation/builtins/number.js +10 -12
  18. package/dist/transformation/builtins/object.d.ts +2 -3
  19. package/dist/transformation/builtins/object.js +16 -17
  20. package/dist/transformation/builtins/promise.d.ts +1 -2
  21. package/dist/transformation/builtins/promise.js +5 -6
  22. package/dist/transformation/builtins/string.d.ts +2 -3
  23. package/dist/transformation/builtins/string.js +7 -9
  24. package/dist/transformation/builtins/symbol.d.ts +2 -2
  25. package/dist/transformation/builtins/symbol.js +6 -7
  26. package/dist/transformation/context/context.d.ts +2 -2
  27. package/dist/transformation/context/context.js +1 -1
  28. package/dist/transformation/utils/export.d.ts +1 -1
  29. package/dist/transformation/utils/function-context.js +1 -1
  30. package/dist/transformation/utils/lua-ast.d.ts +1 -1
  31. package/dist/transformation/utils/lua-ast.js +83 -1
  32. package/dist/transformation/utils/typescript/index.js +2 -2
  33. package/dist/transformation/visitors/async-await.d.ts +1 -1
  34. package/dist/transformation/visitors/async-await.js +7 -14
  35. package/dist/transformation/visitors/binary-expression/compound.d.ts +4 -1
  36. package/dist/transformation/visitors/binary-expression/compound.js +10 -19
  37. package/dist/transformation/visitors/call.d.ts +1 -3
  38. package/dist/transformation/visitors/call.js +25 -14
  39. package/dist/transformation/visitors/errors.js +52 -11
  40. package/dist/transformation/visitors/function.js +1 -1
  41. package/dist/transformation/visitors/return.js +5 -4
  42. package/dist/transpilation/index.js +9 -4
  43. package/dist/transpilation/resolve.js +2 -2
  44. package/dist/transpilation/transpiler.js +3 -2
  45. package/package.json +9 -9
@@ -23,6 +23,7 @@ export interface TypeScriptToLuaOptions {
23
23
  luaTarget?: LuaTarget;
24
24
  luaLibImport?: LuaLibImportKind;
25
25
  luaPlugins?: LuaPluginImport[];
26
+ noImplicitGlobalVariables?: boolean;
26
27
  noImplicitSelf?: boolean;
27
28
  noHeader?: boolean;
28
29
  noResolvePaths?: string[];
package/dist/cli/parse.js CHANGED
@@ -39,6 +39,11 @@ exports.optionDeclarations = [
39
39
  type: "enum",
40
40
  choices: Object.values(CompilerOptions_1.LuaTarget),
41
41
  },
42
+ {
43
+ name: "noImplicitGlobalVariables",
44
+ description: 'Specify to prevent implicitly turning "normal" variants into global variables in the transpiled output.',
45
+ type: "boolean",
46
+ },
42
47
  {
43
48
  name: "noImplicitSelf",
44
49
  description: 'If "this" is implicitly considered an any type, do not generate a self parameter.',
@@ -2,7 +2,7 @@ local function __TS__AsyncAwaiter(generator)
2
2
  return __TS__New(
3
3
  __TS__Promise,
4
4
  function(____, resolve, reject)
5
- local adopt, fulfilled, rejected, step, asyncCoroutine
5
+ local adopt, fulfilled, step, resolved, asyncCoroutine
6
6
  function adopt(self, value)
7
7
  local ____temp_0
8
8
  if __TS__InstanceOf(value, __TS__Promise) then
@@ -13,55 +13,42 @@ local function __TS__AsyncAwaiter(generator)
13
13
  return ____temp_0
14
14
  end
15
15
  function fulfilled(self, value)
16
- local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine, value)
16
+ local success, resultOrError = coroutine.resume(asyncCoroutine, value)
17
17
  if success then
18
- step(nil, resultOrError, errorOrErrorHandler)
18
+ step(nil, resultOrError)
19
19
  else
20
- reject(nil, errorOrErrorHandler)
20
+ reject(nil, resultOrError)
21
21
  end
22
22
  end
23
- function rejected(self, handler)
24
- if handler then
25
- return function(____, value)
26
- local success, hasReturnedOrError, returnedValue = pcall(handler, value)
27
- if success then
28
- if hasReturnedOrError then
29
- resolve(nil, returnedValue)
30
- else
31
- step(nil, hasReturnedOrError, handler)
32
- end
33
- else
34
- reject(nil, hasReturnedOrError)
35
- end
36
- end
37
- else
38
- return function(____, value)
39
- reject(nil, value)
40
- end
23
+ function step(self, result)
24
+ if resolved then
25
+ return
41
26
  end
42
- end
43
- function step(self, result, errorHandler)
44
27
  if coroutine.status(asyncCoroutine) == "dead" then
45
28
  resolve(nil, result)
46
29
  else
47
30
  local ____self_1 = adopt(nil, result)
48
- ____self_1["then"](
49
- ____self_1,
50
- fulfilled,
51
- rejected(nil, errorHandler)
52
- )
31
+ ____self_1["then"](____self_1, fulfilled, reject)
53
32
  end
54
33
  end
34
+ resolved = false
55
35
  asyncCoroutine = coroutine.create(generator)
56
- local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine)
36
+ local success, resultOrError = coroutine.resume(
37
+ asyncCoroutine,
38
+ function(____, v)
39
+ resolved = true
40
+ local ____self_2 = adopt(nil, v)
41
+ ____self_2["then"](____self_2, resolve, reject)
42
+ end
43
+ )
57
44
  if success then
58
- step(nil, resultOrError, errorOrErrorHandler)
45
+ step(nil, resultOrError)
59
46
  else
60
- reject(nil, errorOrErrorHandler)
47
+ reject(nil, resultOrError)
61
48
  end
62
49
  end
63
50
  )
64
51
  end
65
- local function __TS__Await(errorHandler, thing)
66
- return coroutine.yield(errorHandler, thing)
52
+ local function __TS__Await(thing)
53
+ return coroutine.yield(thing)
67
54
  end
@@ -30,10 +30,23 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
30
30
  "(%S+)%.lua:(%d+)",
31
31
  function(file, line) return replacer(nil, file .. ".lua", file .. ".ts", line) end
32
32
  )
33
+ local function stringReplacer(____, file, line)
34
+ local fileSourceMap = _G.__TS__sourcemap[file]
35
+ if fileSourceMap and fileSourceMap[line] then
36
+ local chunkName = string.match(file, "%[string \"([^\"]+)\"%]")
37
+ local sourceName = string.gsub(chunkName, ".lua$", ".ts")
38
+ local data = fileSourceMap[line]
39
+ if type(data) == "number" then
40
+ return (sourceName .. ":") .. tostring(data)
41
+ end
42
+ return (tostring(data.file) .. ":") .. tostring(data.line)
43
+ end
44
+ return (file .. ":") .. line
45
+ end
33
46
  result = string.gsub(
34
47
  result,
35
48
  "(%[string \"[^\"]+\"%]):(%d+)",
36
- function(file, line) return replacer(nil, file, "unknown", line) end
49
+ function(file, line) return stringReplacer(nil, file, line) end
37
50
  )
38
51
  return result
39
52
  end
@@ -753,7 +753,7 @@ local function __TS__AsyncAwaiter(generator)
753
753
  return __TS__New(
754
754
  __TS__Promise,
755
755
  function(____, resolve, reject)
756
- local adopt, fulfilled, rejected, step, asyncCoroutine
756
+ local adopt, fulfilled, step, resolved, asyncCoroutine
757
757
  function adopt(self, value)
758
758
  local ____temp_0
759
759
  if __TS__InstanceOf(value, __TS__Promise) then
@@ -764,57 +764,44 @@ local function __TS__AsyncAwaiter(generator)
764
764
  return ____temp_0
765
765
  end
766
766
  function fulfilled(self, value)
767
- local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine, value)
767
+ local success, resultOrError = coroutine.resume(asyncCoroutine, value)
768
768
  if success then
769
- step(nil, resultOrError, errorOrErrorHandler)
769
+ step(nil, resultOrError)
770
770
  else
771
- reject(nil, errorOrErrorHandler)
771
+ reject(nil, resultOrError)
772
772
  end
773
773
  end
774
- function rejected(self, handler)
775
- if handler then
776
- return function(____, value)
777
- local success, hasReturnedOrError, returnedValue = pcall(handler, value)
778
- if success then
779
- if hasReturnedOrError then
780
- resolve(nil, returnedValue)
781
- else
782
- step(nil, hasReturnedOrError, handler)
783
- end
784
- else
785
- reject(nil, hasReturnedOrError)
786
- end
787
- end
788
- else
789
- return function(____, value)
790
- reject(nil, value)
791
- end
774
+ function step(self, result)
775
+ if resolved then
776
+ return
792
777
  end
793
- end
794
- function step(self, result, errorHandler)
795
778
  if coroutine.status(asyncCoroutine) == "dead" then
796
779
  resolve(nil, result)
797
780
  else
798
781
  local ____self_1 = adopt(nil, result)
799
- ____self_1["then"](
800
- ____self_1,
801
- fulfilled,
802
- rejected(nil, errorHandler)
803
- )
782
+ ____self_1["then"](____self_1, fulfilled, reject)
804
783
  end
805
784
  end
785
+ resolved = false
806
786
  asyncCoroutine = coroutine.create(generator)
807
- local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine)
787
+ local success, resultOrError = coroutine.resume(
788
+ asyncCoroutine,
789
+ function(____, v)
790
+ resolved = true
791
+ local ____self_2 = adopt(nil, v)
792
+ ____self_2["then"](____self_2, resolve, reject)
793
+ end
794
+ )
808
795
  if success then
809
- step(nil, resultOrError, errorOrErrorHandler)
796
+ step(nil, resultOrError)
810
797
  else
811
- reject(nil, errorOrErrorHandler)
798
+ reject(nil, resultOrError)
812
799
  end
813
800
  end
814
801
  )
815
802
  end
816
- local function __TS__Await(errorHandler, thing)
817
- return coroutine.yield(errorHandler, thing)
803
+ local function __TS__Await(thing)
804
+ return coroutine.yield(thing)
818
805
  end
819
806
 
820
807
  local function __TS__ClassExtends(target, base)
@@ -2083,10 +2070,23 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
2083
2070
  "(%S+)%.lua:(%d+)",
2084
2071
  function(file, line) return replacer(nil, file .. ".lua", file .. ".ts", line) end
2085
2072
  )
2073
+ local function stringReplacer(____, file, line)
2074
+ local fileSourceMap = _G.__TS__sourcemap[file]
2075
+ if fileSourceMap and fileSourceMap[line] then
2076
+ local chunkName = string.match(file, "%[string \"([^\"]+)\"%]")
2077
+ local sourceName = string.gsub(chunkName, ".lua$", ".ts")
2078
+ local data = fileSourceMap[line]
2079
+ if type(data) == "number" then
2080
+ return (sourceName .. ":") .. tostring(data)
2081
+ end
2082
+ return (tostring(data.file) .. ":") .. tostring(data.line)
2083
+ end
2084
+ return (file .. ":") .. line
2085
+ end
2086
2086
  result = string.gsub(
2087
2087
  result,
2088
2088
  "(%[string \"[^\"]+\"%]):(%d+)",
2089
- function(file, line) return replacer(nil, file, "unknown", line) end
2089
+ function(file, line) return stringReplacer(nil, file, line) end
2090
2090
  )
2091
2091
  return result
2092
2092
  end
@@ -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
- 303: (file: ts.SourceFile, context: tstl.TransformationContext) => tstl.File;
10
+ 305: (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[];
@@ -1,7 +1,6 @@
1
1
  import * as ts from "typescript";
2
2
  import * as lua from "../../LuaAST";
3
3
  import { TransformationContext } from "../context";
4
- import { PropertyCallExpression } from "../visitors/call";
5
- export declare function transformArrayConstructorCall(context: TransformationContext, node: PropertyCallExpression): lua.Expression | undefined;
6
- export declare function transformArrayPrototypeCall(context: TransformationContext, node: PropertyCallExpression): lua.Expression | undefined;
4
+ export declare function transformArrayConstructorCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
5
+ export declare function transformArrayPrototypeCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
7
6
  export declare function transformArrayProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.UnaryExpression | undefined;
@@ -9,11 +9,10 @@ const call_1 = require("../visitors/call");
9
9
  const typescript_1 = require("../utils/typescript");
10
10
  const expression_list_1 = require("../visitors/expression-list");
11
11
  const lua_ast_1 = require("../utils/lua-ast");
12
- function transformArrayConstructorCall(context, node) {
13
- const expression = node.expression;
12
+ function transformArrayConstructorCall(context, node, calledMethod) {
14
13
  const signature = context.checker.getResolvedSignature(node);
15
14
  const params = (0, call_1.transformArguments)(context, node.arguments, signature);
16
- const expressionName = expression.name.text;
15
+ const expressionName = calledMethod.name.text;
17
16
  switch (expressionName) {
18
17
  case "from":
19
18
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayFrom, node, ...params);
@@ -22,7 +21,7 @@ function transformArrayConstructorCall(context, node) {
22
21
  case "of":
23
22
  return (0, lua_ast_1.wrapInTable)(...params);
24
23
  default:
25
- context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(expression.name, "Array", expressionName));
24
+ context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "Array", expressionName));
26
25
  }
27
26
  }
28
27
  exports.transformArrayConstructorCall = transformArrayConstructorCall;
@@ -45,11 +44,10 @@ function transformSingleElementArrayPush(context, node, caller, param) {
45
44
  context.addPrecedingStatements(pushStatement);
46
45
  return expressionIsUsed ? lengthExpression : lua.createNilLiteral();
47
46
  }
48
- function transformArrayPrototypeCall(context, node) {
49
- const expression = node.expression;
47
+ function transformArrayPrototypeCall(context, node, calledMethod) {
50
48
  const signature = context.checker.getResolvedSignature(node);
51
- const [caller, params] = (0, call_1.transformCallAndArguments)(context, expression.expression, node.arguments, signature);
52
- const expressionName = expression.name.text;
49
+ const [caller, params] = (0, call_1.transformCallAndArguments)(context, calledMethod.expression, node.arguments, signature);
50
+ const expressionName = calledMethod.name.text;
53
51
  switch (expressionName) {
54
52
  case "concat":
55
53
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayConcat, node, caller, ...params);
@@ -103,7 +101,7 @@ function transformArrayPrototypeCall(context, node) {
103
101
  case "splice":
104
102
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArraySplice, node, caller, ...params);
105
103
  case "join":
106
- const callerType = context.checker.getTypeAtLocation(expression.expression);
104
+ const callerType = context.checker.getTypeAtLocation(calledMethod.expression);
107
105
  const elementType = context.checker.getElementTypeOfArrayType(callerType);
108
106
  if (elementType && ((0, typescript_1.isStringType)(context, elementType) || (0, typescript_1.isNumberType)(context, elementType))) {
109
107
  const defaultSeparatorLiteral = lua.createStringLiteral(",");
@@ -124,7 +122,7 @@ function transformArrayPrototypeCall(context, node) {
124
122
  case "flatMap":
125
123
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayFlatMap, node, caller, ...params);
126
124
  default:
127
- context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(expression.name, "array", expressionName));
125
+ context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "array", expressionName));
128
126
  }
129
127
  }
130
128
  exports.transformArrayPrototypeCall = transformArrayPrototypeCall;
@@ -1,4 +1,4 @@
1
+ import * as ts from "typescript";
1
2
  import * as lua from "../../LuaAST";
2
3
  import { TransformationContext } from "../context";
3
- import { PropertyCallExpression } from "../visitors/call";
4
- export declare function transformConsoleCall(context: TransformationContext, expression: PropertyCallExpression): lua.Expression | undefined;
4
+ export declare function transformConsoleCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
@@ -6,17 +6,16 @@ const lua = require("../../LuaAST");
6
6
  const diagnostics_1 = require("../utils/diagnostics");
7
7
  const call_1 = require("../visitors/call");
8
8
  const isStringFormatTemplate = (node) => ts.isStringLiteral(node) && node.text.includes("%");
9
- function transformConsoleCall(context, expression) {
10
- const method = expression.expression;
11
- const methodName = method.name.text;
12
- const signature = context.checker.getResolvedSignature(expression);
13
- const parameters = (0, call_1.transformArguments)(context, expression.arguments, signature);
9
+ function transformConsoleCall(context, node, calledMethod) {
10
+ const methodName = calledMethod.name.text;
11
+ const signature = context.checker.getResolvedSignature(node);
12
+ const parameters = (0, call_1.transformArguments)(context, node.arguments, signature);
14
13
  switch (methodName) {
15
14
  case "error":
16
15
  case "info":
17
16
  case "log":
18
17
  case "warn":
19
- if (expression.arguments.length > 0 && isStringFormatTemplate(expression.arguments[0])) {
18
+ if (node.arguments.length > 0 && isStringFormatTemplate(node.arguments[0])) {
20
19
  // print(string.format([arguments]))
21
20
  const stringFormatCall = lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("string"), lua.createStringLiteral("format")), parameters);
22
21
  return lua.createCallExpression(lua.createIdentifier("print"), [stringFormatCall]);
@@ -24,7 +23,7 @@ function transformConsoleCall(context, expression) {
24
23
  // print([arguments])
25
24
  return lua.createCallExpression(lua.createIdentifier("print"), parameters);
26
25
  case "assert":
27
- if (expression.arguments.length > 1 && isStringFormatTemplate(expression.arguments[1])) {
26
+ if (node.arguments.length > 1 && isStringFormatTemplate(node.arguments[1])) {
28
27
  // assert([condition], string.format([arguments]))
29
28
  const stringFormatCall = lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("string"), lua.createStringLiteral("format")), parameters.slice(1));
30
29
  return lua.createCallExpression(lua.createIdentifier("assert"), [parameters[0], stringFormatCall]);
@@ -32,7 +31,7 @@ function transformConsoleCall(context, expression) {
32
31
  // assert()
33
32
  return lua.createCallExpression(lua.createIdentifier("assert"), parameters);
34
33
  case "trace":
35
- if (expression.arguments.length > 0 && isStringFormatTemplate(expression.arguments[0])) {
34
+ if (node.arguments.length > 0 && isStringFormatTemplate(node.arguments[0])) {
36
35
  // print(debug.traceback(string.format([arguments])))
37
36
  const stringFormatCall = lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("string"), lua.createStringLiteral("format")), parameters);
38
37
  const debugTracebackCall = lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("debug"), lua.createStringLiteral("traceback")), [stringFormatCall]);
@@ -42,7 +41,7 @@ function transformConsoleCall(context, expression) {
42
41
  const debugTracebackCall = lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("debug"), lua.createStringLiteral("traceback")), parameters);
43
42
  return lua.createCallExpression(lua.createIdentifier("print"), [debugTracebackCall]);
44
43
  default:
45
- context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(method.name, "console", methodName));
44
+ context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "console", methodName));
46
45
  }
47
46
  }
48
47
  exports.transformConsoleCall = transformConsoleCall;
@@ -1,6 +1,5 @@
1
1
  import * as ts from "typescript";
2
2
  import * as lua from "../../LuaAST";
3
3
  import { TransformationContext } from "../context";
4
- import { PropertyCallExpression } from "../visitors/call";
5
- export declare function transformFunctionPrototypeCall(context: TransformationContext, node: PropertyCallExpression): lua.CallExpression | undefined;
4
+ export declare function transformFunctionPrototypeCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.CallExpression | undefined;
6
5
  export declare function transformFunctionProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.Expression | undefined;
@@ -8,15 +8,14 @@ const function_context_1 = require("../utils/function-context");
8
8
  const lua_ast_1 = require("../utils/lua-ast");
9
9
  const lualib_1 = require("../utils/lualib");
10
10
  const call_1 = require("../visitors/call");
11
- function transformFunctionPrototypeCall(context, node) {
12
- const expression = node.expression;
13
- const callerType = context.checker.getTypeAtLocation(expression.expression);
11
+ function transformFunctionPrototypeCall(context, node, calledMethod) {
12
+ const callerType = context.checker.getTypeAtLocation(calledMethod.expression);
14
13
  if ((0, function_context_1.getFunctionContextType)(context, callerType) === function_context_1.ContextType.Void) {
15
14
  context.diagnostics.push((0, diagnostics_1.unsupportedSelfFunctionConversion)(node));
16
15
  }
17
16
  const signature = context.checker.getResolvedSignature(node);
18
- const [caller, params] = (0, call_1.transformCallAndArguments)(context, expression.expression, node.arguments, signature);
19
- const expressionName = expression.name.text;
17
+ const [caller, params] = (0, call_1.transformCallAndArguments)(context, calledMethod.expression, node.arguments, signature);
18
+ const expressionName = calledMethod.name.text;
20
19
  switch (expressionName) {
21
20
  case "apply":
22
21
  const nonContextArgs = params.length > 1 ? [(0, lua_ast_1.createUnpackCall)(context, params[1], node.arguments[1])] : [];
@@ -26,7 +25,7 @@ function transformFunctionPrototypeCall(context, node) {
26
25
  case "call":
27
26
  return lua.createCallExpression(caller, params, node);
28
27
  case "toString":
29
- context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(expression.name, "function", expressionName));
28
+ context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "function", expressionName));
30
29
  }
31
30
  }
32
31
  exports.transformFunctionPrototypeCall = transformFunctionPrototypeCall;
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkForLuaLibType = exports.transformBuiltinIdentifierExpression = exports.transformBuiltinCallExpression = exports.transformBuiltinPropertyAccessExpression = void 0;
4
4
  const ts = require("typescript");
5
5
  const lua = require("../../LuaAST");
6
- const utils_1 = require("../../utils");
7
6
  const lua_ast_1 = require("../utils/lua-ast");
8
7
  const lualib_1 = require("../utils/lualib");
9
8
  const symbols_1 = require("../utils/symbols");
10
9
  const typescript_1 = require("../utils/typescript");
10
+ const call_1 = require("../visitors/call");
11
11
  const array_1 = require("./array");
12
12
  const console_1 = require("./console");
13
13
  const function_1 = require("./function");
@@ -55,80 +55,79 @@ function transformBuiltinCallExpression(context, node, isOptionalCall) {
55
55
  return result;
56
56
  }
57
57
  }
58
- const expression = ts.getOriginalNode(node.expression);
59
- if (!ts.isPropertyAccessExpression(expression)) {
58
+ const calledMethod = ts.getOriginalNode((0, call_1.getCalledExpression)(node));
59
+ if (!ts.isPropertyAccessExpression(calledMethod)) {
60
60
  return;
61
61
  }
62
- const isOptionalAccess = expression.questionDotToken;
63
- (0, utils_1.assume)(node);
62
+ const isOptionalAccess = calledMethod.questionDotToken;
64
63
  // If the function being called is of type owner.func, get the type of owner
65
- const ownerType = context.checker.getTypeAtLocation(expression.expression);
64
+ const ownerType = context.checker.getTypeAtLocation(calledMethod.expression);
66
65
  if ((0, typescript_1.isStandardLibraryType)(context, ownerType, undefined)) {
67
66
  const symbol = ownerType.getSymbol();
68
67
  switch (symbol === null || symbol === void 0 ? void 0 : symbol.name) {
69
68
  case "ArrayConstructor":
70
69
  if (isOptionalCall || isOptionalAccess)
71
70
  return unsupportedOptionalCall();
72
- return (0, array_1.transformArrayConstructorCall)(context, node);
71
+ return (0, array_1.transformArrayConstructorCall)(context, node, calledMethod);
73
72
  case "Console":
74
73
  if (isOptionalCall || isOptionalAccess)
75
74
  return unsupportedOptionalCall();
76
- return (0, console_1.transformConsoleCall)(context, node);
75
+ return (0, console_1.transformConsoleCall)(context, node, calledMethod);
77
76
  case "Math":
78
77
  if (isOptionalCall || isOptionalAccess)
79
78
  return unsupportedOptionalCall();
80
- return (0, math_1.transformMathCall)(context, node);
79
+ return (0, math_1.transformMathCall)(context, node, calledMethod);
81
80
  case "StringConstructor":
82
81
  if (isOptionalCall || isOptionalAccess)
83
82
  return unsupportedOptionalCall();
84
- return (0, string_1.transformStringConstructorCall)(context, node);
83
+ return (0, string_1.transformStringConstructorCall)(context, node, calledMethod);
85
84
  case "ObjectConstructor":
86
85
  if (isOptionalCall || isOptionalAccess)
87
86
  return unsupportedOptionalCall();
88
- return (0, object_1.transformObjectConstructorCall)(context, node);
87
+ return (0, object_1.transformObjectConstructorCall)(context, node, calledMethod);
89
88
  case "SymbolConstructor":
90
89
  if (isOptionalCall || isOptionalAccess)
91
90
  return unsupportedOptionalCall();
92
- return (0, symbol_1.transformSymbolConstructorCall)(context, node);
91
+ return (0, symbol_1.transformSymbolConstructorCall)(context, node, calledMethod);
93
92
  case "NumberConstructor":
94
93
  if (isOptionalCall || isOptionalAccess)
95
94
  return unsupportedOptionalCall();
96
- return (0, number_1.transformNumberConstructorCall)(context, node);
95
+ return (0, number_1.transformNumberConstructorCall)(context, node, calledMethod);
97
96
  case "PromiseConstructor":
98
97
  if (isOptionalCall || isOptionalAccess)
99
98
  return unsupportedOptionalCall();
100
- return (0, promise_1.transformPromiseConstructorCall)(context, node);
99
+ return (0, promise_1.transformPromiseConstructorCall)(context, node, calledMethod);
101
100
  }
102
101
  }
103
102
  const isStringFunction = (0, typescript_1.isStringType)(context, ownerType) ||
104
- (expression.questionDotToken && (0, typescript_1.isNullableType)(context, ownerType, typescript_1.isStringType));
103
+ (calledMethod.questionDotToken && (0, typescript_1.isNullableType)(context, ownerType, typescript_1.isStringType));
105
104
  if (isStringFunction && (0, typescript_1.hasStandardLibrarySignature)(context, node)) {
106
105
  if (isOptionalCall)
107
106
  return unsupportedOptionalCall();
108
- return (0, string_1.transformStringPrototypeCall)(context, node);
107
+ return (0, string_1.transformStringPrototypeCall)(context, node, calledMethod);
109
108
  }
110
109
  const isNumberFunction = (0, typescript_1.isNumberType)(context, ownerType) ||
111
- (expression.questionDotToken && (0, typescript_1.isNullableType)(context, ownerType, typescript_1.isNumberType));
110
+ (calledMethod.questionDotToken && (0, typescript_1.isNullableType)(context, ownerType, typescript_1.isNumberType));
112
111
  if (isNumberFunction && (0, typescript_1.hasStandardLibrarySignature)(context, node)) {
113
112
  if (isOptionalCall)
114
113
  return unsupportedOptionalCall();
115
- return (0, number_1.transformNumberPrototypeCall)(context, node);
114
+ return (0, number_1.transformNumberPrototypeCall)(context, node, calledMethod);
116
115
  }
117
116
  const isArrayFunction = (0, typescript_1.isArrayType)(context, ownerType) ||
118
- (expression.questionDotToken && (0, typescript_1.isNullableType)(context, ownerType, typescript_1.isArrayType));
117
+ (calledMethod.questionDotToken && (0, typescript_1.isNullableType)(context, ownerType, typescript_1.isArrayType));
119
118
  if (isArrayFunction && (0, typescript_1.hasStandardLibrarySignature)(context, node)) {
120
119
  if (isOptionalCall)
121
120
  return unsupportedOptionalCall();
122
- return (0, array_1.transformArrayPrototypeCall)(context, node);
121
+ return (0, array_1.transformArrayPrototypeCall)(context, node, calledMethod);
123
122
  }
124
123
  const isFunctionFunction = (0, typescript_1.isFunctionType)(ownerType) ||
125
- (expression.questionDotToken && (0, typescript_1.isNullableType)(context, ownerType, (_, t) => (0, typescript_1.isFunctionType)(t)));
124
+ (calledMethod.questionDotToken && (0, typescript_1.isNullableType)(context, ownerType, (_, t) => (0, typescript_1.isFunctionType)(t)));
126
125
  if (isFunctionFunction && (0, typescript_1.hasStandardLibrarySignature)(context, node)) {
127
126
  if (isOptionalCall)
128
127
  return unsupportedOptionalCall();
129
- return (0, function_1.transformFunctionPrototypeCall)(context, node);
128
+ return (0, function_1.transformFunctionPrototypeCall)(context, node, calledMethod);
130
129
  }
131
- const objectResult = (0, object_1.transformObjectPrototypeCall)(context, node, expression);
130
+ const objectResult = (0, object_1.transformObjectPrototypeCall)(context, node, calledMethod);
132
131
  if (objectResult) {
133
132
  if (isOptionalCall)
134
133
  return unsupportedOptionalCall();
@@ -1,6 +1,5 @@
1
1
  import * as ts from "typescript";
2
2
  import * as lua from "../../LuaAST";
3
3
  import { TransformationContext } from "../context";
4
- import { PropertyCallExpression } from "../visitors/call";
5
4
  export declare function transformMathProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.Expression | undefined;
6
- export declare function transformMathCall(context: TransformationContext, node: PropertyCallExpression): lua.Expression | undefined;
5
+ export declare function transformMathCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
@@ -26,12 +26,11 @@ function transformMathProperty(context, node) {
26
26
  }
27
27
  }
28
28
  exports.transformMathProperty = transformMathProperty;
29
- function transformMathCall(context, node) {
30
- const expression = node.expression;
29
+ function transformMathCall(context, node, calledMethod) {
31
30
  const signature = context.checker.getResolvedSignature(node);
32
31
  const params = (0, call_1.transformArguments)(context, node.arguments, signature);
33
32
  const math = lua.createIdentifier("math");
34
- const expressionName = expression.name.text;
33
+ const expressionName = calledMethod.name.text;
35
34
  switch (expressionName) {
36
35
  // Lua 5.3: math.atan(y, x)
37
36
  // Otherwise: math.atan2(y, x)
@@ -90,7 +89,7 @@ function transformMathCall(context, node) {
90
89
  return lua.createCallExpression(lua.createTableIndexExpression(math, method), params, node);
91
90
  }
92
91
  default:
93
- context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(expression.name, "Math", expressionName));
92
+ context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "Math", expressionName));
94
93
  }
95
94
  }
96
95
  exports.transformMathCall = transformMathCall;
@@ -1,5 +1,5 @@
1
+ import ts = require("typescript");
1
2
  import * as lua from "../../LuaAST";
2
3
  import { TransformationContext } from "../context";
3
- import { PropertyCallExpression } from "../visitors/call";
4
- export declare function transformNumberPrototypeCall(context: TransformationContext, node: PropertyCallExpression): lua.Expression | undefined;
5
- export declare function transformNumberConstructorCall(context: TransformationContext, expression: PropertyCallExpression): lua.CallExpression | undefined;
4
+ export declare function transformNumberPrototypeCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
5
+ export declare function transformNumberConstructorCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.CallExpression | undefined;
@@ -5,33 +5,31 @@ const lua = require("../../LuaAST");
5
5
  const diagnostics_1 = require("../utils/diagnostics");
6
6
  const lualib_1 = require("../utils/lualib");
7
7
  const call_1 = require("../visitors/call");
8
- function transformNumberPrototypeCall(context, node) {
9
- const expression = node.expression;
8
+ function transformNumberPrototypeCall(context, node, calledMethod) {
10
9
  const signature = context.checker.getResolvedSignature(node);
11
10
  const params = (0, call_1.transformArguments)(context, node.arguments, signature);
12
- const caller = context.transformExpression(expression.expression);
13
- const expressionName = expression.name.text;
11
+ const caller = context.transformExpression(calledMethod.expression);
12
+ const expressionName = calledMethod.name.text;
14
13
  switch (expressionName) {
15
14
  case "toString":
16
15
  return params.length === 0
17
16
  ? lua.createCallExpression(lua.createIdentifier("tostring"), [caller], node)
18
17
  : (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberToString, node, caller, ...params);
19
18
  default:
20
- context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(expression.name, "number", expressionName));
19
+ context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "number", expressionName));
21
20
  }
22
21
  }
23
22
  exports.transformNumberPrototypeCall = transformNumberPrototypeCall;
24
- function transformNumberConstructorCall(context, expression) {
25
- const method = expression.expression;
26
- const parameters = (0, call_1.transformArguments)(context, expression.arguments);
27
- const methodName = method.name.text;
23
+ function transformNumberConstructorCall(context, node, calledMethod) {
24
+ const parameters = (0, call_1.transformArguments)(context, node.arguments);
25
+ const methodName = calledMethod.name.text;
28
26
  switch (methodName) {
29
27
  case "isNaN":
30
- return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberIsNaN, expression, ...parameters);
28
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberIsNaN, node, ...parameters);
31
29
  case "isFinite":
32
- return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberIsFinite, expression, ...parameters);
30
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberIsFinite, node, ...parameters);
33
31
  default:
34
- context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(method.name, "Number", methodName));
32
+ context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "Number", methodName));
35
33
  }
36
34
  }
37
35
  exports.transformNumberConstructorCall = transformNumberConstructorCall;