typescript-to-lua 1.4.1 → 1.4.4
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/CompilerOptions.d.ts +4 -1
- package/dist/LuaAST.d.ts +9 -7
- package/dist/LuaAST.js +19 -13
- package/dist/LuaLib.d.ts +1 -2
- package/dist/LuaLib.js +1 -2
- package/dist/LuaPrinter.js +1 -2
- package/dist/cli/parse.js +5 -0
- package/dist/lualib/ArrayConcat.lua +16 -12
- package/dist/lualib/ArrayEvery.lua +4 -8
- package/dist/lualib/ArrayFilter.lua +6 -8
- package/dist/lualib/ArrayFind.lua +4 -7
- package/dist/lualib/ArrayFindIndex.lua +4 -9
- package/dist/lualib/ArrayFlat.lua +17 -7
- package/dist/lualib/ArrayFlatMap.lua +11 -10
- package/dist/lualib/ArrayForEach.lua +3 -7
- package/dist/lualib/ArrayFrom.lua +2 -5
- package/dist/lualib/ArrayIncludes.lua +2 -2
- package/dist/lualib/ArrayIndexOf.lua +13 -21
- package/dist/lualib/ArrayIsArray.lua +1 -1
- package/dist/lualib/ArrayJoin.lua +4 -7
- package/dist/lualib/ArrayMap.lua +5 -9
- package/dist/lualib/ArrayPush.lua +6 -4
- package/dist/lualib/ArrayPushArray.lua +8 -0
- package/dist/lualib/ArrayReduce.lua +8 -8
- package/dist/lualib/ArrayReduceRight.lua +8 -8
- package/dist/lualib/ArrayReverse.lua +7 -7
- package/dist/lualib/ArraySetLength.lua +3 -7
- package/dist/lualib/ArraySlice.lua +26 -19
- package/dist/lualib/ArraySome.lua +4 -8
- package/dist/lualib/ArraySort.lua +4 -4
- package/dist/lualib/ArraySplice.lua +47 -58
- package/dist/lualib/ArrayToObject.lua +3 -7
- package/dist/lualib/ArrayUnshift.lua +11 -8
- package/dist/lualib/FunctionBind.lua +5 -11
- package/dist/lualib/ObjectAssign.lua +5 -7
- package/dist/lualib/ObjectEntries.lua +3 -1
- package/dist/lualib/ObjectKeys.lua +3 -1
- package/dist/lualib/ObjectValues.lua +3 -1
- package/dist/lualib/Promise.lua +8 -7
- package/dist/lualib/PromiseAny.lua +3 -3
- package/dist/lualib/PromiseRace.lua +1 -1
- package/dist/lualib/SourceMapTraceBack.lua +14 -1
- package/dist/lualib/Spread.lua +5 -7
- package/dist/lualib/StringReplace.lua +17 -14
- package/dist/lualib/StringReplaceAll.lua +36 -29
- package/dist/lualib/StringSplit.lua +32 -32
- package/dist/lualib/lualib_bundle.lua +372 -389
- package/dist/lualib/lualib_module_info.json +13 -23
- package/dist/transformation/builtins/array.d.ts +1 -1
- package/dist/transformation/builtins/array.js +35 -2
- package/dist/transformation/builtins/promise.d.ts +1 -0
- package/dist/transformation/builtins/promise.js +2 -1
- package/dist/transformation/builtins/string.js +1 -1
- package/dist/transformation/utils/diagnostics.d.ts +7 -2
- package/dist/transformation/utils/diagnostics.js +4 -1
- package/dist/transformation/utils/lua-ast.d.ts +1 -0
- package/dist/transformation/utils/lua-ast.js +6 -2
- package/dist/transformation/utils/typescript/index.d.ts +1 -0
- package/dist/transformation/utils/typescript/index.js +9 -1
- package/dist/transformation/visitors/call.js +4 -0
- package/dist/transformation/visitors/class/index.js +1 -1
- package/dist/transformation/visitors/class/members/accessors.js +1 -1
- package/dist/transformation/visitors/class/members/constructor.js +1 -1
- package/dist/transformation/visitors/errors.js +4 -2
- package/dist/transformation/visitors/function.js +4 -4
- package/dist/transformation/visitors/modules/import.d.ts +1 -0
- package/dist/transformation/visitors/modules/import.js +9 -1
- package/dist/transformation/visitors/spread.js +1 -7
- package/dist/transpilation/resolve.js +1 -0
- package/package.json +1 -1
- package/dist/lualib/ArrayShift.lua +0 -3
- package/dist/lualib/StringConcat.lua +0 -8
|
@@ -15,7 +15,7 @@ export interface LuaPluginImport {
|
|
|
15
15
|
import?: string;
|
|
16
16
|
[option: string]: any;
|
|
17
17
|
}
|
|
18
|
-
export
|
|
18
|
+
export interface TypeScriptToLuaOptions {
|
|
19
19
|
buildMode?: BuildMode;
|
|
20
20
|
extension?: string;
|
|
21
21
|
luaBundle?: string;
|
|
@@ -29,6 +29,9 @@ export declare type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & {
|
|
|
29
29
|
plugins?: Array<ts.PluginImport | TransformerImport>;
|
|
30
30
|
sourceMapTraceback?: boolean;
|
|
31
31
|
tstlVerbose?: boolean;
|
|
32
|
+
lua51AllowTryCatchInAsyncAwait?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & TypeScriptToLuaOptions & {
|
|
32
35
|
[option: string]: any;
|
|
33
36
|
};
|
|
34
37
|
export declare enum LuaLibImportKind {
|
package/dist/LuaAST.d.ts
CHANGED
|
@@ -65,12 +65,19 @@ export declare type Operator = UnaryOperator | BinaryOperator;
|
|
|
65
65
|
export declare type SymbolId = number & {
|
|
66
66
|
_symbolIdBrand: any;
|
|
67
67
|
};
|
|
68
|
+
export declare enum NodeFlags {
|
|
69
|
+
None = 0,
|
|
70
|
+
Inline = 1,
|
|
71
|
+
Declaration = 2,
|
|
72
|
+
TableUnpackCall = 4
|
|
73
|
+
}
|
|
68
74
|
export interface TextRange {
|
|
69
75
|
line?: number;
|
|
70
76
|
column?: number;
|
|
71
77
|
}
|
|
72
78
|
export interface Node extends TextRange {
|
|
73
79
|
kind: SyntaxKind;
|
|
80
|
+
flags: NodeFlags;
|
|
74
81
|
}
|
|
75
82
|
export declare function createNode(kind: SyntaxKind, tsOriginal?: ts.Node): Node;
|
|
76
83
|
export declare function cloneNode<T extends Node>(node: T): T;
|
|
@@ -78,6 +85,7 @@ export declare function setNodePosition<T extends Node>(node: T, position: TextR
|
|
|
78
85
|
export declare function setNodeOriginal<T extends Node>(node: T, tsOriginal: ts.Node): T;
|
|
79
86
|
export declare function setNodeOriginal<T extends Node>(node: T | undefined, tsOriginal: ts.Node): T | undefined;
|
|
80
87
|
export declare function getOriginalPos(node: Node): TextRange;
|
|
88
|
+
export declare function setNodeFlags<T extends Node>(node: T, flags: NodeFlags): T;
|
|
81
89
|
export interface File extends Node {
|
|
82
90
|
kind: SyntaxKind.File;
|
|
83
91
|
statements: Statement[];
|
|
@@ -217,20 +225,14 @@ export interface StringLiteral extends Expression {
|
|
|
217
225
|
export declare function isStringLiteral(node: Node): node is StringLiteral;
|
|
218
226
|
export declare function createStringLiteral(value: string, tsOriginal?: ts.Node): StringLiteral;
|
|
219
227
|
export declare function isLiteral(node: Node): node is NilLiteral | DotsLiteral | BooleanLiteral | NumericLiteral | StringLiteral;
|
|
220
|
-
export declare enum FunctionExpressionFlags {
|
|
221
|
-
None = 1,
|
|
222
|
-
Inline = 2,
|
|
223
|
-
Declaration = 4
|
|
224
|
-
}
|
|
225
228
|
export interface FunctionExpression extends Expression {
|
|
226
229
|
kind: SyntaxKind.FunctionExpression;
|
|
227
230
|
params?: Identifier[];
|
|
228
231
|
dots?: DotsLiteral;
|
|
229
232
|
body: Block;
|
|
230
|
-
flags: FunctionExpressionFlags;
|
|
231
233
|
}
|
|
232
234
|
export declare function isFunctionExpression(node: Node): node is FunctionExpression;
|
|
233
|
-
export declare function createFunctionExpression(body: Block, params?: Identifier[], dots?: DotsLiteral, flags?:
|
|
235
|
+
export declare function createFunctionExpression(body: Block, params?: Identifier[], dots?: DotsLiteral, flags?: NodeFlags, tsOriginal?: ts.Node): FunctionExpression;
|
|
234
236
|
export interface TableFieldExpression extends Expression {
|
|
235
237
|
kind: SyntaxKind.TableFieldExpression;
|
|
236
238
|
value: Expression;
|
package/dist/LuaAST.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Simplified Lua AST based roughly on http://lua-users.org/wiki/MetaLuaAbstractSyntaxTree,
|
|
3
3
|
// https://www.lua.org/manual/5.3/manual.html#9 and the TS AST implementation
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.
|
|
6
|
-
exports.isInlineFunctionExpression = exports.isFunctionDefinition = exports.isAssignmentLeftHandSideExpression = exports.createTableIndexExpression = exports.isTableIndexExpression = exports.createAnonymousIdentifier = exports.cloneIdentifier = exports.createIdentifier = exports.isIdentifier = exports.createMethodCallExpression = exports.isMethodCallExpression = exports.createCallExpression = exports.isCallExpression = exports.createBinaryExpression = exports.isBinaryExpression = exports.createUnaryExpression = exports.isUnaryExpression = exports.createTableExpression = exports.isTableExpression = exports.createTableFieldExpression = exports.isTableFieldExpression = exports.createFunctionExpression = void 0;
|
|
5
|
+
exports.isLiteral = exports.createStringLiteral = exports.isStringLiteral = exports.createNumericLiteral = exports.isNumericLiteral = exports.createDotsLiteral = exports.isDotsLiteral = exports.createBooleanLiteral = exports.isBooleanLiteral = exports.createNilLiteral = exports.isNilLiteral = exports.createExpressionStatement = exports.isExpressionStatement = exports.createBreakStatement = exports.isBreakStatement = exports.createReturnStatement = exports.isReturnStatement = exports.createLabelStatement = exports.isLabelStatement = exports.createGotoStatement = exports.isGotoStatement = exports.createForInStatement = exports.isForInStatement = exports.createForStatement = exports.isForStatement = exports.createRepeatStatement = exports.isRepeatStatement = exports.createWhileStatement = exports.isWhileStatement = exports.isIterationStatement = exports.createIfStatement = exports.isIfStatement = exports.createAssignmentStatement = exports.isAssignmentStatement = exports.createVariableDeclarationStatement = exports.isVariableDeclarationStatement = exports.createDoStatement = exports.isDoStatement = exports.createBlock = exports.isBlock = exports.createFile = exports.isFile = exports.setNodeFlags = exports.getOriginalPos = exports.setNodeOriginal = exports.setNodePosition = exports.cloneNode = exports.createNode = exports.NodeFlags = exports.SyntaxKind = void 0;
|
|
6
|
+
exports.isInlineFunctionExpression = exports.isFunctionDefinition = exports.isAssignmentLeftHandSideExpression = exports.createTableIndexExpression = exports.isTableIndexExpression = exports.createAnonymousIdentifier = exports.cloneIdentifier = exports.createIdentifier = exports.isIdentifier = exports.createMethodCallExpression = exports.isMethodCallExpression = exports.createCallExpression = exports.isCallExpression = exports.createBinaryExpression = exports.isBinaryExpression = exports.createUnaryExpression = exports.isUnaryExpression = exports.createTableExpression = exports.isTableExpression = exports.createTableFieldExpression = exports.isTableFieldExpression = exports.createFunctionExpression = exports.isFunctionExpression = void 0;
|
|
7
7
|
// We can elide a lot of nodes especially tokens and keywords
|
|
8
8
|
// because we don't create the AST from text
|
|
9
9
|
const ts = require("typescript");
|
|
@@ -77,16 +77,23 @@ var SyntaxKind;
|
|
|
77
77
|
SyntaxKind[SyntaxKind["BitwiseLeftShiftOperator"] = 53] = "BitwiseLeftShiftOperator";
|
|
78
78
|
SyntaxKind[SyntaxKind["BitwiseNotOperator"] = 54] = "BitwiseNotOperator";
|
|
79
79
|
})(SyntaxKind = exports.SyntaxKind || (exports.SyntaxKind = {}));
|
|
80
|
+
var NodeFlags;
|
|
81
|
+
(function (NodeFlags) {
|
|
82
|
+
NodeFlags[NodeFlags["None"] = 0] = "None";
|
|
83
|
+
NodeFlags[NodeFlags["Inline"] = 1] = "Inline";
|
|
84
|
+
NodeFlags[NodeFlags["Declaration"] = 2] = "Declaration";
|
|
85
|
+
NodeFlags[NodeFlags["TableUnpackCall"] = 4] = "TableUnpackCall";
|
|
86
|
+
})(NodeFlags = exports.NodeFlags || (exports.NodeFlags = {}));
|
|
80
87
|
function createNode(kind, tsOriginal) {
|
|
81
88
|
if (tsOriginal === undefined) {
|
|
82
|
-
return { kind };
|
|
89
|
+
return { kind, flags: NodeFlags.None };
|
|
83
90
|
}
|
|
84
91
|
const sourcePosition = getSourcePosition(tsOriginal);
|
|
85
92
|
if (sourcePosition) {
|
|
86
|
-
return { kind, line: sourcePosition.line, column: sourcePosition.column };
|
|
93
|
+
return { kind, line: sourcePosition.line, column: sourcePosition.column, flags: NodeFlags.None };
|
|
87
94
|
}
|
|
88
95
|
else {
|
|
89
|
-
return { kind };
|
|
96
|
+
return { kind, flags: NodeFlags.None };
|
|
90
97
|
}
|
|
91
98
|
}
|
|
92
99
|
exports.createNode = createNode;
|
|
@@ -124,6 +131,11 @@ function getOriginalPos(node) {
|
|
|
124
131
|
return { line: node.line, column: node.column };
|
|
125
132
|
}
|
|
126
133
|
exports.getOriginalPos = getOriginalPos;
|
|
134
|
+
function setNodeFlags(node, flags) {
|
|
135
|
+
node.flags = flags;
|
|
136
|
+
return node;
|
|
137
|
+
}
|
|
138
|
+
exports.setNodeFlags = setNodeFlags;
|
|
127
139
|
function isFile(node) {
|
|
128
140
|
return node.kind === SyntaxKind.File;
|
|
129
141
|
}
|
|
@@ -346,17 +358,11 @@ function isLiteral(node) {
|
|
|
346
358
|
isStringLiteral(node));
|
|
347
359
|
}
|
|
348
360
|
exports.isLiteral = isLiteral;
|
|
349
|
-
var FunctionExpressionFlags;
|
|
350
|
-
(function (FunctionExpressionFlags) {
|
|
351
|
-
FunctionExpressionFlags[FunctionExpressionFlags["None"] = 1] = "None";
|
|
352
|
-
FunctionExpressionFlags[FunctionExpressionFlags["Inline"] = 2] = "Inline";
|
|
353
|
-
FunctionExpressionFlags[FunctionExpressionFlags["Declaration"] = 4] = "Declaration";
|
|
354
|
-
})(FunctionExpressionFlags = exports.FunctionExpressionFlags || (exports.FunctionExpressionFlags = {}));
|
|
355
361
|
function isFunctionExpression(node) {
|
|
356
362
|
return node.kind === SyntaxKind.FunctionExpression;
|
|
357
363
|
}
|
|
358
364
|
exports.isFunctionExpression = isFunctionExpression;
|
|
359
|
-
function createFunctionExpression(body, params, dots, flags =
|
|
365
|
+
function createFunctionExpression(body, params, dots, flags = NodeFlags.None, tsOriginal) {
|
|
360
366
|
const expression = createNode(SyntaxKind.FunctionExpression, tsOriginal);
|
|
361
367
|
expression.body = body;
|
|
362
368
|
expression.params = params;
|
|
@@ -481,7 +487,7 @@ function isInlineFunctionExpression(expression) {
|
|
|
481
487
|
return (((_a = expression.body.statements) === null || _a === void 0 ? void 0 : _a.length) === 1 &&
|
|
482
488
|
isReturnStatement(expression.body.statements[0]) &&
|
|
483
489
|
expression.body.statements[0].expressions !== undefined &&
|
|
484
|
-
(expression.flags &
|
|
490
|
+
(expression.flags & NodeFlags.Inline) !== 0);
|
|
485
491
|
}
|
|
486
492
|
exports.isInlineFunctionExpression = isInlineFunctionExpression;
|
|
487
493
|
//# sourceMappingURL=LuaAST.js.map
|
package/dist/LuaLib.d.ts
CHANGED
|
@@ -15,10 +15,10 @@ export declare enum LuaLibFeature {
|
|
|
15
15
|
ArrayJoin = "ArrayJoin",
|
|
16
16
|
ArrayMap = "ArrayMap",
|
|
17
17
|
ArrayPush = "ArrayPush",
|
|
18
|
+
ArrayPushArray = "ArrayPushArray",
|
|
18
19
|
ArrayReduce = "ArrayReduce",
|
|
19
20
|
ArrayReduceRight = "ArrayReduceRight",
|
|
20
21
|
ArrayReverse = "ArrayReverse",
|
|
21
|
-
ArrayShift = "ArrayShift",
|
|
22
22
|
ArrayUnshift = "ArrayUnshift",
|
|
23
23
|
ArraySort = "ArraySort",
|
|
24
24
|
ArraySlice = "ArraySlice",
|
|
@@ -78,7 +78,6 @@ export declare enum LuaLibFeature {
|
|
|
78
78
|
StringAccess = "StringAccess",
|
|
79
79
|
StringCharAt = "StringCharAt",
|
|
80
80
|
StringCharCodeAt = "StringCharCodeAt",
|
|
81
|
-
StringConcat = "StringConcat",
|
|
82
81
|
StringEndsWith = "StringEndsWith",
|
|
83
82
|
StringIncludes = "StringIncludes",
|
|
84
83
|
StringPadEnd = "StringPadEnd",
|
package/dist/LuaLib.js
CHANGED
|
@@ -19,10 +19,10 @@ var LuaLibFeature;
|
|
|
19
19
|
LuaLibFeature["ArrayJoin"] = "ArrayJoin";
|
|
20
20
|
LuaLibFeature["ArrayMap"] = "ArrayMap";
|
|
21
21
|
LuaLibFeature["ArrayPush"] = "ArrayPush";
|
|
22
|
+
LuaLibFeature["ArrayPushArray"] = "ArrayPushArray";
|
|
22
23
|
LuaLibFeature["ArrayReduce"] = "ArrayReduce";
|
|
23
24
|
LuaLibFeature["ArrayReduceRight"] = "ArrayReduceRight";
|
|
24
25
|
LuaLibFeature["ArrayReverse"] = "ArrayReverse";
|
|
25
|
-
LuaLibFeature["ArrayShift"] = "ArrayShift";
|
|
26
26
|
LuaLibFeature["ArrayUnshift"] = "ArrayUnshift";
|
|
27
27
|
LuaLibFeature["ArraySort"] = "ArraySort";
|
|
28
28
|
LuaLibFeature["ArraySlice"] = "ArraySlice";
|
|
@@ -82,7 +82,6 @@ var LuaLibFeature;
|
|
|
82
82
|
LuaLibFeature["StringAccess"] = "StringAccess";
|
|
83
83
|
LuaLibFeature["StringCharAt"] = "StringCharAt";
|
|
84
84
|
LuaLibFeature["StringCharCodeAt"] = "StringCharCodeAt";
|
|
85
|
-
LuaLibFeature["StringConcat"] = "StringConcat";
|
|
86
85
|
LuaLibFeature["StringEndsWith"] = "StringEndsWith";
|
|
87
86
|
LuaLibFeature["StringIncludes"] = "StringIncludes";
|
|
88
87
|
LuaLibFeature["StringPadEnd"] = "StringPadEnd";
|
package/dist/LuaPrinter.js
CHANGED
|
@@ -291,8 +291,7 @@ class LuaPrinter {
|
|
|
291
291
|
printVariableAssignmentStatement(statement) {
|
|
292
292
|
const chunks = [];
|
|
293
293
|
chunks.push(this.indent());
|
|
294
|
-
if (lua.isFunctionDefinition(statement) &&
|
|
295
|
-
(statement.right[0].flags & lua.FunctionExpressionFlags.Declaration) !== 0) {
|
|
294
|
+
if (lua.isFunctionDefinition(statement) && (statement.right[0].flags & lua.NodeFlags.Declaration) !== 0) {
|
|
296
295
|
// Use `function foo()` instead of `foo = function()`
|
|
297
296
|
const name = this.printExpression(statement.left[0]);
|
|
298
297
|
if (isValidLuaFunctionDeclarationName(name.toString(), this.options)) {
|
package/dist/cli/parse.js
CHANGED
|
@@ -69,6 +69,11 @@ exports.optionDeclarations = [
|
|
|
69
69
|
description: "An array of paths that tstl should not resolve and keep as-is.",
|
|
70
70
|
type: "array",
|
|
71
71
|
},
|
|
72
|
+
{
|
|
73
|
+
name: "lua51AllowTryCatchInAsyncAwait",
|
|
74
|
+
description: "Always allow try/catch in async/await functions for Lua 5.1.",
|
|
75
|
+
type: "boolean",
|
|
76
|
+
},
|
|
72
77
|
];
|
|
73
78
|
function updateParsedConfigFile(parsedConfigFile) {
|
|
74
79
|
let hasRootLevelOptions = false;
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
local function __TS__ArrayConcat(
|
|
2
|
-
local
|
|
3
|
-
local
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
local function __TS__ArrayConcat(self, ...)
|
|
2
|
+
local items = {...}
|
|
3
|
+
local result = {}
|
|
4
|
+
local len = 0
|
|
5
|
+
for i = 1, #self do
|
|
6
|
+
len = len + 1
|
|
7
|
+
result[len] = self[i]
|
|
6
8
|
end
|
|
7
|
-
for
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
for
|
|
11
|
-
|
|
9
|
+
for i = 1, #items do
|
|
10
|
+
local item = items[i]
|
|
11
|
+
if __TS__ArrayIsArray(item) then
|
|
12
|
+
for j = 1, #item do
|
|
13
|
+
len = len + 1
|
|
14
|
+
result[len] = item[j]
|
|
12
15
|
end
|
|
13
16
|
else
|
|
14
|
-
|
|
17
|
+
len = len + 1
|
|
18
|
+
result[len] = item
|
|
15
19
|
end
|
|
16
20
|
end
|
|
17
|
-
return
|
|
21
|
+
return result
|
|
18
22
|
end
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
local function __TS__ArrayEvery(
|
|
2
|
-
do
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if not callbackfn(nil, arr[i + 1], i, arr) then
|
|
6
|
-
return false
|
|
7
|
-
end
|
|
8
|
-
i = i + 1
|
|
1
|
+
local function __TS__ArrayEvery(self, callbackfn, thisArg)
|
|
2
|
+
for i = 1, #self do
|
|
3
|
+
if not callbackfn(thisArg, self[i], i - 1, self) then
|
|
4
|
+
return false
|
|
9
5
|
end
|
|
10
6
|
end
|
|
11
7
|
return true
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
local function __TS__ArrayFilter(
|
|
1
|
+
local function __TS__ArrayFilter(self, callbackfn, thisArg)
|
|
2
2
|
local result = {}
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
end
|
|
9
|
-
i = i + 1
|
|
3
|
+
local len = 0
|
|
4
|
+
for i = 1, #self do
|
|
5
|
+
if callbackfn(thisArg, self[i], i - 1, self) then
|
|
6
|
+
len = len + 1
|
|
7
|
+
result[len] = self[i]
|
|
10
8
|
end
|
|
11
9
|
end
|
|
12
10
|
return result
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
local function __TS__ArrayFind(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
local elem = arr[k + 1]
|
|
6
|
-
if predicate(nil, elem, k, arr) then
|
|
1
|
+
local function __TS__ArrayFind(self, predicate, thisArg)
|
|
2
|
+
for i = 1, #self do
|
|
3
|
+
local elem = self[i]
|
|
4
|
+
if predicate(thisArg, elem, i - 1, self) then
|
|
7
5
|
return elem
|
|
8
6
|
end
|
|
9
|
-
k = k + 1
|
|
10
7
|
end
|
|
11
8
|
return nil
|
|
12
9
|
end
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
local function __TS__ArrayFindIndex(
|
|
2
|
-
do
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
while i < len do
|
|
6
|
-
if callbackFn(nil, arr[i + 1], i, arr) then
|
|
7
|
-
return i
|
|
8
|
-
end
|
|
9
|
-
i = i + 1
|
|
1
|
+
local function __TS__ArrayFindIndex(self, callbackFn, thisArg)
|
|
2
|
+
for i = 1, #self do
|
|
3
|
+
if callbackFn(thisArg, self[i], i - 1, self) then
|
|
4
|
+
return i - 1
|
|
10
5
|
end
|
|
11
6
|
end
|
|
12
7
|
return -1
|
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
local function __TS__ArrayFlat(
|
|
1
|
+
local function __TS__ArrayFlat(self, depth)
|
|
2
2
|
if depth == nil then
|
|
3
3
|
depth = 1
|
|
4
4
|
end
|
|
5
5
|
local result = {}
|
|
6
|
-
|
|
6
|
+
local len = 0
|
|
7
|
+
for i = 1, #self do
|
|
8
|
+
local value = self[i]
|
|
7
9
|
if depth > 0 and __TS__ArrayIsArray(value) then
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
local toAdd
|
|
11
|
+
if depth == 1 then
|
|
12
|
+
toAdd = value
|
|
13
|
+
else
|
|
14
|
+
toAdd = __TS__ArrayFlat(value, depth - 1)
|
|
15
|
+
end
|
|
16
|
+
for j = 1, #toAdd do
|
|
17
|
+
local val = toAdd[j]
|
|
18
|
+
len = len + 1
|
|
19
|
+
result[len] = val
|
|
20
|
+
end
|
|
12
21
|
else
|
|
13
|
-
|
|
22
|
+
len = len + 1
|
|
23
|
+
result[len] = value
|
|
14
24
|
end
|
|
15
25
|
end
|
|
16
26
|
return result
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
local function __TS__ArrayFlatMap(
|
|
1
|
+
local function __TS__ArrayFlatMap(self, callback, thisArg)
|
|
2
2
|
local result = {}
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
result[#result + 1] = value
|
|
3
|
+
local len = 0
|
|
4
|
+
for i = 1, #self do
|
|
5
|
+
local value = callback(thisArg, self[i], i - 1, self)
|
|
6
|
+
if __TS__ArrayIsArray(value) then
|
|
7
|
+
for j = 1, #value do
|
|
8
|
+
len = len + 1
|
|
9
|
+
result[len] = value[j]
|
|
11
10
|
end
|
|
12
|
-
|
|
11
|
+
else
|
|
12
|
+
len = len + 1
|
|
13
|
+
result[len] = value
|
|
13
14
|
end
|
|
14
15
|
end
|
|
15
16
|
return result
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
local function __TS__ArrayForEach(
|
|
2
|
-
do
|
|
3
|
-
|
|
4
|
-
while i < #arr do
|
|
5
|
-
callbackFn(nil, arr[i + 1], i, arr)
|
|
6
|
-
i = i + 1
|
|
7
|
-
end
|
|
1
|
+
local function __TS__ArrayForEach(self, callbackFn, thisArg)
|
|
2
|
+
for i = 1, #self do
|
|
3
|
+
callbackFn(thisArg, self[i], i - 1, self)
|
|
8
4
|
end
|
|
9
5
|
end
|
|
@@ -17,14 +17,11 @@ do
|
|
|
17
17
|
local result = {}
|
|
18
18
|
if mapFn == nil then
|
|
19
19
|
for ____, v in arrayLikeIterator(arrayLike) do
|
|
20
|
-
|
|
20
|
+
result[#result + 1] = v
|
|
21
21
|
end
|
|
22
22
|
else
|
|
23
23
|
for i, v in arrayLikeIterator(arrayLike) do
|
|
24
|
-
|
|
25
|
-
result,
|
|
26
|
-
mapFn(thisArg, v, i - 1)
|
|
27
|
-
)
|
|
24
|
+
result[#result + 1] = mapFn(thisArg, v, i - 1)
|
|
28
25
|
end
|
|
29
26
|
end
|
|
30
27
|
return result
|
|
@@ -1,31 +1,23 @@
|
|
|
1
|
-
local function __TS__ArrayIndexOf(
|
|
2
|
-
|
|
1
|
+
local function __TS__ArrayIndexOf(self, searchElement, fromIndex)
|
|
2
|
+
if fromIndex == nil then
|
|
3
|
+
fromIndex = 0
|
|
4
|
+
end
|
|
5
|
+
local len = #self
|
|
3
6
|
if len == 0 then
|
|
4
7
|
return -1
|
|
5
8
|
end
|
|
6
|
-
|
|
7
|
-
if fromIndex then
|
|
8
|
-
n = fromIndex
|
|
9
|
-
end
|
|
10
|
-
if n >= len then
|
|
9
|
+
if fromIndex >= len then
|
|
11
10
|
return -1
|
|
12
11
|
end
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
k = len + n
|
|
18
|
-
if k < 0 then
|
|
19
|
-
k = 0
|
|
12
|
+
if fromIndex < 0 then
|
|
13
|
+
fromIndex = len + fromIndex
|
|
14
|
+
if fromIndex < 0 then
|
|
15
|
+
fromIndex = 0
|
|
20
16
|
end
|
|
21
17
|
end
|
|
22
|
-
do
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if arr[i + 1] == searchElement then
|
|
26
|
-
return i
|
|
27
|
-
end
|
|
28
|
-
i = i + 1
|
|
18
|
+
for i = fromIndex + 1, len do
|
|
19
|
+
if self[i] == searchElement then
|
|
20
|
+
return i - 1
|
|
29
21
|
end
|
|
30
22
|
end
|
|
31
23
|
return -1
|
|
@@ -2,12 +2,9 @@ local function __TS__ArrayJoin(self, separator)
|
|
|
2
2
|
if separator == nil then
|
|
3
3
|
separator = ","
|
|
4
4
|
end
|
|
5
|
-
local
|
|
6
|
-
for
|
|
7
|
-
|
|
8
|
-
result = result .. separator
|
|
9
|
-
end
|
|
10
|
-
result = result .. tostring(value)
|
|
5
|
+
local parts = {}
|
|
6
|
+
for i = 1, #self do
|
|
7
|
+
parts[i] = tostring(self[i])
|
|
11
8
|
end
|
|
12
|
-
return
|
|
9
|
+
return table.concat(parts, separator)
|
|
13
10
|
end
|
package/dist/lualib/ArrayMap.lua
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
local function __TS__ArrayMap(
|
|
2
|
-
local
|
|
3
|
-
do
|
|
4
|
-
|
|
5
|
-
while i < #arr do
|
|
6
|
-
newArray[i + 1] = callbackfn(nil, arr[i + 1], i, arr)
|
|
7
|
-
i = i + 1
|
|
8
|
-
end
|
|
1
|
+
local function __TS__ArrayMap(self, callbackfn, thisArg)
|
|
2
|
+
local result = {}
|
|
3
|
+
for i = 1, #self do
|
|
4
|
+
result[i] = callbackfn(thisArg, self[i], i - 1, self)
|
|
9
5
|
end
|
|
10
|
-
return
|
|
6
|
+
return result
|
|
11
7
|
end
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
local function __TS__ArrayPush(
|
|
1
|
+
local function __TS__ArrayPush(self, ...)
|
|
2
2
|
local items = {...}
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
local len = #self
|
|
4
|
+
for i = 1, #items do
|
|
5
|
+
len = len + 1
|
|
6
|
+
self[len] = items[i]
|
|
5
7
|
end
|
|
6
|
-
return
|
|
8
|
+
return len
|
|
7
9
|
end
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
local function __TS__ArrayReduce(
|
|
2
|
-
local len = #
|
|
1
|
+
local function __TS__ArrayReduce(self, callbackFn, ...)
|
|
2
|
+
local len = #self
|
|
3
3
|
local k = 0
|
|
4
4
|
local accumulator = nil
|
|
5
5
|
if select("#", ...) ~= 0 then
|
|
6
|
-
accumulator =
|
|
6
|
+
accumulator = ...
|
|
7
7
|
elseif len > 0 then
|
|
8
|
-
accumulator =
|
|
8
|
+
accumulator = self[1]
|
|
9
9
|
k = 1
|
|
10
10
|
else
|
|
11
11
|
error("Reduce of empty array with no initial value", 0)
|
|
12
12
|
end
|
|
13
|
-
for i = k, len
|
|
13
|
+
for i = k + 1, len do
|
|
14
14
|
accumulator = callbackFn(
|
|
15
15
|
nil,
|
|
16
16
|
accumulator,
|
|
17
|
-
|
|
18
|
-
i,
|
|
19
|
-
|
|
17
|
+
self[i],
|
|
18
|
+
i - 1,
|
|
19
|
+
self
|
|
20
20
|
)
|
|
21
21
|
end
|
|
22
22
|
return accumulator
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
local function __TS__ArrayReduceRight(
|
|
2
|
-
local len = #
|
|
1
|
+
local function __TS__ArrayReduceRight(self, callbackFn, ...)
|
|
2
|
+
local len = #self
|
|
3
3
|
local k = len - 1
|
|
4
4
|
local accumulator = nil
|
|
5
5
|
if select("#", ...) ~= 0 then
|
|
6
|
-
accumulator =
|
|
6
|
+
accumulator = ...
|
|
7
7
|
elseif len > 0 then
|
|
8
|
-
accumulator =
|
|
8
|
+
accumulator = self[k + 1]
|
|
9
9
|
k = k - 1
|
|
10
10
|
else
|
|
11
11
|
error("Reduce of empty array with no initial value", 0)
|
|
12
12
|
end
|
|
13
|
-
for i = k,
|
|
13
|
+
for i = k + 1, 1, -1 do
|
|
14
14
|
accumulator = callbackFn(
|
|
15
15
|
nil,
|
|
16
16
|
accumulator,
|
|
17
|
-
|
|
18
|
-
i,
|
|
19
|
-
|
|
17
|
+
self[i],
|
|
18
|
+
i - 1,
|
|
19
|
+
self
|
|
20
20
|
)
|
|
21
21
|
end
|
|
22
22
|
return accumulator
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
local function __TS__ArrayReverse(
|
|
2
|
-
local i =
|
|
3
|
-
local j = #
|
|
1
|
+
local function __TS__ArrayReverse(self)
|
|
2
|
+
local i = 1
|
|
3
|
+
local j = #self
|
|
4
4
|
while i < j do
|
|
5
|
-
local temp =
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
local temp = self[j]
|
|
6
|
+
self[j] = self[i]
|
|
7
|
+
self[i] = temp
|
|
8
8
|
i = i + 1
|
|
9
9
|
j = j - 1
|
|
10
10
|
end
|
|
11
|
-
return
|
|
11
|
+
return self
|
|
12
12
|
end
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
local function __TS__ArraySetLength(
|
|
1
|
+
local function __TS__ArraySetLength(self, length)
|
|
2
2
|
if length < 0 or length ~= length or length == math.huge or math.floor(length) ~= length then
|
|
3
3
|
error(
|
|
4
4
|
"invalid array length: " .. tostring(length),
|
|
5
5
|
0
|
|
6
6
|
)
|
|
7
7
|
end
|
|
8
|
-
do
|
|
9
|
-
|
|
10
|
-
while i >= length do
|
|
11
|
-
arr[i + 1] = nil
|
|
12
|
-
i = i - 1
|
|
13
|
-
end
|
|
8
|
+
for i = length + 1, #self do
|
|
9
|
+
self[i] = nil
|
|
14
10
|
end
|
|
15
11
|
return length
|
|
16
12
|
end
|