typescript-to-lua 1.19.3 → 1.20.1

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
@@ -6,6 +6,7 @@ export declare enum LuaLibFeature {
6
6
  ArrayConcat = "ArrayConcat",
7
7
  ArrayEntries = "ArrayEntries",
8
8
  ArrayEvery = "ArrayEvery",
9
+ ArrayFill = "ArrayFill",
9
10
  ArrayFilter = "ArrayFilter",
10
11
  ArrayForEach = "ArrayForEach",
11
12
  ArrayFind = "ArrayFind",
package/dist/LuaLib.js CHANGED
@@ -11,6 +11,7 @@ var LuaLibFeature;
11
11
  LuaLibFeature["ArrayConcat"] = "ArrayConcat";
12
12
  LuaLibFeature["ArrayEntries"] = "ArrayEntries";
13
13
  LuaLibFeature["ArrayEvery"] = "ArrayEvery";
14
+ LuaLibFeature["ArrayFill"] = "ArrayFill";
14
15
  LuaLibFeature["ArrayFilter"] = "ArrayFilter";
15
16
  LuaLibFeature["ArrayForEach"] = "ArrayForEach";
16
17
  LuaLibFeature["ArrayFind"] = "ArrayFind";
@@ -0,0 +1,18 @@
1
+ local function __TS__ArrayFill(self, value, start, ____end)
2
+ local relativeStart = start or 0
3
+ local relativeEnd = ____end or table.getn(self)
4
+ if relativeStart < 0 then
5
+ relativeStart = relativeStart + table.getn(self)
6
+ end
7
+ if relativeEnd < 0 then
8
+ relativeEnd = relativeEnd + table.getn(self)
9
+ end
10
+ do
11
+ local i = relativeStart
12
+ while i < relativeEnd do
13
+ self[i + 1] = value
14
+ i = i + 1
15
+ end
16
+ end
17
+ return self
18
+ end
@@ -74,6 +74,25 @@ local function __TS__ArrayEvery(self, callbackfn, thisArg)
74
74
  return true
75
75
  end
76
76
 
77
+ local function __TS__ArrayFill(self, value, start, ____end)
78
+ local relativeStart = start or 0
79
+ local relativeEnd = ____end or table.getn(self)
80
+ if relativeStart < 0 then
81
+ relativeStart = relativeStart + table.getn(self)
82
+ end
83
+ if relativeEnd < 0 then
84
+ relativeEnd = relativeEnd + table.getn(self)
85
+ end
86
+ do
87
+ local i = relativeStart
88
+ while i < relativeEnd do
89
+ self[i + 1] = value
90
+ i = i + 1
91
+ end
92
+ end
93
+ return self
94
+ end
95
+
77
96
  local function __TS__ArrayFilter(self, callbackfn, thisArg)
78
97
  local result = {}
79
98
  local len = 0
@@ -2548,6 +2567,7 @@ return {
2548
2567
  __TS__ArrayConcat = __TS__ArrayConcat,
2549
2568
  __TS__ArrayEntries = __TS__ArrayEntries,
2550
2569
  __TS__ArrayEvery = __TS__ArrayEvery,
2570
+ __TS__ArrayFill = __TS__ArrayFill,
2551
2571
  __TS__ArrayFilter = __TS__ArrayFilter,
2552
2572
  __TS__ArrayForEach = __TS__ArrayForEach,
2553
2573
  __TS__ArrayFind = __TS__ArrayFind,
@@ -25,6 +25,11 @@
25
25
  "__TS__ArrayEvery"
26
26
  ]
27
27
  },
