typescript-to-lua 1.26.2 → 1.27.1

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.
@@ -20,8 +20,14 @@ do
20
20
  result[table.getn(result) + 1] = v
21
21
  end
22
22
  else
23
- for i, v in arrayLikeIterator(arrayLike) do
24
- result[table.getn(result) + 1] = mapFn(thisArg, v, i - 1)
23
+ local i = 0
24
+ for ____, v in arrayLikeIterator(arrayLike) do
25
+ local ____mapFn_3 = mapFn
26
+ local ____thisArg_1 = thisArg
27
+ local ____v_2 = v
28
+ local ____i_0 = i
29
+ i = ____i_0 + 1
30
+ result[table.getn(result) + 1] = ____mapFn_3(____thisArg_1, ____v_2, ____i_0)
25
31
  end
26
32
  end
27
33
  return result
@@ -15,23 +15,17 @@ local function __TS__ObjectDefineProperty(target, key, desc)
15
15
  local valueExists = value ~= nil
16
16
  local ____desc_set_4 = desc.set
17
17
  local ____desc_get_5 = desc.get
18
- local ____temp_0
19
- if desc.configurable ~= nil then
20
- ____temp_0 = desc.configurable
21
- else
22
- ____temp_0 = valueExists
18
+ local ____desc_configurable_0 = desc.configurable
19
+ if ____desc_configurable_0 == nil then
20
+ ____desc_configurable_0 = valueExists
23
21
  end
24
- local ____temp_1
25
- if desc.enumerable ~= nil then
26
- ____temp_1 = desc.enumerable
27
- else
28
- ____temp_1 = valueExists
22
+ local ____desc_enumerable_1 = desc.enumerable
23
+ if ____desc_enumerable_1 == nil then
24
+ ____desc_enumerable_1 = valueExists
29
25
  end
30
- local ____temp_2
31
- if desc.writable ~= nil then
32
- ____temp_2 = desc.writable
33
- else
34
- ____temp_2 = valueExists
26
+ local ____desc_writable_2 = desc.writable
27
+ if ____desc_writable_2 == nil then
28
+ ____desc_writable_2 = valueExists
35
29
  end
36
30
  local ____temp_3
37
31
  if desc.value ~= nil then
@@ -42,9 +36,9 @@ local function __TS__ObjectDefineProperty(target, key, desc)
42
36
  descriptor = {
43
37
  set = ____desc_set_4,
44
38
  get = ____desc_get_5,
45
- configurable = ____temp_0,
46
- enumerable = ____temp_1,
47
- writable = ____temp_2,
39
+ configurable = ____desc_configurable_0,
40
+ enumerable = ____desc_enumerable_1,
41
+ writable = ____desc_writable_2,
48
42
  value = ____temp_3
49
43
  }
50
44
  end
@@ -2,10 +2,7 @@ local function __TS__Using(self, cb, ...)
2
2
  local args = arg
3
3
  local thrownError
