xray16 1.0.0 → 1.0.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.
Files changed (97) hide show
  1. package/README.md +30 -1
  2. package/package.json +7 -4
  3. package/plugins/built_at_info.js +14 -0
  4. package/plugins/from_cast_utils.js +29 -0
  5. package/plugins/global_declarations_transform.js +20 -0
  6. package/plugins/inject_filename.js +20 -0
  7. package/plugins/plugins/built_at_info.js +12 -0
  8. package/plugins/plugins/from_cast_utils.js +27 -0
  9. package/plugins/plugins/global_declarations_transform.js +18 -0
  10. package/plugins/plugins/inject_filename.js +18 -0
  11. package/plugins/plugins/strip_lua_logger.js +51 -0
  12. package/plugins/plugins/transform_luabind_class/plugin.js +34 -0
  13. package/plugins/plugins/transform_luabind_class/transformation/class_declaration.js +141 -0
  14. package/plugins/plugins/transform_luabind_class/transformation/constants.js +4 -0
  15. package/plugins/plugins/transform_luabind_class/transformation/decorators.js +12 -0
  16. package/plugins/plugins/transform_luabind_class/transformation/errors.js +25 -0
  17. package/plugins/{transform_luabind_class/transformation/index.ts → plugins/transform_luabind_class/transformation/index.js} +5 -5
  18. package/plugins/plugins/transform_luabind_class/transformation/members/accessors.js +35 -0
  19. package/plugins/plugins/transform_luabind_class/transformation/members/constructor.js +56 -0
  20. package/plugins/plugins/transform_luabind_class/transformation/members/fields.js +36 -0
  21. package/plugins/plugins/transform_luabind_class/transformation/members/method.js +49 -0
  22. package/plugins/plugins/transform_luabind_class/transformation/new.js +8 -0
  23. package/plugins/plugins/transform_luabind_class/transformation/setup.js +76 -0
  24. package/plugins/plugins/transform_luabind_class/transformation/super.js +65 -0
  25. package/plugins/plugins/transform_luabind_class/transformation/utils.js +67 -0
  26. package/plugins/plugins/utils/diagnostics.js +17 -0
  27. package/plugins/strip_lua_logger.js +53 -0
  28. package/plugins/transform_luabind_class/plugin.js +36 -0
  29. package/plugins/transform_luabind_class/transformation/class_declaration.js +147 -0
  30. package/plugins/transform_luabind_class/transformation/constants.js +7 -0
  31. package/plugins/transform_luabind_class/transformation/decorators.js +16 -0
  32. package/plugins/transform_luabind_class/transformation/errors.js +28 -0
  33. package/plugins/transform_luabind_class/transformation/index.js +21 -0
  34. package/plugins/transform_luabind_class/transformation/members/accessors.js +39 -0
  35. package/plugins/transform_luabind_class/transformation/members/constructor.js +61 -0
  36. package/plugins/transform_luabind_class/transformation/members/fields.js +41 -0
  37. package/plugins/transform_luabind_class/transformation/members/method.js +56 -0
  38. package/plugins/transform_luabind_class/transformation/new.js +12 -0
  39. package/plugins/transform_luabind_class/transformation/setup.js +81 -0
  40. package/plugins/transform_luabind_class/transformation/super.js +72 -0
  41. package/plugins/transform_luabind_class/transformation/utils.js +77 -0
  42. package/plugins/utils/diagnostics.js +22 -0
  43. package/types/index.d.ts +28 -0
  44. package/{src → types}/xr_global.d.ts +35 -0
  45. package/{src → types}/xr_lib/xr_fs.d.ts +8 -1
  46. package/{src → types}/xr_object/xr_client_object.d.ts +31 -17
  47. package/{src → types}/xr_object/xr_server_object.d.ts +2 -0
  48. package/plugins/built_at_info.ts +0 -18
  49. package/plugins/from_cast_utils.ts +0 -34
  50. package/plugins/global_declarations_transform.ts +0 -24
  51. package/plugins/inject_filename.ts +0 -22
  52. package/plugins/strip_lua_logger.ts +0 -73
  53. package/plugins/transform_luabind_class/plugin.ts +0 -51
  54. package/plugins/transform_luabind_class/transformation/class_declaration.ts +0 -226
  55. package/plugins/transform_luabind_class/transformation/constants.ts +0 -4
  56. package/plugins/transform_luabind_class/transformation/decorators.ts +0 -16
  57. package/plugins/transform_luabind_class/transformation/errors.ts +0 -31
  58. package/plugins/transform_luabind_class/transformation/members/accessors.ts +0 -48
  59. package/plugins/transform_luabind_class/transformation/members/constructor.ts +0 -107
  60. package/plugins/transform_luabind_class/transformation/members/fields.ts +0 -53
  61. package/plugins/transform_luabind_class/transformation/members/method.ts +0 -70
  62. package/plugins/transform_luabind_class/transformation/new.ts +0 -14
  63. package/plugins/transform_luabind_class/transformation/setup.ts +0 -128
  64. package/plugins/transform_luabind_class/transformation/super.ts +0 -92
  65. package/plugins/transform_luabind_class/transformation/utils.ts +0 -90
  66. package/plugins/utils/diagnostics.ts +0 -24
  67. package/src/index.d.ts +0 -63
  68. /package/{src → types}/xr_constant.d.ts +0 -0
  69. /package/{src → types}/xr_core.d.ts +0 -0
  70. /package/{src → types}/xr_lib/xr_math.d.ts +0 -0
  71. /package/{src → types}/xr_lib/xr_utils.d.ts +0 -0
  72. /package/{src → types}/xr_luabind.d.ts +0 -0
  73. /package/{src → types}/xr_map/xr_map.d.ts +0 -0
  74. /package/{src → types}/xr_object/xr_action.d.ts +0 -0
  75. /package/{src → types}/xr_object/xr_alife.d.ts +0 -0
  76. /package/{src → types}/xr_object/xr_anomaly.d.ts +0 -0
  77. /package/{src → types}/xr_object/xr_artefact.d.ts +0 -0
  78. /package/{src → types}/xr_object/xr_creature.d.ts +0 -0
  79. /package/{src → types}/xr_object/xr_dialog.d.ts +0 -0
  80. /package/{src → types}/xr_object/xr_item.d.ts +0 -0
  81. /package/{src → types}/xr_object/xr_level.d.ts +0 -0
  82. /package/{src → types}/xr_object/xr_physic.d.ts +0 -0
  83. /package/{src → types}/xr_object/xr_quest.d.ts +0 -0
  84. /package/{src → types}/xr_online/xr_multiplayer.d.ts +0 -0
  85. /package/{src → types}/xr_sound/xr_sound.d.ts +0 -0
  86. /package/{src → types}/xr_type/xr_enums.d.ts +0 -0
  87. /package/{src → types}/xr_type/xr_type.d.ts +0 -0
  88. /package/{src → types}/xr_ui/README.md +0 -0
  89. /package/{src → types}/xr_ui/demo/CServerList.png +0 -0
  90. /package/{src → types}/xr_ui/demo/CUI3tButton.png +0 -0
  91. /package/{src → types}/xr_ui/demo/CUICheckButton.png +0 -0
  92. /package/{src → types}/xr_ui/demo/CUIComboBox.png +0 -0
  93. /package/{src → types}/xr_ui/demo/CUICustomEdit.png +0 -0
  94. /package/{src → types}/xr_ui/demo/CUIStatic.png +0 -0
  95. /package/{src → types}/xr_ui/demo/CUITrackBar.png +0 -0
  96. /package/{src → types}/xr_ui/xr_ui_core.d.ts +0 -0
  97. /package/{src → types}/xr_ui/xr_ui_interface.d.ts +0 -0
