typescript-to-lua 1.3.1 → 1.3.2

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.
package/dist/LuaLib.d.ts CHANGED
@@ -42,6 +42,7 @@ export declare enum LuaLibFeature {
42
42
  Iterator = "Iterator",
43
43
  Map = "Map",
44
44
  MathAtan2 = "MathAtan2",
45
+ MathSign = "MathSign",
45
46
  New = "New",
46
47
  Number = "Number",
47
48
  NumberIsFinite = "NumberIsFinite",
package/dist/LuaLib.js CHANGED
@@ -46,6 +46,7 @@ var LuaLibFeature;
46
46
  LuaLibFeature["Iterator"] = "Iterator";
47
47
  LuaLibFeature["Map"] = "Map";
48
48
  LuaLibFeature["MathAtan2"] = "MathAtan2";
49
+ LuaLibFeature["MathSign"] = "MathSign";
49
50
  LuaLibFeature["New"] = "New";
50
51
  LuaLibFeature["Number"] = "Number";
51
52
  LuaLibFeature["NumberIsFinite"] = "NumberIsFinite";
@@ -0,0 +1,8 @@
1
+ function __TS__MathSign(val)
2
+ if val > 0 then
3
+ return 1
4
+ elseif val < 0 then
5
+ return -1
6
+ end
7
+ return 0
8
+ end
@@ -1335,6 +1335,15 @@ Map = Map
1335
1335
 
1336
1336
  __TS__MathAtan2 = math.atan2 or math.atan
1337
1337
 
1338
+ function __TS__MathSign(val)
1339
+ if val > 0 then
1340
+ return 1
1341
+ elseif val < 0 then
1342
+ return -1
1343
+ end
1344
+ return 0
1345
+ end
1346
+
1338
1347
  function __TS__Number(value)
1339
1348
  local valueType = type(value)
1340
1349
  if valueType == "number" then
@@ -57,6 +57,10 @@ function transformMathCall(context, node) {
57
57
  const add = lua.createBinaryExpression(one, params[0], lua.SyntaxKind.AdditionOperator);
58
58
  return lua.createCallExpression(lua.createTableIndexExpression(math, log), [add], node);
59
59
  }
60
+ case "pow": {
61
+ // Translate to base ^ power
62
+ return lua.createBinaryExpression(params[0], params[1], lua.SyntaxKind.PowerOperator, node);
63
+ }
60
64
  // math.floor(x + 0.5)
61
65
  case "round": {
62
66
  const floor = lua.createStringLiteral("floor");
@@ -64,6 +68,9 @@ function transformMathCall(context, node) {
64
68
  const add = lua.createBinaryExpression(params[0], half, lua.SyntaxKind.AdditionOperator);
65
69
  return lua.createCallExpression(lua.createTableIndexExpression(math, floor), [add], node);
66
70
  }
71
+ case "sign": {
72
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.MathSign, node, ...params);
73
+ }
67
74
  case "abs":
68
75
  case "acos":
69
76
  case "asin":
@@ -75,7 +82,6 @@ function transformMathCall(context, node) {
75
82
  case "log":
76
83
  case "max":
77
84
  case "min":
78
- case "pow":
79
85
  case "random":
80
86
  case "sin":
81
87
  case "sqrt":
@@ -4,6 +4,7 @@ exports.transformConstructorDeclaration = exports.createConstructorName = export
4
4
  const ts = require("typescript");
5
5
  const lua = require("../../../../LuaAST");
6
6
  const lua_ast_1 = require("../../../utils/lua-ast");
7
+ const preceding_statements_1 = require("../../../utils/preceding-statements");
7
8
  const scope_1 = require("../../../utils/scope");
8
9
  const function_1 = require("../../function");
9
10
  const identifier_1 = require("../../identifier");
@@ -29,7 +30,7 @@ function transformConstructorDeclaration(context, statement, className, instance
29
30
  const bodyWithFieldInitializers = (0, function_1.transformFunctionBodyHeader)(context, scope, statement.parameters, restParamName);
30
31
  // Check for field declarations in constructor
31
32
  const constructorFieldsDeclarations = statement.parameters.filter(p => p.modifiers !== undefined);
32
- const classInstanceFields = (0, fields_1.transformClassInstanceFields)(context, instanceFields);
33
+ const [fieldsPrecedingStatements, classInstanceFields] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => (0, fields_1.transformClassInstanceFields)(context, instanceFields));
33
34
  // If there are field initializers and the first statement is a super call,
34
35
  // move super call between default assignments and initializers
35
36
  if ((constructorFieldsDeclarations.length > 0 || classInstanceFields.length > 0) &&
@@ -54,6 +55,7 @@ function transformConstructorDeclaration(context, statement, className, instance
54
55
  }
55
56
  // else { TypeScript error: A parameter property may not be declared using a binding pattern }
56
57
  }
58
+ bodyWithFieldInitializers.push(...fieldsPrecedingStatements);
57
59
  bodyWithFieldInitializers.push(...classInstanceFields);
58
60
  bodyWithFieldInitializers.push(...body);
59
61
  const block = lua.createBlock(bodyWithFieldInitializers);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
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/",