xray16 1.5.4 → 1.6.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.
Files changed (55) hide show
  1. package/README.md +6 -0
  2. package/package.json +12 -6
  3. package/plugins/optimize_return_ternary.d.ts +6 -0
  4. package/plugins/optimize_return_ternary.js +65 -0
  5. package/xray16.d.ts +30847 -0
  6. package/types/index.d.ts +0 -55
  7. package/types/xr_ai/xr_action.d.ts +0 -1802
  8. package/types/xr_ai/xr_alife.d.ts +0 -1870
  9. package/types/xr_ai/xr_enemy_evaluation.d.ts +0 -134
  10. package/types/xr_ai/xr_goap.d.ts +0 -1116
  11. package/types/xr_ai/xr_graph.d.ts +0 -135
  12. package/types/xr_ai/xr_memory.d.ts +0 -382
  13. package/types/xr_lib/xr_animation.d.ts +0 -252
  14. package/types/xr_lib/xr_bitwise.d.ts +0 -44
  15. package/types/xr_lib/xr_color.d.ts +0 -142
  16. package/types/xr_lib/xr_debug.d.ts +0 -181
  17. package/types/xr_lib/xr_dialog.d.ts +0 -132
  18. package/types/xr_lib/xr_flags.d.ts +0 -592
  19. package/types/xr_lib/xr_fs.d.ts +0 -615
  20. package/types/xr_lib/xr_game.d.ts +0 -362
  21. package/types/xr_lib/xr_hit.d.ts +0 -125
  22. package/types/xr_lib/xr_ini.d.ts +0 -473
  23. package/types/xr_lib/xr_level.d.ts +0 -795
  24. package/types/xr_lib/xr_luabind.d.ts +0 -90
  25. package/types/xr_lib/xr_map.d.ts +0 -192
  26. package/types/xr_lib/xr_math.d.ts +0 -871
  27. package/types/xr_lib/xr_multiplayer.d.ts +0 -1079
  28. package/types/xr_lib/xr_profile.d.ts +0 -272
  29. package/types/xr_lib/xr_properties.d.ts +0 -610
  30. package/types/xr_lib/xr_relation.d.ts +0 -231
  31. package/types/xr_lib/xr_render.d.ts +0 -167
  32. package/types/xr_lib/xr_save.d.ts +0 -833
  33. package/types/xr_lib/xr_sound.d.ts +0 -515
  34. package/types/xr_lib/xr_stats.ts +0 -49
  35. package/types/xr_lib/xr_task.d.ts +0 -388
  36. package/types/xr_lib/xr_time.d.ts +0 -177
  37. package/types/xr_lib/xr_type.d.ts +0 -75
  38. package/types/xr_object/client/xr_anomaly.d.ts +0 -70
  39. package/types/xr_object/client/xr_artefact.d.ts +0 -153
  40. package/types/xr_object/client/xr_client_object.d.ts +0 -207
  41. package/types/xr_object/client/xr_creature.d.ts +0 -243
  42. package/types/xr_object/client/xr_item.d.ts +0 -370
  43. package/types/xr_object/client/xr_level.d.ts +0 -753
  44. package/types/xr_object/client/xr_physic.d.ts +0 -644
  45. package/types/xr_object/client/xr_zone.d.ts +0 -85
  46. package/types/xr_object/script/xr_script_interface.d.ts +0 -819
  47. package/types/xr_object/script/xr_script_object.d.ts +0 -5719
  48. package/types/xr_object/script/xr_script_trade.d.ts +0 -51
  49. package/types/xr_object/server/xr_server_object.d.ts +0 -1486
  50. package/types/xr_ui/xr_ui_asset.d.ts +0 -364
  51. package/types/xr_ui/xr_ui_core.d.ts +0 -424
  52. package/types/xr_ui/xr_ui_event.d.ts +0 -1449
  53. package/types/xr_ui/xr_ui_interface.d.ts +0 -2447
  54. package/types/xr_ui/xr_ui_menu.d.ts +0 -385
  55. package/types/xrf_plugin.d.ts +0 -109
package/README.md CHANGED
@@ -61,6 +61,7 @@ Plugins can be included in [tstl tsconfig](https://typescripttolua.github.io/doc
61
61
  { "name": "xray16/plugins/strip_lua_logger" },
62
62
  { "name": "xray16/plugins/inject_filename" },
63
63
  { "name": "xray16/plugins/from_cast_utils" },
64
+ { "name": "xray16/plugins/optimize_return_ternary" },
64
65
  { "name": "xray16/plugins/inject_tracy_zones" }
65
66
  ]
66
67
  }
@@ -106,6 +107,11 @@ Lua does not provide convenient API do get filename in runtime and static step i
106
107
  Plugin to simplify casting from `LuaTable` to typescript array/map objects.\
107
108
  All the calls are completely gets stripped and removed from runtime.
108
109
 
110
+ ### optimize_return_ternary
111
+
112
+ Plugin rewrites returned ternary expressions into direct `if` / `else` branch returns when it is safe.\
113
+ This avoids temporary result locals for patterns like `return condition ? first : second` while preserving general ternary semantics.
114
+
109
115
  ### inject_tracy_zones
110
116
 
