typescript-to-lua 1.31.1 → 1.31.3

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.
@@ -111,7 +111,8 @@ function computeDeclarationContextType(context, signatureDeclaration) {
111
111
  ts.isConstructSignatureDeclaration(signatureDeclaration) ||
112
112
  ts.isConstructorDeclaration(signatureDeclaration) ||
113
113
  (signatureDeclaration.parent && ts.isPropertyDeclaration(signatureDeclaration.parent)) ||
114
- (signatureDeclaration.parent && ts.isPropertySignature(signatureDeclaration.parent))) {
114
+ (signatureDeclaration.parent && ts.isPropertySignature(signatureDeclaration.parent)) ||
115
+ (signatureDeclaration.parent && ts.isIndexSignatureDeclaration(signatureDeclaration.parent))) {
115
116
  // Class/interface methods only respect @noSelf on their parent
116
117
  const scopeDeclaration = (0, typescript_1.findFirstNodeAbove)(signatureDeclaration, (n) => ts.isClassDeclaration(n) || ts.isClassExpression(n) || ts.isInterfaceDeclaration(n));
117
118
  if (scopeDeclaration !== undefined && (0, annotations_1.getNodeAnnotations)(scopeDeclaration).has(annotations_1.AnnotationKind.NoSelf)) {
@@ -110,7 +110,7 @@ function transformContextualCallExpression(context, node, args) {
110
110
  return lua.createCallExpression(expression, transformedArguments, node);
111
111
  }
112
112
  }
113
- else if (ts.isIdentifier(left)) {
113
+ else if (ts.isIdentifier(left) || ts.isCallExpression(left)) {
114
114
  const callContext = context.isStrict ? ts.factory.createNull() : ts.factory.createIdentifier("_G");
115
115
  let expression;
116
116
  [expression, transformedArguments] = transformCallWithArguments(context, left, transformedArguments, argPrecedingStatements, callContext);
@@ -143,7 +143,7 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
143
143
  const iif = lua.createFunctionExpression(lua.createBlock(bodyStatements), [
144
144
  lua.createIdentifier("self"),
145
145
  ]);
146
- const iife = lua.createCallExpression(iif, [className]);
146
+ const iife = lua.createCallExpression(iif, [localClassName]);
147
147
  result.push(lua.createExpressionStatement(iife, member));
148
148
  }
149
149
  }
@@ -156,7 +156,7 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
156
156
  if ((0, export_1.shouldBeExported)(classDeclaration)) {
157
157
  const exportExpression = (0, export_1.hasDefaultExportModifier)(classDeclaration)
158
158
  ? (0, export_1.createDefaultExportExpression)(classDeclaration)
159
- : (0, export_1.createExportedIdentifier)(context, className);
159
+ : (0, export_1.createExportedIdentifier)(context, localClassName);
160
160
  const classAssignment = lua.createAssignmentStatement(exportExpression, localClassName);
161
161
  result.push(classAssignment);
162
162
  }
@@ -6,8 +6,10 @@ const lua = require("../../../LuaAST");
6
6
  const preceding_statements_1 = require("../../utils/preceding-statements");
7
7
  const variable_declaration_1 = require("../variable-declaration");
8
8
  const utils_1 = require("./utils");
9
+ const scope_1 = require("../../utils/scope");
9
10
  const transformForStatement = (statement, context) => {
10
11
  const result = [];
12
+ context.pushScope(scope_1.ScopeType.Loop);
11
13
  if (statement.initializer) {
12
14
  if (ts.isVariableDeclarationList(statement.initializer)) {
13
15
  (0, variable_declaration_1.checkVariableDeclarationList)(context, statement.initializer);
@@ -47,6 +49,7 @@ const transformForStatement = (statement, context) => {
47
49
  }
48
50
  // while (condition) do ... end
49
51
  result.push(lua.createWhileStatement(lua.createBlock(body), condition, statement));
52
+ context.popScope();
50
53
  return lua.createDoStatement(result, statement);
51
54
  };
52
55
  exports.transformForStatement = transformForStatement;
@@ -28,10 +28,24 @@ function transformLoopBody(context, loop) {
28
28
  case scope_1.LoopContinued.WithRepeatBreak:
29
29
  const identifier = lua.createIdentifier(`__continue${scopeId}`);
30
30
  const literalTrue = lua.createBooleanLiteral(true);
31
+ // If there is a break in the body statements, do not include any code afterwards
32
+ const transformedBodyStatements = [];
33
+ let bodyBroken = false;
34
+ for (const statement of body) {
35
+ transformedBodyStatements.push(statement);
36
+ if (lua.isBreakStatement(statement)) {
37
+ bodyBroken = true;
38
+ break;
39
+ }
40
+ }
41
+ if (!bodyBroken) {
42
+ // Tell loop to continue if not broken
43
+ transformedBodyStatements.push(lua.createAssignmentStatement(identifier, literalTrue));
44
+ }
31
45
  return [
32
46
  lua.createDoStatement([
33
47
  lua.createVariableDeclarationStatement(identifier),
34
- lua.createRepeatStatement(lua.createBlock([...body, lua.createAssignmentStatement(identifier, literalTrue)]), literalTrue),
48
+ lua.createRepeatStatement(lua.createBlock(transformedBodyStatements), literalTrue),
35
49
  lua.createIfStatement(lua.createUnaryExpression(identifier, lua.SyntaxKind.NotOperator), lua.createBlock([lua.createBreakStatement()])),
36
50
  ]),
37
51
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.31.1",
3
+ "version": "1.31.3",
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/",