typescript-to-lua 1.19.3 → 1.20.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.
@@ -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.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/",