typescript-to-lua
Advanced tools
Comparing version 1.19.3 to 1.20.0
@@ -27,2 +27,4 @@ "use strict"; | ||
switch (ownerType.symbol.name) { | ||
case "NumberConstructor": | ||
return (0, number_1.transformNumberProperty)(context, node); | ||
case "Math": | ||
@@ -29,0 +31,0 @@ return (0, math_1.transformMathProperty)(context, node); |
@@ -5,2 +5,3 @@ import ts = require("typescript"); | ||
export declare function transformNumberPrototypeCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined; | ||
export declare function transformNumberProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.Expression | undefined; | ||
export declare function transformNumberConstructorCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.CallExpression | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transformNumberConstructorCall = exports.transformNumberPrototypeCall = void 0; | ||
exports.transformNumberConstructorCall = exports.transformNumberProperty = exports.transformNumberPrototypeCall = void 0; | ||
const lua = require("../../LuaAST"); | ||
const lua_ast_1 = require("../utils/lua-ast"); | ||
const diagnostics_1 = require("../utils/diagnostics"); | ||
const lualib_1 = require("../utils/lualib"); | ||
const call_1 = require("../visitors/call"); | ||
const CompilerOptions_1 = require("../../CompilerOptions"); | ||
function transformNumberPrototypeCall(context, node, calledMethod) { | ||
@@ -25,2 +27,48 @@ const signature = context.checker.getResolvedSignature(node); | ||
exports.transformNumberPrototypeCall = transformNumberPrototypeCall; | ||
function transformNumberProperty(context, node) { | ||
const name = node.name.text; | ||
/* | ||
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. | ||
Most of them should be fairly straight forward base on their name(s) though. | ||
*/ | ||
switch (name) { | ||
case "POSITIVE_INFINITY": | ||
if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) { | ||
const one = lua.createNumericLiteral(1); | ||
const zero = lua.createNumericLiteral(0); | ||
return lua.createBinaryExpression(one, zero, lua.SyntaxKind.DivisionOperator); | ||
} | ||
else { | ||
const math = lua.createIdentifier("math"); | ||
const huge = lua.createStringLiteral("huge"); | ||
return lua.createTableIndexExpression(math, huge, node); | ||
} | ||
case "NEGATIVE_INFINITY": | ||
if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) { | ||
const one = lua.createNumericLiteral(1); | ||
const zero = lua.createNumericLiteral(0); | ||
return lua.createUnaryExpression(lua.createBinaryExpression(one, zero, lua.SyntaxKind.DivisionOperator), lua.SyntaxKind.NegationOperator); | ||
} | ||
else { | ||
const math = lua.createIdentifier("math"); | ||
const huge = lua.createStringLiteral("huge"); | ||
return lua.createUnaryExpression(lua.createTableIndexExpression(math, huge, node), lua.SyntaxKind.NegationOperator); | ||
} | ||
case "NaN": | ||
return (0, lua_ast_1.createNaN)(node); | ||
case "EPSILON": | ||
return lua.createBinaryExpression(lua.createNumericLiteral(2), lua.createNumericLiteral(-52), lua.SyntaxKind.PowerOperator, node); | ||
case "MIN_VALUE": | ||
return lua.createBinaryExpression(lua.createNumericLiteral(-2), lua.createNumericLiteral(1074), lua.SyntaxKind.PowerOperator, node); | ||
case "MIN_SAFE_INTEGER": | ||
return lua.createBinaryExpression(lua.createNumericLiteral(-2), lua.createNumericLiteral(1074), lua.SyntaxKind.PowerOperator, node); | ||
case "MAX_SAFE_INTEGER": | ||
return lua.createBinaryExpression(lua.createNumericLiteral(2), lua.createNumericLiteral(1024), lua.SyntaxKind.PowerOperator, node); | ||
case "MAX_VALUE": | ||
return lua.createBinaryExpression(lua.createNumericLiteral(2), lua.createNumericLiteral(1024), lua.SyntaxKind.PowerOperator, node); | ||
default: | ||
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(node.name, "Number", name)); | ||
} | ||
} | ||
exports.transformNumberProperty = transformNumberProperty; | ||
function transformNumberConstructorCall(context, node, calledMethod) { | ||
@@ -27,0 +75,0 @@ const parameters = (0, call_1.transformArguments)(context, node.arguments); |
@@ -91,2 +91,6 @@ "use strict"; | ||
if (pluginResolvedPath !== undefined) { | ||
// If resolved path is absolute no need to further resolve it | ||
if (path.isAbsolute(pluginResolvedPath)) { | ||
return pluginResolvedPath; | ||
} | ||
// If lua file is in node_module | ||
@@ -93,0 +97,0 @@ if (requiredFromLuaFile && isNodeModulesFile(requiringFile.fileName)) { |
{ | ||
"name": "typescript-to-lua", | ||
"version": "1.19.3", | ||
"version": "1.20.0", | ||
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/TypeScriptToLua/TypeScriptToLua", |
1082911
15435