typescript-to-lua 1.3.2 → 1.3.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.
@@ -4,7 +4,6 @@ exports.transformConstructorDeclaration = exports.createConstructorName = export
4
4
  const ts = require("typescript");
5
5
  const lua = require("../../../../LuaAST");
6
6
  const lua_ast_1 = require("../../../utils/lua-ast");
7
- const preceding_statements_1 = require("../../../utils/preceding-statements");
8
7
  const scope_1 = require("../../../utils/scope");
9
8
  const function_1 = require("../../function");
10
9
  const identifier_1 = require("../../identifier");
@@ -30,7 +29,7 @@ function transformConstructorDeclaration(context, statement, className, instance
30
29
  const bodyWithFieldInitializers = (0, function_1.transformFunctionBodyHeader)(context, scope, statement.parameters, restParamName);
31
30
  // Check for field declarations in constructor
32
31
  const constructorFieldsDeclarations = statement.parameters.filter(p => p.modifiers !== undefined);
33
- const [fieldsPrecedingStatements, classInstanceFields] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => (0, fields_1.transformClassInstanceFields)(context, instanceFields));
32
+ const classInstanceFields = (0, fields_1.transformClassInstanceFields)(context, instanceFields);
34
33
  // If there are field initializers and the first statement is a super call,
35
34
  // move super call between default assignments and initializers
36
35
  if ((constructorFieldsDeclarations.length > 0 || classInstanceFields.length > 0) &&
@@ -55,7 +54,6 @@ function transformConstructorDeclaration(context, statement, className, instance
55
54
  }
56
55
  // else { TypeScript error: A parameter property may not be declared using a binding pattern }
57
56
  }
58
- bodyWithFieldInitializers.push(...fieldsPrecedingStatements);
59
57
  bodyWithFieldInitializers.push(...classInstanceFields);
60
58
  bodyWithFieldInitializers.push(...body);
61
59
  const block = lua.createBlock(bodyWithFieldInitializers);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformStaticPropertyDeclaration = exports.transformClassInstanceFields = exports.createPropertyDecoratingExpression = void 0;
4
4
  const lua = require("../../../../LuaAST");
5
5
  const lua_ast_1 = require("../../../utils/lua-ast");
6
+ const preceding_statements_1 = require("../../../utils/preceding-statements");
6
7
  const literal_1 = require("../../literal");
7
8
  const decorators_1 = require("../decorators");
8
9
  const method_1 = require("./method");
@@ -17,14 +18,17 @@ exports.createPropertyDecoratingExpression = createPropertyDecoratingExpression;
17
18
  function transformClassInstanceFields(context, instanceFields) {
18
19
  const statements = [];
19
20
  for (const f of instanceFields) {
20
- // Get identifier
21
- const fieldName = (0, literal_1.transformPropertyName)(context, f.name);
22
- const value = f.initializer ? context.transformExpression(f.initializer) : undefined;
23
- // self[fieldName]
24
- const selfIndex = lua.createTableIndexExpression((0, lua_ast_1.createSelfIdentifier)(), fieldName);
25
- // self[fieldName] = value
26
- const assignClassField = lua.createAssignmentStatement(selfIndex, value, f);
27
- statements.push(assignClassField);
21
+ const [precedingStatements, statement] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => {
22
+ // Get identifier
23
+ const fieldName = (0, literal_1.transformPropertyName)(context, f.name);
24
+ const value = f.initializer ? context.transformExpression(f.initializer) : undefined;
25
+ // self[fieldName]
26
+ const selfIndex = lua.createTableIndexExpression((0, lua_ast_1.createSelfIdentifier)(), fieldName);
27
+ // self[fieldName] = value
28
+ const assignClassField = lua.createAssignmentStatement(selfIndex, value, f);
29
+ return assignClassField;
30
+ });
31
+ statements.push(...precedingStatements, statement);
28
32
  }
29
33
  return statements;
30
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.3.2",
3
+ "version": "1.3.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/",