typescript-to-lua 1.8.1 → 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.
@@ -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
- if (!(0, typescript_1.isStandardLibraryType)(context, ownerType, undefined))
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
- var _a;
110
- const signatureDeclaration = (_a = context.checker.getResolvedSignature(node)) === null || _a === void 0 ? void 0 : _a.declaration;
111
- if (!signatureDeclaration || !(0, typescript_1.isStandardLibraryDeclaration)(context, signatureDeclaration))
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
@@ -11,7 +11,9 @@ function isMultiReturnType(type) {
11
11
  }
12
12
  exports.isMultiReturnType = isMultiReturnType;
13
13
  function canBeMultiReturnType(type) {
14
- return isMultiReturnType(type) || (type.isUnion() && type.types.some(t => canBeMultiReturnType(t)));
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
- if (ts.isCallExpression(node)) {
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, node)) {
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)(node));
24
+ context.diagnostics.push((0, diagnostics_1.invalidMultiFunctionReturnType)(innerNode));
22
25
  }
23
- let returnValues = (0, call_1.transformArguments)(context, node.arguments);
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 && (0, multi_1.returnsMultiType)(context, node) && !(0, multi_1.shouldMultiReturnCallBeWrapped)(context, node)) {
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, node) && (0, multi_1.isMultiReturnType)(expressionType)) {
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(node), node)];
41
+ return [(0, lua_ast_1.createUnpackCall)(context, context.transformExpression(innerNode), innerNode)];
37
42
  }
38
43
  return [context.transformExpression(node)];
39
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.8.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/",