typescript-to-lua 1.13.1 → 1.13.3
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 +1 -0
- package/dist/LuaLib.js +1 -0
- package/dist/lualib/5.0/NumberToFixed.lua +13 -0
- package/dist/lualib/5.0/lualib_bundle.lua +15 -0
- package/dist/lualib/5.0/lualib_module_info.json +5 -0
- package/dist/lualib/universal/NumberToFixed.lua +13 -0
- package/dist/lualib/universal/lualib_bundle.lua +15 -0
- package/dist/lualib/universal/lualib_module_info.json +5 -0
- package/dist/transformation/builtins/array.js +4 -3
- package/dist/transformation/builtins/math.js +4 -3
- package/dist/transformation/builtins/number.js +2 -0
- package/dist/transformation/builtins/string.js +7 -4
- package/dist/transformation/utils/diagnostics.d.ts +4 -0
- package/dist/transformation/utils/diagnostics.js +3 -1
- package/dist/transformation/utils/lua-ast.js +10 -8
- package/dist/transformation/visitors/binary-expression/assignments.js +10 -4
- package/dist/transformation/visitors/language-extensions/multi.js +10 -9
- package/dist/transformation/visitors/spread.js +18 -3
- package/package.json +1 -1
package/dist/LuaLib.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ export declare enum LuaLibFeature {
|
|
|
55
55
|
NumberIsFinite = "NumberIsFinite",
|
|
56
56
|
NumberIsNaN = "NumberIsNaN",
|
|
57
57
|
NumberToString = "NumberToString",
|
|
58
|
+
NumberToFixed = "NumberToFixed",
|
|
58
59
|
ObjectAssign = "ObjectAssign",
|
|
59
60
|
ObjectDefineProperty = "ObjectDefineProperty",
|
|
60
61
|
ObjectEntries = "ObjectEntries",
|
package/dist/LuaLib.js
CHANGED
|
@@ -60,6 +60,7 @@ var LuaLibFeature;
|
|
|
60
60
|
LuaLibFeature["NumberIsFinite"] = "NumberIsFinite";
|
|
61
61
|
LuaLibFeature["NumberIsNaN"] = "NumberIsNaN";
|
|
62
62
|
LuaLibFeature["NumberToString"] = "NumberToString";
|
|
63
|
+
LuaLibFeature["NumberToFixed"] = "NumberToFixed";
|
|
63
64
|
LuaLibFeature["ObjectAssign"] = "ObjectAssign";
|
|
64
65
|
LuaLibFeature["ObjectDefineProperty"] = "ObjectDefineProperty";
|
|
65
66
|
LuaLibFeature["ObjectEntries"] = "ObjectEntries";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
local function __TS__NumberToFixed(self, fractionDigits)
|
|
2
|
+
if math.abs(self) >= 1e+21 or self ~= self then
|
|
3
|
+
return tostring(self)
|
|
4
|
+
end
|
|
5
|
+
local f = math.floor(fractionDigits or 0)
|
|
6
|
+
if f < 0 or f > 99 then
|
|
7
|
+
error("toFixed() digits argument must be between 0 and 99", 0)
|
|
8
|
+
end
|
|
9
|
+
return string.format(
|
|
10
|
+
("%." .. tostring(f)) .. "f",
|
|
11
|
+
self
|
|
12
|
+
)
|
|
13
|
+
end
|
|
@@ -1498,6 +1498,20 @@ do
|
|
|
1498
1498
|
end
|
|
1499
1499
|
end
|
|
1500
1500
|
|
|
1501
|
+
local function __TS__NumberToFixed(self, fractionDigits)
|
|
1502
|
+
if math.abs(self) >= 1e+21 or self ~= self then
|
|
1503
|
+
return tostring(self)
|
|
1504
|
+
end
|
|
1505
|
+
local f = math.floor(fractionDigits or 0)
|
|
1506
|
+
if f < 0 or f > 99 then
|
|
1507
|
+
error("toFixed() digits argument must be between 0 and 99", 0)
|
|
1508
|
+
end
|
|
1509
|
+
return string.format(
|
|
1510
|
+
("%." .. tostring(f)) .. "f",
|
|
1511
|
+
self
|
|
1512
|
+
)
|
|
1513
|
+
end
|
|
1514
|
+
|
|
1501
1515
|
local function __TS__ObjectDefineProperty(target, key, desc)
|
|
1502
1516
|
local luaKey = type(key) == "number" and key + 1 or key
|
|
1503
1517
|
local value = rawget(target, luaKey)
|
|
@@ -2467,6 +2481,7 @@ return {
|
|
|
2467
2481
|
__TS__NumberIsFinite = __TS__NumberIsFinite,
|
|
2468
2482
|
__TS__NumberIsNaN = __TS__NumberIsNaN,
|
|
2469
2483
|
__TS__NumberToString = __TS__NumberToString,
|
|
2484
|
+
__TS__NumberToFixed = __TS__NumberToFixed,
|
|
2470
2485
|
__TS__ObjectAssign = __TS__ObjectAssign,
|
|
2471
2486
|
__TS__ObjectDefineProperty = __TS__ObjectDefineProperty,
|
|
2472
2487
|
__TS__ObjectEntries = __TS__ObjectEntries,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
local function __TS__NumberToFixed(self, fractionDigits)
|
|
2
|
+
if math.abs(self) >= 1e+21 or self ~= self then
|
|
3
|
+
return tostring(self)
|
|
4
|
+
end
|
|
5
|
+
local f = math.floor(fractionDigits or 0)
|
|
6
|
+
if f < 0 or f > 99 then
|
|
7
|
+
error("toFixed() digits argument must be between 0 and 99", 0)
|
|
8
|
+
end
|
|
9
|
+
return string.format(
|
|
10
|
+
("%." .. tostring(f)) .. "f",
|
|
11
|
+
self
|
|
12
|
+
)
|
|
13
|
+
end
|
|
@@ -1440,6 +1440,20 @@ do
|
|
|
1440
1440
|
end
|
|
1441
1441
|
end
|
|
1442
1442
|
|
|
1443
|
+
local function __TS__NumberToFixed(self, fractionDigits)
|
|
1444
|
+
if math.abs(self) >= 1e+21 or self ~= self then
|
|
1445
|
+
return tostring(self)
|
|
1446
|
+
end
|
|
1447
|
+
local f = math.floor(fractionDigits or 0)
|
|
1448
|
+
if f < 0 or f > 99 then
|
|
1449
|
+
error("toFixed() digits argument must be between 0 and 99", 0)
|
|
1450
|
+
end
|
|
1451
|
+
return string.format(
|
|
1452
|
+
("%." .. tostring(f)) .. "f",
|
|
1453
|
+
self
|
|
1454
|
+
)
|
|
1455
|
+
end
|
|
1456
|
+
|
|
1443
1457
|
local function __TS__ObjectDefineProperty(target, key, desc)
|
|
1444
1458
|
local luaKey = type(key) == "number" and key + 1 or key
|
|
1445
1459
|
local value = rawget(target, luaKey)
|
|
@@ -2412,6 +2426,7 @@ return {
|
|
|
2412
2426
|
__TS__NumberIsFinite = __TS__NumberIsFinite,
|
|
2413
2427
|
__TS__NumberIsNaN = __TS__NumberIsNaN,
|
|
2414
2428
|
__TS__NumberToString = __TS__NumberToString,
|
|
2429
|
+
__TS__NumberToFixed = __TS__NumberToFixed,
|
|
2415
2430
|
__TS__ObjectAssign = __TS__ObjectAssign,
|
|
2416
2431
|
__TS__ObjectDefineProperty = __TS__ObjectDefineProperty,
|
|
2417
2432
|
__TS__ObjectEntries = __TS__ObjectEntries,
|
|
@@ -55,6 +55,7 @@ function transformSingleElementArrayPush(context, node, caller, param) {
|
|
|
55
55
|
return expressionIsUsed ? lengthExpression : lua.createNilLiteral();
|
|
56
56
|
}
|
|
57
57
|
function transformArrayPrototypeCall(context, node, calledMethod) {
|
|
58
|
+
var _a, _b, _c;
|
|
58
59
|
const signature = context.checker.getResolvedSignature(node);
|
|
59
60
|
const [caller, params] = (0, call_1.transformCallAndArguments)(context, calledMethod.expression, node.arguments, signature);
|
|
60
61
|
const expressionName = calledMethod.name.text;
|
|
@@ -65,9 +66,9 @@ function transformArrayPrototypeCall(context, node, calledMethod) {
|
|
|
65
66
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayEntries, node, caller);
|
|
66
67
|
case "push":
|
|
67
68
|
if (node.arguments.length === 1) {
|
|
68
|
-
const param = params[0];
|
|
69
|
+
const param = (_a = params[0]) !== null && _a !== void 0 ? _a : lua.createNilLiteral();
|
|
69
70
|
if ((0, lua_ast_1.isUnpackCall)(param)) {
|
|
70
|
-
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayPushArray, node, caller, param.params[0]);
|
|
71
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayPushArray, node, caller, (_b = param.params[0]) !== null && _b !== void 0 ? _b : lua.createNilLiteral());
|
|
71
72
|
}
|
|
72
73
|
if (!lua.isDotsLiteral(param)) {
|
|
73
74
|
return transformSingleElementArrayPush(context, node, caller, param);
|
|
@@ -116,7 +117,7 @@ function transformArrayPrototypeCall(context, node, calledMethod) {
|
|
|
116
117
|
if (elementType &&
|
|
117
118
|
(0, typescript_1.typeAlwaysHasSomeOfFlags)(context, elementType, ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike)) {
|
|
118
119
|
const defaultSeparatorLiteral = lua.createStringLiteral(",");
|
|
119
|
-
const param = params[0];
|
|
120
|
+
const param = (_c = params[0]) !== null && _c !== void 0 ? _c : lua.createNilLiteral();
|
|
120
121
|
const parameters = [
|
|
121
122
|
caller,
|
|
122
123
|
node.arguments.length === 0
|
|
@@ -27,6 +27,7 @@ function transformMathProperty(context, node) {
|
|
|
27
27
|
}
|
|
28
28
|
exports.transformMathProperty = transformMathProperty;
|
|
29
29
|
function transformMathCall(context, node, calledMethod) {
|
|
30
|
+
var _a, _b, _c, _d;
|
|
30
31
|
const signature = context.checker.getResolvedSignature(node);
|
|
31
32
|
const params = (0, call_1.transformArguments)(context, node.arguments, signature);
|
|
32
33
|
const math = lua.createIdentifier("math");
|
|
@@ -53,18 +54,18 @@ function transformMathCall(context, node, calledMethod) {
|
|
|
53
54
|
case "log1p": {
|
|
54
55
|
const log = lua.createStringLiteral("log");
|
|
55
56
|
const one = lua.createNumericLiteral(1);
|
|
56
|
-
const add = lua.createBinaryExpression(one, params[0], lua.SyntaxKind.AdditionOperator);
|
|
57
|
+
const add = lua.createBinaryExpression(one, (_a = params[0]) !== null && _a !== void 0 ? _a : lua.createNilLiteral(), lua.SyntaxKind.AdditionOperator);
|
|
57
58
|
return lua.createCallExpression(lua.createTableIndexExpression(math, log), [add], node);
|
|
58
59
|
}
|
|
59
60
|
case "pow": {
|
|
60
61
|
// Translate to base ^ power
|
|
61
|
-
return lua.createBinaryExpression(params[0], params[1], lua.SyntaxKind.PowerOperator, node);
|
|
62
|
+
return lua.createBinaryExpression((_b = params[0]) !== null && _b !== void 0 ? _b : lua.createNilLiteral(), (_c = params[1]) !== null && _c !== void 0 ? _c : lua.createNilLiteral(), lua.SyntaxKind.PowerOperator, node);
|
|
62
63
|
}
|
|
63
64
|
// math.floor(x + 0.5)
|
|
64
65
|
case "round": {
|
|
65
66
|
const floor = lua.createStringLiteral("floor");
|
|
66
67
|
const half = lua.createNumericLiteral(0.5);
|
|
67
|
-
const add = lua.createBinaryExpression(params[0], half, lua.SyntaxKind.AdditionOperator);
|
|
68
|
+
const add = lua.createBinaryExpression((_d = params[0]) !== null && _d !== void 0 ? _d : lua.createNilLiteral(), half, lua.SyntaxKind.AdditionOperator);
|
|
68
69
|
return lua.createCallExpression(lua.createTableIndexExpression(math, floor), [add], node);
|
|
69
70
|
}
|
|
70
71
|
case "sign": {
|
|
@@ -15,6 +15,8 @@ function transformNumberPrototypeCall(context, node, calledMethod) {
|
|
|
15
15
|
return params.length === 0
|
|
16
16
|
? lua.createCallExpression(lua.createIdentifier("tostring"), [caller], node)
|
|
17
17
|
: (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberToString, node, caller, ...params);
|
|
18
|
+
case "toFixed":
|
|
19
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberToFixed, node, caller, ...params);
|
|
18
20
|
default:
|
|
19
21
|
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "number", expressionName));
|
|
20
22
|
}
|
|
@@ -12,6 +12,7 @@ function createStringCall(methodName, tsOriginal, ...params) {
|
|
|
12
12
|
return lua.createCallExpression(lua.createTableIndexExpression(stringIdentifier, lua.createStringLiteral(methodName)), params, tsOriginal);
|
|
13
13
|
}
|
|
14
14
|
function transformStringPrototypeCall(context, node, calledMethod) {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
15
16
|
const signature = context.checker.getResolvedSignature(node);
|
|
16
17
|
const [caller, params] = (0, call_1.transformCallAndArguments)(context, calledMethod.expression, node.arguments, signature);
|
|
17
18
|
const expressionName = calledMethod.name.text;
|
|
@@ -23,7 +24,7 @@ function transformStringPrototypeCall(context, node, calledMethod) {
|
|
|
23
24
|
case "concat":
|
|
24
25
|
return lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("table"), lua.createStringLiteral("concat")), [(0, lua_ast_1.wrapInTable)(caller, ...params)], node);
|
|
25
26
|
case "indexOf": {
|
|
26
|
-
const stringExpression = createStringCall("find", node, caller, params[0], params[1]
|
|
27
|
+
const stringExpression = createStringCall("find", node, caller, (_a = params[0]) !== null && _a !== void 0 ? _a : lua.createNilLiteral(), params[1]
|
|
27
28
|
? // string.find handles negative indexes by making it relative to string end, but for indexOf it's the same as 0
|
|
28
29
|
lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("math"), lua.createStringLiteral("max")), [(0, lua_ast_1.addToNumericExpression)(params[1], 1), lua.createNumericLiteral(1)])
|
|
29
30
|
: lua.createNilLiteral(), lua.createBooleanLiteral(true));
|
|
@@ -73,7 +74,7 @@ function transformStringPrototypeCall(context, node, calledMethod) {
|
|
|
73
74
|
const literalValue = (0, lua_ast_1.getNumberLiteralValue)(params[0]);
|
|
74
75
|
// Inline string.sub call if we know that parameter is pure and isn't negative
|
|
75
76
|
if (literalValue !== undefined && literalValue >= 0) {
|
|
76
|
-
const firstParamPlusOne = (0, lua_ast_1.addToNumericExpression)(params[0], 1);
|
|
77
|
+
const firstParamPlusOne = (0, lua_ast_1.addToNumericExpression)((_b = params[0]) !== null && _b !== void 0 ? _b : lua.createNilLiteral(), 1);
|
|
77
78
|
return createStringCall("sub", node, caller, firstParamPlusOne, firstParamPlusOne);
|
|
78
79
|
}
|
|
79
80
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringCharAt, node, caller, ...params);
|
|
@@ -82,7 +83,7 @@ function transformStringPrototypeCall(context, node, calledMethod) {
|
|
|
82
83
|
const literalValue = (0, lua_ast_1.getNumberLiteralValue)(params[0]);
|
|
83
84
|
// Inline string.sub call if we know that parameter is pure and isn't negative
|
|
84
85
|
if (literalValue !== undefined && literalValue >= 0) {
|
|
85
|
-
return lua.createBinaryExpression(createStringCall("byte", node, caller, (0, lua_ast_1.addToNumericExpression)(params[0], 1)), (0, lua_ast_1.createNaN)(), lua.SyntaxKind.OrOperator);
|
|
86
|
+
return lua.createBinaryExpression(createStringCall("byte", node, caller, (0, lua_ast_1.addToNumericExpression)((_c = params[0]) !== null && _c !== void 0 ? _c : lua.createNilLiteral(), 1)), (0, lua_ast_1.createNaN)(), lua.SyntaxKind.OrOperator);
|
|
86
87
|
}
|
|
87
88
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringCharCodeAt, node, caller, ...params);
|
|
88
89
|
}
|
|
@@ -95,7 +96,9 @@ function transformStringPrototypeCall(context, node, calledMethod) {
|
|
|
95
96
|
case "repeat":
|
|
96
97
|
const math = lua.createIdentifier("math");
|
|
97
98
|
const floor = lua.createStringLiteral("floor");
|
|
98
|
-
const parameter = lua.createCallExpression(lua.createTableIndexExpression(math, floor), [
|
|
99
|
+
const parameter = lua.createCallExpression(lua.createTableIndexExpression(math, floor), [
|
|
100
|
+
(_d = params[0]) !== null && _d !== void 0 ? _d : lua.createNilLiteral(),
|
|
101
|
+
]);
|
|
99
102
|
return createStringCall("rep", node, caller, parameter);
|
|
100
103
|
case "padStart":
|
|
101
104
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringPadStart, node, caller, ...params);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
|
+
import * as lua from "../../LuaAST";
|
|
2
3
|
import { LuaTarget, TypeScriptToLuaOptions } from "../../CompilerOptions";
|
|
3
4
|
import { AnnotationKind } from "./annotations";
|
|
4
5
|
export declare const unsupportedNodeKind: ((node: ts.Node, kind: ts.SyntaxKind) => ts.Diagnostic) & {
|
|
@@ -97,3 +98,6 @@ export declare const invalidMethodCallExtensionUse: ((node: ts.Node, ...args: an
|
|
|
97
98
|
export declare const invalidSpreadInCallExtension: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
98
99
|
code: number;
|
|
99
100
|
};
|
|
101
|
+
export declare const cannotAssignToNodeOfKind: ((node: ts.Node, kind: lua.SyntaxKind) => ts.Diagnostic) & {
|
|
102
|
+
code: number;
|
|
103
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.invalidSpreadInCallExtension = exports.invalidMethodCallExtensionUse = exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
|
|
3
|
+
exports.cannotAssignToNodeOfKind = exports.invalidSpreadInCallExtension = exports.invalidMethodCallExtensionUse = exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
|
+
const lua = require("../../LuaAST");
|
|
5
6
|
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
6
7
|
const utils_1 = require("../../utils");
|
|
7
8
|
const createDiagnosticFactory = (category, message) => (0, utils_1.createSerialDiagnosticFactory)((node, ...args) => ({
|
|
@@ -61,4 +62,5 @@ exports.unsupportedOptionalCompileMembersOnly = createErrorDiagnosticFactory("Op
|
|
|
61
62
|
exports.undefinedInArrayLiteral = createErrorDiagnosticFactory("Array literals may not contain undefined or null.");
|
|
62
63
|
exports.invalidMethodCallExtensionUse = createErrorDiagnosticFactory("This language extension must be called as a method.");
|
|
63
64
|
exports.invalidSpreadInCallExtension = createErrorDiagnosticFactory("Spread elements are not supported in call extensions.");
|
|
65
|
+
exports.cannotAssignToNodeOfKind = createErrorDiagnosticFactory((kind) => `Cannot create assignment assigning to a node of type ${lua.SyntaxKind[kind]}.`);
|
|
64
66
|
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -251,15 +251,17 @@ function getJSDocCommentFromTSNode(context, tsOriginal) {
|
|
|
251
251
|
// https://stevedonovan.github.io/ldoc/manual/doc.md.html
|
|
252
252
|
// LDoc comments require that the first line starts with three hyphens.
|
|
253
253
|
// Thus, need to add a hyphen to the first line.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
254
|
+
if (lines.length > 0) {
|
|
255
|
+
const firstLine = lines[0];
|
|
256
|
+
if (firstLine.startsWith(" @")) {
|
|
257
|
+
lines.unshift("-");
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
lines.shift();
|
|
261
|
+
lines.unshift("-" + firstLine);
|
|
262
|
+
}
|
|
263
|
+
return lines;
|
|
261
264
|
}
|
|
262
|
-
return lines;
|
|
263
265
|
}
|
|
264
266
|
const createNaN = (tsOriginal) => lua.createBinaryExpression(lua.createNumericLiteral(0), lua.createNumericLiteral(0), lua.SyntaxKind.DivisionOperator, tsOriginal);
|
|
265
267
|
exports.createNaN = createNaN;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transformAssignmentStatement = exports.transformAssignmentExpression = exports.transformAssignmentWithRightPrecedingStatements = exports.transformAssignment = exports.transformAssignmentLeftHandSideExpression = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../../LuaAST");
|
|
6
|
-
const utils_1 = require("../../../utils");
|
|
7
6
|
const assignment_validation_1 = require("../../utils/assignment-validation");
|
|
8
7
|
const export_1 = require("../../utils/export");
|
|
9
8
|
const lua_ast_1 = require("../../utils/lua-ast");
|
|
@@ -32,9 +31,16 @@ function transformAssignmentLeftHandSideExpression(context, node, rightHasPreced
|
|
|
32
31
|
}
|
|
33
32
|
const symbol = context.checker.getSymbolAtLocation(node);
|
|
34
33
|
const left = context.transformExpression(node);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
if (lua.isIdentifier(left) && symbol && (0, export_1.isSymbolExported)(context, symbol)) {
|
|
35
|
+
return (0, export_1.createExportedIdentifier)(context, left);
|
|
36
|
+
}
|
|
37
|
+
if (lua.isAssignmentLeftHandSideExpression(left)) {
|
|
38
|
+
return left;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
context.diagnostics.push((0, diagnostics_1.cannotAssignToNodeOfKind)(node, left.kind));
|
|
42
|
+
return lua.createAnonymousIdentifier();
|
|
43
|
+
}
|
|
38
44
|
}
|
|
39
45
|
exports.transformAssignmentLeftHandSideExpression = transformAssignmentLeftHandSideExpression;
|
|
40
46
|
function transformAssignment(context,
|
|
@@ -50,35 +50,36 @@ function shouldMultiReturnCallBeWrapped(context, node) {
|
|
|
50
50
|
if (!returnsMultiType(context, node)) {
|
|
51
51
|
return false;
|
|
52
52
|
}
|
|
53
|
+
const parent = (0, typescript_1.findFirstNonOuterParent)(node);
|
|
53
54
|
// Variable declaration with destructuring
|
|
54
|
-
if (ts.isVariableDeclaration(
|
|
55
|
+
if (ts.isVariableDeclaration(parent) && ts.isArrayBindingPattern(parent.name)) {
|
|
55
56
|
return false;
|
|
56
57
|
}
|
|
57
58
|
// Variable assignment with destructuring
|
|
58
|
-
if (ts.isBinaryExpression(
|
|
59
|
-
|
|
60
|
-
ts.isArrayLiteralExpression(
|
|
59
|
+
if (ts.isBinaryExpression(parent) &&
|
|
60
|
+
parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
61
|
+
ts.isArrayLiteralExpression(parent.left)) {
|
|
61
62
|
return false;
|
|
62
63
|
}
|
|
63
64
|
// Spread operator
|
|
64
|
-
if (ts.isSpreadElement(
|
|
65
|
+
if (ts.isSpreadElement(parent)) {
|
|
65
66
|
return false;
|
|
66
67
|
}
|
|
67
68
|
// Stand-alone expression
|
|
68
|
-
if (ts.isExpressionStatement(
|
|
69
|
+
if (ts.isExpressionStatement(parent)) {
|
|
69
70
|
return false;
|
|
70
71
|
}
|
|
71
72
|
// Forwarded multi-return call
|
|
72
|
-
if ((ts.isReturnStatement(
|
|
73
|
+
if ((ts.isReturnStatement(parent) || ts.isArrowFunction(parent)) && // Body-less arrow func
|
|
73
74
|
isInMultiReturnFunction(context, node)) {
|
|
74
75
|
return false;
|
|
75
76
|
}
|
|
76
77
|
// Element access expression 'foo()[0]' will be optimized using 'select'
|
|
77
|
-
if (ts.isElementAccessExpression(
|
|
78
|
+
if (ts.isElementAccessExpression(parent)) {
|
|
78
79
|
return false;
|
|
79
80
|
}
|
|
80
81
|
// LuaIterable in for...of
|
|
81
|
-
if (ts.isForOfStatement(
|
|
82
|
+
if (ts.isForOfStatement(parent) &&
|
|
82
83
|
(0, language_extensions_1.getIterableExtensionKindForNode)(context, node) === language_extensions_1.IterableExtensionKind.Iterable) {
|
|
83
84
|
return false;
|
|
84
85
|
}
|
|
@@ -4,6 +4,7 @@ exports.transformSpreadElement = exports.isOptimizedVarArgSpread = void 0;
|
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
6
6
|
const lua = require("../../LuaAST");
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
7
8
|
const language_extensions_1 = require("../utils/language-extensions");
|
|
8
9
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
9
10
|
const lualib_1 = require("../utils/lualib");
|
|
@@ -63,10 +64,24 @@ const transformSpreadElement = (node, context) => {
|
|
|
63
64
|
const innerExpression = context.transformExpression(node.expression);
|
|
64
65
|
if ((0, multi_1.isMultiReturnCall)(context, tsInnerExpression))
|
|
65
66
|
return innerExpression;
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
|
|
67
|
+
const iterableExtensionType = (0, language_extensions_1.getIterableExtensionKindForNode)(context, node.expression);
|
|
68
|
+
if (iterableExtensionType) {
|
|
69
|
+
if (iterableExtensionType === language_extensions_1.IterableExtensionKind.Iterable) {
|
|
70
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.LuaIteratorSpread, node, innerExpression);
|
|
71
|
+
}
|
|
72
|
+
else if (iterableExtensionType === language_extensions_1.IterableExtensionKind.Pairs) {
|
|
73
|
+
const objectEntries = (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ObjectEntries, node, innerExpression);
|
|
74
|
+
return (0, lua_ast_1.createUnpackCall)(context, objectEntries, node);
|
|
75
|
+
}
|
|
76
|
+
else if (iterableExtensionType === language_extensions_1.IterableExtensionKind.PairsKey) {
|
|
77
|
+
const objectKeys = (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ObjectKeys, node, innerExpression);
|
|
78
|
+
return (0, lua_ast_1.createUnpackCall)(context, objectKeys, node);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
(0, utils_1.assertNever)(iterableExtensionType);
|
|
82
|
+
}
|
|
69
83
|
}
|
|
84
|
+
const type = context.checker.getTypeAtLocation(node.expression); // not ts-inner expression, in case of casts
|
|
70
85
|
if ((0, typescript_1.isArrayType)(context, type)) {
|
|
71
86
|
return (0, lua_ast_1.createUnpackCall)(context, innerExpression, node);
|
|
72
87
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.3",
|
|
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/",
|