typescript-to-lua 1.31.1 → 1.31.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.
@@ -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);
@@ -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.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/",