typescript-to-lua 1.7.2 → 1.8.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.
- package/dist/CompilerOptions.js +3 -0
- package/dist/LuaLib.d.ts +1 -0
- package/dist/LuaLib.js +1 -0
- package/dist/lualib/LuaIteratorSpread.lua +9 -0
- package/dist/lualib/lualib_bundle.lua +11 -0
- package/dist/lualib/lualib_module_info.json +8 -0
- package/dist/transformation/builtins/index.js +17 -7
- package/dist/transformation/utils/language-extensions.d.ts +1 -0
- package/dist/transformation/utils/language-extensions.js +5 -1
- package/dist/transformation/visitors/language-extensions/multi.js +3 -1
- package/dist/transformation/visitors/return.js +12 -7
- package/dist/transformation/visitors/spread.js +4 -0
- package/dist/transpilation/diagnostics.d.ts +3 -0
- package/dist/transpilation/diagnostics.js +2 -1
- package/package.json +1 -1
package/dist/CompilerOptions.js
CHANGED
|
@@ -39,6 +39,9 @@ function validateOptions(options) {
|
|
|
39
39
|
if (options.jsx && options.jsx !== typescript_1.JsxEmit.React) {
|
|
40
40
|
diagnostics.push(diagnosticFactories.unsupportedJsxEmit());
|
|
41
41
|
}
|
|
42
|
+
if (options.paths && !options.baseUrl) {
|
|
43
|
+
diagnostics.push(diagnosticFactories.pathsWithoutBaseUrl());
|
|
44
|
+
}
|
|
42
45
|
return diagnostics;
|
|
43
46
|
}
|
|
44
47
|
exports.validateOptions = validateOptions;
|
package/dist/LuaLib.d.ts
CHANGED
package/dist/LuaLib.js
CHANGED
|
@@ -46,6 +46,7 @@ var LuaLibFeature;
|
|
|
46
46
|
LuaLibFeature["InstanceOf"] = "InstanceOf";
|
|
47
47
|
LuaLibFeature["InstanceOfObject"] = "InstanceOfObject";
|
|
48
48
|
LuaLibFeature["Iterator"] = "Iterator";
|
|
49
|
+
LuaLibFeature["LuaIteratorSpread"] = "LuaIteratorSpread";
|
|
49
50
|
LuaLibFeature["Map"] = "Map";
|
|
50
51
|
LuaLibFeature["MathAtan2"] = "MathAtan2";
|
|
51
52
|
LuaLibFeature["MathSign"] = "MathSign";
|
|
@@ -1207,6 +1207,16 @@ local function __TS__InstanceOfObject(value)
|
|
|
1207
1207
|
return valueType == "table" or valueType == "function"
|
|
1208
1208
|
end
|
|
1209
1209
|
|
|
1210
|
+
local function __TS__LuaIteratorSpread(self, state, firstKey)
|
|
1211
|
+
local results = {}
|
|
1212
|
+
local key, value = self(state, firstKey)
|
|
1213
|
+
while key do
|
|
1214
|
+
results[#results + 1] = {key, value}
|
|
1215
|
+
key, value = self(state, key)
|
|
1216
|
+
end
|
|
1217
|
+
return __TS__Unpack(results)
|
|
1218
|
+
end
|
|
1219
|
+
|
|
1210
1220
|
local Map
|
|
1211
1221
|
do
|
|
1212
1222
|
Map = __TS__Class()
|
|
@@ -2448,6 +2458,7 @@ return {
|
|
|
2448
2458
|
__TS__InstanceOf = __TS__InstanceOf,
|
|
2449
2459
|
__TS__InstanceOfObject = __TS__InstanceOfObject,
|
|
2450
2460
|
__TS__Iterator = __TS__Iterator,
|
|
2461
|
+
__TS__LuaIteratorSpread = __TS__LuaIteratorSpread,
|
|
2451
2462
|
Map = Map,
|
|
2452
2463
|
__TS__MathAtan2 = __TS__MathAtan2,
|
|
2453
2464
|
__TS__MathSign = __TS__MathSign,
|
|
@@ -67,9 +67,7 @@ function transformBuiltinCallExpression(context, node) {
|
|
|
67
67
|
exports.transformBuiltinCallExpression = transformBuiltinCallExpression;
|
|
68
68
|
function tryTransformBuiltinGlobalMethodCall(context, node, calledMethod) {
|
|
69
69
|
const ownerType = context.checker.getTypeAtLocation(calledMethod.expression);
|
|
70
|
-
|
|
71
|
-
return;
|
|
72
|
-
const ownerSymbol = ownerType.symbol;
|
|
70
|
+
const ownerSymbol = tryGetStandardLibrarySymbolOfType(context, ownerType);
|
|
73
71
|
if (!ownerSymbol || ownerSymbol.parent)
|
|
74
72
|
return;
|
|
75
73
|
let result;
|
|
@@ -106,11 +104,10 @@ function tryTransformBuiltinGlobalMethodCall(context, node, calledMethod) {
|
|
|
106
104
|
return result;
|
|
107
105
|
}
|
|
108
106
|
function tryTransformBuiltinPropertyCall(context, node, calledMethod) {
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
if (!
|
|
107
|
+
const functionType = context.checker.getTypeAtLocation(node.expression);
|
|
108
|
+
const callSymbol = tryGetStandardLibrarySymbolOfType(context, functionType);
|
|
109
|
+
if (!callSymbol)
|
|
112
110
|
return;
|
|
113
|
-
const callSymbol = context.checker.getTypeAtLocation(signatureDeclaration).symbol;
|
|
114
111
|
const ownerSymbol = callSymbol.parent;
|
|
115
112
|
if (!ownerSymbol || ownerSymbol.parent)
|
|
116
113
|
return;
|
|
@@ -187,4 +184,17 @@ function checkForLuaLibType(context, type) {
|
|
|
187
184
|
}
|
|
188
185
|
}
|
|
189
186
|
exports.checkForLuaLibType = checkForLuaLibType;
|
|
187
|
+
function tryGetStandardLibrarySymbolOfType(context, type) {
|
|
188
|
+
if (type.isUnionOrIntersection()) {
|
|
189
|
+
for (const subType of type.types) {
|
|
190
|
+
const symbol = tryGetStandardLibrarySymbolOfType(context, subType);
|
|
191
|
+
if (symbol)
|
|
192
|
+
return symbol;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else if ((0, typescript_1.isStandardLibraryType)(context, type, undefined)) {
|
|
196
|
+
return type.symbol;
|
|
197
|
+
}
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
190
200
|
//# sourceMappingURL=index.js.map
|
|
@@ -60,5 +60,6 @@ export declare enum IterableExtensionKind {
|
|
|
60
60
|
Pairs = "Pairs",
|
|
61
61
|
PairsKey = "PairsKey"
|
|
62
62
|
}
|
|
63
|
+
export declare function isLuaIterable(context: TransformationContext, type: ts.Type): boolean;
|
|
63
64
|
export declare function getIterableExtensionTypeForType(context: TransformationContext, type: ts.Type): IterableExtensionKind | undefined;
|
|
64
65
|
export declare function getIterableExtensionKindForNode(context: TransformationContext, node: ts.Node): IterableExtensionKind | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getIterableExtensionKindForNode = exports.getIterableExtensionTypeForType = exports.IterableExtensionKind = exports.getExtensionKindForSymbol = exports.getExtensionKindForNode = exports.getExtensionKindForType = exports.ExtensionKind = void 0;
|
|
3
|
+
exports.getIterableExtensionKindForNode = exports.getIterableExtensionTypeForType = exports.isLuaIterable = exports.IterableExtensionKind = exports.getExtensionKindForSymbol = exports.getExtensionKindForNode = exports.getExtensionKindForType = exports.ExtensionKind = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
var ExtensionKind;
|
|
6
6
|
(function (ExtensionKind) {
|
|
@@ -96,6 +96,10 @@ var IterableExtensionKind;
|
|
|
96
96
|
IterableExtensionKind["Pairs"] = "Pairs";
|
|
97
97
|
IterableExtensionKind["PairsKey"] = "PairsKey";
|
|
98
98
|
})(IterableExtensionKind = exports.IterableExtensionKind || (exports.IterableExtensionKind = {}));
|
|
99
|
+
function isLuaIterable(context, type) {
|
|
100
|
+
return getPropertyValue(context, type, "__tstlIterable") !== undefined;
|
|
101
|
+
}
|
|
102
|
+
exports.isLuaIterable = isLuaIterable;
|
|
99
103
|
function getIterableExtensionTypeForType(context, type) {
|
|
100
104
|
const value = getPropertyValue(context, type, "__tstlIterable");
|
|
101
105
|
if (value && value in IterableExtensionKind) {
|
|
@@ -11,7 +11,9 @@ function isMultiReturnType(type) {
|
|
|
11
11
|
}
|
|
12
12
|
exports.isMultiReturnType = isMultiReturnType;
|
|
13
13
|
function canBeMultiReturnType(type) {
|
|
14
|
-
return
|
|
14
|
+
return ((type.flags & ts.TypeFlags.Any) !== 0 ||
|
|
15
|
+
isMultiReturnType(type) ||
|
|
16
|
+
(type.isUnion() && type.types.some(t => canBeMultiReturnType(t))));
|
|
15
17
|
}
|
|
16
18
|
exports.canBeMultiReturnType = canBeMultiReturnType;
|
|
17
19
|
function isMultiFunctionCall(context, expression) {
|
|
@@ -12,28 +12,33 @@ const diagnostics_1 = require("../utils/diagnostics");
|
|
|
12
12
|
const typescript_1 = require("../utils/typescript");
|
|
13
13
|
function transformExpressionsInReturn(context, node, insideTryCatch) {
|
|
14
14
|
const expressionType = context.checker.getTypeAtLocation(node);
|
|
15
|
-
|
|
15
|
+
// skip type assertions
|
|
16
|
+
// don't skip parenthesis as it may arise confusion with lua behavior (where parenthesis are significant)
|
|
17
|
+
const innerNode = ts.skipOuterExpressions(node, ts.OuterExpressionKinds.Assertions);
|
|
18
|
+
if (ts.isCallExpression(innerNode)) {
|
|
16
19
|
// $multi(...)
|
|
17
|
-
if ((0, multi_1.isMultiFunctionCall)(context,
|
|
20
|
+
if ((0, multi_1.isMultiFunctionCall)(context, innerNode)) {
|
|
18
21
|
// Don't allow $multi to be implicitly cast to something other than LuaMultiReturn
|
|
19
22
|
const type = context.checker.getContextualType(node);
|
|
20
23
|
if (type && !(0, multi_1.canBeMultiReturnType)(type)) {
|
|
21
|
-
context.diagnostics.push((0, diagnostics_1.invalidMultiFunctionReturnType)(
|
|
24
|
+
context.diagnostics.push((0, diagnostics_1.invalidMultiFunctionReturnType)(innerNode));
|
|
22
25
|
}
|
|
23
|
-
let returnValues = (0, call_1.transformArguments)(context,
|
|
26
|
+
let returnValues = (0, call_1.transformArguments)(context, innerNode.arguments);
|
|
24
27
|
if (insideTryCatch) {
|
|
25
28
|
returnValues = [(0, lua_ast_1.wrapInTable)(...returnValues)]; // Wrap results when returning inside try/catch
|
|
26
29
|
}
|
|
27
30
|
return returnValues;
|
|
28
31
|
}
|
|
29
32
|
// Force-wrap LuaMultiReturn when returning inside try/catch
|
|
30
|
-
if (insideTryCatch &&
|
|
33
|
+
if (insideTryCatch &&
|
|
34
|
+
(0, multi_1.returnsMultiType)(context, innerNode) &&
|
|
35
|
+
!(0, multi_1.shouldMultiReturnCallBeWrapped)(context, innerNode)) {
|
|
31
36
|
return [(0, lua_ast_1.wrapInTable)(context.transformExpression(node))];
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
|
-
else if ((0, multi_1.isInMultiReturnFunction)(context,
|
|
39
|
+
else if ((0, multi_1.isInMultiReturnFunction)(context, innerNode) && (0, multi_1.isMultiReturnType)(expressionType)) {
|
|
35
40
|
// Unpack objects typed as LuaMultiReturn
|
|
36
|
-
return [(0, lua_ast_1.createUnpackCall)(context, context.transformExpression(
|
|
41
|
+
return [(0, lua_ast_1.createUnpackCall)(context, context.transformExpression(innerNode), innerNode)];
|
|
37
42
|
}
|
|
38
43
|
return [context.transformExpression(node)];
|
|
39
44
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transformSpreadElement = exports.isOptimizedVarArgSpread = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
|
+
const language_extensions_1 = require("../utils/language-extensions");
|
|
6
7
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
7
8
|
const lualib_1 = require("../utils/lualib");
|
|
8
9
|
const scope_1 = require("../utils/scope");
|
|
@@ -60,6 +61,9 @@ const transformSpreadElement = (node, context) => {
|
|
|
60
61
|
if ((0, multi_1.isMultiReturnCall)(context, tsInnerExpression))
|
|
61
62
|
return innerExpression;
|
|
62
63
|
const type = context.checker.getTypeAtLocation(node.expression); // not ts-inner expression, in case of casts
|
|
64
|
+
if ((0, language_extensions_1.isLuaIterable)(context, type)) {
|
|
65
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.LuaIteratorSpread, node, innerExpression);
|
|
66
|
+
}
|
|
63
67
|
if ((0, typescript_1.isArrayType)(context, type)) {
|
|
64
68
|
return (0, lua_ast_1.createUnpackCall)(context, innerExpression, node);
|
|
65
69
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unsupportedJsxEmit = exports.cannotBundleLibrary = exports.usingLuaBundleWithInlineMightGenerateDuplicateCode = exports.luaBundleEntryIsRequired = exports.couldNotFindBundleEntryPoint = exports.transformerShouldBeATsTransformerFactory = exports.shouldHaveAExport = exports.couldNotResolveFrom = exports.toLoadItShouldBeTranspiled = exports.couldNotReadDependency = exports.couldNotResolveRequire = void 0;
|
|
3
|
+
exports.pathsWithoutBaseUrl = exports.unsupportedJsxEmit = exports.cannotBundleLibrary = exports.usingLuaBundleWithInlineMightGenerateDuplicateCode = exports.luaBundleEntryIsRequired = exports.couldNotFindBundleEntryPoint = exports.transformerShouldBeATsTransformerFactory = exports.shouldHaveAExport = exports.couldNotResolveFrom = exports.toLoadItShouldBeTranspiled = exports.couldNotReadDependency = exports.couldNotResolveRequire = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const createDiagnosticFactory = (getMessage, category = ts.DiagnosticCategory.Error) => (0, utils_1.createSerialDiagnosticFactory)((...args) => ({ messageText: getMessage(...args), category }));
|
|
@@ -19,4 +19,5 @@ exports.usingLuaBundleWithInlineMightGenerateDuplicateCode = (0, utils_1.createS
|
|
|
19
19
|
}));
|
|
20
20
|
exports.cannotBundleLibrary = createDiagnosticFactory(() => 'Cannot bundle probjects with"buildmode": "library". Projects including the library can still bundle (which will include external library files).');
|
|
21
21
|
exports.unsupportedJsxEmit = createDiagnosticFactory(() => 'JSX is only supported with "react" jsx option.');
|
|
22
|
+
exports.pathsWithoutBaseUrl = createDiagnosticFactory(() => "When configuring 'paths' in tsconfig.json, the option 'baseUrl' must also be provided.");
|
|
22
23
|
//# sourceMappingURL=diagnostics.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
|
|
5
5
|
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
|
|
6
6
|
"homepage": "https://typescripttolua.github.io/",
|