From c42e176e34a97d32c6772de92965c078c39130f4 Mon Sep 17 00:00:00 2001 From: Zerio Date: Sun, 24 Sep 2023 22:58:07 +0200 Subject: [PATCH 01/17] Basic number literal structure --- src/transformation/builtins/index.ts | 18 +++++++++++++++++- src/transformation/visitors/identifier.ts | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/transformation/builtins/index.ts b/src/transformation/builtins/index.ts index 64f0d4228..8a73fcb48 100644 --- a/src/transformation/builtins/index.ts +++ b/src/transformation/builtins/index.ts @@ -162,7 +162,23 @@ export function transformBuiltinIdentifierExpression( const huge = lua.createStringLiteral("huge"); return lua.createTableIndexExpression(math, huge, node); } - + case "Number": + if ("identifiers" in context.sourceFile && context.sourceFile.identifiers instanceof Map) { + const keys = context.sourceFile.identifiers.keys(); + keys.next(); + + const identifier = keys.next().value; + + console.log(identifier); + if (identifier) { + switch (identifier) { + default: + console.log(identifier); + break; + } + } + } + break; case "globalThis": return lua.createIdentifier("_G", node, getIdentifierSymbolId(context, node, symbol), "globalThis"); } diff --git a/src/transformation/visitors/identifier.ts b/src/transformation/visitors/identifier.ts index 6262a316f..4d127ac9d 100644 --- a/src/transformation/visitors/identifier.ts +++ b/src/transformation/visitors/identifier.ts @@ -73,14 +73,17 @@ export function transformIdentifierWithSymbol( const text = hasUnsafeIdentifierName(context, node, symbol) ? createSafeName(name) : name; const symbolId = getIdentifierSymbolId(context, node, symbol); const identifier = lua.createIdentifier(text, node, symbolId, name); + console.log("1"); return createExportedIdentifier(context, identifier, exportScope); } } const builtinResult = transformBuiltinIdentifierExpression(context, node, symbol); if (builtinResult) { + console.log("2"); return builtinResult; } + console.log("3"); return transformNonValueIdentifier(context, node, symbol); } From 9148ab9bd3f488303eebc78604cf687117a30099 Mon Sep 17 00:00:00 2001 From: Zerio Date: Sun, 24 Sep 2023 23:01:45 +0200 Subject: [PATCH 02/17] Setup `POSITIVE_INFINITY` --- src/transformation/builtins/index.ts | 13 ++++++++++--- src/transformation/visitors/identifier.ts | 3 --- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/transformation/builtins/index.ts b/src/transformation/builtins/index.ts index 8a73fcb48..f36e69646 100644 --- a/src/transformation/builtins/index.ts +++ b/src/transformation/builtins/index.ts @@ -169,11 +169,18 @@ export function transformBuiltinIdentifierExpression( const identifier = keys.next().value; - console.log(identifier); if (identifier) { switch (identifier) { - default: - console.log(identifier); + case "POSITIVE_INFINITY": + if (context.luaTarget === 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); + } break; } } diff --git a/src/transformation/visitors/identifier.ts b/src/transformation/visitors/identifier.ts index 4d127ac9d..6262a316f 100644 --- a/src/transformation/visitors/identifier.ts +++ b/src/transformation/visitors/identifier.ts @@ -73,17 +73,14 @@ export function transformIdentifierWithSymbol( const text = hasUnsafeIdentifierName(context, node, symbol) ? createSafeName(name) : name; const symbolId = getIdentifierSymbolId(context, node, symbol); const identifier = lua.createIdentifier(text, node, symbolId, name); - console.log("1"); return createExportedIdentifier(context, identifier, exportScope); } } const builtinResult = transformBuiltinIdentifierExpression(context, node, symbol); if (builtinResult) { - console.log("2"); return builtinResult; } - console.log("3"); return transformNonValueIdentifier(context, node, symbol); } From 44a5442d5c2b14c3f0047a3290767bcdc3631ed6 Mon Sep 17 00:00:00 2001 From: Zerio Date: Mon, 25 Sep 2023 08:09:12 +0200 Subject: [PATCH 03/17] Better structure for number literals --- src/transformation/builtins/index.ts | 28 +++------------------------ src/transformation/builtins/number.ts | 23 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/transformation/builtins/index.ts b/src/transformation/builtins/index.ts index f36e69646..b7528cf6e 100644 --- a/src/transformation/builtins/index.ts +++ b/src/transformation/builtins/index.ts @@ -11,7 +11,7 @@ import { transformConsoleCall } from "./console"; import { transformFunctionPrototypeCall, transformFunctionProperty } from "./function"; import { tryTransformBuiltinGlobalCall } from "./global"; import { transformMathCall, transformMathProperty } from "./math"; -import { transformNumberConstructorCall, transformNumberPrototypeCall } from "./number"; +import { transformNumberConstructorCall, transformNumberPrototypeCall, transformNumberProperty } from "./number"; import { transformObjectConstructorCall, tryTransformObjectPrototypeCall } from "./object"; import { transformPromiseConstructorCall } from "./promise"; import { transformStringConstructorCall, transformStringProperty, transformStringPrototypeCall } from "./string"; @@ -27,6 +27,8 @@ export function transformBuiltinPropertyAccessExpression( if (ts.isIdentifier(node.expression) && isStandardLibraryType(context, ownerType, undefined)) { switch (ownerType.symbol.name) { + case "NumberConstructor": + return transformNumberProperty(context, node); case "Math": return transformMathProperty(context, node); case "SymbolConstructor": @@ -162,30 +164,6 @@ export function transformBuiltinIdentifierExpression( const huge = lua.createStringLiteral("huge"); return lua.createTableIndexExpression(math, huge, node); } - case "Number": - if ("identifiers" in context.sourceFile && context.sourceFile.identifiers instanceof Map) { - const keys = context.sourceFile.identifiers.keys(); - keys.next(); - - const identifier = keys.next().value; - - if (identifier) { - switch (identifier) { - case "POSITIVE_INFINITY": - if (context.luaTarget === 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); - } - break; - } - } - } - break; case "globalThis": return lua.createIdentifier("_G", node, getIdentifierSymbolId(context, node, symbol), "globalThis"); } diff --git a/src/transformation/builtins/number.ts b/src/transformation/builtins/number.ts index c8ca98503..0817135b1 100644 --- a/src/transformation/builtins/number.ts +++ b/src/transformation/builtins/number.ts @@ -4,6 +4,7 @@ import { TransformationContext } from "../context"; import { unsupportedProperty } from "../utils/diagnostics"; import { LuaLibFeature, transformLuaLibFunction } from "../utils/lualib"; import { transformArguments } from "../visitors/call"; +import { LuaTarget } from "../../CompilerOptions"; export function transformNumberPrototypeCall( context: TransformationContext, @@ -27,6 +28,28 @@ export function transformNumberPrototypeCall( } } +export function transformNumberProperty( + context: TransformationContext, + node: ts.PropertyAccessExpression +): lua.Expression | undefined { + const name = node.name.text; + switch (name) { + case "POSITIVE_INFINITY": + if (context.luaTarget === 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); + } + + default: + context.diagnostics.push(unsupportedProperty(node.name, "Number", name)); + } +} + export function transformNumberConstructorCall( context: TransformationContext, node: ts.CallExpression, From dbff97a24c72537725e4ac479765f8ba50b43b8b Mon Sep 17 00:00:00 2001 From: Zerio Date: Mon, 25 Sep 2023 08:17:12 +0200 Subject: [PATCH 04/17] Setup `NEGATIVE_INFINITY` --- src/transformation/builtins/number.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/transformation/builtins/number.ts b/src/transformation/builtins/number.ts index 0817135b1..59c043321 100644 --- a/src/transformation/builtins/number.ts +++ b/src/transformation/builtins/number.ts @@ -44,6 +44,24 @@ export function transformNumberProperty( const huge = lua.createStringLiteral("huge"); return lua.createTableIndexExpression(math, huge, node); } + case "NEGATIVE_INFINITY": + if (context.luaTarget === LuaTarget.Lua50) { + const one = lua.createNumericLiteral(1); + const zero = lua.createNumericLiteral(0); + return lua.createBinaryExpression( + lua.createNumericLiteral(0), + lua.createBinaryExpression(one, zero, lua.SyntaxKind.DivisionOperator), + lua.SyntaxKind.SubtractionOperator + ); + } else { + const math = lua.createIdentifier("math"); + const huge = lua.createStringLiteral("huge"); + return lua.createBinaryExpression( + lua.createNumericLiteral(0), + lua.createTableIndexExpression(math, huge, node), + lua.SyntaxKind.SubtractionOperator + ); + } default: context.diagnostics.push(unsupportedProperty(node.name, "Number", name)); From 152025c66181f994114f9dc8b72207fb6ef1e3b1 Mon Sep 17 00:00:00 2001 From: Zerio Date: Mon, 25 Sep 2023 08:30:59 +0200 Subject: [PATCH 05/17] Add `NaN` --- src/transformation/builtins/number.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/transformation/builtins/number.ts b/src/transformation/builtins/number.ts index 59c043321..f1bb6078d 100644 --- a/src/transformation/builtins/number.ts +++ b/src/transformation/builtins/number.ts @@ -1,5 +1,6 @@ import ts = require("typescript"); import * as lua from "../../LuaAST"; +import { createNaN } from "../utils/lua-ast"; import { TransformationContext } from "../context"; import { unsupportedProperty } from "../utils/diagnostics"; import { LuaLibFeature, transformLuaLibFunction } from "../utils/lualib"; @@ -44,6 +45,8 @@ export function transformNumberProperty( const huge = lua.createStringLiteral("huge"); return lua.createTableIndexExpression(math, huge, node); } + case "NaN": + return createNaN(node); case "NEGATIVE_INFINITY": if (context.luaTarget === LuaTarget.Lua50) { const one = lua.createNumericLiteral(1); From 4e6e79c7a6c7606e2b984397fa944bdcc3fefd31 Mon Sep 17 00:00:00 2001 From: Zerio Date: Mon, 25 Sep 2023 08:33:54 +0200 Subject: [PATCH 06/17] Setup `EPSILON` --- src/transformation/builtins/number.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/transformation/builtins/number.ts b/src/transformation/builtins/number.ts index f1bb6078d..772b7ef7f 100644 --- a/src/transformation/builtins/number.ts +++ b/src/transformation/builtins/number.ts @@ -47,6 +47,13 @@ export function transformNumberProperty( } case "NaN": return createNaN(node); + case "EPSILON": + return lua.createBinaryExpression( + lua.createNumericLiteral(2), + lua.createNumericLiteral(-52), + lua.SyntaxKind.PowerOperator, + node + ); case "NEGATIVE_INFINITY": if (context.luaTarget === LuaTarget.Lua50) { const one = lua.createNumericLiteral(1); From 237b14c7fc99832b2940ba33b87a69f2494de3f0 Mon Sep 17 00:00:00 2001 From: Zerio Date: Mon, 25 Sep 2023 14:15:01 +0200 Subject: [PATCH 07/17] Add `MIN_VALUE` --- src/transformation/builtins/number.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/transformation/builtins/number.ts b/src/transformation/builtins/number.ts index 772b7ef7f..d3b799268 100644 --- a/src/transformation/builtins/number.ts +++ b/src/transformation/builtins/number.ts @@ -54,6 +54,13 @@ export function transformNumberProperty( lua.SyntaxKind.PowerOperator, node ); + case "MIN_VALUE": + return lua.createBinaryExpression( + lua.createNumericLiteral(2), + lua.createNumericLiteral(-1074), + lua.SyntaxKind.PowerOperator, + node + ); case "NEGATIVE_INFINITY": if (context.luaTarget === LuaTarget.Lua50) { const one = lua.createNumericLiteral(1); From 8ecf52954557ccd12011c28142ec04fde5175455 Mon Sep 17 00:00:00 2001 From: Zerio Date: Mon, 25 Sep 2023 14:18:45 +0200 Subject: [PATCH 08/17] Setup `MAX_VALUE` --- src/transformation/builtins/number.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/transformation/builtins/number.ts b/src/transformation/builtins/number.ts index d3b799268..bf5335269 100644 --- a/src/transformation/builtins/number.ts +++ b/src/transformation/builtins/number.ts @@ -61,6 +61,13 @@ export function transformNumberProperty( lua.SyntaxKind.PowerOperator, node ); + case "MAX_VALUE": + return lua.createBinaryExpression( + lua.createNumericLiteral(2), + lua.createNumericLiteral(1024), + lua.SyntaxKind.PowerOperator, + node + ); case "NEGATIVE_INFINITY": if (context.luaTarget === LuaTarget.Lua50) { const one = lua.createNumericLiteral(1); From 9c1c65671e06b0a11165956ffe45f26419613139 Mon Sep 17 00:00:00 2001 From: Zerio Date: Mon, 25 Sep 2023 14:20:24 +0200 Subject: [PATCH 09/17] Setup `MAX_SAFE_INTEGER` --- src/transformation/builtins/number.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/transformation/builtins/number.ts b/src/transformation/builtins/number.ts index bf5335269..42c3b273b 100644 --- a/src/transformation/builtins/number.ts +++ b/src/transformation/builtins/number.ts @@ -61,6 +61,13 @@ export function transformNumberProperty( lua.SyntaxKind.PowerOperator, node ); + case "MAX_SAFE_INTEGER": + return lua.createBinaryExpression( + lua.createNumericLiteral(2), + lua.createNumericLiteral(53), + lua.SyntaxKind.PowerOperator, + node + ); case "MAX_VALUE": return lua.createBinaryExpression( lua.createNumericLiteral(2), From f36d27418598c19da9ec0582641f3e781d01a582 Mon Sep 17 00:00:00 2001 From: Zerio Date: Mon, 25 Sep 2023 14:22:29 +0200 Subject: [PATCH 10/17] Setup `MIN_SAFE_INTEGER` --- src/transformation/builtins/number.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/transformation/builtins/number.ts b/src/transformation/builtins/number.ts index 42c3b273b..b1437c6fe 100644 --- a/src/transformation/builtins/number.ts +++ b/src/transformation/builtins/number.ts @@ -68,6 +68,13 @@ export function transformNumberProperty( lua.SyntaxKind.PowerOperator, node ); + case "MIN_SAFE_INTEGER": + return lua.createBinaryExpression( + lua.createNumericLiteral(-2), + lua.createNumericLiteral(53), + lua.SyntaxKind.PowerOperator, + node + ); case "MAX_VALUE": return lua.createBinaryExpression( lua.createNumericLiteral(2), From 648059f480786949449692bd1bdaf9f827d906ab Mon Sep 17 00:00:00 2001 From: Zerio Date: Mon, 25 Sep 2023 15:06:37 +0200 Subject: [PATCH 11/17] explenation --- src/transformation/builtins/number.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/transformation/builtins/number.ts b/src/transformation/builtins/number.ts index b1437c6fe..2810c76f4 100644 --- a/src/transformation/builtins/number.ts +++ b/src/transformation/builtins/number.ts @@ -34,6 +34,12 @@ export function transformNumberProperty( node: ts.PropertyAccessExpression ): lua.Expression | undefined { 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 === LuaTarget.Lua50) { From 0a2a9ba66fb2fcd72c52b3b8fc9446857dd62f79 Mon Sep 17 00:00:00 2001 From: Z3rio Date: Tue, 26 Sep 2023 09:30:45 +0200 Subject: [PATCH 12/17] use unary expressions --- src/transformation/builtins/number.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/transformation/builtins/number.ts b/src/transformation/builtins/number.ts index 2810c76f4..afe4fc1f3 100644 --- a/src/transformation/builtins/number.ts +++ b/src/transformation/builtins/number.ts @@ -92,18 +92,16 @@ export function transformNumberProperty( if (context.luaTarget === LuaTarget.Lua50) { const one = lua.createNumericLiteral(1); const zero = lua.createNumericLiteral(0); - return lua.createBinaryExpression( - lua.createNumericLiteral(0), + return lua.createUnaryExpression( lua.createBinaryExpression(one, zero, lua.SyntaxKind.DivisionOperator), - lua.SyntaxKind.SubtractionOperator + lua.SyntaxKind.NegationOperator ); } else { const math = lua.createIdentifier("math"); const huge = lua.createStringLiteral("huge"); - return lua.createBinaryExpression( - lua.createNumericLiteral(0), + return lua.createUnaryExpression( lua.createTableIndexExpression(math, huge, node), - lua.SyntaxKind.SubtractionOperator + lua.SyntaxKind.NegationOperator ); } From 8f7802e71fb54e8fbafb5078e76e42135b36bcae Mon Sep 17 00:00:00 2001 From: Z3rio Date: Tue, 26 Sep 2023 09:36:09 +0200 Subject: [PATCH 13/17] add perry's tests --- test/unit/builtins/numbers.spec.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/unit/builtins/numbers.spec.ts b/test/unit/builtins/numbers.spec.ts index 26b90d4e6..6d81ded4f 100644 --- a/test/unit/builtins/numbers.spec.ts +++ b/test/unit/builtins/numbers.spec.ts @@ -206,3 +206,15 @@ test.each(["42", "undefined"])("prototype call on nullable number (%p)", value = .setOptions({ strictNullChecks: true }) .expectToMatchJsResult(); }); + +test.each([ + "Number.NEGATIVE_INFINITY < Number.MIN_VALUE", + "Number.MIN_VALUE < Number.MIN_SAFE_INTEGER", + "Number.MIN_SAFE_INTEGER < 0", + "0 < Number.EPSILON", + "Number.EPSILON < Number.MAX_SAFE_INTEGER", + "Number.MAX_SAFE_INTEGER < Number.MAX_VALUE", + "Number.MAX_VALUE < Number.POSITIVE_INFINITY", +])("Numer constants have correct relative sizes (%p)", comparison => { + util.testExpression(comparison).expectToEqual(true); +}); From 031e964cbd5986fde883f703bc4e1dcdd11ae2eb Mon Sep 17 00:00:00 2001 From: Z3rio Date: Tue, 26 Sep 2023 22:44:05 +0200 Subject: [PATCH 14/17] more correct? --- src/transformation/builtins/number.ts | 42 +++++++++++++-------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/transformation/builtins/number.ts b/src/transformation/builtins/number.ts index afe4fc1f3..f7f9d7822 100644 --- a/src/transformation/builtins/number.ts +++ b/src/transformation/builtins/number.ts @@ -51,6 +51,22 @@ export function transformNumberProperty( const huge = lua.createStringLiteral("huge"); return lua.createTableIndexExpression(math, huge, node); } + case "NEGATIVE_INFINITY": + if (context.luaTarget === 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 createNaN(node); case "EPSILON": @@ -67,17 +83,17 @@ export function transformNumberProperty( lua.SyntaxKind.PowerOperator, node ); - case "MAX_SAFE_INTEGER": + case "MIN_SAFE_INTEGER": return lua.createBinaryExpression( lua.createNumericLiteral(2), - lua.createNumericLiteral(53), + lua.createNumericLiteral(-1074), lua.SyntaxKind.PowerOperator, node ); - case "MIN_SAFE_INTEGER": + case "MAX_SAFE_INTEGER": return lua.createBinaryExpression( - lua.createNumericLiteral(-2), - lua.createNumericLiteral(53), + lua.createNumericLiteral(2), + lua.createNumericLiteral(1024), lua.SyntaxKind.PowerOperator, node ); @@ -88,22 +104,6 @@ export function transformNumberProperty( lua.SyntaxKind.PowerOperator, node ); - case "NEGATIVE_INFINITY": - if (context.luaTarget === 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 - ); - } default: context.diagnostics.push(unsupportedProperty(node.name, "Number", name)); From 9e11a62816b0dea0b248d452a3b3f089dd3c6fcf Mon Sep 17 00:00:00 2001 From: Z3rio Date: Tue, 26 Sep 2023 22:44:37 +0200 Subject: [PATCH 15/17] fix failing test --- test/unit/builtins/numbers.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/builtins/numbers.spec.ts b/test/unit/builtins/numbers.spec.ts index 6d81ded4f..ee564e468 100644 --- a/test/unit/builtins/numbers.spec.ts +++ b/test/unit/builtins/numbers.spec.ts @@ -214,7 +214,7 @@ test.each([ "0 < Number.EPSILON", "Number.EPSILON < Number.MAX_SAFE_INTEGER", "Number.MAX_SAFE_INTEGER < Number.MAX_VALUE", - "Number.MAX_VALUE < Number.POSITIVE_INFINITY", + "Number.MAX_VALUE <= Number.POSITIVE_INFINITY", ])("Numer constants have correct relative sizes (%p)", comparison => { util.testExpression(comparison).expectToEqual(true); }); From 300fb3a8b6c9921f76bf2f6d8a7be74687aa65e2 Mon Sep 17 00:00:00 2001 From: Z3rio Date: Tue, 26 Sep 2023 23:01:54 +0200 Subject: [PATCH 16/17] fix tests --- src/transformation/builtins/number.ts | 8 ++++---- test/unit/builtins/numbers.spec.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/transformation/builtins/number.ts b/src/transformation/builtins/number.ts index f7f9d7822..d07ef7066 100644 --- a/src/transformation/builtins/number.ts +++ b/src/transformation/builtins/number.ts @@ -78,15 +78,15 @@ export function transformNumberProperty( ); case "MIN_VALUE": return lua.createBinaryExpression( - lua.createNumericLiteral(2), - lua.createNumericLiteral(-1074), + lua.createNumericLiteral(-2), + lua.createNumericLiteral(1074), lua.SyntaxKind.PowerOperator, node ); case "MIN_SAFE_INTEGER": return lua.createBinaryExpression( - lua.createNumericLiteral(2), - lua.createNumericLiteral(-1074), + lua.createNumericLiteral(-2), + lua.createNumericLiteral(1074), lua.SyntaxKind.PowerOperator, node ); diff --git a/test/unit/builtins/numbers.spec.ts b/test/unit/builtins/numbers.spec.ts index ee564e468..f9d9f42ed 100644 --- a/test/unit/builtins/numbers.spec.ts +++ b/test/unit/builtins/numbers.spec.ts @@ -209,11 +209,11 @@ test.each(["42", "undefined"])("prototype call on nullable number (%p)", value = test.each([ "Number.NEGATIVE_INFINITY < Number.MIN_VALUE", - "Number.MIN_VALUE < Number.MIN_SAFE_INTEGER", + "Number.MIN_VALUE <= Number.MIN_SAFE_INTEGER", "Number.MIN_SAFE_INTEGER < 0", "0 < Number.EPSILON", "Number.EPSILON < Number.MAX_SAFE_INTEGER", - "Number.MAX_SAFE_INTEGER < Number.MAX_VALUE", + "Number.MAX_SAFE_INTEGER <= Number.MAX_VALUE", "Number.MAX_VALUE <= Number.POSITIVE_INFINITY", ])("Numer constants have correct relative sizes (%p)", comparison => { util.testExpression(comparison).expectToEqual(true); From 813ddecd78a2134ebbf9fe126262dce252397dd1 Mon Sep 17 00:00:00 2001 From: Z3rio Date: Tue, 26 Sep 2023 23:20:38 +0200 Subject: [PATCH 17/17] final number tests fix --- test/unit/builtins/numbers.spec.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/unit/builtins/numbers.spec.ts b/test/unit/builtins/numbers.spec.ts index f9d9f42ed..c5f3b7d2b 100644 --- a/test/unit/builtins/numbers.spec.ts +++ b/test/unit/builtins/numbers.spec.ts @@ -208,13 +208,15 @@ test.each(["42", "undefined"])("prototype call on nullable number (%p)", value = }); test.each([ - "Number.NEGATIVE_INFINITY < Number.MIN_VALUE", + "Number.NEGATIVE_INFINITY <= Number.MIN_VALUE", "Number.MIN_VALUE <= Number.MIN_SAFE_INTEGER", + + "Number.MAX_SAFE_INTEGER <= Number.MAX_VALUE", + "Number.MAX_VALUE <= Number.POSITIVE_INFINITY", "Number.MIN_SAFE_INTEGER < 0", + "0 < Number.EPSILON", "Number.EPSILON < Number.MAX_SAFE_INTEGER", - "Number.MAX_SAFE_INTEGER <= Number.MAX_VALUE", - "Number.MAX_VALUE <= Number.POSITIVE_INFINITY", ])("Numer constants have correct relative sizes (%p)", comparison => { util.testExpression(comparison).expectToEqual(true); });