typescript-to-lua 1.3.4 → 1.4.2

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.
Files changed (139) hide show
  1. package/dist/CompilerOptions.d.ts +1 -1
  2. package/dist/CompilerOptions.js +0 -1
  3. package/dist/LuaLib.d.ts +13 -1
  4. package/dist/LuaLib.js +62 -65
  5. package/dist/LuaPrinter.js +13 -12
  6. package/dist/cli/parse.js +5 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +5 -1
  9. package/dist/lualib/ArrayConcat.lua +1 -1
  10. package/dist/lualib/ArrayEntries.lua +1 -1
  11. package/dist/lualib/ArrayEvery.lua +2 -2
  12. package/dist/lualib/ArrayFilter.lua +2 -2
  13. package/dist/lualib/ArrayFind.lua +2 -2
  14. package/dist/lualib/ArrayFindIndex.lua +2 -2
  15. package/dist/lualib/ArrayFlat.lua +1 -1
  16. package/dist/lualib/ArrayFlatMap.lua +2 -2
  17. package/dist/lualib/ArrayForEach.lua +2 -2
  18. package/dist/lualib/ArrayFrom.lua +32 -0
  19. package/dist/lualib/ArrayIncludes.lua +1 -1
  20. package/dist/lualib/ArrayIndexOf.lua +1 -1
  21. package/dist/lualib/ArrayIsArray.lua +1 -1
  22. package/dist/lualib/ArrayJoin.lua +1 -1
  23. package/dist/lualib/ArrayMap.lua +2 -2
  24. package/dist/lualib/ArrayPush.lua +1 -1
  25. package/dist/lualib/ArrayReduce.lua +2 -2
  26. package/dist/lualib/ArrayReduceRight.lua +2 -2
  27. package/dist/lualib/ArrayReverse.lua +1 -1
  28. package/dist/lualib/ArraySetLength.lua +1 -1
  29. package/dist/lualib/ArrayShift.lua +1 -1
  30. package/dist/lualib/ArraySlice.lua +1 -1
  31. package/dist/lualib/ArraySome.lua +2 -2
  32. package/dist/lualib/ArraySort.lua +2 -2
  33. package/dist/lualib/ArraySplice.lua +1 -1
  34. package/dist/lualib/ArrayToObject.lua +1 -1
  35. package/dist/lualib/ArrayUnshift.lua +1 -1
  36. package/dist/lualib/Await.lua +13 -13
  37. package/dist/lualib/Class.lua +1 -1
  38. package/dist/lualib/ClassExtends.lua +1 -1
  39. package/dist/lualib/CloneDescriptor.lua +1 -1
  40. package/dist/lualib/Decorate.lua +5 -5
  41. package/dist/lualib/DecorateParam.lua +2 -2
  42. package/dist/lualib/DelegatedYield.lua +1 -1
  43. package/dist/lualib/Delete.lua +1 -1
  44. package/dist/lualib/Error.lua +68 -69
  45. package/dist/lualib/FunctionBind.lua +1 -1
  46. package/dist/lualib/Generator.lua +26 -23
  47. package/dist/lualib/InstanceOf.lua +1 -1
  48. package/dist/lualib/InstanceOfObject.lua +1 -1
  49. package/dist/lualib/Iterator.lua +35 -32
  50. package/dist/lualib/Map.lua +131 -129
  51. package/dist/lualib/MathAtan2.lua +1 -1
  52. package/dist/lualib/MathSign.lua +1 -1
  53. package/dist/lualib/New.lua +1 -1
  54. package/dist/lualib/Number.lua +1 -1
  55. package/dist/lualib/NumberIsFinite.lua +1 -1
  56. package/dist/lualib/NumberIsNaN.lua +1 -1
  57. package/dist/lualib/NumberToString.lua +42 -39
  58. package/dist/lualib/ObjectAssign.lua +1 -1
  59. package/dist/lualib/ObjectDefineProperty.lua +1 -1
  60. package/dist/lualib/ObjectEntries.lua +1 -1
  61. package/dist/lualib/ObjectFromEntries.lua +1 -1
  62. package/dist/lualib/ObjectGetOwnPropertyDescriptor.lua +1 -1
  63. package/dist/lualib/ObjectGetOwnPropertyDescriptors.lua +1 -1
  64. package/dist/lualib/ObjectKeys.lua +1 -1
  65. package/dist/lualib/ObjectRest.lua +1 -1
  66. package/dist/lualib/ObjectValues.lua +1 -1
  67. package/dist/lualib/ParseFloat.lua +1 -1
  68. package/dist/lualib/ParseInt.lua +39 -36
  69. package/dist/lualib/Promise.lua +148 -152
  70. package/dist/lualib/PromiseAll.lua +5 -5
  71. package/dist/lualib/PromiseAllSettled.lua +5 -5
  72. package/dist/lualib/PromiseAny.lua +5 -5
  73. package/dist/lualib/PromiseRace.lua +5 -5
  74. package/dist/lualib/Set.lua +120 -118
  75. package/dist/lualib/SetDescriptor.lua +67 -64
  76. package/dist/lualib/SourceMapTraceBack.lua +7 -6
  77. package/dist/lualib/SparseArrayNew.lua +1 -1
  78. package/dist/lualib/SparseArrayPush.lua +1 -1
  79. package/dist/lualib/SparseArraySpread.lua +1 -1
  80. package/dist/lualib/Spread.lua +1 -1
  81. package/dist/lualib/StringAccess.lua +1 -1
  82. package/dist/lualib/StringCharAt.lua +1 -1
  83. package/dist/lualib/StringCharCodeAt.lua +1 -1
  84. package/dist/lualib/StringConcat.lua +1 -1
  85. package/dist/lualib/StringEndsWith.lua +1 -1
  86. package/dist/lualib/StringIncludes.lua +1 -1
  87. package/dist/lualib/StringPadEnd.lua +1 -1
  88. package/dist/lualib/StringPadStart.lua +1 -1
  89. package/dist/lualib/StringReplace.lua +2 -2
  90. package/dist/lualib/StringReplaceAll.lua +4 -4
  91. package/dist/lualib/StringSlice.lua +1 -1
  92. package/dist/lualib/StringSplit.lua +1 -1
  93. package/dist/lualib/StringStartsWith.lua +1 -1
  94. package/dist/lualib/StringSubstr.lua +1 -1
  95. package/dist/lualib/StringSubstring.lua +1 -1
  96. package/dist/lualib/StringTrim.lua +1 -1
  97. package/dist/lualib/StringTrimEnd.lua +1 -1
  98. package/dist/lualib/StringTrimStart.lua +1 -1
  99. package/dist/lualib/Symbol.lua +14 -11
  100. package/dist/lualib/SymbolRegistry.lua +13 -10
  101. package/dist/lualib/TypeOf.lua +1 -1
  102. package/dist/lualib/Unpack.lua +1 -1
  103. package/dist/lualib/WeakMap.lua +41 -39
  104. package/dist/lualib/WeakSet.lua +37 -35
  105. package/dist/lualib/lualib_bundle.lua +1096 -932
  106. package/dist/lualib/lualib_module_info.json +628 -0
  107. package/dist/lualib-build/plugin.d.ts +23 -0
  108. package/dist/lualib-build/plugin.js +138 -0
  109. package/dist/lualib-build/util.d.ts +19 -0
  110. package/dist/lualib-build/util.js +43 -0
  111. package/dist/transformation/builtins/array.d.ts +1 -1
  112. package/dist/transformation/builtins/array.js +5 -0
  113. package/dist/transformation/builtins/function.js +2 -1
  114. package/dist/transformation/builtins/index.d.ts +1 -0
  115. package/dist/transformation/builtins/index.js +63 -16
  116. package/dist/transformation/context/index.js +5 -1
  117. package/dist/transformation/utils/diagnostics.d.ts +3 -0
  118. package/dist/transformation/utils/diagnostics.js +2 -1
  119. package/dist/transformation/utils/typescript/index.js +5 -1
  120. package/dist/transformation/utils/typescript/types.d.ts +2 -0
  121. package/dist/transformation/utils/typescript/types.js +10 -1
  122. package/dist/transformation/visitors/class/index.js +1 -5
  123. package/dist/transformation/visitors/class/new.d.ts +1 -2
  124. package/dist/transformation/visitors/class/new.js +1 -40
  125. package/dist/transformation/visitors/conditional.js +15 -14
  126. package/dist/transformation/visitors/identifier.js +5 -0
  127. package/dist/transformation/visitors/literal.js +22 -0
  128. package/dist/transformation/visitors/modules/import.js +4 -14
  129. package/dist/transpilation/bundle.js +1 -1
  130. package/dist/transpilation/index.js +5 -1
  131. package/dist/transpilation/plugins.d.ts +19 -1
  132. package/dist/transpilation/plugins.js +6 -2
  133. package/dist/transpilation/resolve.js +1 -0
  134. package/dist/transpilation/transpile.d.ts +1 -1
  135. package/dist/transpilation/transpile.js +13 -5
  136. package/dist/transpilation/transpiler.js +25 -11
  137. package/dist/transpilation/utils.d.ts +2 -0
  138. package/package.json +12 -11
  139. 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
  }
