typescript-to-lua 1.3.3 → 1.4.1
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 +1 -1
- package/dist/CompilerOptions.js +0 -1
- package/dist/LuaLib.d.ts +13 -1
- package/dist/LuaLib.js +62 -65
- package/dist/LuaPrinter.js +13 -12
- package/dist/cli/parse.js +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -1
- package/dist/lualib/ArrayConcat.lua +1 -1
- package/dist/lualib/ArrayEntries.lua +1 -1
- package/dist/lualib/ArrayEvery.lua +2 -2
- package/dist/lualib/ArrayFilter.lua +2 -2
- package/dist/lualib/ArrayFind.lua +2 -2
- package/dist/lualib/ArrayFindIndex.lua +2 -2
- package/dist/lualib/ArrayFlat.lua +1 -1
- package/dist/lualib/ArrayFlatMap.lua +2 -2
- package/dist/lualib/ArrayForEach.lua +2 -2
- package/dist/lualib/ArrayFrom.lua +32 -0
- package/dist/lualib/ArrayIncludes.lua +1 -1
- package/dist/lualib/ArrayIndexOf.lua +1 -1
- package/dist/lualib/ArrayIsArray.lua +1 -1
- package/dist/lualib/ArrayJoin.lua +1 -1
- package/dist/lualib/ArrayMap.lua +2 -2
- package/dist/lualib/ArrayPush.lua +1 -1
- package/dist/lualib/ArrayReduce.lua +2 -2
- package/dist/lualib/ArrayReduceRight.lua +2 -2
- package/dist/lualib/ArrayReverse.lua +1 -1
- package/dist/lualib/ArraySetLength.lua +1 -1
- package/dist/lualib/ArrayShift.lua +1 -1
- package/dist/lualib/ArraySlice.lua +1 -1
- package/dist/lualib/ArraySome.lua +2 -2
- package/dist/lualib/ArraySort.lua +2 -2
- package/dist/lualib/ArraySplice.lua +1 -1
- package/dist/lualib/ArrayToObject.lua +1 -1
- package/dist/lualib/ArrayUnshift.lua +1 -1
- package/dist/lualib/Await.lua +13 -13
- package/dist/lualib/Class.lua +1 -1
- package/dist/lualib/ClassExtends.lua +1 -1
- package/dist/lualib/CloneDescriptor.lua +1 -1
- package/dist/lualib/Decorate.lua +5 -5
- package/dist/lualib/DecorateParam.lua +2 -2
- package/dist/lualib/DelegatedYield.lua +1 -1
- package/dist/lualib/Delete.lua +1 -1
- package/dist/lualib/Error.lua +68 -69
- package/dist/lualib/FunctionBind.lua +1 -1
- package/dist/lualib/Generator.lua +26 -23
- package/dist/lualib/InstanceOf.lua +1 -1
- package/dist/lualib/InstanceOfObject.lua +1 -1
- package/dist/lualib/Iterator.lua +35 -32
- package/dist/lualib/Map.lua +131 -129
- package/dist/lualib/MathAtan2.lua +1 -1
- package/dist/lualib/MathSign.lua +1 -1
- package/dist/lualib/New.lua +1 -1
- package/dist/lualib/Number.lua +1 -1
- package/dist/lualib/NumberIsFinite.lua +1 -1
- package/dist/lualib/NumberIsNaN.lua +1 -1
- package/dist/lualib/NumberToString.lua +42 -39
- package/dist/lualib/ObjectAssign.lua +1 -1
- package/dist/lualib/ObjectDefineProperty.lua +1 -1
- package/dist/lualib/ObjectEntries.lua +1 -1
- package/dist/lualib/ObjectFromEntries.lua +1 -1
- package/dist/lualib/ObjectGetOwnPropertyDescriptor.lua +1 -1
- package/dist/lualib/ObjectGetOwnPropertyDescriptors.lua +1 -1
- package/dist/lualib/ObjectKeys.lua +1 -1
- package/dist/lualib/ObjectRest.lua +1 -1
- package/dist/lualib/ObjectValues.lua +1 -1
- package/dist/lualib/ParseFloat.lua +1 -1
- package/dist/lualib/ParseInt.lua +39 -36
- package/dist/lualib/Promise.lua +148 -152
- package/dist/lualib/PromiseAll.lua +5 -5
- package/dist/lualib/PromiseAllSettled.lua +5 -5
- package/dist/lualib/PromiseAny.lua +5 -5
- package/dist/lualib/PromiseRace.lua +5 -5
- package/dist/lualib/Set.lua +120 -118
- package/dist/lualib/SetDescriptor.lua +67 -64
- package/dist/lualib/SourceMapTraceBack.lua +7 -6
- package/dist/lualib/SparseArrayNew.lua +1 -1
- package/dist/lualib/SparseArrayPush.lua +1 -1
- package/dist/lualib/SparseArraySpread.lua +1 -1
- package/dist/lualib/Spread.lua +1 -1
- package/dist/lualib/StringAccess.lua +1 -1
- package/dist/lualib/StringCharAt.lua +1 -1
- package/dist/lualib/StringCharCodeAt.lua +1 -1
- package/dist/lualib/StringConcat.lua +1 -1
- package/dist/lualib/StringEndsWith.lua +1 -1
- package/dist/lualib/StringIncludes.lua +1 -1
- package/dist/lualib/StringPadEnd.lua +1 -1
- package/dist/lualib/StringPadStart.lua +1 -1
- package/dist/lualib/StringReplace.lua +2 -2
- package/dist/lualib/StringReplaceAll.lua +4 -4
- package/dist/lualib/StringSlice.lua +1 -1
- package/dist/lualib/StringSplit.lua +1 -1
- package/dist/lualib/StringStartsWith.lua +1 -1
- package/dist/lualib/StringSubstr.lua +1 -1
- package/dist/lualib/StringSubstring.lua +1 -1
- package/dist/lualib/StringTrim.lua +1 -1
- package/dist/lualib/StringTrimEnd.lua +1 -1
- package/dist/lualib/StringTrimStart.lua +1 -1
- package/dist/lualib/Symbol.lua +14 -11
- package/dist/lualib/SymbolRegistry.lua +13 -10
- package/dist/lualib/TypeOf.lua +1 -1
- package/dist/lualib/Unpack.lua +1 -1
- package/dist/lualib/WeakMap.lua +41 -39
- package/dist/lualib/WeakSet.lua +37 -35
- package/dist/lualib/lualib_bundle.lua +1096 -932
- package/dist/lualib/lualib_module_info.json +628 -0
- package/dist/lualib-build/plugin.d.ts +23 -0
- package/dist/lualib-build/plugin.js +138 -0
- package/dist/lualib-build/util.d.ts +19 -0
- package/dist/lualib-build/util.js +43 -0
- package/dist/transformation/builtins/array.d.ts +1 -1
- package/dist/transformation/builtins/array.js +5 -0
- package/dist/transformation/builtins/function.js +2 -1
- package/dist/transformation/builtins/index.d.ts +1 -0
- package/dist/transformation/builtins/index.js +63 -16
- package/dist/transformation/context/index.js +5 -1
- package/dist/transformation/utils/diagnostics.d.ts +3 -0
- package/dist/transformation/utils/diagnostics.js +2 -1
- package/dist/transformation/utils/typescript/index.js +5 -1
- package/dist/transformation/utils/typescript/types.d.ts +2 -0
- package/dist/transformation/utils/typescript/types.js +10 -1
- package/dist/transformation/visitors/class/index.js +1 -5
- package/dist/transformation/visitors/class/new.d.ts +1 -2
- package/dist/transformation/visitors/class/new.js +1 -40
- package/dist/transformation/visitors/conditional.js +15 -14
- package/dist/transformation/visitors/identifier.js +5 -0
- package/dist/transformation/visitors/literal.js +22 -0
- package/dist/transformation/visitors/modules/import.js +4 -14
- package/dist/transpilation/bundle.js +1 -1
- package/dist/transpilation/index.js +5 -1
- package/dist/transpilation/plugins.d.ts +19 -1
- package/dist/transpilation/plugins.js +6 -2
- package/dist/transpilation/resolve.js +2 -2
- package/dist/transpilation/transpile.d.ts +1 -1
- package/dist/transpilation/transpile.js +13 -5
- package/dist/transpilation/transpiler.js +25 -11
- package/dist/transpilation/utils.d.ts +2 -0
- package/package.json +12 -11
- package/CHANGELOG.md +0 -703
|
@@ -17,6 +17,7 @@ export interface LuaPluginImport {
|
|
|
17
17
|
}
|
|
18
18
|
export declare type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & {
|
|
19
19
|
buildMode?: BuildMode;
|
|
20
|
+
extension?: string;
|
|
20
21
|
luaBundle?: string;
|
|
21
22
|
luaBundleEntry?: string;
|
|
22
23
|
luaTarget?: LuaTarget;
|
|
@@ -32,7 +33,6 @@ export declare type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & {
|
|
|
32
33
|
};
|
|
33
34
|
export declare enum LuaLibImportKind {
|
|
34
35
|
None = "none",
|
|
35
|
-
Always = "always",
|
|
36
36
|
Inline = "inline",
|
|
37
37
|
Require = "require"
|
|
38
38
|
}
|
package/dist/CompilerOptions.js
CHANGED
|
@@ -6,7 +6,6 @@ const diagnosticFactories = require("./transpilation/diagnostics");
|
|
|
6
6
|
var LuaLibImportKind;
|
|
7
7
|
(function (LuaLibImportKind) {
|
|
8
8
|
LuaLibImportKind["None"] = "none";
|
|
9
|
-
LuaLibImportKind["Always"] = "always";
|
|
10
9
|
LuaLibImportKind["Inline"] = "inline";
|
|
11
10
|
LuaLibImportKind["Require"] = "require";
|
|
12
11
|
})(LuaLibImportKind = exports.LuaLibImportKind || (exports.LuaLibImportKind = {}));
|
package/dist/LuaLib.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EmitHost } from "./transpilation";
|
|
2
|
+
import * as lua from "./LuaAST";
|
|
2
3
|
export declare enum LuaLibFeature {
|
|
3
4
|
ArrayConcat = "ArrayConcat",
|
|
4
5
|
ArrayEntries = "ArrayEntries",
|
|
@@ -7,6 +8,7 @@ export declare enum LuaLibFeature {
|
|
|
7
8
|
ArrayForEach = "ArrayForEach",
|
|
8
9
|
ArrayFind = "ArrayFind",
|
|
9
10
|
ArrayFindIndex = "ArrayFindIndex",
|
|
11
|
+
ArrayFrom = "ArrayFrom",
|
|
10
12
|
ArrayIncludes = "ArrayIncludes",
|
|
11
13
|
ArrayIndexOf = "ArrayIndexOf",
|
|
12
14
|
ArrayIsArray = "ArrayIsArray",
|
|
@@ -96,5 +98,15 @@ export declare enum LuaLibFeature {
|
|
|
96
98
|
TypeOf = "TypeOf",
|
|
97
99
|
Unpack = "Unpack"
|
|
98
100
|
}
|
|
99
|
-
export
|
|
101
|
+
export interface LuaLibFeatureInfo {
|
|
102
|
+
dependencies?: LuaLibFeature[];
|
|
103
|
+
exports: string[];
|
|
104
|
+
}
|
|
105
|
+
export declare type LuaLibModulesInfo = Record<LuaLibFeature, LuaLibFeatureInfo>;
|
|
106
|
+
export declare const luaLibModulesInfoFileName = "lualib_module_info.json";
|
|
107
|
+
export declare function getLuaLibModulesInfo(emitHost: EmitHost): LuaLibModulesInfo;
|
|
108
|
+
export declare function readLuaLibFeature(feature: LuaLibFeature, emitHost: EmitHost): string;
|
|
109
|
+
export declare function resolveRecursiveLualibFeatures(features: Iterable<LuaLibFeature>, emitHost: EmitHost, luaLibModulesInfo?: LuaLibModulesInfo): LuaLibFeature[];
|
|
110
|
+
export declare function loadInlineLualibFeatures(features: Iterable<LuaLibFeature>, emitHost: EmitHost): string;
|
|
111
|
+
export declare function loadImportedLualibFeatures(features: Iterable<LuaLibFeature>, emitHost: EmitHost): lua.Statement[];
|
|
100
112
|
export declare function getLuaLibBundle(emitHost: EmitHost): string;
|
package/dist/LuaLib.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLuaLibBundle = exports.
|
|
3
|
+
exports.getLuaLibBundle = exports.loadImportedLualibFeatures = exports.loadInlineLualibFeatures = exports.resolveRecursiveLualibFeatures = exports.readLuaLibFeature = exports.getLuaLibModulesInfo = exports.luaLibModulesInfoFileName = exports.LuaLibFeature = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
|
+
const lua = require("./LuaAST");
|
|
5
6
|
var LuaLibFeature;
|
|
6
7
|
(function (LuaLibFeature) {
|
|
7
8
|
LuaLibFeature["ArrayConcat"] = "ArrayConcat";
|
|
@@ -11,6 +12,7 @@ var LuaLibFeature;
|
|
|
11
12
|
LuaLibFeature["ArrayForEach"] = "ArrayForEach";
|
|
12
13
|
LuaLibFeature["ArrayFind"] = "ArrayFind";
|
|
13
14
|
LuaLibFeature["ArrayFindIndex"] = "ArrayFindIndex";
|
|
15
|
+
LuaLibFeature["ArrayFrom"] = "ArrayFrom";
|
|
14
16
|
LuaLibFeature["ArrayIncludes"] = "ArrayIncludes";
|
|
15
17
|
LuaLibFeature["ArrayIndexOf"] = "ArrayIndexOf";
|
|
16
18
|
LuaLibFeature["ArrayIsArray"] = "ArrayIsArray";
|
|
@@ -100,84 +102,79 @@ var LuaLibFeature;
|
|
|
100
102
|
LuaLibFeature["TypeOf"] = "TypeOf";
|
|
101
103
|
LuaLibFeature["Unpack"] = "Unpack";
|
|
102
104
|
})(LuaLibFeature = exports.LuaLibFeature || (exports.LuaLibFeature = {}));
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
PromiseAny: [
|
|
130
|
-
LuaLibFeature.ArrayPush,
|
|
131
|
-
LuaLibFeature.InstanceOf,
|
|
132
|
-
LuaLibFeature.New,
|
|
133
|
-
LuaLibFeature.Promise,
|
|
134
|
-
LuaLibFeature.Iterator,
|
|
135
|
-
],
|
|
136
|
-
PromiseRace: [
|
|
137
|
-
LuaLibFeature.ArrayPush,
|
|
138
|
-
LuaLibFeature.InstanceOf,
|
|
139
|
-
LuaLibFeature.New,
|
|
140
|
-
LuaLibFeature.Promise,
|
|
141
|
-
LuaLibFeature.Iterator,
|
|
142
|
-
],
|
|
143
|
-
ParseFloat: [LuaLibFeature.StringAccess],
|
|
144
|
-
ParseInt: [LuaLibFeature.StringSubstr, LuaLibFeature.StringSubstring],
|
|
145
|
-
SetDescriptor: [LuaLibFeature.CloneDescriptor],
|
|
146
|
-
Spread: [LuaLibFeature.Iterator, LuaLibFeature.StringAccess, LuaLibFeature.Unpack],
|
|
147
|
-
StringSplit: [LuaLibFeature.StringSubstring, LuaLibFeature.StringAccess],
|
|
148
|
-
SymbolRegistry: [LuaLibFeature.Symbol],
|
|
149
|
-
Map: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
|
|
150
|
-
Set: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
|
|
151
|
-
WeakMap: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
|
|
152
|
-
WeakSet: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
|
|
153
|
-
};
|
|
154
|
-
/* eslint-enable @typescript-eslint/naming-convention */
|
|
155
|
-
function loadLuaLibFeatures(features, emitHost) {
|
|
156
|
-
let result = "";
|
|
105
|
+
exports.luaLibModulesInfoFileName = "lualib_module_info.json";
|
|
106
|
+
let luaLibModulesInfo;
|
|
107
|
+
function getLuaLibModulesInfo(emitHost) {
|
|
108
|
+
if (luaLibModulesInfo === undefined) {
|
|
109
|
+
const lualibPath = path.resolve(__dirname, `../dist/lualib/${exports.luaLibModulesInfoFileName}`);
|
|
110
|
+
const result = emitHost.readFile(lualibPath);
|
|
111
|
+
if (result !== undefined) {
|
|
112
|
+
luaLibModulesInfo = JSON.parse(result);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
throw new Error(`Could not load lualib dependencies from '${lualibPath}'`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return luaLibModulesInfo;
|
|
119
|
+
}
|
|
120
|
+
exports.getLuaLibModulesInfo = getLuaLibModulesInfo;
|
|
121
|
+
function readLuaLibFeature(feature, emitHost) {
|
|
122
|
+
const featurePath = path.resolve(__dirname, `../dist/lualib/${feature}.lua`);
|
|
123
|
+
const luaLibFeature = emitHost.readFile(featurePath);
|
|
124
|
+
if (luaLibFeature === undefined) {
|
|
125
|
+
throw new Error(`Could not load lualib feature from '${featurePath}'`);
|
|
126
|
+
}
|
|
127
|
+
return luaLibFeature;
|
|
128
|
+
}
|
|
129
|
+
exports.readLuaLibFeature = readLuaLibFeature;
|
|
130
|
+
function resolveRecursiveLualibFeatures(features, emitHost, luaLibModulesInfo = getLuaLibModulesInfo(emitHost)) {
|
|
157
131
|
const loadedFeatures = new Set();
|
|
132
|
+
const result = [];
|
|
158
133
|
function load(feature) {
|
|
134
|
+
var _a;
|
|
159
135
|
if (loadedFeatures.has(feature))
|
|
160
136
|
return;
|
|
161
137
|
loadedFeatures.add(feature);
|
|
162
|
-
const dependencies =
|
|
138
|
+
const dependencies = (_a = luaLibModulesInfo[feature]) === null || _a === void 0 ? void 0 : _a.dependencies;
|
|
163
139
|
if (dependencies) {
|
|
164
140
|
dependencies.forEach(load);
|
|
165
141
|
}
|
|
166
|
-
|
|
167
|
-
const luaLibFeature = emitHost.readFile(featurePath);
|
|
168
|
-
if (luaLibFeature !== undefined) {
|
|
169
|
-
result += luaLibFeature + "\n";
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
throw new Error(`Could not load lualib feature from '${featurePath}'`);
|
|
173
|
-
}
|
|
142
|
+
result.push(feature);
|
|
174
143
|
}
|
|
175
144
|
for (const feature of features) {
|
|
176
145
|
load(feature);
|
|
177
146
|
}
|
|
178
147
|
return result;
|
|
179
148
|
}
|
|
180
|
-
exports.
|
|
149
|
+
exports.resolveRecursiveLualibFeatures = resolveRecursiveLualibFeatures;
|
|
150
|
+
function loadInlineLualibFeatures(features, emitHost) {
|
|
151
|
+
let result = "";
|
|
152
|
+
for (const feature of resolveRecursiveLualibFeatures(features, emitHost)) {
|
|
153
|
+
const luaLibFeature = readLuaLibFeature(feature, emitHost);
|
|
154
|
+
result += luaLibFeature + "\n";
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
exports.loadInlineLualibFeatures = loadInlineLualibFeatures;
|
|
159
|
+
function loadImportedLualibFeatures(features, emitHost) {
|
|
160
|
+
const luaLibModuleInfo = getLuaLibModulesInfo(emitHost);
|
|
161
|
+
const imports = Array.from(features).flatMap(feature => luaLibModuleInfo[feature].exports);
|
|
162
|
+
const requireCall = lua.createCallExpression(lua.createIdentifier("require"), [
|
|
163
|
+
lua.createStringLiteral("lualib_bundle"),
|
|
164
|
+
]);
|
|
165
|
+
if (imports.length === 0) {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
const luaLibId = lua.createIdentifier("____lualib");
|
|
169
|
+
const importStatement = lua.createVariableDeclarationStatement(luaLibId, requireCall);
|
|
170
|
+
const statements = [importStatement];
|
|
171
|
+
// local <export> = ____luaLib.<export>
|
|
172
|
+
for (const item of imports) {
|
|
173
|
+
statements.push(lua.createVariableDeclarationStatement(lua.createIdentifier(item), lua.createTableIndexExpression(luaLibId, lua.createStringLiteral(item))));
|
|
174
|
+
}
|
|
175
|
+
return statements;
|
|
176
|
+
}
|
|
177
|
+
exports.loadImportedLualibFeatures = loadImportedLualibFeatures;
|
|
181
178
|
let luaLibBundleContent;
|
|
182
179
|
function getLuaLibBundle(emitHost) {
|
|
183
180
|
if (luaLibBundleContent === undefined) {
|
package/dist/LuaPrinter.js
CHANGED
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LuaPrinter = exports.createPrinter = exports.tstlHeader = exports.escapeString = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const source_map_1 = require("source-map");
|
|
6
|
-
const _1 = require(".");
|
|
7
6
|
const CompilerOptions_1 = require("./CompilerOptions");
|
|
8
7
|
const lua = require("./LuaAST");
|
|
9
8
|
const LuaLib_1 = require("./LuaLib");
|
|
10
9
|
const safe_names_1 = require("./transformation/utils/safe-names");
|
|
10
|
+
const transpilation_1 = require("./transpilation");
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
12
|
// https://www.lua.org/pil/2.4.html
|
|
13
13
|
// https://www.ecma-international.org/ecma-262/10.0/index.html#table-34
|
|
@@ -79,7 +79,7 @@ class LuaPrinter {
|
|
|
79
79
|
this.sourceFile = sourceFile;
|
|
80
80
|
this.currentIndent = "";
|
|
81
81
|
this.options = program.getCompilerOptions();
|
|
82
|
-
this.luaFile = (0, utils_1.normalizeSlashes)((0,
|
|
82
|
+
this.luaFile = (0, utils_1.normalizeSlashes)((0, transpilation_1.getEmitPath)(this.sourceFile, this.program));
|
|
83
83
|
// Source nodes contain relative path from mapped lua file to original TS source file
|
|
84
84
|
this.relativeSourcePath = (0, utils_1.normalizeSlashes)(path.relative(path.dirname(this.luaFile), this.sourceFile));
|
|
85
85
|
}
|
|
@@ -129,27 +129,28 @@ class LuaPrinter {
|
|
|
129
129
|
}
|
|
130
130
|
printFile(file) {
|
|
131
131
|
var _a;
|
|
132
|
-
let
|
|
132
|
+
let sourceChunks = [file.trivia];
|
|
133
133
|
if (!this.options.noHeader) {
|
|
134
|
-
|
|
134
|
+
sourceChunks.push(exports.tstlHeader);
|
|
135
135
|
}
|
|
136
136
|
const luaLibImport = (_a = this.options.luaLibImport) !== null && _a !== void 0 ? _a : CompilerOptions_1.LuaLibImportKind.Require;
|
|
137
|
-
if (luaLibImport === CompilerOptions_1.LuaLibImportKind.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
header += 'require("lualib_bundle");\n';
|
|
137
|
+
if (luaLibImport === CompilerOptions_1.LuaLibImportKind.Require && file.luaLibFeatures.size > 0) {
|
|
138
|
+
// Import lualib features
|
|
139
|
+
sourceChunks = this.printStatementArray((0, LuaLib_1.loadImportedLualibFeatures)(file.luaLibFeatures, this.emitHost));
|
|
141
140
|
}
|
|
142
141
|
else if (luaLibImport === CompilerOptions_1.LuaLibImportKind.Inline && file.luaLibFeatures.size > 0) {
|
|
143
142
|
// Inline lualib features
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
sourceChunks.push("-- Lua Library inline imports\n");
|
|
144
|
+
sourceChunks.push((0, LuaLib_1.loadInlineLualibFeatures)(file.luaLibFeatures, this.emitHost));
|
|
146
145
|
}
|
|
147
146
|
if (this.options.sourceMapTraceback && !(0, CompilerOptions_1.isBundleEnabled)(this.options)) {
|
|
148
147
|
// In bundle mode the traceback is being generated for the entire file in getBundleResult
|
|
149
148
|
// Otherwise, traceback is being generated locally
|
|
150
|
-
|
|
149
|
+
sourceChunks.push(`${LuaPrinter.sourceMapTracebackPlaceholder}\n`);
|
|
151
150
|
}
|
|
152
|
-
|
|
151
|
+
// Print reest of the statements in file
|
|
152
|
+
sourceChunks.push(...this.printStatementArray(file.statements));
|
|
153
|
+
return this.concatNodes(...sourceChunks);
|
|
153
154
|
}
|
|
154
155
|
pushIndent() {
|
|
155
156
|
this.currentIndent += " ";
|
package/dist/cli/parse.js
CHANGED
|
@@ -11,6 +11,11 @@ exports.optionDeclarations = [
|
|
|
11
11
|
type: "enum",
|
|
12
12
|
choices: Object.values(CompilerOptions_1.BuildMode),
|
|
13
13
|
},
|
|
14
|
+
{
|
|
15
|
+
name: "extension",
|
|
16
|
+
description: 'File extension for the resulting Lua files. Defaults to ".lua"',
|
|
17
|
+
type: "string",
|
|
18
|
+
},
|
|
14
19
|
{
|
|
15
20
|
name: "luaBundle",
|
|
16
21
|
description: "The name of the lua file to bundle output lua to. Requires luaBundleEntry.",
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
function __TS__ArrayEvery(arr, callbackfn)
|
|
1
|
+
local function __TS__ArrayEvery(arr, callbackfn)
|
|
2
2
|
do
|
|
3
3
|
local i = 0
|
|
4
4
|
while i < #arr do
|
|
5
|
-
if not callbackfn(
|
|
5
|
+
if not callbackfn(nil, arr[i + 1], i, arr) then
|
|
6
6
|
return false
|
|
7
7
|
end
|
|
8
8
|
i = i + 1
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function __TS__ArrayFilter(arr, callbackfn)
|
|
1
|
+
local function __TS__ArrayFilter(arr, callbackfn)
|
|
2
2
|
local result = {}
|
|
3
3
|
do
|
|
4
4
|
local i = 0
|
|
5
5
|
while i < #arr do
|
|
6
|
-
if callbackfn(
|
|
6
|
+
if callbackfn(nil, arr[i + 1], i, arr) then
|
|
7
7
|
result[#result + 1] = arr[i + 1]
|
|
8
8
|
end
|
|
9
9
|
i = i + 1
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function __TS__ArrayFind(arr, predicate)
|
|
1
|
+
local function __TS__ArrayFind(arr, predicate)
|
|
2
2
|
local len = #arr
|
|
3
3
|
local k = 0
|
|
4
4
|
while k < len do
|
|
5
5
|
local elem = arr[k + 1]
|
|
6
|
-
if predicate(
|
|
6
|
+
if predicate(nil, elem, k, arr) then
|
|
7
7
|
return elem
|
|
8
8
|
end
|
|
9
9
|
k = k + 1
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function __TS__ArrayFindIndex(arr, callbackFn)
|
|
1
|
+
local function __TS__ArrayFindIndex(arr, callbackFn)
|
|
2
2
|
do
|
|
3
3
|
local i = 0
|
|
4
4
|
local len = #arr
|
|
5
5
|
while i < len do
|
|
6
|
-
if callbackFn(
|
|
6
|
+
if callbackFn(nil, arr[i + 1], i, arr) then
|
|
7
7
|
return i
|
|
8
8
|
end
|
|
9
9
|
i = i + 1
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function __TS__ArrayFlatMap(array, callback)
|
|
1
|
+
local function __TS__ArrayFlatMap(array, callback)
|
|
2
2
|
local result = {}
|
|
3
3
|
do
|
|
4
4
|
local i = 0
|
|
5
5
|
while i < #array do
|
|
6
|
-
local value = callback(
|
|
6
|
+
local value = callback(nil, array[i + 1], i, array)
|
|
7
7
|
if type(value) == "table" and __TS__ArrayIsArray(value) then
|
|
8
8
|
result = __TS__ArrayConcat(result, value)
|
|
9
9
|
else
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
local __TS__ArrayFrom
|
|
2
|
+
do
|
|
3
|
+
local function arrayLikeStep(self, index)
|
|
4
|
+
index = index + 1
|
|
5
|
+
if index > self.length then
|
|
6
|
+
return
|
|
7
|
+
end
|
|
8
|
+
return index, self[index]
|
|
9
|
+
end
|
|
10
|
+
local function arrayLikeIterator(arr)
|
|
11
|
+
if type(arr.length) == "number" then
|
|
12
|
+
return arrayLikeStep, arr, 0
|
|
13
|
+
end
|
|
14
|
+
return __TS__Iterator(arr)
|
|
15
|
+
end
|
|
16
|
+
function __TS__ArrayFrom(arrayLike, mapFn, thisArg)
|
|
17
|
+
local result = {}
|
|
18
|
+
if mapFn == nil then
|
|
19
|
+
for ____, v in arrayLikeIterator(arrayLike) do
|
|
20
|
+
__TS__ArrayPush(result, v)
|
|
21
|
+
end
|
|
22
|
+
else
|
|
23
|
+
for i, v in arrayLikeIterator(arrayLike) do
|
|
24
|
+
__TS__ArrayPush(
|
|
25
|
+
result,
|
|
26
|
+
mapFn(thisArg, v, i - 1)
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
return result
|
|
31
|
+
end
|
|
32
|
+
end
|
package/dist/lualib/ArrayMap.lua
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function __TS__ArrayMap(arr, callbackfn)
|
|
1
|
+
local function __TS__ArrayMap(arr, callbackfn)
|
|
2
2
|
local newArray = {}
|
|
3
3
|
do
|
|
4
4
|
local i = 0
|
|
5
5
|
while i < #arr do
|
|
6
|
-
newArray[i + 1] = callbackfn(
|
|
6
|
+
newArray[i + 1] = callbackfn(nil, arr[i + 1], i, arr)
|
|
7
7
|
i = i + 1
|
|
8
8
|
end
|
|
9
9
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function __TS__ArrayReduce(arr, callbackFn, ...)
|
|
1
|
+
local function __TS__ArrayReduce(arr, callbackFn, ...)
|
|
2
2
|
local len = #arr
|
|
3
3
|
local k = 0
|
|
4
4
|
local accumulator = nil
|
|
@@ -12,7 +12,7 @@ function __TS__ArrayReduce(arr, callbackFn, ...)
|
|
|
12
12
|
end
|
|
13
13
|
for i = k, len - 1 do
|
|
14
14
|
accumulator = callbackFn(
|
|
15
|
-
|
|
15
|
+
nil,
|
|
16
16
|
accumulator,
|
|
17
17
|
arr[i + 1],
|
|
18
18
|
i,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function __TS__ArrayReduceRight(arr, callbackFn, ...)
|
|
1
|
+
local function __TS__ArrayReduceRight(arr, callbackFn, ...)
|
|
2
2
|
local len = #arr
|
|
3
3
|
local k = len - 1
|
|
4
4
|
local accumulator = nil
|
|
@@ -12,7 +12,7 @@ function __TS__ArrayReduceRight(arr, callbackFn, ...)
|
|
|
12
12
|
end
|
|
13
13
|
for i = k, 0, -1 do
|
|
14
14
|
accumulator = callbackFn(
|
|
15
|
-
|
|
15
|
+
nil,
|
|
16
16
|
accumulator,
|
|
17
17
|
arr[i + 1],
|
|
18
18
|
i,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
function __TS__ArraySort(arr, compareFn)
|
|
1
|
+
local function __TS__ArraySort(arr, compareFn)
|
|
2
2
|
if compareFn ~= nil then
|
|
3
3
|
table.sort(
|
|
4
4
|
arr,
|
|
5
|
-
function(a, b) return compareFn(
|
|
5
|
+
function(a, b) return compareFn(nil, a, b) < 0 end
|
|
6
6
|
)
|
|
7
7
|
else
|
|
8
8
|
table.sort(arr)
|