typescript-to-lua 0.42.0 → 1.1.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/CHANGELOG.md +31 -1
- package/dist/CompilerOptions.d.ts +4 -3
- package/dist/LuaAST.js +4 -4
- package/dist/LuaLib.d.ts +7 -0
- package/dist/LuaLib.js +32 -1
- package/dist/LuaPrinter.d.ts +6 -2
- package/dist/LuaPrinter.js +25 -16
- package/dist/cli/diagnostics.js +2 -2
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +14 -0
- package/dist/cli/report.js +1 -1
- package/dist/cli/tsconfig.js +4 -4
- package/dist/lualib/Await.lua +59 -0
- package/dist/lualib/OptionalMethodCall.lua +3 -1
- package/dist/lualib/Promise.lua +172 -0
- package/dist/lualib/PromiseAll.lua +44 -0
- package/dist/lualib/PromiseAllSettled.lua +48 -0
- package/dist/lualib/PromiseAny.lua +41 -0
- package/dist/lualib/PromiseRace.lua +28 -0
- package/dist/lualib/SourceMapTraceBack.lua +20 -10
- package/dist/lualib/StringReplace.lua +8 -13
- package/dist/lualib/StringReplaceAll.lua +35 -0
- package/dist/lualib/lualib_bundle.lua +503 -62
- package/dist/transformation/builtins/array.js +29 -29
- package/dist/transformation/builtins/console.js +2 -2
- package/dist/transformation/builtins/function.js +9 -9
- package/dist/transformation/builtins/global.js +8 -8
- package/dist/transformation/builtins/index.js +35 -32
- package/dist/transformation/builtins/math.js +4 -4
- package/dist/transformation/builtins/number.js +7 -7
- package/dist/transformation/builtins/object.js +11 -11
- package/dist/transformation/builtins/promise.d.ts +7 -0
- package/dist/transformation/builtins/promise.js +46 -0
- package/dist/transformation/builtins/string.js +32 -30
- package/dist/transformation/builtins/symbol.js +3 -3
- package/dist/transformation/context/context.js +5 -5
- package/dist/transformation/index.js +1 -1
- package/dist/transformation/utils/annotations.d.ts +1 -4
- package/dist/transformation/utils/annotations.js +2 -39
- package/dist/transformation/utils/assignment-validation.js +8 -7
- package/dist/transformation/utils/diagnostics.d.ts +3 -0
- package/dist/transformation/utils/diagnostics.js +6 -5
- package/dist/transformation/utils/export.d.ts +3 -2
- package/dist/transformation/utils/export.js +14 -7
- package/dist/transformation/utils/function-context.js +19 -13
- package/dist/transformation/utils/lua-ast.js +18 -19
- package/dist/transformation/utils/lualib.js +1 -1
- package/dist/transformation/utils/safe-names.js +5 -5
- package/dist/transformation/utils/scope.d.ts +6 -0
- package/dist/transformation/utils/scope.js +70 -40
- package/dist/transformation/utils/symbols.js +6 -6
- package/dist/transformation/utils/transform.js +3 -3
- package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
- package/dist/transformation/utils/typescript/nodes.js +21 -1
- package/dist/transformation/visitors/access.js +16 -16
- package/dist/transformation/visitors/async-await.d.ts +6 -0
- package/dist/transformation/visitors/async-await.js +38 -0
- package/dist/transformation/visitors/binary-expression/assignments.js +29 -29
- package/dist/transformation/visitors/binary-expression/bit.js +4 -4
- package/dist/transformation/visitors/binary-expression/compound.js +18 -18
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +17 -17
- package/dist/transformation/visitors/binary-expression/index.js +21 -21
- package/dist/transformation/visitors/block.js +6 -6
- package/dist/transformation/visitors/break-continue.js +4 -9
- package/dist/transformation/visitors/call.js +38 -33
- package/dist/transformation/visitors/class/decorators.js +3 -3
- package/dist/transformation/visitors/class/index.js +41 -34
- package/dist/transformation/visitors/class/members/accessors.js +6 -6
- package/dist/transformation/visitors/class/members/constructor.js +7 -7
- package/dist/transformation/visitors/class/members/fields.js +6 -6
- package/dist/transformation/visitors/class/members/method.js +6 -6
- package/dist/transformation/visitors/class/new.js +13 -13
- package/dist/transformation/visitors/class/setup.js +11 -11
- package/dist/transformation/visitors/class/utils.js +2 -2
- package/dist/transformation/visitors/conditional.js +6 -6
- package/dist/transformation/visitors/delete.js +4 -4
- package/dist/transformation/visitors/enum.js +8 -8
- package/dist/transformation/visitors/errors.js +30 -31
- package/dist/transformation/visitors/expression-statement.js +10 -6
- package/dist/transformation/visitors/function.js +33 -21
- package/dist/transformation/visitors/identifier.js +25 -19
- package/dist/transformation/visitors/index.js +4 -2
- package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
- package/dist/transformation/visitors/language-extensions/multi.d.ts +1 -1
- package/dist/transformation/visitors/language-extensions/multi.js +5 -7
- package/dist/transformation/visitors/language-extensions/operators.js +6 -6
- package/dist/transformation/visitors/language-extensions/range.js +6 -6
- package/dist/transformation/visitors/language-extensions/table.js +5 -5
- package/dist/transformation/visitors/literal.d.ts +1 -2
- package/dist/transformation/visitors/literal.js +19 -42
- package/dist/transformation/visitors/loops/do-while.js +2 -2
- package/dist/transformation/visitors/loops/for-in.js +4 -4
- package/dist/transformation/visitors/loops/for-of.js +13 -13
- package/dist/transformation/visitors/loops/for.js +3 -3
- package/dist/transformation/visitors/loops/utils.js +9 -9
- package/dist/transformation/visitors/modules/export.js +13 -14
- package/dist/transformation/visitors/modules/import.js +10 -10
- package/dist/transformation/visitors/namespace.js +13 -13
- package/dist/transformation/visitors/return.d.ts +1 -0
- package/dist/transformation/visitors/return.js +41 -49
- package/dist/transformation/visitors/sourceFile.js +8 -8
- package/dist/transformation/visitors/spread.js +16 -11
- package/dist/transformation/visitors/switch.js +132 -30
- package/dist/transformation/visitors/template.js +5 -5
- package/dist/transformation/visitors/typeof.js +2 -2
- package/dist/transformation/visitors/typescript.js +1 -1
- package/dist/transformation/visitors/unary-expression.js +9 -9
- package/dist/transformation/visitors/variable-declaration.js +28 -28
- package/dist/transformation/visitors/void.d.ts +6 -0
- package/dist/transformation/visitors/void.js +23 -0
- package/dist/transpilation/bundle.d.ts +3 -0
- package/dist/transpilation/bundle.js +56 -13
- package/dist/transpilation/diagnostics.js +3 -3
- package/dist/transpilation/index.js +2 -2
- package/dist/transpilation/output-collector.js +2 -2
- package/dist/transpilation/plugins.js +1 -1
- package/dist/transpilation/resolve.js +28 -15
- package/dist/transpilation/transformers.d.ts +1 -0
- package/dist/transpilation/transformers.js +61 -25
- package/dist/transpilation/transpile.js +7 -7
- package/dist/transpilation/transpiler.js +8 -8
- package/dist/transpilation/utils.js +3 -2
- package/dist/tstl.js +8 -8
- package/dist/utils.js +2 -2
- package/package.json +15 -12
- package/dist/transformation/visitors/jsx/jsx.d.ts +0 -9
- package/dist/transformation/visitors/jsx/jsx.js +0 -237
- package/dist/transformation/visitors/jsx/xhtml.d.ts +0 -3
- package/dist/transformation/visitors/jsx/xhtml.js +0 -260
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
- **[Breaking]** We now use TypeScript's JSX transformer instead of maintaining our own. As a result, `React.createElement` now requires a self parameter, so remove `@noSelf`, `this: void` if necessary.
|
|
6
|
+
- **[Breaking(-ish)]** Due to limitations in 5.1, try/catch can no longer be used in async or generator functions when targetting Lua 5.1. This was already broken but now tstl will explicitly give an error if you try.
|
|
7
|
+
- Added support for the `switch` statement in all versions! (Before they were not supported in 5.1 and universal).
|
|
8
|
+
- Added support for `string.prototype.replaceAll` and improved `string.prototype.replace` implementation.
|
|
9
|
+
- Added `noResolvePaths` tsconfig option to disable module resolution for environment-provided modules.
|
|
10
|
+
- Implemented support for void expressions, i.e `void(0)` or `void(ignoreThisReturnValue())`.
|
|
11
|
+
- Upgraded TypeScript to 4.4.4 and made it a peer dependency to hopefully avoid plugin issues due to mismatching TypeScript versions.
|
|
12
|
+
- The `$vararg` language extension can be used to access CLI arguments, now also in bundles.
|
|
13
|
+
- Fixed a bug regarding `baseUrl` and relative imports.
|
|
14
|
+
- Fixed `sourceMapTraceback: true` not working correctly for bundles.
|
|
15
|
+
- Fixed an issue regarding hoisting in switch case clauses.
|
|
16
|
+
- Added missing function context validation cases for object literals.
|
|
17
|
+
- Fixed a problem where awaiting rejected promises in try/catch would give the wrong result.
|
|
18
|
+
- Fixed an issue where chained `.then` calls on already-resolved or already-rejected promises would cause some callbacks to not fire while they should.
|
|
19
|
+
- Fixed source file paths in source maps being absolute, they are now relative again.
|
|
20
|
+
|
|
21
|
+
## 1.0.0
|
|
22
|
+
|
|
23
|
+
- **[Breaking]** `/* @tupleReturn */` has been removed and will no longer have any effect. You will get an error if you try ot use it or if you use declarations that use it.
|
|
24
|
+
- Added support for the `Promise` class.
|
|
25
|
+
- Added support for `async` and `await` using coroutines.
|
|
26
|
+
- Module resolution now also correctly resolves `<directory>/init.lua` files for `require("<directory>")`.
|
|
27
|
+
- Fixed an error not being thrown when trying to call a method in an optional chain that does not exist. (If the method itself is not optional)
|
|
28
|
+
- Fixed a bug where parentheses could break the context parameter being resolved for a method.
|
|
29
|
+
- Fixed a bug where context parameters in object literal methods were not inferred correctly.
|
|
30
|
+
- Fixed a bug with sourceMapTraceback.
|
|
31
|
+
- Fixed TS emitting empty JSON files if you use JSON source files.
|
|
32
|
+
|
|
3
33
|
## 0.42.0
|
|
4
34
|
|
|
5
35
|
- **[Breaking]** The `/** @tupleReturn */` is now deprecated, and will be removed next release. If you are still using it, please upgrade to the [LuaMultiReturn language extension](https://typescripttolua.github.io/docs/advanced/language-extensions#luamultireturn-type).
|
|
6
|
-
- Added support for
|
|
36
|
+
- Added support for JSX, see [documentation](https://typescripttolua.github.io/docs/jsx) for more information.
|
|
7
37
|
- Added support for the `baseUrl` configuration key for module resolution.
|
|
8
38
|
|
|
9
39
|
A large list of bugfixes:
|
|
@@ -17,15 +17,16 @@ export interface LuaPluginImport {
|
|
|
17
17
|
}
|
|
18
18
|
export declare type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & {
|
|
19
19
|
buildMode?: BuildMode;
|
|
20
|
-
noImplicitSelf?: boolean;
|
|
21
|
-
noHeader?: boolean;
|
|
22
20
|
luaBundle?: string;
|
|
23
21
|
luaBundleEntry?: string;
|
|
24
22
|
luaTarget?: LuaTarget;
|
|
25
23
|
luaLibImport?: LuaLibImportKind;
|
|
26
|
-
sourceMapTraceback?: boolean;
|
|
27
24
|
luaPlugins?: LuaPluginImport[];
|
|
25
|
+
noImplicitSelf?: boolean;
|
|
26
|
+
noHeader?: boolean;
|
|
27
|
+
noResolvePaths?: string[];
|
|
28
28
|
plugins?: Array<ts.PluginImport | TransformerImport>;
|
|
29
|
+
sourceMapTraceback?: boolean;
|
|
29
30
|
tstlVerbose?: boolean;
|
|
30
31
|
[option: string]: any;
|
|
31
32
|
};
|
package/dist/LuaAST.js
CHANGED
|
@@ -162,9 +162,9 @@ function isVariableDeclarationStatement(node) {
|
|
|
162
162
|
exports.isVariableDeclarationStatement = isVariableDeclarationStatement;
|
|
163
163
|
function createVariableDeclarationStatement(left, right, tsOriginal) {
|
|
164
164
|
const statement = createNode(SyntaxKind.VariableDeclarationStatement, tsOriginal);
|
|
165
|
-
statement.left = utils_1.castArray(left);
|
|
165
|
+
statement.left = (0, utils_1.castArray)(left);
|
|
166
166
|
if (right)
|
|
167
|
-
statement.right = utils_1.castArray(right);
|
|
167
|
+
statement.right = (0, utils_1.castArray)(right);
|
|
168
168
|
return statement;
|
|
169
169
|
}
|
|
170
170
|
exports.createVariableDeclarationStatement = createVariableDeclarationStatement;
|
|
@@ -174,8 +174,8 @@ function isAssignmentStatement(node) {
|
|
|
174
174
|
exports.isAssignmentStatement = isAssignmentStatement;
|
|
175
175
|
function createAssignmentStatement(left, right, tsOriginal) {
|
|
176
176
|
const statement = createNode(SyntaxKind.AssignmentStatement, tsOriginal);
|
|
177
|
-
statement.left = utils_1.castArray(left);
|
|
178
|
-
statement.right = right ? utils_1.castArray(right) : [];
|
|
177
|
+
statement.left = (0, utils_1.castArray)(left);
|
|
178
|
+
statement.right = right ? (0, utils_1.castArray)(right) : [];
|
|
179
179
|
return statement;
|
|
180
180
|
}
|
|
181
181
|
exports.createAssignmentStatement = createAssignmentStatement;
|
package/dist/LuaLib.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export declare enum LuaLibFeature {
|
|
|
26
26
|
ArrayFlat = "ArrayFlat",
|
|
27
27
|
ArrayFlatMap = "ArrayFlatMap",
|
|
28
28
|
ArraySetLength = "ArraySetLength",
|
|
29
|
+
Await = "Await",
|
|
29
30
|
Class = "Class",
|
|
30
31
|
ClassExtends = "ClassExtends",
|
|
31
32
|
CloneDescriptor = "CloneDescriptor",
|
|
@@ -60,6 +61,11 @@ export declare enum LuaLibFeature {
|
|
|
60
61
|
OptionalMethodCall = "OptionalMethodCall",
|
|
61
62
|
ParseFloat = "ParseFloat",
|
|
62
63
|
ParseInt = "ParseInt",
|
|
64
|
+
Promise = "Promise",
|
|
65
|
+
PromiseAll = "PromiseAll",
|
|
66
|
+
PromiseAllSettled = "PromiseAllSettled",
|
|
67
|
+
PromiseAny = "PromiseAny",
|
|
68
|
+
PromiseRace = "PromiseRace",
|
|
63
69
|
Set = "Set",
|
|
64
70
|
SetDescriptor = "SetDescriptor",
|
|
65
71
|
WeakMap = "WeakMap",
|
|
@@ -75,6 +81,7 @@ export declare enum LuaLibFeature {
|
|
|
75
81
|
StringPadEnd = "StringPadEnd",
|
|
76
82
|
StringPadStart = "StringPadStart",
|
|
77
83
|
StringReplace = "StringReplace",
|
|
84
|
+
StringReplaceAll = "StringReplaceAll",
|
|
78
85
|
StringSlice = "StringSlice",
|
|
79
86
|
StringSplit = "StringSplit",
|
|
80
87
|
StringStartsWith = "StringStartsWith",
|
package/dist/LuaLib.js
CHANGED
|
@@ -30,6 +30,7 @@ var LuaLibFeature;
|
|
|
30
30
|
LuaLibFeature["ArrayFlat"] = "ArrayFlat";
|
|
31
31
|
LuaLibFeature["ArrayFlatMap"] = "ArrayFlatMap";
|
|
32
32
|
LuaLibFeature["ArraySetLength"] = "ArraySetLength";
|
|
33
|
+
LuaLibFeature["Await"] = "Await";
|
|
33
34
|
LuaLibFeature["Class"] = "Class";
|
|
34
35
|
LuaLibFeature["ClassExtends"] = "ClassExtends";
|
|
35
36
|
LuaLibFeature["CloneDescriptor"] = "CloneDescriptor";
|
|
@@ -64,6 +65,11 @@ var LuaLibFeature;
|
|
|
64
65
|
LuaLibFeature["OptionalMethodCall"] = "OptionalMethodCall";
|
|
65
66
|
LuaLibFeature["ParseFloat"] = "ParseFloat";
|
|
66
67
|
LuaLibFeature["ParseInt"] = "ParseInt";
|
|
68
|
+
LuaLibFeature["Promise"] = "Promise";
|
|
69
|
+
LuaLibFeature["PromiseAll"] = "PromiseAll";
|
|
70
|
+
LuaLibFeature["PromiseAllSettled"] = "PromiseAllSettled";
|
|
71
|
+
LuaLibFeature["PromiseAny"] = "PromiseAny";
|
|
72
|
+
LuaLibFeature["PromiseRace"] = "PromiseRace";
|
|
67
73
|
LuaLibFeature["Set"] = "Set";
|
|
68
74
|
LuaLibFeature["SetDescriptor"] = "SetDescriptor";
|
|
69
75
|
LuaLibFeature["WeakMap"] = "WeakMap";
|
|
@@ -79,6 +85,7 @@ var LuaLibFeature;
|
|
|
79
85
|
LuaLibFeature["StringPadEnd"] = "StringPadEnd";
|
|
80
86
|
LuaLibFeature["StringPadStart"] = "StringPadStart";
|
|
81
87
|
LuaLibFeature["StringReplace"] = "StringReplace";
|
|
88
|
+
LuaLibFeature["StringReplaceAll"] = "StringReplaceAll";
|
|
82
89
|
LuaLibFeature["StringSlice"] = "StringSlice";
|
|
83
90
|
LuaLibFeature["StringSplit"] = "StringSplit";
|
|
84
91
|
LuaLibFeature["StringStartsWith"] = "StringStartsWith";
|
|
@@ -97,6 +104,7 @@ const luaLibDependencies = {
|
|
|
97
104
|
ArrayConcat: [LuaLibFeature.ArrayIsArray],
|
|
98
105
|
ArrayFlat: [LuaLibFeature.ArrayConcat, LuaLibFeature.ArrayIsArray],
|
|
99
106
|
ArrayFlatMap: [LuaLibFeature.ArrayConcat, LuaLibFeature.ArrayIsArray],
|
|
107
|
+
Await: [LuaLibFeature.InstanceOf, LuaLibFeature.New],
|
|
100
108
|
Decorate: [LuaLibFeature.ObjectGetOwnPropertyDescriptor, LuaLibFeature.SetDescriptor, LuaLibFeature.ObjectAssign],
|
|
101
109
|
DelegatedYield: [LuaLibFeature.StringAccess],
|
|
102
110
|
Delete: [LuaLibFeature.ObjectGetOwnPropertyDescriptors],
|
|
@@ -108,16 +116,39 @@ const luaLibDependencies = {
|
|
|
108
116
|
NumberToString: [LuaLibFeature.StringAccess],
|
|
109
117
|
ObjectDefineProperty: [LuaLibFeature.CloneDescriptor, LuaLibFeature.SetDescriptor],
|
|
110
118
|
ObjectFromEntries: [LuaLibFeature.Iterator, LuaLibFeature.Symbol],
|
|
119
|
+
Promise: [
|
|
120
|
+
LuaLibFeature.ArrayPush,
|
|
121
|
+
LuaLibFeature.Class,
|
|
122
|
+
LuaLibFeature.FunctionBind,
|
|
123
|
+
LuaLibFeature.InstanceOf,
|
|
124
|
+
LuaLibFeature.New,
|
|
125
|
+
],
|
|
126
|
+
PromiseAll: [LuaLibFeature.InstanceOf, LuaLibFeature.New, LuaLibFeature.Promise, LuaLibFeature.Iterator],
|
|
127
|
+
PromiseAllSettled: [LuaLibFeature.InstanceOf, LuaLibFeature.New, LuaLibFeature.Promise, LuaLibFeature.Iterator],
|
|
128
|
+
PromiseAny: [
|
|
129
|
+
LuaLibFeature.ArrayPush,
|
|
130
|
+
LuaLibFeature.InstanceOf,
|
|
131
|
+
LuaLibFeature.New,
|
|
132
|
+
LuaLibFeature.Promise,
|
|
133
|
+
LuaLibFeature.Iterator,
|
|
134
|
+
],
|
|
135
|
+
PromiseRace: [
|
|
136
|
+
LuaLibFeature.ArrayPush,
|
|
137
|
+
LuaLibFeature.InstanceOf,
|
|
138
|
+
LuaLibFeature.New,
|
|
139
|
+
LuaLibFeature.Promise,
|
|
140
|
+
LuaLibFeature.Iterator,
|
|
141
|
+
],
|
|
111
142
|
ParseFloat: [LuaLibFeature.StringAccess],
|
|
112
143
|
ParseInt: [LuaLibFeature.StringSubstr, LuaLibFeature.StringSubstring],
|
|
113
144
|
SetDescriptor: [LuaLibFeature.CloneDescriptor],
|
|
145
|
+
Spread: [LuaLibFeature.Iterator, LuaLibFeature.StringAccess, LuaLibFeature.Unpack],
|
|
114
146
|
StringSplit: [LuaLibFeature.StringSubstring, LuaLibFeature.StringAccess],
|
|
115
147
|
SymbolRegistry: [LuaLibFeature.Symbol],
|
|
116
148
|
Map: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
|
|
117
149
|
Set: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
|
|
118
150
|
WeakMap: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
|
|
119
151
|
WeakSet: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
|
|
120
|
-
Spread: [LuaLibFeature.Iterator, LuaLibFeature.StringAccess, LuaLibFeature.Unpack],
|
|
121
152
|
};
|
|
122
153
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
123
154
|
function loadLuaLibFeatures(features, emitHost) {
|
package/dist/LuaPrinter.d.ts
CHANGED
|
@@ -14,11 +14,15 @@ export interface PrintResult {
|
|
|
14
14
|
export declare function createPrinter(printers: Printer[]): Printer;
|
|
15
15
|
export declare class LuaPrinter {
|
|
16
16
|
private emitHost;
|
|
17
|
+
private program;
|
|
18
|
+
private sourceFile;
|
|
17
19
|
private static operatorMap;
|
|
18
20
|
private currentIndent;
|
|
19
|
-
private
|
|
21
|
+
private luaFile;
|
|
22
|
+
private relativeSourcePath;
|
|
20
23
|
private options;
|
|
21
|
-
|
|
24
|
+
static readonly sourceMapTracebackPlaceholder = "{#SourceMapTraceback}";
|
|
25
|
+
constructor(emitHost: EmitHost, program: ts.Program, sourceFile: string);
|
|
22
26
|
print(file: lua.File): PrintResult;
|
|
23
27
|
private printInlineSourceMap;
|
|
24
28
|
private printStackTraceOverride;
|
package/dist/LuaPrinter.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LuaPrinter = exports.createPrinter = exports.tstlHeader = exports.escapeString = void 0;
|
|
4
|
+
const path = require("path");
|
|
4
5
|
const source_map_1 = require("source-map");
|
|
6
|
+
const _1 = require(".");
|
|
5
7
|
const CompilerOptions_1 = require("./CompilerOptions");
|
|
6
8
|
const lua = require("./LuaAST");
|
|
7
9
|
const LuaLib_1 = require("./LuaLib");
|
|
@@ -71,11 +73,15 @@ function createPrinter(printers) {
|
|
|
71
73
|
}
|
|
72
74
|
exports.createPrinter = createPrinter;
|
|
73
75
|
class LuaPrinter {
|
|
74
|
-
constructor(emitHost, program,
|
|
76
|
+
constructor(emitHost, program, sourceFile) {
|
|
75
77
|
this.emitHost = emitHost;
|
|
78
|
+
this.program = program;
|
|
79
|
+
this.sourceFile = sourceFile;
|
|
76
80
|
this.currentIndent = "";
|
|
77
81
|
this.options = program.getCompilerOptions();
|
|
78
|
-
this.
|
|
82
|
+
this.luaFile = (0, utils_1.normalizeSlashes)((0, _1.getEmitPath)(this.sourceFile, this.program));
|
|
83
|
+
// Source nodes contain relative path from mapped lua file to original TS source file
|
|
84
|
+
this.relativeSourcePath = (0, utils_1.normalizeSlashes)(path.relative(path.dirname(this.luaFile), this.sourceFile));
|
|
79
85
|
}
|
|
80
86
|
print(file) {
|
|
81
87
|
// Add traceback lualib if sourcemap traceback option is enabled
|
|
@@ -94,7 +100,7 @@ class LuaPrinter {
|
|
|
94
100
|
}
|
|
95
101
|
if (this.options.sourceMapTraceback) {
|
|
96
102
|
const stackTraceOverride = this.printStackTraceOverride(rootSourceNode);
|
|
97
|
-
code = code.replace(
|
|
103
|
+
code = code.replace(LuaPrinter.sourceMapTracebackPlaceholder, stackTraceOverride);
|
|
98
104
|
}
|
|
99
105
|
return { code, sourceMap: sourceMap.toString(), sourceMapNode: rootSourceNode };
|
|
100
106
|
}
|
|
@@ -136,10 +142,12 @@ class LuaPrinter {
|
|
|
136
142
|
else if (luaLibImport === CompilerOptions_1.LuaLibImportKind.Inline && file.luaLibFeatures.size > 0) {
|
|
137
143
|
// Inline lualib features
|
|
138
144
|
header += "-- Lua Library inline imports\n";
|
|
139
|
-
header += LuaLib_1.loadLuaLibFeatures(file.luaLibFeatures, this.emitHost);
|
|
145
|
+
header += (0, LuaLib_1.loadLuaLibFeatures)(file.luaLibFeatures, this.emitHost);
|
|
140
146
|
}
|
|
141
|
-
if (this.options.sourceMapTraceback) {
|
|
142
|
-
|
|
147
|
+
if (this.options.sourceMapTraceback && !(0, CompilerOptions_1.isBundleEnabled)(this.options)) {
|
|
148
|
+
// In bundle mode the traceback is being generated for the entire file in getBundleResult
|
|
149
|
+
// Otherwise, traceback is being generated locally
|
|
150
|
+
header += `${LuaPrinter.sourceMapTracebackPlaceholder}\n`;
|
|
143
151
|
}
|
|
144
152
|
return this.concatNodes(header, ...this.printStatementArray(file.statements));
|
|
145
153
|
}
|
|
@@ -155,11 +163,11 @@ class LuaPrinter {
|
|
|
155
163
|
createSourceNode(node, chunks, name) {
|
|
156
164
|
const { line, column } = lua.getOriginalPos(node);
|
|
157
165
|
return line !== undefined && column !== undefined
|
|
158
|
-
? new source_map_1.SourceNode(line + 1, column, this.
|
|
159
|
-
: new source_map_1.SourceNode(null, null, this.
|
|
166
|
+
? new source_map_1.SourceNode(line + 1, column, this.relativeSourcePath, chunks, name)
|
|
167
|
+
: new source_map_1.SourceNode(null, null, this.relativeSourcePath, chunks, name);
|
|
160
168
|
}
|
|
161
169
|
concatNodes(...chunks) {
|
|
162
|
-
return new source_map_1.SourceNode(null, null, this.
|
|
170
|
+
return new source_map_1.SourceNode(null, null, this.relativeSourcePath, chunks);
|
|
163
171
|
}
|
|
164
172
|
printBlock(block) {
|
|
165
173
|
return this.concatNodes(...this.printStatementArray(block.statements));
|
|
@@ -195,7 +203,7 @@ class LuaPrinter {
|
|
|
195
203
|
if (lua.isReturnStatement(statement))
|
|
196
204
|
break;
|
|
197
205
|
}
|
|
198
|
-
return statementNodes.length > 0 ? [...utils_1.intersperse(statementNodes, "\n"), "\n"] : [];
|
|
206
|
+
return statementNodes.length > 0 ? [...(0, utils_1.intersperse)(statementNodes, "\n"), "\n"] : [];
|
|
199
207
|
}
|
|
200
208
|
printStatement(statement) {
|
|
201
209
|
let resultNode = this.printStatementExcludingComments(statement);
|
|
@@ -422,7 +430,7 @@ class LuaPrinter {
|
|
|
422
430
|
}
|
|
423
431
|
}
|
|
424
432
|
printStringLiteral(expression) {
|
|
425
|
-
return this.createSourceNode(expression, exports.escapeString(expression.value));
|
|
433
|
+
return this.createSourceNode(expression, (0, exports.escapeString)(expression.value));
|
|
426
434
|
}
|
|
427
435
|
printNumericLiteral(expression) {
|
|
428
436
|
return this.createSourceNode(expression, String(expression.value));
|
|
@@ -486,7 +494,7 @@ class LuaPrinter {
|
|
|
486
494
|
const chunks = [];
|
|
487
495
|
const value = this.printExpression(expression.value);
|
|
488
496
|
if (expression.key) {
|
|
489
|
-
if (lua.isStringLiteral(expression.key) && safe_names_1.isValidLuaIdentifier(expression.key.value)) {
|
|
497
|
+
if (lua.isStringLiteral(expression.key) && (0, safe_names_1.isValidLuaIdentifier)(expression.key.value)) {
|
|
490
498
|
chunks.push(expression.key.value, " = ", value);
|
|
491
499
|
}
|
|
492
500
|
else {
|
|
@@ -553,7 +561,7 @@ class LuaPrinter {
|
|
|
553
561
|
printTableIndexExpression(expression) {
|
|
554
562
|
const chunks = [];
|
|
555
563
|
chunks.push(this.printExpressionInParenthesesIfNeeded(expression.table));
|
|
556
|
-
if (lua.isStringLiteral(expression.index) && safe_names_1.isValidLuaIdentifier(expression.index.value)) {
|
|
564
|
+
if (lua.isStringLiteral(expression.index) && (0, safe_names_1.isValidLuaIdentifier)(expression.index.value)) {
|
|
557
565
|
chunks.push(".", this.createSourceNode(expression.index, expression.index.value));
|
|
558
566
|
}
|
|
559
567
|
else {
|
|
@@ -562,10 +570,10 @@ class LuaPrinter {
|
|
|
562
570
|
return this.createSourceNode(expression, chunks);
|
|
563
571
|
}
|
|
564
572
|
printOperator(kind) {
|
|
565
|
-
return new source_map_1.SourceNode(null, null, this.
|
|
573
|
+
return new source_map_1.SourceNode(null, null, this.relativeSourcePath, LuaPrinter.operatorMap[kind]);
|
|
566
574
|
}
|
|
567
575
|
joinChunksWithComma(chunks) {
|
|
568
|
-
return utils_1.intersperse(chunks, ", ");
|
|
576
|
+
return (0, utils_1.intersperse)(chunks, ", ");
|
|
569
577
|
}
|
|
570
578
|
printExpressionList(expressions) {
|
|
571
579
|
const chunks = [];
|
|
@@ -588,7 +596,7 @@ class LuaPrinter {
|
|
|
588
596
|
// will not generate 'empty' mappings in the source map that point to nothing in the original TS.
|
|
589
597
|
buildSourceMap(sourceRoot, rootSourceNode) {
|
|
590
598
|
const map = new source_map_1.SourceMapGenerator({
|
|
591
|
-
file:
|
|
599
|
+
file: path.basename(this.luaFile),
|
|
592
600
|
sourceRoot,
|
|
593
601
|
});
|
|
594
602
|
let generatedLine = 1;
|
|
@@ -667,4 +675,5 @@ LuaPrinter.operatorMap = {
|
|
|
667
675
|
[lua.SyntaxKind.BitwiseLeftShiftOperator]: "<<",
|
|
668
676
|
[lua.SyntaxKind.BitwiseNotOperator]: "~",
|
|
669
677
|
};
|
|
678
|
+
LuaPrinter.sourceMapTracebackPlaceholder = "{#SourceMapTraceback}";
|
|
670
679
|
//# sourceMappingURL=LuaPrinter.js.map
|
package/dist/cli/diagnostics.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.optionBuildMustBeFirstCommandLineArgument = exports.optionCanOnlyBeSpecifiedInTsconfigJsonFile = exports.argumentForOptionMustBe = exports.compilerOptionExpectsAnArgument = exports.theSpecifiedPathDoesNotExist = exports.cannotFindATsconfigJsonAtTheSpecifiedDirectory = exports.optionProjectCannotBeMixedWithSourceFilesOnACommandLine = exports.compilerOptionRequiresAValueOfType = exports.unknownCompilerOption = exports.watchErrorSummary = exports.tstlOptionsAreMovingToTheTstlObject = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
exports.tstlOptionsAreMovingToTheTstlObject = utils_1.createSerialDiagnosticFactory((tstl) => ({
|
|
6
|
+
exports.tstlOptionsAreMovingToTheTstlObject = (0, utils_1.createSerialDiagnosticFactory)((tstl) => ({
|
|
7
7
|
category: ts.DiagnosticCategory.Warning,
|
|
8
8
|
messageText: 'TSTL options are moving to the "tstl" object. Adjust your tsconfig to look like\n' +
|
|
9
9
|
`"tstl": ${JSON.stringify(tstl, undefined, 4)}`,
|
|
@@ -19,7 +19,7 @@ const watchErrorSummary = (errorCount) => ({
|
|
|
19
19
|
: `Found ${errorCount} errors. Watching for file changes.`,
|
|
20
20
|
});
|
|
21
21
|
exports.watchErrorSummary = watchErrorSummary;
|
|
22
|
-
const createCommandLineError = (code, getMessage) => utils_1.createDiagnosticFactoryWithCode(code, (...args) => ({ messageText: getMessage(...args) }));
|
|
22
|
+
const createCommandLineError = (code, getMessage) => (0, utils_1.createDiagnosticFactoryWithCode)(code, (...args) => ({ messageText: getMessage(...args) }));
|
|
23
23
|
exports.unknownCompilerOption = createCommandLineError(5023, (name) => `Unknown compiler option '${name}'.`);
|
|
24
24
|
exports.compilerOptionRequiresAValueOfType = createCommandLineError(5024, (name, type) => `Compiler option '${name}' requires a value of type ${type}.`);
|
|
25
25
|
exports.optionProjectCannotBeMixedWithSourceFilesOnACommandLine = createCommandLineError(5042, () => "Option 'project' cannot be mixed with source files on a command line.");
|
package/dist/cli/parse.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ interface CommandLineOptionOfEnum extends CommandLineOptionBase {
|
|
|
13
13
|
choices: string[];
|
|
14
14
|
}
|
|
15
15
|
interface CommandLineOptionOfPrimitive extends CommandLineOptionBase {
|
|
16
|
-
type: "boolean" | "string" | "object";
|
|
16
|
+
type: "boolean" | "string" | "object" | "array";
|
|
17
17
|
}
|
|
18
18
|
declare type CommandLineOption = CommandLineOptionOfEnum | CommandLineOptionOfPrimitive;
|
|
19
19
|
export declare const optionDeclarations: CommandLineOption[];
|
package/dist/cli/parse.js
CHANGED
|
@@ -59,6 +59,11 @@ exports.optionDeclarations = [
|
|
|
59
59
|
description: "Provide verbose output useful for diagnosing problems.",
|
|
60
60
|
type: "boolean",
|
|
61
61
|
},
|
|
62
|
+
{
|
|
63
|
+
name: "noResolvePaths",
|
|
64
|
+
description: "An array of paths that tstl should not resolve and keep as-is.",
|
|
65
|
+
type: "array",
|
|
66
|
+
},
|
|
62
67
|
];
|
|
63
68
|
function updateParsedConfigFile(parsedConfigFile) {
|
|
64
69
|
let hasRootLevelOptions = false;
|
|
@@ -162,6 +167,15 @@ function readValue(option, value) {
|
|
|
162
167
|
}
|
|
163
168
|
return { value };
|
|
164
169
|
}
|
|
170
|
+
case "array": {
|
|
171
|
+
if (!Array.isArray(value)) {
|
|
172
|
+
return {
|
|
173
|
+
value: undefined,
|
|
174
|
+
error: cliDiagnostics.compilerOptionRequiresAValueOfType(option.name, option.type),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return { value };
|
|
178
|
+
}
|
|
165
179
|
case "enum": {
|
|
166
180
|
if (typeof value !== "string") {
|
|
167
181
|
return {
|
package/dist/cli/report.js
CHANGED
|
@@ -6,7 +6,7 @@ const prepareDiagnosticForFormatting = (diagnostic) => diagnostic.source === "ty
|
|
|
6
6
|
exports.prepareDiagnosticForFormatting = prepareDiagnosticForFormatting;
|
|
7
7
|
function createDiagnosticReporter(pretty, system = ts.sys) {
|
|
8
8
|
const reporter = ts.createDiagnosticReporter(system, pretty);
|
|
9
|
-
return diagnostic => reporter(exports.prepareDiagnosticForFormatting(diagnostic));
|
|
9
|
+
return diagnostic => reporter((0, exports.prepareDiagnosticForFormatting)(diagnostic));
|
|
10
10
|
}
|
|
11
11
|
exports.createDiagnosticReporter = createDiagnosticReporter;
|
|
12
12
|
//# sourceMappingURL=report.js.map
|
package/dist/cli/tsconfig.js
CHANGED
|
@@ -12,14 +12,14 @@ function locateConfigFile(commandLine) {
|
|
|
12
12
|
if (commandLine.fileNames.length > 0) {
|
|
13
13
|
return undefined;
|
|
14
14
|
}
|
|
15
|
-
const searchPath = utils_1.normalizeSlashes(process.cwd());
|
|
15
|
+
const searchPath = (0, utils_1.normalizeSlashes)(process.cwd());
|
|
16
16
|
return ts.findConfigFile(searchPath, ts.sys.fileExists);
|
|
17
17
|
}
|
|
18
18
|
if (commandLine.fileNames.length !== 0) {
|
|
19
19
|
return cliDiagnostics.optionProjectCannotBeMixedWithSourceFilesOnACommandLine();
|
|
20
20
|
}
|
|
21
21
|
// TODO: Unlike tsc, this resolves `.` to absolute path
|
|
22
|
-
const fileOrDirectory = utils_1.normalizeSlashes(path.resolve(process.cwd(), project));
|
|
22
|
+
const fileOrDirectory = (0, utils_1.normalizeSlashes)(path.resolve(process.cwd(), project));
|
|
23
23
|
if (ts.sys.directoryExists(fileOrDirectory)) {
|
|
24
24
|
const configFileName = path.posix.join(fileOrDirectory, "tsconfig.json");
|
|
25
25
|
if (ts.sys.fileExists(configFileName)) {
|
|
@@ -39,7 +39,7 @@ function locateConfigFile(commandLine) {
|
|
|
39
39
|
exports.locateConfigFile = locateConfigFile;
|
|
40
40
|
function parseConfigFileWithSystem(configFileName, commandLineOptions, system = ts.sys) {
|
|
41
41
|
const parsedConfigFile = ts.parseJsonSourceFileConfigFileContent(ts.readJsonConfigFile(configFileName, system.readFile), system, path.dirname(configFileName), commandLineOptions, configFileName);
|
|
42
|
-
return parse_1.updateParsedConfigFile(parsedConfigFile);
|
|
42
|
+
return (0, parse_1.updateParsedConfigFile)(parsedConfigFile);
|
|
43
43
|
}
|
|
44
44
|
exports.parseConfigFileWithSystem = parseConfigFileWithSystem;
|
|
45
45
|
function createConfigFileUpdater(optionsToExtend) {
|
|
@@ -49,7 +49,7 @@ function createConfigFileUpdater(optionsToExtend) {
|
|
|
49
49
|
if (!configFile || !configFilePath)
|
|
50
50
|
return [];
|
|
51
51
|
if (!configFileMap.has(configFile)) {
|
|
52
|
-
const parsedConfigFile = parse_1.updateParsedConfigFile(ts.parseJsonSourceFileConfigFileContent(configFile, ts.sys, path.dirname(configFilePath), optionsToExtend, configFilePath));
|
|
52
|
+
const parsedConfigFile = (0, parse_1.updateParsedConfigFile)(ts.parseJsonSourceFileConfigFileContent(configFile, ts.sys, path.dirname(configFilePath), optionsToExtend, configFilePath));
|
|
53
53
|
configFileMap.set(configFile, parsedConfigFile);
|
|
54
54
|
}
|
|
55
55
|
const parsedConfigFile = configFileMap.get(configFile);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
function __TS__AsyncAwaiter(generator)
|
|
2
|
+
return __TS__New(
|
|
3
|
+
__TS__Promise,
|
|
4
|
+
function(____, resolve, reject)
|
|
5
|
+
local adopt, fulfilled, rejected, step, asyncCoroutine
|
|
6
|
+
function adopt(self, value)
|
|
7
|
+
return ((__TS__InstanceOf(value, __TS__Promise) and (function() return value end)) or (function() return __TS__Promise.resolve(value) end))()
|
|
8
|
+
end
|
|
9
|
+
function fulfilled(self, value)
|
|
10
|
+
local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine, value)
|
|
11
|
+
if success then
|
|
12
|
+
step(_G, resultOrError, errorOrErrorHandler)
|
|
13
|
+
else
|
|
14
|
+
reject(_G, resultOrError)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
function rejected(self, handler)
|
|
18
|
+
if handler then
|
|
19
|
+
return function(____, value)
|
|
20
|
+
local success, valueOrError = pcall(handler, value)
|
|
21
|
+
if success then
|
|
22
|
+
step(_G, valueOrError, handler)
|
|
23
|
+
else
|
|
24
|
+
reject(_G, valueOrError)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
return function(____, value)
|
|
29
|
+
reject(_G, value)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
function step(self, result, errorHandler)
|
|
34
|
+
if coroutine.status(asyncCoroutine) == "dead" then
|
|
35
|
+
resolve(_G, result)
|
|
36
|
+
else
|
|
37
|
+
(function()
|
|
38
|
+
local ____self = adopt(_G, result)
|
|
39
|
+
return ____self["then"](
|
|
40
|
+
____self,
|
|
41
|
+
fulfilled,
|
|
42
|
+
rejected(_G, errorHandler)
|
|
43
|
+
)
|
|
44
|
+
end)()
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
asyncCoroutine = coroutine.create(generator)
|
|
48
|
+
local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine)
|
|
49
|
+
if success then
|
|
50
|
+
step(_G, resultOrError, errorOrErrorHandler)
|
|
51
|
+
else
|
|
52
|
+
reject(_G, errorOrErrorHandler)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
)
|
|
56
|
+
end
|
|
57
|
+
function __TS__Await(errorHandler, thing)
|
|
58
|
+
return coroutine.yield(errorHandler, thing)
|
|
59
|
+
end
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
function __TS__OptionalMethodCall(____table, methodName, ...)
|
|
1
|
+
function __TS__OptionalMethodCall(____table, methodName, isMethodOptional, ...)
|
|
2
2
|
if ____table then
|
|
3
3
|
local method = ____table[methodName]
|
|
4
4
|
if method then
|
|
5
5
|
return method(____table, ...)
|
|
6
|
+
elseif not isMethodOptional then
|
|
7
|
+
error(methodName .. " is not a function", 0)
|
|
6
8
|
end
|
|
7
9
|
end
|
|
8
10
|
return nil
|