typescript-to-lua 1.36.0 → 1.37.0
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/lualib/5.0/Promise.lua +31 -8
- package/dist/lualib/5.0/lualib_bundle.lua +31 -8
- package/dist/lualib/universal/Promise.lua +31 -8
- package/dist/lualib/universal/lualib_bundle.lua +31 -8
- package/dist/transformation/utils/diagnostics.d.ts +6 -0
- package/dist/transformation/utils/diagnostics.js +4 -2
- package/dist/transformation/utils/function-context.js +7 -0
- package/dist/transformation/visitors/function.js +4 -0
- package/dist/transformation/visitors/loops/for-of.js +4 -0
- package/dist/transpilation/resolve.js +9 -7
- package/package.json +1 -1
|
@@ -74,16 +74,39 @@ do
|
|
|
74
74
|
return self["then"](self, nil, onRejected)
|
|
75
75
|
end
|
|
76
76
|
function __TS__Promise.prototype.finally(self, onFinally)
|
|
77
|
+
if type(onFinally) ~= "function" then
|
|
78
|
+
return self["then"](self, onFinally, onFinally)
|
|
79
|
+
end
|
|
77
80
|
return self["then"](
|
|
78
81
|
self,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
function(____, x)
|
|
83
|
+
local ____self_2 = __TS__New(
|
|
84
|
+
__TS__Promise,
|
|
85
|
+
function(____, resolve) return resolve(
|
|
86
|
+
nil,
|
|
87
|
+
onFinally(nil)
|
|
88
|
+
) end
|
|
89
|
+
)
|
|
90
|
+
return ____self_2["then"](
|
|
91
|
+
____self_2,
|
|
92
|
+
function() return x end
|
|
93
|
+
)
|
|
94
|
+
end,
|
|
95
|
+
function(____, e)
|
|
96
|
+
local ____self_3 = __TS__New(
|
|
97
|
+
__TS__Promise,
|
|
98
|
+
function(____, resolve) return resolve(
|
|
99
|
+
nil,
|
|
100
|
+
onFinally(nil)
|
|
101
|
+
) end
|
|
102
|
+
)
|
|
103
|
+
return ____self_3["then"](
|
|
104
|
+
____self_3,
|
|
105
|
+
function()
|
|
106
|
+
error(e, 0)
|
|
107
|
+
end
|
|
108
|
+
)
|
|
109
|
+
end
|
|
87
110
|
)
|
|
88
111
|
end
|
|
89
112
|
function __TS__Promise.prototype.resolve(self, value)
|
|
@@ -706,16 +706,39 @@ do
|
|
|
706
706
|
return self["then"](self, nil, onRejected)
|
|
707
707
|
end
|
|
708
708
|
function __TS__Promise.prototype.finally(self, onFinally)
|
|
709
|
+
if type(onFinally) ~= "function" then
|
|
710
|
+
return self["then"](self, onFinally, onFinally)
|
|
711
|
+
end
|
|
709
712
|
return self["then"](
|
|
710
713
|
self,
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
714
|
+
function(____, x)
|
|
715
|
+
local ____self_2 = __TS__New(
|
|
716
|
+
__TS__Promise,
|
|
717
|
+
function(____, resolve) return resolve(
|
|
718
|
+
nil,
|
|
719
|
+
onFinally(nil)
|
|
720
|
+
) end
|
|
721
|
+
)
|
|
722
|
+
return ____self_2["then"](
|
|
723
|
+
____self_2,
|
|
724
|
+
function() return x end
|
|
725
|
+
)
|
|
726
|
+
end,
|
|
727
|
+
function(____, e)
|
|
728
|
+
local ____self_3 = __TS__New(
|
|
729
|
+
__TS__Promise,
|
|
730
|
+
function(____, resolve) return resolve(
|
|
731
|
+
nil,
|
|
732
|
+
onFinally(nil)
|
|
733
|
+
) end
|
|
734
|
+
)
|
|
735
|
+
return ____self_3["then"](
|
|
736
|
+
____self_3,
|
|
737
|
+
function()
|
|
738
|
+
error(e, 0)
|
|
739
|
+
end
|
|
740
|
+
)
|
|
741
|
+
end
|
|
719
742
|
)
|
|
720
743
|
end
|
|
721
744
|
function __TS__Promise.prototype.resolve(self, value)
|
|
@@ -74,16 +74,39 @@ do
|
|
|
74
74
|
return self["then"](self, nil, onRejected)
|
|
75
75
|
end
|
|
76
76
|
function __TS__Promise.prototype.finally(self, onFinally)
|
|
77
|
+
if type(onFinally) ~= "function" then
|
|
78
|
+
return self["then"](self, onFinally, onFinally)
|
|
79
|
+
end
|
|
77
80
|
return self["then"](
|
|
78
81
|
self,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
function(____, x)
|
|
83
|
+
local ____self_2 = __TS__New(
|
|
84
|
+
__TS__Promise,
|
|
85
|
+
function(____, resolve) return resolve(
|
|
86
|
+
nil,
|
|
87
|
+
onFinally(nil)
|
|
88
|
+
) end
|
|
89
|
+
)
|
|
90
|
+
return ____self_2["then"](
|
|
91
|
+
____self_2,
|
|
92
|
+
function() return x end
|
|
93
|
+
)
|
|
94
|
+
end,
|
|
95
|
+
function(____, e)
|
|
96
|
+
local ____self_3 = __TS__New(
|
|
97
|
+
__TS__Promise,
|
|
98
|
+
function(____, resolve) return resolve(
|
|
99
|
+
nil,
|
|
100
|
+
onFinally(nil)
|
|
101
|
+
) end
|
|
102
|
+
)
|
|
103
|
+
return ____self_3["then"](
|
|
104
|
+
____self_3,
|
|
105
|
+
function()
|
|
106
|
+
error(e, 0)
|
|
107
|
+
end
|
|
108
|
+
)
|
|
109
|
+
end
|
|
87
110
|
)
|
|
88
111
|
end
|
|
89
112
|
function __TS__Promise.prototype.resolve(self, value)
|
|
@@ -702,16 +702,39 @@ do
|
|
|
702
702
|
return self["then"](self, nil, onRejected)
|
|
703
703
|
end
|
|
704
704
|
function __TS__Promise.prototype.finally(self, onFinally)
|
|
705
|
+
if type(onFinally) ~= "function" then
|
|
706
|
+
return self["then"](self, onFinally, onFinally)
|
|
707
|
+
end
|
|
705
708
|
return self["then"](
|
|
706
709
|
self,
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
710
|
+
function(____, x)
|
|
711
|
+
local ____self_2 = __TS__New(
|
|
712
|
+
__TS__Promise,
|
|
713
|
+
function(____, resolve) return resolve(
|
|
714
|
+
nil,
|
|
715
|
+
onFinally(nil)
|
|
716
|
+
) end
|
|
717
|
+
)
|
|
718
|
+
return ____self_2["then"](
|
|
719
|
+
____self_2,
|
|
720
|
+
function() return x end
|
|
721
|
+
)
|
|
722
|
+
end,
|
|
723
|
+
function(____, e)
|
|
724
|
+
local ____self_3 = __TS__New(
|
|
725
|
+
__TS__Promise,
|
|
726
|
+
function(____, resolve) return resolve(
|
|
727
|
+
nil,
|
|
728
|
+
onFinally(nil)
|
|
729
|
+
) end
|
|
730
|
+
)
|
|
731
|
+
return ____self_3["then"](
|
|
732
|
+
____self_3,
|
|
733
|
+
function()
|
|
734
|
+
error(e, 0)
|
|
735
|
+
end
|
|
736
|
+
)
|
|
737
|
+
end
|
|
715
738
|
)
|
|
716
739
|
end
|
|
717
740
|
function __TS__Promise.prototype.resolve(self, value)
|
|
@@ -83,6 +83,12 @@ export declare const notAllowedOptionalAssignment: ((node: ts.Node, ...args: any
|
|
|
83
83
|
export declare const awaitMustBeInAsyncFunction: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
84
84
|
code: number;
|
|
85
85
|
};
|
|
86
|
+
export declare const unsupportedAsyncGenerator: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
87
|
+
code: number;
|
|
88
|
+
};
|
|
89
|
+
export declare const unsupportedForAwaitOf: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
90
|
+
code: number;
|
|
91
|
+
};
|
|
86
92
|
export declare const unsupportedBuiltinOptionalCall: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
87
93
|
code: number;
|
|
88
94
|
};
|
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.unsupportedArrayWithLengthConstructor = exports.incompleteFieldDecoratorWarning = exports.cannotAssignToNodeOfKind = exports.invalidSpreadInCallExtension = exports.invalidMethodCallExtensionUse = exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
|
|
36
|
+
exports.unsupportedArrayWithLengthConstructor = exports.incompleteFieldDecoratorWarning = exports.cannotAssignToNodeOfKind = exports.invalidSpreadInCallExtension = exports.invalidMethodCallExtensionUse = exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.unsupportedForAwaitOf = exports.unsupportedAsyncGenerator = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
|
|
37
37
|
const ts = __importStar(require("typescript"));
|
|
38
38
|
const lua = __importStar(require("../../LuaAST"));
|
|
39
39
|
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
@@ -72,7 +72,7 @@ exports.invalidRangeControlVariable = createErrorDiagnosticFactory("For loop usi
|
|
|
72
72
|
exports.invalidMultiIterableWithoutDestructuring = createErrorDiagnosticFactory("LuaIterable with a LuaMultiReturn return value type must be destructured.");
|
|
73
73
|
exports.invalidPairsIterableWithoutDestructuring = createErrorDiagnosticFactory("LuaPairsIterable type must be destructured in a for...of statement.");
|
|
74
74
|
exports.unsupportedAccessorInObjectLiteral = createErrorDiagnosticFactory("Accessors in object literal are not supported.");
|
|
75
|
-
exports.unsupportedRightShiftOperator = createErrorDiagnosticFactory("
|
|
75
|
+
exports.unsupportedRightShiftOperator = createErrorDiagnosticFactory("Signed right shift `>>` is not supported on Lua 5.3+: Lua's native `>>` is logical (zero-fill) on 64-bit integers, with no built-in arithmetic shift. Use `>>>` if you don't need sign extension, or write your own helper.");
|
|
76
76
|
const getLuaTargetName = (version) => (version === CompilerOptions_1.LuaTarget.LuaJIT ? "LuaJIT" : `Lua ${version}`);
|
|
77
77
|
exports.unsupportedForTarget = createErrorDiagnosticFactory((functionality, version) => `${functionality} is/are not supported for target ${getLuaTargetName(version)}.`);
|
|
78
78
|
exports.unsupportedForTargetButOverrideAvailable = createErrorDiagnosticFactory((functionality, version, optionName) => `As a precaution, ${functionality} is/are not supported for target ${getLuaTargetName(version)} due to language features/limitations. ` +
|
|
@@ -90,6 +90,8 @@ exports.annotationDeprecated = createWarningDiagnosticFactory((kind) => `'@${kin
|
|
|
90
90
|
exports.truthyOnlyConditionalValue = createWarningDiagnosticFactory("Only false and nil evaluate to 'false' in Lua, everything else is considered 'true'. Explicitly compare the value with ===.");
|
|
91
91
|
exports.notAllowedOptionalAssignment = createErrorDiagnosticFactory("The left-hand side of an assignment expression may not be an optional property access.");
|
|
92
92
|
exports.awaitMustBeInAsyncFunction = createErrorDiagnosticFactory("Await can only be used inside async functions.");
|
|
93
|
+
exports.unsupportedAsyncGenerator = createErrorDiagnosticFactory("Async generator functions are not supported.");
|
|
94
|
+
exports.unsupportedForAwaitOf = createErrorDiagnosticFactory("'for await...of' loops are not supported.");
|
|
93
95
|
exports.unsupportedBuiltinOptionalCall = createErrorDiagnosticFactory("Optional calls are not supported for builtin or language extension functions.");
|
|
94
96
|
exports.unsupportedOptionalCompileMembersOnly = createErrorDiagnosticFactory("Optional calls are not supported on enums marked with @compileMembersOnly.");
|
|
95
97
|
exports.undefinedInArrayLiteral = createErrorDiagnosticFactory("Array literals may not contain undefined or null.");
|
|
@@ -155,6 +155,13 @@ function computeDeclarationContextType(context, signatureDeclaration) {
|
|
|
155
155
|
if (signatureDeclaration.parent && ts.isTypeParameterDeclaration(signatureDeclaration.parent)) {
|
|
156
156
|
return ContextType.NonVoid;
|
|
157
157
|
}
|
|
158
|
+
// Call signature inside a class or interface respects @noSelf on the enclosing class/interface
|
|
159
|
+
if (ts.isCallSignatureDeclaration(signatureDeclaration)) {
|
|
160
|
+
const scopeDeclaration = (0, typescript_1.findFirstNodeAbove)(signatureDeclaration, (n) => ts.isClassDeclaration(n) || ts.isClassExpression(n) || ts.isInterfaceDeclaration(n));
|
|
161
|
+
if (scopeDeclaration !== undefined && (0, annotations_1.getNodeAnnotations)(scopeDeclaration).has(annotations_1.AnnotationKind.NoSelf)) {
|
|
162
|
+
return ContextType.Void;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
158
165
|
// When using --noImplicitSelf and the signature is defined in a file targeted by the program apply the @noSelf rule.
|
|
159
166
|
const program = context.program;
|
|
160
167
|
const options = program.getCompilerOptions();
|
|
@@ -54,6 +54,7 @@ const lualib_1 = require("../utils/lualib");
|
|
|
54
54
|
const preceding_statements_1 = require("../utils/preceding-statements");
|
|
55
55
|
const scope_1 = require("../utils/scope");
|
|
56
56
|
const typescript_1 = require("../utils/typescript");
|
|
57
|
+
const diagnostics_1 = require("../utils/diagnostics");
|
|
57
58
|
const async_await_1 = require("./async-await");
|
|
58
59
|
const identifier_1 = require("./identifier");
|
|
59
60
|
const return_1 = require("./return");
|
|
@@ -197,6 +198,9 @@ function transformParameters(context, parameters, functionContext) {
|
|
|
197
198
|
function transformFunctionToExpression(context, node) {
|
|
198
199
|
var _a;
|
|
199
200
|
(0, utils_1.assert)(node.body);
|
|
201
|
+
if (node.asteriskToken && (0, async_await_1.isAsyncFunction)(node)) {
|
|
202
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedAsyncGenerator)(node));
|
|
203
|
+
}
|
|
200
204
|
const type = context.checker.getTypeAtLocation(node);
|
|
201
205
|
let functionContext;
|
|
202
206
|
const firstParam = node.parameters[0];
|
|
@@ -42,6 +42,7 @@ const iterable_1 = require("../language-extensions/iterable");
|
|
|
42
42
|
const range_1 = require("../language-extensions/range");
|
|
43
43
|
const utils_1 = require("./utils");
|
|
44
44
|
const language_extensions_1 = require("../../utils/language-extensions");
|
|
45
|
+
const diagnostics_1 = require("../../utils/diagnostics");
|
|
45
46
|
const utils_2 = require("../../../utils");
|
|
46
47
|
function transformForOfArrayStatement(context, statement, block) {
|
|
47
48
|
const valueVariable = (0, utils_1.transformForInitializer)(context, statement.initializer, block);
|
|
@@ -56,6 +57,9 @@ function transformForOfIteratorStatement(context, statement, block) {
|
|
|
56
57
|
return lua.createForInStatement(block, [lua.createAnonymousIdentifier(), valueVariable], [iterable], statement);
|
|
57
58
|
}
|
|
58
59
|
const transformForOfStatement = (node, context) => {
|
|
60
|
+
if (node.awaitModifier) {
|
|
61
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedForAwaitOf)(node.awaitModifier));
|
|
62
|
+
}
|
|
59
63
|
const body = lua.createBlock((0, utils_1.transformLoopBody)(context, node));
|
|
60
64
|
if (ts.isCallExpression(node.expression) && (0, range_1.isRangeFunction)(context, node.expression)) {
|
|
61
65
|
return (0, range_1.transformRangeStatement)(context, node, body);
|
|
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.resolveDependencies = resolveDependencies;
|
|
37
37
|
const path = __importStar(require("path"));
|
|
38
38
|
const resolve = __importStar(require("enhanced-resolve"));
|
|
39
|
+
const ts = __importStar(require("typescript"));
|
|
39
40
|
const fs = __importStar(require("fs"));
|
|
40
41
|
const source_map_1 = require("source-map");
|
|
41
42
|
const transpiler_1 = require("./transpiler");
|
|
@@ -195,13 +196,9 @@ class ResolutionContext {
|
|
|
195
196
|
if (resolvedNodeModulesFile)
|
|
196
197
|
return resolvedNodeModulesFile;
|
|
197
198
|
}
|
|
198
|
-
//
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (fileFromPath)
|
|
202
|
-
return fileFromPath;
|
|
203
|
-
if (this.options.paths) {
|
|
204
|
-
// If no file found yet and paths are present, try to find project file via paths mappings
|
|
199
|
+
// Bare specifiers: check paths mappings first, matching TypeScript's resolution order.
|
|
200
|
+
// TS never applies paths to relative imports, so skip for those.
|
|
201
|
+
if (!ts.isExternalModuleNameRelative(dependencyPath) && this.options.paths) {
|
|
205
202
|
// When baseUrl is not set, resolve paths relative to the tsconfig directory (TS 6.0+ behavior)
|
|
206
203
|
const pathsBase = (_a = this.options.baseUrl) !== null && _a !== void 0 ? _a : (this.options.configFilePath ? path.dirname(this.options.configFilePath) : undefined);
|
|
207
204
|
if (pathsBase) {
|
|
@@ -210,6 +207,11 @@ class ResolutionContext {
|
|
|
210
207
|
return fileFromPaths;
|
|
211
208
|
}
|
|
212
209
|
}
|
|
210
|
+
// Check if file is a file in the project
|
|
211
|
+
const resolvedPath = this.formatPathToFile(dependencyPath, requiringFile);
|
|
212
|
+
const fileFromPath = this.getFileFromPath(resolvedPath);
|
|
213
|
+
if (fileFromPath)
|
|
214
|
+
return fileFromPath;
|
|
213
215
|
// Not a TS file in our project sources, use resolver to check if we can find dependency
|
|
214
216
|
try {
|
|
215
217
|
const resolveResult = resolver.resolveSync({}, fileDirectory, dependencyPath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.37.0",
|
|
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/",
|