@@ -1,48 +0,0 @@
1
- import { unsupportedStaticAccessor } from "../errors";
2
- import { AccessorDeclaration } from "typescript";
3
- import { AllAccessorDeclarations, LuaLibFeature, TransformationContext } from "typescript-to-lua";
4
- import * as lua from "typescript-to-lua";
5
- import { createSelfIdentifier } from "typescript-to-lua/dist/transformation/utils/lua-ast";
6
- import { transformLuaLibFunction } from "typescript-to-lua/dist/transformation/utils/lualib";
7
- import { transformFunctionBody, transformParameters } from "typescript-to-lua/dist/transformation/visitors/function";
8
- import { transformPropertyName } from "typescript-to-lua/dist/transformation/visitors/literal";
9
- import { isStaticNode } from "../utils";
10
-
11
- function transformAccessor(context: TransformationContext, node: AccessorDeclaration): lua.FunctionExpression {
12
- const [params, dot, restParam] = transformParameters(context, node.parameters, createSelfIdentifier());
13
- const body = node.body ? transformFunctionBody(context, node.parameters, node.body, restParam)[0] : [];
14
- return lua.createFunctionExpression(lua.createBlock(body), params, dot, lua.NodeFlags.Declaration);
15
- }
16
-
17
- export function transformAccessorDeclarations(
18
- context: TransformationContext,
19
- { firstAccessor, getAccessor, setAccessor }: AllAccessorDeclarations,
20
- className: lua.Identifier
21
- ): lua.Statement | undefined {
22
- const propertyName = transformPropertyName(context, firstAccessor.name);
23
- const descriptor = lua.createTableExpression([]);
24
-
25
- if (getAccessor) {
26
- const getterFunction = transformAccessor(context, getAccessor);
27
- descriptor.fields.push(lua.createTableFieldExpression(getterFunction, lua.createStringLiteral("get")));
28
- }
29
-
30
- if (setAccessor) {
31
- const setterFunction = transformAccessor(context, setAccessor);
32
- descriptor.fields.push(lua.createTableFieldExpression(setterFunction, lua.createStringLiteral("set")));
33
- }
34
-
35
- const isStatic = isStaticNode(firstAccessor);
36
-
37
- if (isStatic) {
38
- context.diagnostics.push(unsupportedStaticAccessor(firstAccessor));
39
- return;
40
- }
41
-
42
- const target = lua.cloneIdentifier(className);
43
- const feature = LuaLibFeature.ObjectDefineProperty;
44
- const parameters: lua.Expression[] = [target, propertyName, descriptor];
45
-
46
- const call = transformLuaLibFunction(context, feature, undefined, ...parameters);
47
- return lua.createExpressionStatement(call);
48
- }
@@ -1,107 +0,0 @@
1
- import { LUABIND_CONSTRUCTOR_METHOD } from "../constants";
2
- import {
3
- ClassLikeDeclaration,
4
- ConstructorDeclaration,
5
- isCallExpression,
6
- isExpressionStatement,
7
- isIdentifier,
8
- PropertyDeclaration,
9
- SyntaxKind,
10
- } from "typescript";
11
- import { TransformationContext } from "typescript-to-lua";
12
- import * as lua from "typescript-to-lua";
13
- import { createSelfIdentifier } from "typescript-to-lua/dist/transformation/utils/lua-ast";
14
- import { ScopeType } from "typescript-to-lua/dist/transformation/utils/scope";
15
- import {
16
- transformFunctionBodyContent,
17
- transformFunctionBodyHeader,
18
- transformParameters,
19
- } from "typescript-to-lua/dist/transformation/visitors/function";
20
- import { transformIdentifier } from "typescript-to-lua/dist/transformation/visitors/identifier";
21
- import { transformClassInstanceFields } from "./fields";
22
-
23
- export function createConstructorName(className: lua.Identifier): lua.TableIndexExpression {
24
- return lua.createTableIndexExpression(
25
- lua.cloneIdentifier(className),
26
- lua.createStringLiteral(LUABIND_CONSTRUCTOR_METHOD)
27
- );
28
- }
29
-
30
- export function transformConstructorDeclaration(
31
- context: TransformationContext,
32
- statement: ConstructorDeclaration,
33
- className: lua.Identifier,
34
- instanceFields: Array<PropertyDeclaration>,
35
- classDeclaration: ClassLikeDeclaration
36
- ): lua.Statement | undefined {
37
- // Don't transform methods without body (overload declarations)
38
- if (!statement.body) {
39
- return undefined;
40
- }
41
-
42
- // Transform body
43
- const scope = context.pushScope(ScopeType.Function);
44
- const body = transformFunctionBodyContent(context, statement.body);
45
-
46
- const [params, dotsLiteral, restParamName] = transformParameters(
47
- context,
48
- statement.parameters,
49
- createSelfIdentifier()
50
- );
51
-
52
- // Make sure default parameters are assigned before fields are initialized
53
- const bodyWithFieldInitializers = transformFunctionBodyHeader(context, scope, statement.parameters, restParamName);
54
-
55
- // Check for field declarations in constructor
56
- const constructorFieldsDeclarations = statement.parameters.filter((p) => p.modifiers !== undefined);
57
-
58
- const classInstanceFields = transformClassInstanceFields(context, instanceFields);
59
-
60
- // If there are field initializers and the first statement is a super call,
61
- // move super call between default assignments and initializers
62
- if (
63
- (constructorFieldsDeclarations.length > 0 || classInstanceFields.length > 0) &&
64
- statement.body &&
65
- statement.body.statements.length > 0
66
- ) {
67
- const firstStatement = statement.body.statements[0];
68
- if (
69
- isExpressionStatement(firstStatement) &&
70
- isCallExpression(firstStatement.expression) &&
71
- firstStatement.expression.expression.kind === SyntaxKind.SuperKeyword
72
- ) {
73
- const superCall = body.shift();
74
- if (superCall) {
75
- bodyWithFieldInitializers.push(superCall);
76
- }
77
- }
78
- }
79
-
80
- // Add in instance field declarations
81
- for (const declaration of constructorFieldsDeclarations) {
82
- if (isIdentifier(declaration.name)) {
83
- // self.declarationName = declarationName
84
- const assignment = lua.createAssignmentStatement(
85
- lua.createTableIndexExpression(createSelfIdentifier(), lua.createStringLiteral(declaration.name.text)),
86
- transformIdentifier(context, declaration.name)
87
- );
88
- bodyWithFieldInitializers.push(assignment);
89
- }
90
- // else { TypeScript error: A parameter property may not be declared using a binding pattern }
91
- }
92
-
93
- bodyWithFieldInitializers.push(...classInstanceFields);
94
- bodyWithFieldInitializers.push(...body);
95
-
96
- const block = lua.createBlock(bodyWithFieldInitializers);
97
-
98
- const constructorWasGenerated = statement.pos === -1;
99
-
100
- context.popScope();
101
-
102
- return lua.createAssignmentStatement(
103
- createConstructorName(className),
104
- lua.createFunctionExpression(block, params, dotsLiteral, lua.NodeFlags.Declaration),
105
- constructorWasGenerated ? classDeclaration : statement
106
- );
107
- }
@@ -1,53 +0,0 @@
1
- import { unsupportedPropertyDecorator } from "../errors";
2
- import { AccessorDeclaration, canHaveDecorators, getDecorators, PropertyDeclaration } from "typescript";
3
- import { TransformationContext } from "typescript-to-lua";
4
- import * as tstl from "typescript-to-lua";
5
- import { createSelfIdentifier } from "typescript-to-lua/dist/transformation/utils/lua-ast";
6
- import { transformInPrecedingStatementScope } from "typescript-to-lua/dist/transformation/utils/preceding-statements";
7
- import { transformPropertyName } from "typescript-to-lua/dist/transformation/visitors/literal";
8
-
9
- /**
10
- * Verify whether decorators provided for luabind class.
11
- */
12
- export function verifyPropertyDecoratingExpression(
13
- context: TransformationContext,
14
- node: PropertyDeclaration | AccessorDeclaration
15
- ): void {
16
- if (!canHaveDecorators(node)) return;
17
-
18
- const decorators = getDecorators(node);
19
-
20
- if (!decorators) return;
21
-
22
- decorators.forEach((decorator) => {
23
- context.diagnostics.push(unsupportedPropertyDecorator(decorator));
24
- });
25
- }
26
-
27
- export function transformClassInstanceFields(
28
- context: TransformationContext,
29
- instanceFields: Array<PropertyDeclaration>
30
- ): Array<tstl.Statement> {
31
- const statements: Array<tstl.Statement> = [];
32
-
33
- for (const f of instanceFields) {
34
- const { precedingStatements, result: statement } = transformInPrecedingStatementScope(context, () => {
35
- // Get identifier
36
- const fieldName = transformPropertyName(context, f.name);
37
-
38
- const value = f.initializer ? context.transformExpression(f.initializer) : undefined;
39
-
40
- // self[fieldName]
41
- const selfIndex = tstl.createTableIndexExpression(createSelfIdentifier(), fieldName);
42
-
43
- // self[fieldName] = value
44
- const assignClassField = tstl.createAssignmentStatement(selfIndex, value, f);
45
-
46
- return assignClassField;
47
- });
48
-
49
- statements.push(...precedingStatements, statement);
50
- }
51
-
52
- return statements;
53
- }
@@ -1,70 +0,0 @@
1
- import { isStaticNode } from "../utils";
2
- import { unsupportedMethodDecorator, unsupportedParameterDecorator, unsupportedStaticMethod } from "../errors";
3
- import { AccessorDeclaration, getDecorators, MethodDeclaration, PropertyDeclaration } from "typescript";
4
- import { TransformationContext } from "typescript-to-lua";
5
- import * as lua from "typescript-to-lua";
6
- import { transformFunctionToExpression } from "typescript-to-lua/dist/transformation/visitors/function";
7
- import { transformPropertyName } from "typescript-to-lua/dist/transformation/visitors/literal";
8
-
9
- export function transformMemberExpressionOwnerName(
10
- node: PropertyDeclaration | MethodDeclaration | AccessorDeclaration,
11
- className: lua.Identifier
12
- ): lua.Expression {
13
- return lua.cloneIdentifier(className);
14
- }
15
-
16
- export function transformMethodName(context: TransformationContext, node: MethodDeclaration): lua.Expression {
17
- const methodName = transformPropertyName(context, node.name);
18
- if (lua.isStringLiteral(methodName) && methodName.value === "toString") {
19
- return lua.createStringLiteral("__tostring", node.name);
20
- }
21
- return methodName;
22
- }
23
-
24
- export function transformMethodDeclaration(
25
- context: TransformationContext,
26
- node: MethodDeclaration,
27
- className: lua.Identifier
28
- ): lua.Statement | undefined {
29
- // Don't transform methods without body (overload declarations)
30
- if (!node.body) return;
31
-
32
- // Don't transform static methods for luabind classes.
33
- if (isStaticNode(node)) {
34
- context.diagnostics.push(unsupportedStaticMethod(node));
35
- return;
36
- }
37
-
38
- const methodTable = transformMemberExpressionOwnerName(node, className);
39
- const methodName = transformMethodName(context, node);
40
- const [functionExpression] = transformFunctionToExpression(context, node);
41
-
42
- return lua.createAssignmentStatement(
43
- lua.createTableIndexExpression(methodTable, methodName),
44
- functionExpression,
45
- node
46
- );
47
- }
48
-
49
- /**
50
- * Verify that method statement is not using decorators for methods/parameters.
51
- */
52
- export function verifyMethodDecoratingExpression(context: TransformationContext, node: MethodDeclaration): void {
53
- node.parameters.flatMap((parameter, index) => {
54
- const decorators = getDecorators(parameter);
55
-
56
- if (decorators?.length) {
57
- decorators.forEach((decorator) => {
58
- context.diagnostics.push(unsupportedParameterDecorator(decorator));
59
- });
60
- }
61
- });
62
-
63
- const decorators = getDecorators(node);
64
-
65
- if (decorators?.length) {
66
- decorators.forEach((decorator) => {
67
- context.diagnostics.push(unsupportedMethodDecorator(decorator));
68
- });
69
- }
70
- }
@@ -1,14 +0,0 @@
1
- import { ITransformationContext } from "./index";
2
- import { NewExpression } from "typescript";
3
- import * as tstl from "typescript-to-lua";
4
- import { transformArguments } from "typescript-to-lua/dist/transformation/visitors/call";
5
-
6
- /**
7
- * Transform new call for luabind class as ClassConstructor() instead of TS_NEW from tstl.
8
- */
9
- export function transformNewCallExpression(expression: NewExpression, context: ITransformationContext) {
10
- return tstl.createCallExpression(
11
- context.transformExpression(expression.expression),
12
- transformArguments(context, expression.arguments ?? [])
13
- );
14
- }
@@ -1,128 +0,0 @@
1
- import { LUABIND_NAME_FIELD } from "./constants";
2
- import { ClassLikeDeclarationBase, isIdentifier, isVariableDeclaration } from "typescript";
3
- import * as tstl from "typescript-to-lua";
4
- import { TransformationContext } from "typescript-to-lua";
5
- import {
6
- createDefaultExportStringLiteral,
7
- createExportedIdentifier,
8
- getIdentifierExportScope,
9
- hasDefaultExportModifier,
10
- } from "typescript-to-lua/dist/transformation/utils/export";
11
- import {
12
- createExportsIdentifier,
13
- createLocalOrExportedOrGlobalDeclaration,
14
- } from "typescript-to-lua/dist/transformation/utils/lua-ast";
15
- import { getExtendedNode } from "./utils";
16
-
17
- /**
18
- * Create full class setup statement with name/super calls/methods/declaration/fields etc.
19
- */
20
- export function createClassSetup(
21
- context: TransformationContext,
22
- statement: ClassLikeDeclarationBase,
23
- className: tstl.Identifier,
24
- localClassName: tstl.Identifier
25
- ) {
26
- const result: tstl.Statement[] = [];
27
-
28
- // class("name")(base)
29
- const classInitializer = createLuabindClassStatement(statement, context, localClassName);
30
-
31
- result.push(tstl.createExpressionStatement(classInitializer));
32
-
33
- const classReference = createLuabindClassGlobalClassRef(statement, context, localClassName);
34
-
35
- const defaultExportLeftHandSide = hasDefaultExportModifier(statement)
36
- ? tstl.createTableIndexExpression(createExportsIdentifier(), createDefaultExportStringLiteral(statement))
37
- : undefined;
38
-
39
- // [____exports.]className = class()
40
- if (defaultExportLeftHandSide) {
41
- result.push(tstl.createAssignmentStatement(defaultExportLeftHandSide, classReference, statement));
42
- } else {
43
- result.push(...createLocalOrExportedOrGlobalDeclaration(context, className, classReference, statement));
44
- }
45
-
46
- if (defaultExportLeftHandSide) {
47
- // local localClassName = ____exports.default
48
- result.push(tstl.createVariableDeclarationStatement(localClassName, defaultExportLeftHandSide));
49
- } else {
50
- const exportScope = getIdentifierExportScope(context, className);
51
- if (exportScope) {
52
- // local localClassName = ____exports.className
53
- result.push(
54
- tstl.createVariableDeclarationStatement(
55
- localClassName,
56
- createExportedIdentifier(context, tstl.cloneIdentifier(className), exportScope)
57
- )
58
- );
59
- }
60
- }
61
-
62
- // localClassName.__name = className
63
- result.push(
64
- tstl.createAssignmentStatement(
65
- tstl.createTableIndexExpression(
66
- tstl.cloneIdentifier(localClassName),
67
- tstl.createStringLiteral(LUABIND_NAME_FIELD)
68
- ),
69
- getReflectionClassName(statement, className),
70
- statement
71
- )
72
- );
73
-
74
- return result;
75
- }
76
-
77
- export function getReflectionClassName(
78
- declaration: ClassLikeDeclarationBase,
79
- className: tstl.Identifier
80
- ): tstl.Expression {
81
- if (declaration.name) {
82
- return tstl.createStringLiteral(declaration.name.text);
83
- } else if (isVariableDeclaration(declaration.parent) && isIdentifier(declaration.parent.name)) {
84
- return tstl.createStringLiteral(declaration.parent.name.text);
85
- } else if (hasDefaultExportModifier(declaration)) {
86
- return tstl.createStringLiteral("default");
87
- }
88
-
89
- if (getExtendedNode(declaration)) {
90
- return tstl.createTableIndexExpression(className, tstl.createStringLiteral("name"));
91
- }
92
-
93
- return tstl.createStringLiteral("");
94
- }
95
-
96
- /**
97
- * Creates class("Name")(base) expression for luabind classes.
98
- */
99
- function createLuabindClassStatement(
100
- declaration: ClassLikeDeclarationBase,
101
- context: TransformationContext,
102
- className: tstl.Identifier
103
- ) {
104
- const extendedNode = getExtendedNode(declaration);
105
-
106
- let classDeclaration = tstl.createCallExpression(tstl.createIdentifier("class"), [
107
- getReflectionClassName(declaration, className),
108
- ]);
109
-
110
- if (extendedNode) {
111
- classDeclaration = tstl.createCallExpression(classDeclaration, [
112
- context.transformExpression(extendedNode.expression),
113
- ]);
114
- }
115
-
116
- return classDeclaration;
117
- }
118
-
119
- /**
120
- * Creates name expression for luabind classes.
121
- */
122
- function createLuabindClassGlobalClassRef(
123
- declaration: ClassLikeDeclarationBase,
124
- context: TransformationContext,
125
- className: tstl.Identifier
126
- ) {
127
- return className;
128
- }
@@ -1,92 +0,0 @@
1
- import { CallExpression, Expression, factory, isIdentifier, SuperExpression, SyntaxKind } from "typescript";
2
- import * as tstl from "typescript-to-lua";
3
- import { isSymbolExported } from "typescript-to-lua/dist/transformation/utils/export";
4
- import { getCalledExpression, transformArguments } from "typescript-to-lua/dist/transformation/visitors/call";
5
- import { transformIdentifier } from "typescript-to-lua/dist/transformation/visitors/identifier";
6
- import { ITransformationContext } from "./class_declaration";
7
- import { LUABIND_CONSTRUCTOR_METHOD } from "./constants";
8
- import { isLuabindClassType } from "./utils";
9
-
10
- /**
11
- * Transform generic methods super calls.
12
- * Example: super.parentMethod(first, second).
13
- */
14
- export function transformClassSuperMethodExpression(expression: Expression, context: ITransformationContext) {
15
- const superInfos = context.classSuperInfos;
16
- const superInfo = superInfos[superInfos.length - 1];
17
-
18
- if (!superInfo.classDeclaration || !isLuabindClassType(superInfo.classDeclaration, context)) {
19
- return context.superTransformExpression(expression);
20
- }
21
-
22
- const { extendedTypeNode } = superInfo;
23
-
24
- // Using `super` without extended type node is a TypeScript error
25
- const extendsExpression = extendedTypeNode?.expression;
26
- let baseClassName: tstl.AssignmentLeftHandSideExpression | undefined;
27
-
28
- if (extendsExpression && isIdentifier(extendsExpression)) {
29
- const symbol = context.checker.getSymbolAtLocation(extendsExpression);
30
- if (symbol && !isSymbolExported(context, symbol)) {
31
- // Use "baseClassName" if base is a simple identifier
32
- baseClassName = transformIdentifier(context, extendsExpression);
33
- }
34
- }
35
-
36
- if (!baseClassName) {
37
- throw new Error("Super without identifier - not supported with luabind.");
38
- }
39
-
40
- return baseClassName;
41
- }
42
-
43
- /**
44
- * Check if super() call is in luabind class target.
45
- */
46
- export function isLuabindClassSuperCall(
47
- expression: CallExpression | SuperExpression,
48
- context: ITransformationContext
49
- ): boolean {
50
- const calledExpression: Expression = getCalledExpression(expression as CallExpression);
51
-
52
- if (calledExpression.kind !== SyntaxKind.SuperKeyword) {
53
- return false;
54
- } else {
55
- const superInfos = context.classSuperInfos;
56
- const superInfo = superInfos[superInfos.length - 1];
57
-
58
- // Handle super calls properly for luabind classes.
59
- return superInfo?.classDeclaration ? isLuabindClassType(superInfo.classDeclaration, context) : false;
60
- }
61
- }
62
-
63
- /**
64
- * Check if super.method() call is in luabind class target.
65
- */
66
- export function isLuabindClassSuperMethodCall(
67
- expression: CallExpression | SuperExpression,
68
- context: ITransformationContext
69
- ): boolean {
70
- const superInfos = context.classSuperInfos;
71
- const superInfo = superInfos[superInfos.length - 1];
72
-
73
- // Handle super calls properly for luabind classes.
74
- return superInfo?.classDeclaration ? isLuabindClassType(superInfo.classDeclaration, context) : false;
75
- }
76
-
77
- /**
78
- * Transform super() call in luabind classes to base_class.__init(self, param).
79
- */
80
- export function transformLuabindConstructorSuperCall(expression: CallExpression, context: ITransformationContext) {
81
- const signature = context.checker.getResolvedSignature(expression);
82
- const parameters = transformArguments(context, expression.arguments, signature, factory.createThis());
83
-
84
- return tstl.createCallExpression(
85
- tstl.createTableIndexExpression(
86
- context.transformExpression(factory.createSuper()),
87
- tstl.createStringLiteral(LUABIND_CONSTRUCTOR_METHOD)
88
- ),
89
- parameters,
90
- expression
91
- );
92
- }
@@ -1,90 +0,0 @@
1
- import { LUABIND_DECORATOR, LUABIND_SYMBOL } from "./constants";
2
- import {
3
- ClassLikeDeclaration,
4
- ClassLikeDeclarationBase,
5
- Expression,
6
- ExpressionWithTypeArguments,
7
- getDecorators,
8
- HasModifiers,
9
- HeritageClause,
10
- SyntaxKind,
11
- Type,
12
- } from "typescript";
13
- import { TransformationContext } from "typescript-to-lua";
14
-
15
- /**
16
- * Whether method / field is static.
17
- */
18
- export function isStaticNode(node: HasModifiers): boolean {
19
- return node.modifiers?.some((m) => m.kind === SyntaxKind.StaticKeyword) === true;
20
- }
21
-
22
- /**
23
- * Get class extends node.
24
- */
25
- export function getExtendsClause(node: ClassLikeDeclarationBase): HeritageClause | undefined {
26
- return node.heritageClauses?.find((clause) => clause.token === SyntaxKind.ExtendsKeyword);
27
- }
28
-
29
- /**
30
- * Get class extended node.
31
- */
32
- export function getExtendedNode(node: ClassLikeDeclarationBase): ExpressionWithTypeArguments | undefined {
33
- const extendsClause = getExtendsClause(node);
34
- if (!extendsClause) return;
35
-
36
- return extendsClause.types[0];
37
- }
38
-
39
- /**
40
- * Get class extended node.
41
- */
42
- export function getExtendedType(context: TransformationContext, node: ClassLikeDeclarationBase): Type | undefined {
43
- const extendedNode = getExtendedNode(node);
44
- return extendedNode && context.checker.getTypeAtLocation(extendedNode);
45
- }
46
-
47
- /**
48
- * Check if class is decorated with provided decorator name.
49
- */
50
- export function isLuabindDecoratedClass(declaration: ClassLikeDeclaration): boolean {
51
- const decorators = getDecorators(declaration);
52
-
53
- if (!decorators) {
54
- return false;
55
- }
56
-
57
- return decorators.some((it) => (it.expression as unknown as any).expression?.escapedText === LUABIND_DECORATOR);
58
- }
59
-
60
- /**
61
- * Mark provided class as Luabind target.
62
- */
63
- export function markTypeAsLuabind(declaration: ClassLikeDeclaration, context: TransformationContext): void {
64
- const typeAtLocation = context.checker.getTypeAtLocation(declaration);
65
- const typeSymbol = typeAtLocation.symbol || typeAtLocation.aliasSymbol;
66
-
67
- (typeSymbol as {})[LUABIND_SYMBOL] = true;
68
- }
69
-
70
- /**
71
- * Check if provided class is specified as LuaBind.
72
- */
73
- export function isLuabindClassType(
74
- declaration: Expression | ClassLikeDeclaration,
75
- context: TransformationContext
76
- ): boolean {
77
- const typeAtLocation = context.checker.getTypeAtLocation(declaration);
78
- const typeSymbol = typeAtLocation.symbol || typeAtLocation.aliasSymbol;
79
-
80
- if (typeSymbol) {
81
- const isMarked = (typeSymbol as {})[LUABIND_SYMBOL] === true;
82
- if (isMarked) {
83
- return true;
84
- } else {
85
- return isLuabindDecoratedClass(typeSymbol.declarations[0] as ClassLikeDeclaration);
86
- }
87
- } else {
88
- return false;
89
- }
90
- }
@@ -1,24 +0,0 @@
1
- import { DiagnosticCategory, getOriginalNode, Node } from "typescript";
2
- import { createSerialDiagnosticFactory } from "typescript-to-lua/dist/utils";
3
-
4
- type MessageProvider<TArgs extends any[]> = string | ((...args: TArgs) => string);
5
-
6
- /**
7
- * Create diagnostics factory to push errors when transpile lua to typescript.
8
- */
9
- export function createDiagnosticFactory<TArgs extends any[]>(
10
- category: DiagnosticCategory,
11
- message: MessageProvider<TArgs>
12
- ) {
13
- return createSerialDiagnosticFactory((node: Node, ...args: TArgs) => ({
14
- file: getOriginalNode(node).getSourceFile(),
15
- start: getOriginalNode(node).getStart(),
16
- length: getOriginalNode(node).getWidth(),
17
- messageText: typeof message === "string" ? message : message(...args),
18
- category,
19
- }));
20
- }
21
-
22
- export function createErrorDiagnosticFactory<TArgs extends any[]>(message: MessageProvider<TArgs>) {
23
- return createDiagnosticFactory(DiagnosticCategory.Error, message);
24
- }