@@ -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 declare function loadLuaLibFeatures(features: Iterable<LuaLibFeature>, emitHost: EmitHost): string;
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.loadLuaLibFeatures = exports.LuaLibFeature = void 0;
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
- /* eslint-disable @typescript-eslint/naming-convention */
104
- const luaLibDependencies = {
105
- ArrayConcat: [LuaLibFeature.ArrayIsArray],
106
- ArrayFlat: [LuaLibFeature.ArrayConcat, LuaLibFeature.ArrayIsArray],
107
- ArrayFlatMap: [LuaLibFeature.ArrayConcat, LuaLibFeature.ArrayIsArray],
108
- Await: [LuaLibFeature.InstanceOf, LuaLibFeature.New, LuaLibFeature.Promise],
109
- Decorate: [LuaLibFeature.ObjectGetOwnPropertyDescriptor, LuaLibFeature.SetDescriptor, LuaLibFeature.ObjectAssign],
110
- DelegatedYield: [LuaLibFeature.StringAccess],
111
- Delete: [LuaLibFeature.ObjectGetOwnPropertyDescriptors, LuaLibFeature.Error, LuaLibFeature.New],
112
- Error: [LuaLibFeature.Class, LuaLibFeature.ClassExtends, LuaLibFeature.New],
113
- FunctionBind: [LuaLibFeature.Unpack],
114
- Generator: [LuaLibFeature.Symbol],
115
- InstanceOf: [LuaLibFeature.Symbol],
116
- Iterator: [LuaLibFeature.Symbol],
117
- NumberToString: [LuaLibFeature.StringAccess],
118
- ObjectDefineProperty: [LuaLibFeature.CloneDescriptor, LuaLibFeature.SetDescriptor],
119
- ObjectFromEntries: [LuaLibFeature.Iterator, LuaLibFeature.Symbol],
120
- Promise: [
121
- LuaLibFeature.ArrayPush,
122
- LuaLibFeature.Class,
123
- LuaLibFeature.FunctionBind,
124
- LuaLibFeature.InstanceOf,
125
- LuaLibFeature.New,
126
- ],
127
- PromiseAll: [LuaLibFeature.InstanceOf, LuaLibFeature.New, LuaLibFeature.Promise, LuaLibFeature.Iterator],
128
- PromiseAllSettled: [LuaLibFeature.InstanceOf, LuaLibFeature.New, LuaLibFeature.Promise, LuaLibFeature.Iterator],
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 = luaLibDependencies[feature];
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
- const featurePath = path.resolve(__dirname, `../dist/lualib/${feature}.lua`);
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.loadLuaLibFeatures = loadLuaLibFeatures;
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) {
@@ -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, _1.getEmitPath)(this.sourceFile, this.program));
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 header = file.trivia;
132
+ let sourceChunks = [file.trivia];
133
133
  if (!this.options.noHeader) {
134
- header += exports.tstlHeader;
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.Always ||
138
- (luaLibImport === CompilerOptions_1.LuaLibImportKind.Require && file.luaLibFeatures.size > 0)) {
139
- // Require lualib bundle
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
- header += "-- Lua Library inline imports\n";
145
- header += (0, LuaLib_1.loadLuaLibFeatures)(file.luaLibFeatures, this.emitHost);
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
- header += `${LuaPrinter.sourceMapTracebackPlaceholder}\n`;
149
+ sourceChunks.push(`${LuaPrinter.sourceMapTracebackPlaceholder}\n`);
151
150
  }
