typescript-to-lua 1.13.3 → 1.14.0

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.
@@ -670,7 +670,6 @@ class LuaPrinter {
670
670
  return map;
671
671
  }
672
672
  }
673
- exports.LuaPrinter = LuaPrinter;
674
673
  LuaPrinter.operatorMap = {
675
674
  [lua.SyntaxKind.AdditionOperator]: "+",
676
675
  [lua.SyntaxKind.SubtractionOperator]: "-",
@@ -727,4 +726,5 @@ LuaPrinter.operatorPrecedence = {
727
726
  };
728
727
  LuaPrinter.rightAssociativeOperators = new Set([lua.SyntaxKind.ConcatOperator, lua.SyntaxKind.PowerOperator]);
729
728
  LuaPrinter.sourceMapTracebackPlaceholder = "{#SourceMapTraceback}";
729
+ exports.LuaPrinter = LuaPrinter;
730
730
  //# sourceMappingURL=LuaPrinter.js.map
@@ -94,7 +94,13 @@ function reduceContextTypes(contexts) {
94
94
  return type;
95
95
  }
96
96
  function getSignatureDeclarations(context, signature) {
97
+ if (signature.compositeSignatures) {
98
+ return signature.compositeSignatures.flatMap(s => getSignatureDeclarations(context, s));
99
+ }
97
100
  const signatureDeclaration = signature.getDeclaration();
101
+ if (signatureDeclaration === undefined) {
102
+ return [];
103
+ }
98
104
  let inferredType;
99
105
  if (ts.isMethodDeclaration(signatureDeclaration) &&
100
106
  ts.isObjectLiteralExpression(signatureDeclaration.parent) &&
@@ -30,7 +30,12 @@ function isInAsyncFunction(node) {
30
30
  if (!declaration) {
31
31
  return false;
32
32
  }
33
- return (_b = (_a = declaration.modifiers) === null || _a === void 0 ? void 0 : _a.some(m => m.kind === ts.SyntaxKind.AsyncKeyword)) !== null && _b !== void 0 ? _b : false;
33
+ if (ts.canHaveModifiers(declaration)) {
34
+ return (_b = (_a = ts.getModifiers(declaration)) === null || _a === void 0 ? void 0 : _a.some(m => m.kind === ts.SyntaxKind.AsyncKeyword)) !== null && _b !== void 0 ? _b : false;
35
+ }
36
+ else {
37
+ return false;
38
+ }
34
39
  }
35
40
  exports.isInAsyncFunction = isInAsyncFunction;
36
41
  function isInGeneratorFunction(node) {
@@ -9,6 +9,7 @@ const index_1 = require("./index");
9
9
  const assignments_1 = require("./assignments");
10
10
  const destructuring_assignments_1 = require("./destructuring-assignments");
11
11
  const lualib_1 = require("../../utils/lualib");
12
+ const diagnostics_1 = require("../../utils/diagnostics");
12
13
  function isLuaExpressionWithSideEffect(expression) {
13
14
  return !(lua.isLiteral(expression) || lua.isIdentifier(expression));
14
15
  }
@@ -43,7 +44,11 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
43
44
  const { precedingStatements, result: lengthSetterStatement } = transformCompoundLengthSetter(context, expression, lhs, rhs, operator);
44
45
  return { precedingStatements, result: lengthSetterStatement.expression };
45
46
  }
46
- const left = (0, utils_1.cast)(context.transformExpression(lhs), lua.isAssignmentLeftHandSideExpression);
47
+ const left = context.transformExpression(lhs);
48
+ if (!lua.isAssignmentLeftHandSideExpression(left)) {
49
+ context.diagnostics.push((0, diagnostics_1.cannotAssignToNodeOfKind)(expression, left.kind));
50
+ return { precedingStatements: [], result: left };
51
+ }
47
52
  const { precedingStatements: rightPrecedingStatements, result: right } = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(rhs));
48
53
  if (lua.isTableIndexExpression(left)) {
49
54
  // Complex property/element accesses need to cache object/index expressions to avoid repeating side-effects
@@ -128,7 +133,11 @@ function transformCompoundAssignmentStatement(context, node, lhs, rhs, operator)
128
133
  const { precedingStatements, result: lengthSetterStatement } = transformCompoundLengthSetter(context, node, lhs, rhs, operator);
129
134
  return [...precedingStatements, lengthSetterStatement];
130
135
  }
131
- const left = (0, utils_1.cast)(context.transformExpression(lhs), lua.isAssignmentLeftHandSideExpression);
136
+ const left = context.transformExpression(lhs);
137
+ if (!lua.isAssignmentLeftHandSideExpression(left)) {
138
+ context.diagnostics.push((0, diagnostics_1.cannotAssignToNodeOfKind)(node, left.kind));
139
+ return [];
140
+ }
132
141
  const { precedingStatements: rightPrecedingStatements, result: right } = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(rhs));
133
142
  if (lua.isTableIndexExpression(left) && shouldCacheTableIndexExpressions(left, rightPrecedingStatements)) {
134
143
  // Complex property/element accesses need to cache object/index expressions to avoid repeating side-effects
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformNewExpression = void 0;
4
- const ts = require("typescript");
5
4
  const lua = require("../../../LuaAST");
6
5
  const annotations_1 = require("../../utils/annotations");
7
6
  const diagnostics_1 = require("../../utils/diagnostics");
@@ -14,7 +13,7 @@ const transformNewExpression = (node, context) => {
14
13
  return lua.createTableExpression(undefined, node);
15
14
  }
16
15
  const signature = context.checker.getResolvedSignature(node);
17
- const [name, params] = (0, call_1.transformCallAndArguments)(context, node.expression, (_a = node.arguments) !== null && _a !== void 0 ? _a : [ts.factory.createTrue()], signature);
16
+ const [name, params] = (0, call_1.transformCallAndArguments)(context, node.expression, (_a = node.arguments) !== null && _a !== void 0 ? _a : [], signature);
18
17
  const type = context.checker.getTypeAtLocation(node);
19
18
  const annotations = (0, annotations_1.getTypeAnnotations)(type);
20
19
  const customConstructorAnnotation = annotations.get(annotations_1.AnnotationKind.CustomConstructor);
@@ -31,7 +31,8 @@ function isOptimizedVarArgSpread(context, symbol, identifier) {
31
31
  return false;
32
32
  }
33
33
  // Scope cannot be an async function
34
- if ((_a = scope.node.modifiers) === null || _a === void 0 ? void 0 : _a.some(m => m.kind === ts.SyntaxKind.AsyncKeyword)) {
34
+ if (ts.canHaveModifiers(scope.node) &&
35
+ ((_a = ts.getModifiers(scope.node)) === null || _a === void 0 ? void 0 : _a.some(m => m.kind === ts.SyntaxKind.AsyncKeyword))) {
35
36
  return false;
36
37
  }
37
38
  // Identifier must be a vararg in the local function scope's parameters
@@ -66,7 +66,7 @@ const stripParenthesisExpressionsTransformer = context => sourceFile => {
66
66
  }
67
67
  return ts.visitEachChild(node, visit, context);
68
68
  }
69
- return ts.visitNode(sourceFile, visit);
69
+ return ts.visitEachChild(sourceFile, visit, context);
70
70
  };
71
71
  exports.stripParenthesisExpressionsTransformer = stripParenthesisExpressionsTransformer;
72
72
  function loadTransformersFromOptions(program, diagnostics) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.13.3",
3
+ "version": "1.14.0",
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/",
@@ -42,7 +42,7 @@
42
42
  "node": ">=16.10.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "typescript": "~4.9.3"
45
+ "typescript": "^5.0.2"
46
46
  },