4
4
  local ok, result = xpcall(
5
- function() return cb(
6
- nil,
7
- unpack(args)
8
- ) end,
5
+ function() return cb(unpack(args)) end,
9
6
  function(err)
10
7
  thrownError = err
11
8
  return thrownError
@@ -193,8 +193,14 @@ do
193
193
  result[table.getn(result) + 1] = v
194
194
  end
195
195
  else
196
- for i, v in arrayLikeIterator(arrayLike) do
197
- result[table.getn(result) + 1] = mapFn(thisArg, v, i - 1)
196
+ local i = 0
197
+ for ____, v in arrayLikeIterator(arrayLike) do
198
+ local ____mapFn_3 = mapFn
199
+ local ____thisArg_1 = thisArg
200
+ local ____v_2 = v
201
+ local ____i_0 = i
202
+ i = ____i_0 + 1
203
+ result[table.getn(result) + 1] = ____mapFn_3(____thisArg_1, ____v_2, ____i_0)
198
204
  end
199
205
  end
200
206
  return result
@@ -1697,23 +1703,17 @@ local function __TS__ObjectDefineProperty(target, key, desc)
1697
1703
  local valueExists = value ~= nil
1698
1704
  local ____desc_set_4 = desc.set
1699
1705
  local ____desc_get_5 = desc.get
1700
- local ____temp_0
1701
- if desc.configurable ~= nil then
1702
- ____temp_0 = desc.configurable
1703
- else
1704
- ____temp_0 = valueExists
1706
+ local ____desc_configurable_0 = desc.configurable
1707
+ if ____desc_configurable_0 == nil then
1708
+ ____desc_configurable_0 = valueExists
1705
1709
  end
1706
- local ____temp_1
1707
- if desc.enumerable ~= nil then
1708
- ____temp_1 = desc.enumerable
1709
- else
1710
- ____temp_1 = valueExists
1710
+ local ____desc_enumerable_1 = desc.enumerable
1711
+ if ____desc_enumerable_1 == nil then
1712
+ ____desc_enumerable_1 = valueExists
1711
1713
  end
1712
- local ____temp_2
1713
- if desc.writable ~= nil then
1714
- ____temp_2 = desc.writable
1715
- else
1716
- ____temp_2 = valueExists
1714
+ local ____desc_writable_2 = desc.writable
1715
+ if ____desc_writable_2 == nil then
1716
+ ____desc_writable_2 = valueExists
1717
1717
  end
1718
1718
  local ____temp_3
1719
1719
  if desc.value ~= nil then
@@ -1724,9 +1724,9 @@ local function __TS__ObjectDefineProperty(target, key, desc)
1724
1724
  descriptor = {
1725
1725
  set = ____desc_set_4,
1726
1726
  get = ____desc_get_5,
1727
- configurable = ____temp_0,
1728
- enumerable = ____temp_1,
1729
- writable = ____temp_2,
1727
+ configurable = ____desc_configurable_0,
1728
+ enumerable = ____desc_enumerable_1,
1729
+ writable = ____desc_writable_2,
1730
1730
  value = ____temp_3
1731
1731
  }
1732
1732
  end
@@ -2602,10 +2602,7 @@ local function __TS__Using(self, cb, ...)
2602
2602
  local args = arg
2603
2603
  local thrownError
2604
2604
  local ok, result = xpcall(
2605
- function() return cb(
2606
- nil,
2607
- unpack(args)
2608
- ) end,
2605
+ function() return cb(unpack(args)) end,
2609
2606
  function(err)
2610
2607
  thrownError = err
2611
2608
  return thrownError
@@ -20,8 +20,14 @@ do
20
20
  result[#result + 1] = v
21
21
  end
22
22
  else
23
- for i, v in arrayLikeIterator(arrayLike) do
24
- result[#result + 1] = mapFn(thisArg, v, i - 1)
23
+ local i = 0
24
+ for ____, v in arrayLikeIterator(arrayLike) do
25
+ local ____mapFn_3 = mapFn
26
+ local ____thisArg_1 = thisArg
27
+ local ____v_2 = v
28
+ local ____i_0 = i
29
+ i = ____i_0 + 1
30
+ result[#result + 1] = ____mapFn_3(____thisArg_1, ____v_2, ____i_0)
25
31
  end
26
32
  end
27
33
  return result
@@ -15,23 +15,17 @@ local function __TS__ObjectDefineProperty(target, key, desc)
15
15
  local valueExists = value ~= nil
16
16
  local ____desc_set_4 = desc.set
17
17
  local ____desc_get_5 = desc.get
18
- local ____temp_0
19
- if desc.configurable ~= nil then
20
- ____temp_0 = desc.configurable
21
- else
22
- ____temp_0 = valueExists
18
+ local ____desc_configurable_0 = desc.configurable
19
+ if ____desc_configurable_0 == nil then
20
+ ____desc_configurable_0 = valueExists
23
21
  end
24
- local ____temp_1
25
- if desc.enumerable ~= nil then
26
- ____temp_1 = desc.enumerable
27
- else
28
- ____temp_1 = valueExists
22
+ local ____desc_enumerable_1 = desc.enumerable
23
+ if ____desc_enumerable_1 == nil then
24
+ ____desc_enumerable_1 = valueExists
29
25
  end
30
- local ____temp_2
31
- if desc.writable ~= nil then
32
- ____temp_2 = desc.writable
33
- else
34
- ____temp_2 = valueExists
26
+ local ____desc_writable_2 = desc.writable
27
+ if ____desc_writable_2 == nil then
28
+ ____desc_writable_2 = valueExists
35
29
  end
36
30
  local ____temp_3
37
31
  if desc.value ~= nil then
@@ -42,9 +36,9 @@ local function __TS__ObjectDefineProperty(target, key, desc)
42
36
  descriptor = {
43
37
  set = ____desc_set_4,
44
38
  get = ____desc_get_5,
45
- configurable = ____temp_0,
46
- enumerable = ____temp_1,
47
- writable = ____temp_2,
39
+ configurable = ____desc_configurable_0,
40
+ enumerable = ____desc_enumerable_1,
41
+ writable = ____desc_writable_2,
48
42
  value = ____temp_3
49
43
  }
50
44
  end
@@ -2,10 +2,7 @@ local function __TS__Using(self, cb, ...)
2
2
  local args = {...}
3
3
  local thrownError
4
4
  local ok, result = xpcall(
5
- function() return cb(
6
- nil,
7
- __TS__Unpack(args)
8
- ) end,
5
+ function() return cb(__TS__Unpack(args)) end,
9
6
  function(err)
10
7
  thrownError = err
11
8
  return thrownError
@@ -193,8 +193,14 @@ do
193
193
  result[#result + 1] = v
194
194
  end
195
195
  else
196
- for i, v in arrayLikeIterator(arrayLike) do
197
- result[#result + 1] = mapFn(thisArg, v, i - 1)
196
+ local i = 0
197
+ for ____, v in arrayLikeIterator(arrayLike) do
198
+ local ____mapFn_3 = mapFn
199
+ local ____thisArg_1 = thisArg
200
+ local ____v_2 = v
201
+ local ____i_0 = i
202
+ i = ____i_0 + 1
203
+ result[#result + 1] = ____mapFn_3(____thisArg_1, ____v_2, ____i_0)
198
204
  end
199
205
  end
200
206
  return result
@@ -1628,23 +1634,17 @@ local function __TS__ObjectDefineProperty(target, key, desc)
1628
1634
  local valueExists = value ~= nil
1629
1635
  local ____desc_set_4 = desc.set
1630
1636
  local ____desc_get_5 = desc.get
1631
- local ____temp_0
1632
- if desc.configurable ~= nil then
1633
- ____temp_0 = desc.configurable
1634
- else
1635
- ____temp_0 = valueExists
1637
+ local ____desc_configurable_0 = desc.configurable
1638
+ if ____desc_configurable_0 == nil then
1639
+ ____desc_configurable_0 = valueExists
1636
1640
  end
1637
- local ____temp_1
1638
- if desc.enumerable ~= nil then
1639
- ____temp_1 = desc.enumerable
1640
- else
1641
- ____temp_1 = valueExists
1641
+ local ____desc_enumerable_1 = desc.enumerable
1642
+ if ____desc_enumerable_1 == nil then
1643
+ ____desc_enumerable_1 = valueExists
1642
1644
  end
1643
- local ____temp_2
1644
- if desc.writable ~= nil then
1645
- ____temp_2 = desc.writable
1646
- else
1647
- ____temp_2 = valueExists
1645
+ local ____desc_writable_2 = desc.writable
1646
+ if ____desc_writable_2 == nil then
1647
+ ____desc_writable_2 = valueExists
1648
1648
  end
1649
1649
  local ____temp_3
1650
1650
  if desc.value ~= nil then
@@ -1655,9 +1655,9 @@ local function __TS__ObjectDefineProperty(target, key, desc)
1655
1655
  descriptor = {
1656
1656
  set = ____desc_set_4,
1657
1657
  get = ____desc_get_5,
1658
- configurable = ____temp_0,
1659
- enumerable = ____temp_1,
1660
- writable = ____temp_2,
1658
+ configurable = ____desc_configurable_0,
1659
+ enumerable = ____desc_enumerable_1,
1660
+ writable = ____desc_writable_2,
1661
1661
  value = ____temp_3
1662
1662
  }
1663
1663
  end
@@ -2542,10 +2542,7 @@ local function __TS__Using(self, cb, ...)
2542
2542
  local args = {...}
2543
2543
  local thrownError
2544
2544
  local ok, result = xpcall(
2545
- function() return cb(
2546
- nil,
2547
- __TS__Unpack(args)
2548
- ) end,
2545
+ function() return cb(__TS__Unpack(args)) end,
2549
2546
  function(err)
2550
2547
  thrownError = err
2551
2548
  return thrownError
@@ -142,6 +142,5 @@ class LuaLibPrinter extends tstl.LuaPrinter {
142
142
  }
143
143
  }
144
144
  const pluginInstance = new LuaLibPlugin();
145
- // eslint-disable-next-line import/no-default-export
146
145
  exports.default = pluginInstance;
147
146
  //# sourceMappingURL=plugin.js.map
@@ -21,7 +21,9 @@ class TransformationContext {
21
21
  this.options = this.program.getCompilerOptions();
22
22
  this.luaTarget = (_a = this.options.luaTarget) !== null && _a !== void 0 ? _a : CompilerOptions_1.LuaTarget.Universal;
23
23
  this.isModule = ts.isExternalModule(this.sourceFile);
24
- this.isStrict = ((_b = this.options.alwaysStrict) !== null && _b !== void 0 ? _b : this.options.strict) ||
24
+ this.isStrict =
25
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
26
+ ((_b = this.options.alwaysStrict) !== null && _b !== void 0 ? _b : this.options.strict) ||
25
27
  (this.isModule && this.options.target !== undefined && this.options.target >= ts.ScriptTarget.ES2015);
26
28
  this.currentNodeVisitors = [];
27
29
  this.currentNodeVisitorsIndex = 0;
@@ -18,7 +18,7 @@ function usingTransformer(context) {
18
18
  ts.setParent(node2, parent[parent.length - 1]);
19
19
  parent.push(node2);
20
20
  ts.visitEachChild(node2, setParent, ctx);
21
- parent.push();
21
+ parent.pop();
22
22
  return node2;
23
23
  }
24
24
  ts.visitEachChild(updatedBlock, setParent, ctx);
@@ -54,7 +54,10 @@ function transformBlockWithUsing(context, statements, block) {
54
54
  const followingStatements = statements.slice(i + 1);
55
55
  const [followingHasUsings, replacedFollowingStatements] = transformBlockWithUsing(context, followingStatements, block);
56
56
  const callbackBody = ts.factory.createBlock(followingHasUsings ? replacedFollowingStatements : followingStatements);
57
- const callback = ts.factory.createFunctionExpression(undefined, undefined, undefined, undefined, variableNames, undefined, callbackBody);
57
+ const callback = ts.factory.createFunctionExpression(
58
+ // Put async keyword in front of callback when we are in an async using
59
+ isAwaitUsing ? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)] : undefined, undefined, undefined, undefined, variableNames, ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), // Required for TS to not freak out trying to infer the type of synthetic nodes
60
+ callbackBody);
58
61
  // Replace using variable list with call to lualib function with callback and followed by all variable initializers
59
62
  const functionIdentifier = ts.factory.createIdentifier(isAwaitUsing ? "__TS__UsingAsync" : "__TS__Using");
60
63
  let call = ts.factory.createCallExpression(functionIdentifier, [], [
@@ -119,6 +119,9 @@ function computeDeclarationContextType(context, signatureDeclaration) {
119
119
  }
120
120
  return ContextType.NonVoid;
121
121
  }
122
+ if (signatureDeclaration.parent && ts.isTypeParameterDeclaration(signatureDeclaration.parent)) {
123
+ return ContextType.NonVoid;
124
+ }
122
125
  // When using --noImplicitSelf and the signature is defined in a file targeted by the program apply the @noSelf rule.
123
126
  const program = context.program;
124
127
  const options = program.getCompilerOptions();
@@ -20,6 +20,7 @@ const multi_1 = require("./language-extensions/multi");
20
20
  const optional_chaining_1 = require("./optional-chaining");
21
21
  const typescript_2 = require("typescript");
22
22
  const identifier_1 = require("./identifier");
23
+ const export_1 = require("../utils/export");
23
24
  function addOneToArrayAccessArgument(context, node, index) {
24
25
  const type = context.checker.getTypeAtLocation(node.expression);
25
26
  const argumentType = context.checker.getTypeAtLocation(node.argumentExpression);
@@ -108,7 +109,16 @@ function transformPropertyAccessExpressionWithCapture(context, node, thisValueCa
108
109
  return { expression };
109
110
  }
110
111
  else {
111
- return { expression: lua.createIdentifier(property, node) };
112
+ // Check if we need to account for enum being exported int his file
113
+ if ((0, export_1.isSymbolExported)(context, type.symbol) &&
114
+ (0, export_1.getSymbolExportScope)(context, type.symbol) === node.expression.getSourceFile()) {
115
+ return {
116
+ expression: lua.createTableIndexExpression((0, lua_ast_1.createExportsIdentifier)(), lua.createStringLiteral(property), node),
117
+ };
118
+ }
119
+ else {
120
+ return { expression: lua.createIdentifier(property, node) };
121
+ }
112
122
  }
113
123
  }
114
124
  const builtinResult = (0, builtins_1.transformBuiltinPropertyAccessExpression)(context, node);
@@ -30,19 +30,16 @@ function transformConstructorDeclaration(context, statement, className, instance
30
30
  // Check for field declarations in constructor
31
31
  const constructorFieldsDeclarations = statement.parameters.filter(p => p.modifiers !== undefined);
32
32
  const classInstanceFields = (0, fields_1.transformClassInstanceFields)(context, instanceFields);
33
- // If there are field initializers and the first statement is a super call,
34
- // move super call between default assignments and initializers
33
+ // If there are field initializers and there is a super call somewhere,
34
+ // move super call and everything before it to between default assignments and initializers
35
35
  if ((constructorFieldsDeclarations.length > 0 || classInstanceFields.length > 0) &&
36
36
  statement.body &&
37
37
  statement.body.statements.length > 0) {
38
- const firstStatement = statement.body.statements[0];
39
- if (ts.isExpressionStatement(firstStatement) &&
40
- ts.isCallExpression(firstStatement.expression) &&
41
- firstStatement.expression.expression.kind === ts.SyntaxKind.SuperKeyword) {
42
- const superCall = body.shift();
43
- if (superCall) {
44
- bodyWithFieldInitializers.push(superCall);
45
- }
38
+ const superIndex = statement.body.statements.findIndex(s => ts.isExpressionStatement(s) &&
39
+ ts.isCallExpression(s.expression) &&
40
+ s.expression.expression.kind === ts.SyntaxKind.SuperKeyword);
41
+ if (superIndex !== -1) {
42
+ bodyWithFieldInitializers.push(...body.splice(0, superIndex + 1));
46
43
  }
47
44
  }
48
45
  // Add in instance field declarations
@@ -43,9 +43,11 @@ function transformForOfMultiIterableStatement(context, statement, block, luaIter
43
43
  return lua.createForInStatement(block, identifiers, [luaIterator], statement);
44
44
  }
45
45
  function transformForOfIterableStatement(context, statement, block) {
46
- var _a;
47
- const type = context.checker.getTypeAtLocation(statement.expression);
48
- if (((_a = type.aliasTypeArguments) === null || _a === void 0 ? void 0 : _a.length) === 2 && (0, multi_1.isMultiReturnType)(type.aliasTypeArguments[0])) {
46
+ const iteratedExpressionType = context.checker.getTypeAtLocation(statement.expression);
47
+ const iterableType = iteratedExpressionType.isIntersection() &&
48
+ iteratedExpressionType.types.find(t => t.symbol.escapedName === "Iterable");
49
+ const iterableTypeArguments = iterableType === null || iterableType === void 0 ? void 0 : iterableType.typeArguments;
50
+ if (iterableTypeArguments && iterableTypeArguments.length > 0 && (0, multi_1.isMultiReturnType)(iterableTypeArguments[0])) {
49
51
  const luaIterator = context.transformExpression(statement.expression);
50
52
  return transformForOfMultiIterableStatement(context, statement, block, luaIterator, diagnostics_1.invalidMultiIterableWithoutDestructuring);
51
53
  }
@@ -6,11 +6,10 @@ const lua = require("../../../LuaAST");
6
6
  const utils_1 = require("../../../utils");
7
7
  const export_1 = require("../../utils/export");
8
8
  const lua_ast_1 = require("../../utils/lua-ast");
9
- const scope_1 = require("../../utils/scope");
10
- const block_1 = require("../block");
11
- const identifier_1 = require("../identifier");
12
9
  const literal_1 = require("../literal");
13
10
  const import_1 = require("./import");
11
+ const safe_names_1 = require("../../utils/safe-names");
12
+ const path = require("path");
14
13
  const transformExportAssignment = (node, context) => {
15
14
  if (!context.resolver.isValueAliasDeclaration(node)) {
16
15
  return undefined;
@@ -62,30 +61,53 @@ function transformExportAll(context, node) {
62
61
  // Wrap this in a DoStatement to prevent polluting the scope.
63
62
  return lua.createDoStatement(result, node);
64
63
  }
65
- const isDefaultExportSpecifier = (node) => (node.name && ts.identifierToKeywordKind(node.name) === ts.SyntaxKind.DefaultKeyword) ||
66
- (node.propertyName && ts.identifierToKeywordKind(node.propertyName) === ts.SyntaxKind.DefaultKeyword);
64
+ const isDefaultExportSpecifier = (node) => (node.name &&
65
+ ts.isIdentifier(node.name) &&
66
+ ts.identifierToKeywordKind(node.name) === ts.SyntaxKind.DefaultKeyword) ||
67
+ (node.propertyName &&
68
+ ts.isIdentifier(node.propertyName) &&
69
+ ts.identifierToKeywordKind(node.propertyName) === ts.SyntaxKind.DefaultKeyword);
67
70
  function transformExportSpecifier(context, node) {
68
- const exportedSymbol = context.checker.getExportSpecifierLocalTargetSymbol(node);
69
- const exportedIdentifier = node.propertyName ? node.propertyName : node.name;
70
- const exportedExpression = (0, literal_1.createShorthandIdentifier)(context, exportedSymbol, exportedIdentifier);
71
- const isDefault = isDefaultExportSpecifier(node);
72
- const exportAssignmentLeftHandSide = isDefault
73
- ? (0, export_1.createDefaultExportExpression)(node)
74
- : (0, export_1.createExportedIdentifier)(context, (0, identifier_1.transformIdentifier)(context, node.name));
75
- return lua.createAssignmentStatement(exportAssignmentLeftHandSide, exportedExpression, node);
71
+ var _a;
72
+ const exportedName = node.name;
73
+ const exportedValue = (_a = node.propertyName) !== null && _a !== void 0 ? _a : node.name;
74
+ let rhs;
75
+ if (ts.isIdentifier(exportedValue)) {
76
+ const exportedSymbol = context.checker.getExportSpecifierLocalTargetSymbol(node);
77
+ rhs = (0, literal_1.createShorthandIdentifier)(context, exportedSymbol, exportedValue);
78
+ }
79
+ else {
80
+ rhs = lua.createStringLiteral(exportedName.text, exportedValue);
81
+ }
82
+ if (isDefaultExportSpecifier(node)) {
83
+ const lhs = (0, export_1.createDefaultExportExpression)(node);
84
+ return lua.createAssignmentStatement(lhs, rhs, node);
85
+ }
86
+ else {
87
+ const exportsTable = (0, lua_ast_1.createExportsIdentifier)();
88
+ const lhs = lua.createTableIndexExpression(exportsTable, lua.createStringLiteral(exportedName.text), exportedName);
89
+ return lua.createAssignmentStatement(lhs, rhs, node);
90
+ }
76
91
  }
77
92
  function transformExportSpecifiersFrom(context, statement, moduleSpecifier, exportSpecifiers) {
78
- // First transpile as import clause
79
- const importClause = ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(exportSpecifiers.map(s => ts.factory.createImportSpecifier(statement.isTypeOnly, s.propertyName, s.name))));
80
- const importDeclaration = ts.factory.createImportDeclaration(statement.modifiers, importClause, moduleSpecifier);
81
- // Wrap in block to prevent imports from hoisting out of `do` statement
82
- const [block] = (0, block_1.transformScopeBlock)(context, ts.factory.createBlock([importDeclaration]), scope_1.ScopeType.Block);
83
- const result = block.statements;
84
- // Now the module is imported, add the imports to the export table
93
+ var _a;
94
+ const result = [];
95
+ const importPath = ts.isStringLiteral(moduleSpecifier) ? moduleSpecifier.text.replace(/"/g, "") : "module";
96
+ // Create the require statement to extract values.
97
+ // local ____module = require("module")
98
+ const importUniqueName = lua.createIdentifier((0, safe_names_1.createSafeName)(path.basename(importPath)));
99
+ const requireCall = (0, import_1.createModuleRequire)(context, moduleSpecifier);
100
+ result.push(lua.createVariableDeclarationStatement(importUniqueName, requireCall, statement));
85
101
  for (const specifier of exportSpecifiers) {
86
- result.push(lua.createAssignmentStatement((0, export_1.createExportedIdentifier)(context, (0, identifier_1.transformIdentifier)(context, specifier.name)), (0, identifier_1.transformIdentifier)(context, specifier.name)));
102
+ // Assign to exports table
103
+ const exportsTable = (0, lua_ast_1.createExportsIdentifier)();
104
+ const exportedName = specifier.name;
105
+ const exportedNameTransformed = (0, literal_1.transformPropertyName)(context, exportedName);
106
+ const lhs = lua.createTableIndexExpression(exportsTable, exportedNameTransformed, exportedName);
107
+ const exportedValue = (_a = specifier.propertyName) !== null && _a !== void 0 ? _a : specifier.name;
108
+ const rhs = lua.createTableIndexExpression(lua.cloneIdentifier(importUniqueName), (0, literal_1.transformPropertyName)(context, exportedValue), specifier);
109
+ result.push(lua.createAssignmentStatement(lhs, rhs, specifier));
87
110
  }
88
- // Wrap this in a DoStatement to prevent polluting the scope.
89
111
  return lua.createDoStatement(result, statement);
90
112
  }
91
113
  const getExported = (context, exportSpecifiers) => exportSpecifiers.elements.filter(exportSpecifier => context.resolver.isValueAliasDeclaration(exportSpecifier));
@@ -124,6 +124,18 @@ function transformOptionalChainWithCapture(context, tsNode, thisValueCapture, is
124
124
  }
125
125
  return result;
126
126
  });
127
+ // handle super calls by passing self as context
128
+ function getLeftMostChainItem(node) {
129
+ if (ts.isPropertyAccessExpression(node)) {
130
+ return getLeftMostChainItem(node.expression);
131
+ }
132
+ else {
133
+ return node;
134
+ }
135
+ }
136
+ if (getLeftMostChainItem(tsLeftExpression).kind === ts.SyntaxKind.SuperKeyword) {
137
+ capturedThisValue = lua.createIdentifier("self");
138
+ }
127
139
  // handle context
128
140
  if (rightContextualCall) {
129
141
  if (capturedThisValue) {
package/dist/utils.js CHANGED
@@ -46,15 +46,12 @@ function formatPathToLuaPath(filePath) {
46
46
  }
47
47
  return filePath.replace(/\.\//g, "").replace(/\//g, ".");
48
48
  }
49
- function getOrUpdate(
50
- // eslint-disable-next-line @typescript-eslint/ban-types
51
- map, key, getDefaultValue) {
49
+ function getOrUpdate(map, key, getDefaultValue) {
52
50
  if (!map.has(key)) {
53
51
  map.set(key, getDefaultValue());
54
52
  }
55
53
  return map.get(key);
56
54
  }
57
- // eslint-disable-next-line @typescript-eslint/ban-types
58
55
  function isNonNull(value) {
59
56
  return value != null;
60
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.26.2",
3
+ "version": "1.27.1",
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/",
@@ -29,7 +29,7 @@
29
29
  "test": "jest",
30
30
  "lint": "npm run lint:eslint && npm run lint:prettier",
31
31
  "lint:prettier": "prettier --check . || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
32
- "lint:eslint": "eslint . --ext .js,.ts",
32
+ "lint:eslint": "eslint .",
33
33
  "fix:prettier": "prettier --write .",
34
34
  "check:language-extensions": "tsc --strict language-extensions/index.d.ts",
35
35
  "preversion": "npm run build && npm test",
@@ -42,11 +42,11 @@
42
42
  "node": ">=16.10.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "typescript": "5.5.2"
45
+ "typescript": "5.6.2"
46
46
  },
47
47
  "dependencies": {
48
48
  "@typescript-to-lua/language-extensions": "1.19.0",
49
- "enhanced-resolve": "^5.8.2",
49
+ "enhanced-resolve": "5.8.2",
50
50
  "picomatch": "^2.3.1",
51
51
  "resolve": "^1.15.1",
52
52
  "source-map": "^0.7.3"
@@ -58,19 +58,18 @@
58
58
  "@types/node": "^13.7.7",
59
59
  "@types/picomatch": "^2.3.0",
60
60
  "@types/resolve": "1.14.0",
61
- "eslint": "^8.57.0",
62
- "eslint-plugin-import": "^2.29.1",
63
- "eslint-plugin-jest": "^26.9.0",
61
+ "eslint": "^9.11.0",
62
+ "eslint-plugin-jest": "^28.8.3",
64
63
  "fs-extra": "^8.1.0",
65
64
  "javascript-stringify": "^2.0.1",
66
65
  "jest": "^29.5.0",
67
66
  "jest-circus": "^29.5.0",
68
67
  "lua-types": "^2.13.0",
69
68
  "lua-wasm-bindings": "^0.3.1",
70
- "prettier": "^2.8.4",
69
+ "prettier": "^2.8.8",
71
70
  "ts-jest": "^29.1.0",
72
71
  "ts-node": "^10.9.1",
73
- "typescript": "^5.5.2",
74
- "typescript-eslint": "^7.13.1"
72
+ "typescript": "^5.6.2",
73
+ "typescript-eslint": "^8.7.0"
75
74
  }
76
75
  }