111
117
  Plugin designed to work specifically with [tracy profiler](https://github.com/wolfpld/tracy).\
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "xray16",
3
- "version": "1.5.4",
3
+ "version": "1.6.1",
4
4
  "author": "Neloreck",
5
5
  "repository": "https://github.com/xray-forge/xray-16-types",
6
+ "homepage": "https://xray-forge.github.io/xray-16-types/index.html",
6
7
  "private": false,
7
- "main": "types/index.d.ts",
8
- "types": "types/index.d.ts",
8
+ "main": "xray16.d.ts",
9
+ "types": "xray16.d.ts",
9
10
  "scripts": {
10
- "prepublish": "npm run build:plugins",
11
+ "prepublish": "npm run build",
12
+ "prepack": "npm run build",
13
+ "build": "npm run build:plugins && npm run build:types",
11
14
  "build:plugins": "tsc -p ./src/tsconfig.json",
12
- "build:types": "typedoc",
15
+ "build:types": "rollup -c rollup.dts.config.mjs",
16
+ "build:docs": "typedoc",
13
17
  "typecheck": "tsc --noEmit",
14
18
  "typedoc": "typedoc",
15
19
  "format": "prettier --write \"**/*.(js|ts|tsx|md)\" && eslint . --fix",
@@ -31,6 +35,8 @@
31
35
  "eslint-plugin-jsdoc": "^63.0.7",
32
36
  "globals": "^17.7.0",
33
37
  "prettier": "^3.4.2",
38
+ "rollup": "^4.62.2",
39
+ "rollup-plugin-dts": "^6.4.1",
34
40
  "typedoc": "^0.27.5",
35
41
  "typescript": "5.7.2",
36
42
  "typescript-eslint": "^8.62.0",
@@ -38,7 +44,7 @@
38
44
  },
39
45
  "files": [
40
46
  "plugins/**/*",
41
- "types/**/*",
47
+ "xray16.d.ts",
42
48
  "README.md",
43
49
  "LICENSE"
44
50
  ]
@@ -0,0 +1,6 @@
1
+ import { type Plugin } from "typescript-to-lua";
2
+ /**
3
+ * Plugin that rewrites returned ternary expressions as direct branch returns.
4
+ */
5
+ declare const plugin: Plugin;
6
+ export default plugin;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ts = require("typescript");
4
+ const lua = require("typescript-to-lua");
5
+ const assignment_validation_1 = require("typescript-to-lua/dist/transformation/utils/assignment-validation");
6
+ const preceding_statements_1 = require("typescript-to-lua/dist/transformation/utils/preceding-statements");
7
+ const conditional_1 = require("typescript-to-lua/dist/transformation/visitors/conditional");
8
+ const multi_1 = require("typescript-to-lua/dist/transformation/visitors/language-extensions/multi");
9
+ const return_1 = require("typescript-to-lua/dist/transformation/visitors/return");
10
+ function getConditionalExpression(expression) {
11
+ let current = expression;
12
+ while (ts.isParenthesizedExpression(current) ||
13
+ ts.isAsExpression(current) ||
14
+ ts.isTypeAssertionExpression(current) ||
15
+ ts.isNonNullExpression(current) ||
16
+ ts.isSatisfiesExpression(current)) {
17
+ current = current.expression;
18
+ }
19
+ return ts.isConditionalExpression(current) ? current : null;
20
+ }
21
+ function hasMultiReturnBranch(context, expression) {
22
+ return ((0, multi_1.isMultiReturnType)(context.checker.getTypeAtLocation(expression.whenTrue)) ||
23
+ (0, multi_1.isMultiReturnType)(context.checker.getTypeAtLocation(expression.whenFalse)));
24
+ }
25
+ function transformExpressionToReturnStatements(context, statement, expression) {
26
+ const conditionalExpression = getConditionalExpression(expression);
27
+ if (conditionalExpression !== null && !hasMultiReturnBranch(context, conditionalExpression)) {
28
+ return transformConditionalReturnStatement(context, statement, conditionalExpression);
29
+ }
30
+ const value = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression));
31
+ return [...value.precedingStatements, (0, return_1.createReturnStatement)(context, [value.result], statement)];
32
+ }
33
+ function transformConditionalReturnStatement(context, statement, expression) {
34
+ (0, conditional_1.checkOnlyTruthyCondition)(expression.condition, context);
35
+ const condition = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.condition));
36
+ const whenTrue = transformExpressionToReturnStatements(context, statement, expression.whenTrue);
37
+ const whenFalse = transformExpressionToReturnStatements(context, statement, expression.whenFalse);
38
+ return [
39
+ ...condition.precedingStatements,
40
+ lua.createIfStatement(condition.result, lua.createBlock(whenTrue), lua.createBlock(whenFalse), expression),
41
+ ];
42
+ }
43
+ /**
44
+ * Plugin that rewrites returned ternary expressions as direct branch returns.
45
+ */
46
+ const plugin = {
47
+ visitors: {
48
+ [ts.SyntaxKind.ReturnStatement]: (statement, context) => {
49
+ if (statement.expression === undefined) {
50
+ return context.superTransformStatements(statement);
51
+ }
52
+ const expression = getConditionalExpression(statement.expression);
53
+ if (expression === null || hasMultiReturnBranch(context, expression)) {
54
+ return context.superTransformStatements(statement);
55
+ }
56
+ const expressionType = context.checker.getTypeAtLocation(statement.expression);
57
+ const returnType = context.checker.getContextualType(statement.expression);
58
+ if (returnType !== undefined) {
59
+ (0, assignment_validation_1.validateAssignment)(context, statement, expressionType, returnType);
60
+ }
61
+ return transformConditionalReturnStatement(context, statement, expression);
62
+ },
63
+ },
64
+ };
65
+ exports.default = plugin;