47
47
  "dependencies": {
48
48
  "@typescript-to-lua/language-extensions": "1.0.0",
@@ -56,20 +56,20 @@
56
56
  "@types/jest": "^27.5.2",
57
57
  "@types/node": "^13.7.7",
58
58
  "@types/resolve": "1.14.0",
59
- "@typescript-eslint/eslint-plugin": "^5.52.0",
60
- "@typescript-eslint/parser": "^5.52.0",
61
- "eslint": "^8.34.0",
59
+ "@typescript-eslint/eslint-plugin": "^5.55.0",
60
+ "@typescript-eslint/parser": "^5.55.0",
61
+ "eslint": "^8.36.0",
62
62
  "eslint-plugin-import": "^2.27.5",
63
63
  "eslint-plugin-jest": "^26.9.0",
64
64
  "fs-extra": "^8.1.0",
65
65
  "javascript-stringify": "^2.0.1",
66
66
  "jest": "^28.1.3",
67
- "jest-circus": "^29.4.2",
67
+ "jest-circus": "^29.5.0",
68
68
  "lua-types": "^2.13.0",
69
69
  "lua-wasm-bindings": "^0.3.1",
70
- "prettier": "^2.3.2",
70
+ "prettier": "^2.8.4",
71
71
  "ts-jest": "^28.0.8",
72
72
  "ts-node": "^10.9.1",
73
- "typescript": "~4.9.3"
73
+ "typescript": "^5.0.2"
74
74
  }
75
75
  }