152
- return this.concatNodes(header, ...this.printStatementArray(file.statements));
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
@@ -8,3 +8,4 @@ export { LuaLibFeature } from "./LuaLib";
8
8
  export * from "./LuaPrinter";
9
9
  export * from "./transformation/context";
10
10
  export * from "./transpilation";
11
+ export { EmitHost, EmitFile, ProcessedFile } from "./transpilation/utils";
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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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,4 +1,4 @@
1
- function __TS__ArrayConcat(arr1, ...)
1
+ local function __TS__ArrayConcat(arr1, ...)
2
2
  local args = {...}
3
3
  local out = {}
4
4
  for ____, val in ipairs(arr1) do
@@ -1,4 +1,4 @@
1
- function __TS__ArrayEntries(array)
1
+ local function __TS__ArrayEntries(array)
2
2
  local key = 0
3
3
  return {
4
4
  [Symbol.iterator] = function(self)
@@ -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(_G, arr[i + 1], i, arr) then
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(_G, arr[i + 1], i, arr) then
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(_G, elem, k, arr) then
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(_G, arr[i + 1], i, arr) then
6
+ if callbackFn(nil, arr[i + 1], i, arr) then
7
7
  return i
8
8
  end
9
9
  i = i + 1
@@ -1,4 +1,4 @@
1
- function __TS__ArrayFlat(array, depth)
1
+ local function __TS__ArrayFlat(array, depth)
2
2
  if depth == nil then
3
3
  depth = 1
4
4
  end
@@ -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(_G, array[i + 1], i, array)
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
@@ -1,8 +1,8 @@
1
- function __TS__ArrayForEach(arr, callbackFn)
1
+ local function __TS__ArrayForEach(arr, callbackFn)
2
2
  do
3
3
  local i = 0
4
4
  while i < #arr do
5
- callbackFn(_G, arr[i + 1], i, arr)
5
+ callbackFn(nil, arr[i + 1], i, arr)
6
6
  i = i + 1
7
7
  end
8
8
  end
@@ -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
@@ -1,4 +1,4 @@
1
- function __TS__ArrayIncludes(self, searchElement, fromIndex)
1
+ local function __TS__ArrayIncludes(self, searchElement, fromIndex)
2
2
  if fromIndex == nil then
3
3
  fromIndex = 0
4
4
  end
@@ -1,4 +1,4 @@
1
- function __TS__ArrayIndexOf(arr, searchElement, fromIndex)
1
+ local function __TS__ArrayIndexOf(arr, searchElement, fromIndex)
2
2
  local len = #arr
3
3
  if len == 0 then
4
4
  return -1
@@ -1,3 +1,3 @@
1
- function __TS__ArrayIsArray(value)
1
+ local function __TS__ArrayIsArray(value)
2
2
  return type(value) == "table" and (value[1] ~= nil or next(value, nil) == nil)
3
3
  end
@@ -1,4 +1,4 @@
1
- function __TS__ArrayJoin(self, separator)
1
+ local function __TS__ArrayJoin(self, separator)
2
2
  if separator == nil then
3
3
  separator = ","
4
4
  end
@@ -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(_G, arr[i + 1], i, arr)
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__ArrayPush(arr, ...)
1
+ local function __TS__ArrayPush(arr, ...)
2
2
  local items = {...}
3
3
  for ____, item in ipairs(items) do
4
4
  arr[#arr + 1] = item
@@ -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
- _G,
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
- _G,
15
+ nil,
16
16
  accumulator,
17
17
  arr[i + 1],
18
18
  i,
@@ -1,4 +1,4 @@
1
- function __TS__ArrayReverse(arr)
1
+ local function __TS__ArrayReverse(arr)
2
2
  local i = 0
3
3
  local j = #arr - 1
4
4
  while i < j do
@@ -1,4 +1,4 @@
1
- function __TS__ArraySetLength(arr, length)
1
+ local function __TS__ArraySetLength(arr, 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),
@@ -1,3 +1,3 @@
1
- function __TS__ArrayShift(arr)
1
+ local function __TS__ArrayShift(arr)
2
2
  return table.remove(arr, 1)
3
3
  end
@@ -1,4 +1,4 @@
1
- function __TS__ArraySlice(list, first, last)
1
+ local function __TS__ArraySlice(list, first, last)
2
2
  local len = #list
3
3
  local relativeStart = first or 0
4
4
  local k
@@ -1,8 +1,8 @@
1
- function __TS__ArraySome(arr, callbackfn)
1
+ local function __TS__ArraySome(arr, callbackfn)
2
2
  do
3
3
  local i = 0
4
4
  while i < #arr do
5
- if callbackfn(_G, arr[i + 1], i, arr) then
5
+ if callbackfn(nil, arr[i + 1], i, arr) then
6
6
  return true
7
7
  end
8
8
  i = i + 1
@@ -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(_G, a, b) < 0 end
5
+ function(a, b) return compareFn(nil, a, b) < 0 end
6
6
  )
7
7
  else
8
8
  table.sort(arr)
@@ -1,4 +1,4 @@
1
- function __TS__ArraySplice(list, ...)
1
+ local function __TS__ArraySplice(list, ...)
2
2
  local len = #list
3
3
  local actualArgumentCount = select("#", ...)
4
4
  local start = select(1, ...)
@@ -1,4 +1,4 @@
1
- function __TS__ArrayToObject(array)
1
+ local function __TS__ArrayToObject(array)
2
2
  local object = {}
3
3
  do
4
4
  local i = 0
@@ -1,4 +1,4 @@
1
- function __TS__ArrayUnshift(arr, ...)
1
+ local function __TS__ArrayUnshift(arr, ...)
2
2
  local items = {...}
3
3
  do
4
4
  local i = #items - 1