28
+ "ArrayFill": {
29
+ "exports": [
30
+ "__TS__ArrayFill"
31
+ ]
32
+ },
28
33
  "ArrayFilter": {
29
34
  "exports": [
30
35
  "__TS__ArrayFilter"
@@ -0,0 +1,18 @@
1
+ local function __TS__ArrayFill(self, value, start, ____end)
2
+ local relativeStart = start or 0
3
+ local relativeEnd = ____end or #self
4
+ if relativeStart < 0 then
5
+ relativeStart = relativeStart + #self
6
+ end
7
+ if relativeEnd < 0 then
8
+ relativeEnd = relativeEnd + #self
9
+ end
10
+ do
11
+ local i = relativeStart
12
+ while i < relativeEnd do
13
+ self[i + 1] = value
14
+ i = i + 1
15
+ end
16
+ end
17
+ return self
18
+ end
@@ -74,6 +74,25 @@ local function __TS__ArrayEvery(self, callbackfn, thisArg)
74
74
  return true
75
75
  end
76
76
 
77
+ local function __TS__ArrayFill(self, value, start, ____end)
78
+ local relativeStart = start or 0
79
+ local relativeEnd = ____end or #self
80
+ if relativeStart < 0 then
81
+ relativeStart = relativeStart + #self
82
+ end
83
+ if relativeEnd < 0 then
84
+ relativeEnd = relativeEnd + #self
85
+ end
86
+ do
87
+ local i = relativeStart
88
+ while i < relativeEnd do
89
+ self[i + 1] = value
90
+ i = i + 1
91
+ end
92
+ end
93
+ return self
94
+ end
95
+
77
96
  local function __TS__ArrayFilter(self, callbackfn, thisArg)
78
97
  local result = {}
79
98
  local len = 0
@@ -2488,6 +2507,7 @@ return {
2488
2507
  __TS__ArrayConcat = __TS__ArrayConcat,
2489
2508
  __TS__ArrayEntries = __TS__ArrayEntries,
2490
2509
  __TS__ArrayEvery = __TS__ArrayEvery,
2510
+ __TS__ArrayFill = __TS__ArrayFill,
2491
2511
  __TS__ArrayFilter = __TS__ArrayFilter,
2492
2512
  __TS__ArrayForEach = __TS__ArrayForEach,
2493
2513
  __TS__ArrayFind = __TS__ArrayFind,
@@ -25,6 +25,11 @@
25
25
  "__TS__ArrayEvery"
26
26
  ]
27
27
  },
28
+ "ArrayFill": {
29
+ "exports": [
30
+ "__TS__ArrayFill"
31
+ ]
32
+ },
28
33
  "ArrayFilter": {
29
34
  "exports": [
30
35
  "__TS__ArrayFilter"
@@ -66,6 +66,8 @@ function transformArrayPrototypeCall(context, node, calledMethod) {
66
66
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayConcat, node, caller, ...params);
67
67
  case "entries":
68
68
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayEntries, node, caller);
69
+ case "fill":
70
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayFill, node, caller, ...params);
69
71
  case "push":
70
72
  if (node.arguments.length === 1) {
71
73
  const param = (_a = params[0]) !== null && _a !== void 0 ? _a : lua.createNilLiteral();
@@ -24,6 +24,8 @@ function transformBuiltinPropertyAccessExpression(context, node) {
24
24
  const ownerType = context.checker.getTypeAtLocation(node.expression);
25
25
  if (ts.isIdentifier(node.expression) && (0, typescript_1.isStandardLibraryType)(context, ownerType, undefined)) {
26
26
  switch (ownerType.symbol.name) {
27
+ case "NumberConstructor":
28
+ return (0, number_1.transformNumberProperty)(context, node);
27
29
  case "Math":
28
30
  return (0, math_1.transformMathProperty)(context, node);
29
31
  case "SymbolConstructor":
@@ -2,4 +2,5 @@ import ts = require("typescript");
2
2
  import * as lua from "../../LuaAST";
3
3
  import { TransformationContext } from "../context";
4
4
  export declare function transformNumberPrototypeCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
5
+ export declare function transformNumberProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.Expression | undefined;
5
6
  export declare function transformNumberConstructorCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.CallExpression | undefined;
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformNumberConstructorCall = exports.transformNumberPrototypeCall = void 0;
3
+ exports.transformNumberConstructorCall = exports.transformNumberProperty = exports.transformNumberPrototypeCall = void 0;
4
4
  const lua = require("../../LuaAST");
5
+ const lua_ast_1 = require("../utils/lua-ast");
5
6
  const diagnostics_1 = require("../utils/diagnostics");
6
7
  const lualib_1 = require("../utils/lualib");
7
8
  const call_1 = require("../visitors/call");
9
+ const CompilerOptions_1 = require("../../CompilerOptions");
8
10
  function transformNumberPrototypeCall(context, node, calledMethod) {
9
11
  const signature = context.checker.getResolvedSignature(node);
10
12
  const params = (0, call_1.transformArguments)(context, node.arguments, signature);
@@ -22,6 +24,52 @@ function transformNumberPrototypeCall(context, node, calledMethod) {
22
24
  }
23
25
  }
24
26
  exports.transformNumberPrototypeCall = transformNumberPrototypeCall;
27
+ function transformNumberProperty(context, node) {
28
+ const name = node.name.text;
29
+ /*
30
+ Read the docs on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number for further info about what these numbers entail.
31
+ Most of them should be fairly straight forward base on their name(s) though.
32
+ */
33
+ switch (name) {
34
+ case "POSITIVE_INFINITY":
35
+ if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) {
36
+ const one = lua.createNumericLiteral(1);
37
+ const zero = lua.createNumericLiteral(0);
38
+ return lua.createBinaryExpression(one, zero, lua.SyntaxKind.DivisionOperator);
39
+ }
40
+ else {
41
+ const math = lua.createIdentifier("math");
42
+ const huge = lua.createStringLiteral("huge");
43
+ return lua.createTableIndexExpression(math, huge, node);
44
+ }
45
+ case "NEGATIVE_INFINITY":
46
+ if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) {
47
+ const one = lua.createNumericLiteral(1);
48
+ const zero = lua.createNumericLiteral(0);
49
+ return lua.createUnaryExpression(lua.createBinaryExpression(one, zero, lua.SyntaxKind.DivisionOperator), lua.SyntaxKind.NegationOperator);
50
+ }
51
+ else {
52
+ const math = lua.createIdentifier("math");
53
+ const huge = lua.createStringLiteral("huge");
54
+ return lua.createUnaryExpression(lua.createTableIndexExpression(math, huge, node), lua.SyntaxKind.NegationOperator);
55
+ }
56
+ case "NaN":
57
+ return (0, lua_ast_1.createNaN)(node);
58
+ case "EPSILON":
59
+ return lua.createBinaryExpression(lua.createNumericLiteral(2), lua.createNumericLiteral(-52), lua.SyntaxKind.PowerOperator, node);
60
+ case "MIN_VALUE":
61
+ return lua.createBinaryExpression(lua.createNumericLiteral(-2), lua.createNumericLiteral(1074), lua.SyntaxKind.PowerOperator, node);
62
+ case "MIN_SAFE_INTEGER":
63
+ return lua.createBinaryExpression(lua.createNumericLiteral(-2), lua.createNumericLiteral(1074), lua.SyntaxKind.PowerOperator, node);
64
+ case "MAX_SAFE_INTEGER":
65
+ return lua.createBinaryExpression(lua.createNumericLiteral(2), lua.createNumericLiteral(1024), lua.SyntaxKind.PowerOperator, node);
66
+ case "MAX_VALUE":
67
+ return lua.createBinaryExpression(lua.createNumericLiteral(2), lua.createNumericLiteral(1024), lua.SyntaxKind.PowerOperator, node);
68
+ default:
69
+ context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(node.name, "Number", name));
70
+ }
71
+ }
72
+ exports.transformNumberProperty = transformNumberProperty;
25
73
  function transformNumberConstructorCall(context, node, calledMethod) {
26
74
  const parameters = (0, call_1.transformArguments)(context, node.arguments);
27
75
  const methodName = calledMethod.name.text;
@@ -88,6 +88,10 @@ class ResolutionContext {
88
88
  if (plugin.moduleResolution != null) {
89
89
  const pluginResolvedPath = plugin.moduleResolution(dependency, requiringFile.fileName, this.options, this.emitHost);
90
90
  if (pluginResolvedPath !== undefined) {
91
+ // If resolved path is absolute no need to further resolve it
92
+ if (path.isAbsolute(pluginResolvedPath)) {
93
+ return pluginResolvedPath;
94
+ }
91
95
  // If lua file is in node_module
92
96
  if (requiredFromLuaFile && isNodeModulesFile(requiringFile.fileName)) {
93
97
  // If requiring file is in lua module, try to resolve sibling in that file first
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.19.3",
3
+ "version": "1.20.1",
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/",