xray16 1.0.0 → 1.0.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.
- package/README.md +29 -0
- package/package.json +7 -4
- package/plugins/built_at_info.js +14 -0
- package/plugins/from_cast_utils.js +29 -0
- package/plugins/global_declarations_transform.js +20 -0
- package/plugins/inject_filename.js +20 -0
- package/plugins/plugins/built_at_info.js +12 -0
- package/plugins/plugins/from_cast_utils.js +27 -0
- package/plugins/plugins/global_declarations_transform.js +18 -0
- package/plugins/plugins/inject_filename.js +18 -0
- package/plugins/plugins/strip_lua_logger.js +51 -0
- package/plugins/plugins/transform_luabind_class/plugin.js +34 -0
- package/plugins/plugins/transform_luabind_class/transformation/class_declaration.js +141 -0
- package/plugins/plugins/transform_luabind_class/transformation/constants.js +4 -0
- package/plugins/plugins/transform_luabind_class/transformation/decorators.js +12 -0
- package/plugins/plugins/transform_luabind_class/transformation/errors.js +25 -0
- package/plugins/{transform_luabind_class/transformation/index.ts → plugins/transform_luabind_class/transformation/index.js} +5 -5
- package/plugins/plugins/transform_luabind_class/transformation/members/accessors.js +35 -0
- package/plugins/plugins/transform_luabind_class/transformation/members/constructor.js +56 -0
- package/plugins/plugins/transform_luabind_class/transformation/members/fields.js +36 -0
- package/plugins/plugins/transform_luabind_class/transformation/members/method.js +49 -0
- package/plugins/plugins/transform_luabind_class/transformation/new.js +8 -0
- package/plugins/plugins/transform_luabind_class/transformation/setup.js +76 -0
- package/plugins/plugins/transform_luabind_class/transformation/super.js +65 -0
- package/plugins/plugins/transform_luabind_class/transformation/utils.js +67 -0
- package/plugins/plugins/utils/diagnostics.js +17 -0
- package/plugins/strip_lua_logger.js +53 -0
- package/plugins/transform_luabind_class/plugin.js +36 -0
- package/plugins/transform_luabind_class/transformation/class_declaration.js +147 -0
- package/plugins/transform_luabind_class/transformation/constants.js +7 -0
- package/plugins/transform_luabind_class/transformation/decorators.js +16 -0
- package/plugins/transform_luabind_class/transformation/errors.js +28 -0
- package/plugins/transform_luabind_class/transformation/index.js +21 -0
- package/plugins/transform_luabind_class/transformation/members/accessors.js +39 -0
- package/plugins/transform_luabind_class/transformation/members/constructor.js +61 -0
- package/plugins/transform_luabind_class/transformation/members/fields.js +41 -0
- package/plugins/transform_luabind_class/transformation/members/method.js +56 -0
- package/plugins/transform_luabind_class/transformation/new.js +12 -0
- package/plugins/transform_luabind_class/transformation/setup.js +81 -0
- package/plugins/transform_luabind_class/transformation/super.js +72 -0
- package/plugins/transform_luabind_class/transformation/utils.js +77 -0
- package/plugins/utils/diagnostics.js +22 -0
- package/types/index.d.ts +63 -0
- package/{src → types}/xr_object/xr_client_object.d.ts +4 -1
- package/plugins/built_at_info.ts +0 -18
- package/plugins/from_cast_utils.ts +0 -34
- package/plugins/global_declarations_transform.ts +0 -24
- package/plugins/inject_filename.ts +0 -22
- package/plugins/strip_lua_logger.ts +0 -73
- package/plugins/transform_luabind_class/plugin.ts +0 -51
- package/plugins/transform_luabind_class/transformation/class_declaration.ts +0 -226
- package/plugins/transform_luabind_class/transformation/constants.ts +0 -4
- package/plugins/transform_luabind_class/transformation/decorators.ts +0 -16
- package/plugins/transform_luabind_class/transformation/errors.ts +0 -31
- package/plugins/transform_luabind_class/transformation/members/accessors.ts +0 -48
- package/plugins/transform_luabind_class/transformation/members/constructor.ts +0 -107
- package/plugins/transform_luabind_class/transformation/members/fields.ts +0 -53
- package/plugins/transform_luabind_class/transformation/members/method.ts +0 -70
- package/plugins/transform_luabind_class/transformation/new.ts +0 -14
- package/plugins/transform_luabind_class/transformation/setup.ts +0 -128
- package/plugins/transform_luabind_class/transformation/super.ts +0 -92
- package/plugins/transform_luabind_class/transformation/utils.ts +0 -90
- package/plugins/utils/diagnostics.ts +0 -24
- package/src/index.d.ts +0 -63
- /package/{src → types}/xr_constant.d.ts +0 -0
- /package/{src → types}/xr_core.d.ts +0 -0
- /package/{src → types}/xr_global.d.ts +0 -0
- /package/{src → types}/xr_lib/xr_fs.d.ts +0 -0
- /package/{src → types}/xr_lib/xr_math.d.ts +0 -0
- /package/{src → types}/xr_lib/xr_utils.d.ts +0 -0
- /package/{src → types}/xr_luabind.d.ts +0 -0
- /package/{src → types}/xr_map/xr_map.d.ts +0 -0
- /package/{src → types}/xr_object/xr_action.d.ts +0 -0
- /package/{src → types}/xr_object/xr_alife.d.ts +0 -0
- /package/{src → types}/xr_object/xr_anomaly.d.ts +0 -0
- /package/{src → types}/xr_object/xr_artefact.d.ts +0 -0
- /package/{src → types}/xr_object/xr_creature.d.ts +0 -0
- /package/{src → types}/xr_object/xr_dialog.d.ts +0 -0
- /package/{src → types}/xr_object/xr_item.d.ts +0 -0
- /package/{src → types}/xr_object/xr_level.d.ts +0 -0
- /package/{src → types}/xr_object/xr_physic.d.ts +0 -0
- /package/{src → types}/xr_object/xr_quest.d.ts +0 -0
- /package/{src → types}/xr_object/xr_server_object.d.ts +0 -0
- /package/{src → types}/xr_online/xr_multiplayer.d.ts +0 -0
- /package/{src → types}/xr_sound/xr_sound.d.ts +0 -0
- /package/{src → types}/xr_type/xr_enums.d.ts +0 -0
- /package/{src → types}/xr_type/xr_type.d.ts +0 -0
- /package/{src → types}/xr_ui/README.md +0 -0
- /package/{src → types}/xr_ui/demo/CServerList.png +0 -0
- /package/{src → types}/xr_ui/demo/CUI3tButton.png +0 -0
- /package/{src → types}/xr_ui/demo/CUICheckButton.png +0 -0
- /package/{src → types}/xr_ui/demo/CUIComboBox.png +0 -0
- /package/{src → types}/xr_ui/demo/CUICustomEdit.png +0 -0
- /package/{src → types}/xr_ui/demo/CUIStatic.png +0 -0
- /package/{src → types}/xr_ui/demo/CUITrackBar.png +0 -0
- /package/{src → types}/xr_ui/xr_ui_core.d.ts +0 -0
- /package/{src → types}/xr_ui/xr_ui_interface.d.ts +0 -0
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CallExpression,
|
|
3
|
-
factory,
|
|
4
|
-
Identifier,
|
|
5
|
-
PropertyAccessExpression,
|
|
6
|
-
SyntaxKind,
|
|
7
|
-
Type,
|
|
8
|
-
TypeChecker,
|
|
9
|
-
VariableDeclaration,
|
|
10
|
-
VariableDeclarationList,
|
|
11
|
-
} from "typescript";
|
|
12
|
-
import { Plugin } from "typescript-to-lua";
|
|
13
|
-
|
|
14
|
-
const LUA_LOGGER_STRIP_TARGET: string = "LuaLogger";
|
|
15
|
-
const IS_LUA_LOGGER_DISABLED: boolean = process.argv.includes("--no-lua-logs");
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Plugin that removes all LuaLogger instance creations and calls when possible.
|
|
19
|
-
*/
|
|
20
|
-
const plugin: Plugin = {
|
|
21
|
-
visitors: {
|
|
22
|
-
[SyntaxKind.VariableStatement]: (statement, context) => {
|
|
23
|
-
if (IS_LUA_LOGGER_DISABLED) {
|
|
24
|
-
let elementsCount: number = 0;
|
|
25
|
-
const list = statement.declarationList as VariableDeclarationList;
|
|
26
|
-
const nodes: Array<VariableDeclaration> = [];
|
|
27
|
-
|
|
28
|
-
list.forEachChild((it: VariableDeclaration) => {
|
|
29
|
-
const checker: TypeChecker = context.program.getTypeChecker();
|
|
30
|
-
const typeSymbol: Type = checker.getTypeAtLocation(it);
|
|
31
|
-
|
|
32
|
-
if (typeSymbol.symbol?.name === LUA_LOGGER_STRIP_TARGET) {
|
|
33
|
-
// nothing
|
|
34
|
-
} else {
|
|
35
|
-
nodes.push(it);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
elementsCount += 1;
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
if (nodes.length === 0) {
|
|
42
|
-
return undefined;
|
|
43
|
-
} else if (nodes.length !== elementsCount) {
|
|
44
|
-
return context.superTransformStatements(
|
|
45
|
-
factory.createVariableStatement(statement.modifiers, factory.updateVariableDeclarationList(list, nodes))
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return context.superTransformStatements(statement);
|
|
51
|
-
},
|
|
52
|
-
[SyntaxKind.ExpressionStatement]: (statement, context) => {
|
|
53
|
-
if (IS_LUA_LOGGER_DISABLED && statement.expression?.kind === SyntaxKind.CallExpression) {
|
|
54
|
-
const expression: CallExpression = statement.expression as CallExpression;
|
|
55
|
-
const propertyAccess: PropertyAccessExpression = expression.expression as PropertyAccessExpression;
|
|
56
|
-
|
|
57
|
-
if (propertyAccess.expression?.kind === SyntaxKind.Identifier) {
|
|
58
|
-
const checker: TypeChecker = context.program.getTypeChecker();
|
|
59
|
-
const identifier: Identifier = propertyAccess.expression as Identifier;
|
|
60
|
-
const typeSymbol: Type = checker.getTypeAtLocation(identifier);
|
|
61
|
-
|
|
62
|
-
if (typeSymbol.symbol?.name === LUA_LOGGER_STRIP_TARGET) {
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return context.superTransformStatements(statement);
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export default plugin;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
transformLuabindClassDeclaration,
|
|
3
|
-
transformNewCallExpression,
|
|
4
|
-
isLuabindClassSuperCall,
|
|
5
|
-
transformClassSuperMethodExpression,
|
|
6
|
-
transformLuabindConstructorSuperCall,
|
|
7
|
-
ITransformationContext,
|
|
8
|
-
isLuabindClassType,
|
|
9
|
-
isLuabindDecoratedClass,
|
|
10
|
-
isLuabindClassSuperMethodCall,
|
|
11
|
-
} from "./transformation";
|
|
12
|
-
import { CallExpression, NewExpression, SuperExpression, SyntaxKind } from "typescript";
|
|
13
|
-
import { Plugin } from "typescript-to-lua";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Plugin that transform TS classes marked with decorator to luabind class declaration.
|
|
17
|
-
*/
|
|
18
|
-
const plugin: Plugin = {
|
|
19
|
-
visitors: {
|
|
20
|
-
[SyntaxKind.CallExpression]: (expression: CallExpression, context: ITransformationContext) => {
|
|
21
|
-
if (isLuabindClassSuperCall(expression, context)) {
|
|
22
|
-
return transformLuabindConstructorSuperCall(expression, context);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return context.superTransformExpression(expression);
|
|
26
|
-
},
|
|
27
|
-
[SyntaxKind.ClassDeclaration]: (declaration, context: ITransformationContext) => {
|
|
28
|
-
if (isLuabindDecoratedClass(declaration)) {
|
|
29
|
-
return transformLuabindClassDeclaration(declaration, context);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return context.superTransformStatements(declaration);
|
|
33
|
-
},
|
|
34
|
-
[SyntaxKind.NewExpression]: (expression: NewExpression, context: ITransformationContext) => {
|
|
35
|
-
if (isLuabindClassType(expression, context)) {
|
|
36
|
-
return transformNewCallExpression(expression, context);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return context.superTransformExpression(expression);
|
|
40
|
-
},
|
|
41
|
-
[SyntaxKind.SuperKeyword]: (expression: SuperExpression, context: ITransformationContext) => {
|
|
42
|
-
if (isLuabindClassSuperMethodCall(expression, context)) {
|
|
43
|
-
return transformClassSuperMethodExpression(expression, context);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return context.superTransformExpression(expression);
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export default plugin;
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { LUABIND_CONSTRUCTOR_METHOD } from "./constants";
|
|
2
|
-
import { checkLuabindClassDecoratorExpression } from "./decorators";
|
|
3
|
-
import { unsupportedStaticMethod } from "./errors";
|
|
4
|
-
import { transformAccessorDeclarations } from "./members/accessors";
|
|
5
|
-
import { createConstructorName, transformConstructorDeclaration } from "./members/constructor";
|
|
6
|
-
import { verifyPropertyDecoratingExpression, transformClassInstanceFields } from "./members/fields";
|
|
7
|
-
import { verifyMethodDecoratingExpression, transformMethodDeclaration } from "./members/method";
|
|
8
|
-
import { createClassSetup } from "./setup";
|
|
9
|
-
import { getExtendedNode, getExtendedType, isStaticNode, markTypeAsLuabind } from "./utils";
|
|
10
|
-
import {
|
|
11
|
-
canHaveDecorators,
|
|
12
|
-
ClassLikeDeclaration,
|
|
13
|
-
ConstructorDeclaration,
|
|
14
|
-
ExpressionWithTypeArguments,
|
|
15
|
-
factory,
|
|
16
|
-
getDecorators,
|
|
17
|
-
isAccessor,
|
|
18
|
-
isConstructorDeclaration,
|
|
19
|
-
isMethodDeclaration,
|
|
20
|
-
isPropertyDeclaration,
|
|
21
|
-
} from "typescript";
|
|
22
|
-
import * as tstl from "typescript-to-lua";
|
|
23
|
-
import { LuaTarget, TransformationContext } from "typescript-to-lua";
|
|
24
|
-
import {
|
|
25
|
-
createDefaultExportExpression,
|
|
26
|
-
createExportedIdentifier,
|
|
27
|
-
hasDefaultExportModifier,
|
|
28
|
-
hasExportModifier,
|
|
29
|
-
} from "typescript-to-lua/dist/transformation/utils/export";
|
|
30
|
-
import { createSelfIdentifier } from "typescript-to-lua/dist/transformation/utils/lua-ast";
|
|
31
|
-
import { transformInPrecedingStatementScope } from "typescript-to-lua/dist/transformation/utils/preceding-statements";
|
|
32
|
-
import { createSafeName, isUnsafeName } from "typescript-to-lua/dist/transformation/utils/safe-names";
|
|
33
|
-
import { transformIdentifier } from "typescript-to-lua/dist/transformation/visitors/identifier";
|
|
34
|
-
|
|
35
|
-
export interface ITransformationContext extends TransformationContext {
|
|
36
|
-
classSuperInfos: Array<ClassSuperInfo>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const transformLuabindClassDeclaration = (declaration, context: TransformationContext) => {
|
|
40
|
-
// If declaration is a default export, transform to export variable assignment instead
|
|
41
|
-
if (hasDefaultExportModifier(declaration)) {
|
|
42
|
-
// Class declaration including assignment to ____exports.default are in preceding statements
|
|
43
|
-
const { precedingStatements } = transformInPrecedingStatementScope(context, () => {
|
|
44
|
-
transformClassAsExpression(declaration, context as ITransformationContext);
|
|
45
|
-
return [];
|
|
46
|
-
});
|
|
47
|
-
return precedingStatements;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const { statements } = transformClassLikeDeclaration(declaration, context as ITransformationContext);
|
|
51
|
-
return statements;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export function transformClassAsExpression(
|
|
55
|
-
expression: ClassLikeDeclaration,
|
|
56
|
-
context: ITransformationContext
|
|
57
|
-
): tstl.Expression {
|
|
58
|
-
const { statements, name } = transformClassLikeDeclaration(expression, context);
|
|
59
|
-
context.addPrecedingStatements(statements);
|
|
60
|
-
return name;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** @internal */
|
|
64
|
-
export interface ClassSuperInfo {
|
|
65
|
-
className: tstl.Identifier;
|
|
66
|
-
classDeclaration: ClassLikeDeclaration;
|
|
67
|
-
extendedTypeNode?: ExpressionWithTypeArguments;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function transformClassLikeDeclaration(
|
|
71
|
-
classDeclaration: ClassLikeDeclaration,
|
|
72
|
-
context: ITransformationContext,
|
|
73
|
-
nameOverride?: tstl.Identifier
|
|
74
|
-
): { statements: tstl.Statement[]; name: tstl.Identifier } {
|
|
75
|
-
let className: tstl.Identifier;
|
|
76
|
-
|
|
77
|
-
if (nameOverride !== undefined) {
|
|
78
|
-
className = nameOverride;
|
|
79
|
-
} else if (classDeclaration.name !== undefined) {
|
|
80
|
-
className = transformIdentifier(context, classDeclaration.name);
|
|
81
|
-
} else {
|
|
82
|
-
className = tstl.createIdentifier(context.createTempName("class"), classDeclaration);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
markTypeAsLuabind(classDeclaration, context);
|
|
86
|
-
|
|
87
|
-
// Get type that is extended
|
|
88
|
-
const extendedTypeNode = getExtendedNode(classDeclaration);
|
|
89
|
-
const extendedType = getExtendedType(context, classDeclaration);
|
|
90
|
-
|
|
91
|
-
context.classSuperInfos.push({ className, classDeclaration: classDeclaration, extendedTypeNode });
|
|
92
|
-
|
|
93
|
-
// Get all properties with value
|
|
94
|
-
const properties = classDeclaration.members.filter(isPropertyDeclaration).filter((member) => member.initializer);
|
|
95
|
-
|
|
96
|
-
// Divide properties into static and non-static
|
|
97
|
-
const instanceFields = properties.filter((prop) => !isStaticNode(prop));
|
|
98
|
-
|
|
99
|
-
const result: tstl.Statement[] = [];
|
|
100
|
-
|
|
101
|
-
let localClassName: tstl.Identifier;
|
|
102
|
-
if (isUnsafeName(className.text, context.options)) {
|
|
103
|
-
localClassName = tstl.createIdentifier(
|
|
104
|
-
createSafeName(className.text),
|
|
105
|
-
undefined,
|
|
106
|
-
className.symbolId,
|
|
107
|
-
className.text
|
|
108
|
-
);
|
|
109
|
-
tstl.setNodePosition(localClassName, className);
|
|
110
|
-
} else {
|
|
111
|
-
localClassName = className;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
result.push(...createClassSetup(context, classDeclaration, className, localClassName));
|
|
115
|
-
|
|
116
|
-
// Find first constructor with body
|
|
117
|
-
const constructor = classDeclaration.members.find(
|
|
118
|
-
(n): n is ConstructorDeclaration => isConstructorDeclaration(n) && n.body !== undefined
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
if (constructor) {
|
|
122
|
-
// Add constructor plus initialization of instance fields
|
|
123
|
-
const constructorResult = transformConstructorDeclaration(
|
|
124
|
-
context,
|
|
125
|
-
constructor,
|
|
126
|
-
localClassName,
|
|
127
|
-
instanceFields,
|
|
128
|
-
classDeclaration
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
if (constructorResult) result.push(constructorResult);
|
|
132
|
-
} else if (!extendedType) {
|
|
133
|
-
// Generate a constructor if none was defined in a base class
|
|
134
|
-
const constructorResult = transformConstructorDeclaration(
|
|
135
|
-
context,
|
|
136
|
-
factory.createConstructorDeclaration([], [], factory.createBlock([], true)),
|
|
137
|
-
localClassName,
|
|
138
|
-
instanceFields,
|
|
139
|
-
classDeclaration
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
if (constructorResult) result.push(constructorResult);
|
|
143
|
-
} else {
|
|
144
|
-
// Generate a constructor if none was defined in a class with instance fields that need initialization
|
|
145
|
-
// localClassName.__init = function(self, ...)
|
|
146
|
-
// baseClassName.__init(self, ...) // or unpack(arg) for Lua 5.0
|
|
147
|
-
// ...
|
|
148
|
-
// Also luabind always needs definition of call expression to use table as class.
|
|
149
|
-
const constructorBody = transformClassInstanceFields(context, instanceFields);
|
|
150
|
-
const argsExpression =
|
|
151
|
-
context.luaTarget === LuaTarget.Lua50
|
|
152
|
-
? tstl.createCallExpression(tstl.createIdentifier("unpack"), [tstl.createArgLiteral()])
|
|
153
|
-
: tstl.createDotsLiteral();
|
|
154
|
-
const superCall = tstl.createExpressionStatement(
|
|
155
|
-
tstl.createCallExpression(
|
|
156
|
-
tstl.createTableIndexExpression(
|
|
157
|
-
context.transformExpression(factory.createSuper()),
|
|
158
|
-
tstl.createStringLiteral(LUABIND_CONSTRUCTOR_METHOD)
|
|
159
|
-
),
|
|
160
|
-
[createSelfIdentifier(), argsExpression]
|
|
161
|
-
)
|
|
162
|
-
);
|
|
163
|
-
constructorBody.unshift(superCall);
|
|
164
|
-
const constructorFunction = tstl.createFunctionExpression(
|
|
165
|
-
tstl.createBlock(constructorBody),
|
|
166
|
-
[createSelfIdentifier()],
|
|
167
|
-
tstl.createDotsLiteral(),
|
|
168
|
-
tstl.NodeFlags.Declaration
|
|
169
|
-
);
|
|
170
|
-
result.push(
|
|
171
|
-
tstl.createAssignmentStatement(createConstructorName(localClassName), constructorFunction, classDeclaration)
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Transform accessors
|
|
176
|
-
for (const member of classDeclaration.members) {
|
|
177
|
-
if (!isAccessor(member)) continue;
|
|
178
|
-
const accessors = context.resolver.getAllAccessorDeclarations(member);
|
|
179
|
-
if (accessors.firstAccessor !== member) continue;
|
|
180
|
-
|
|
181
|
-
const accessorsResult = transformAccessorDeclarations(context, accessors, localClassName);
|
|
182
|
-
if (accessorsResult) {
|
|
183
|
-
result.push(accessorsResult);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const decorationStatements: tstl.Statement[] = [];
|
|
188
|
-
|
|
189
|
-
for (const member of classDeclaration.members) {
|
|
190
|
-
if (isAccessor(member)) {
|
|
191
|
-
verifyPropertyDecoratingExpression(context, member);
|
|
192
|
-
} else if (isMethodDeclaration(member)) {
|
|
193
|
-
const statement = transformMethodDeclaration(context, member, localClassName);
|
|
194
|
-
if (statement) result.push(statement);
|
|
195
|
-
if (member.body) {
|
|
196
|
-
verifyMethodDecoratingExpression(context, member);
|
|
197
|
-
}
|
|
198
|
-
} else if (isPropertyDeclaration(member)) {
|
|
199
|
-
if (isStaticNode(member)) {
|
|
200
|
-
context.diagnostics.push(unsupportedStaticMethod(member));
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
verifyPropertyDecoratingExpression(context, member);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
result.push(...decorationStatements);
|
|
208
|
-
|
|
209
|
-
// Decorate the class
|
|
210
|
-
if (canHaveDecorators(classDeclaration) && getDecorators(classDeclaration)) {
|
|
211
|
-
getDecorators(classDeclaration)?.forEach((d) => checkLuabindClassDecoratorExpression(context, d));
|
|
212
|
-
|
|
213
|
-
if (hasExportModifier(classDeclaration)) {
|
|
214
|
-
const exportExpression = hasDefaultExportModifier(classDeclaration)
|
|
215
|
-
? createDefaultExportExpression(classDeclaration)
|
|
216
|
-
: createExportedIdentifier(context, className);
|
|
217
|
-
|
|
218
|
-
const classAssignment = tstl.createAssignmentStatement(exportExpression, localClassName);
|
|
219
|
-
result.push(classAssignment);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
context.classSuperInfos.pop();
|
|
224
|
-
|
|
225
|
-
return { statements: result, name: className };
|
|
226
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { unsupportedClassDecorator } from "./errors";
|
|
2
|
-
import { LUABIND_DECORATOR } from "./constants";
|
|
3
|
-
import { CallExpression, Decorator, Identifier } from "typescript";
|
|
4
|
-
import { TransformationContext } from "typescript-to-lua";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Transform decorator call expressions for luabind class.
|
|
8
|
-
*/
|
|
9
|
-
export function checkLuabindClassDecoratorExpression(context: TransformationContext, decorator: Decorator) {
|
|
10
|
-
const expression = decorator.expression;
|
|
11
|
-
|
|
12
|
-
// Do not transform luabind decorator.
|
|
13
|
-
if (((expression as CallExpression).expression as Identifier).text !== LUABIND_DECORATOR) {
|
|
14
|
-
context.diagnostics.push(unsupportedClassDecorator(expression));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createErrorDiagnosticFactory } from "../../utils/diagnostics";
|
|
2
|
-
|
|
3
|
-
export const unsupportedStaticMethod = createErrorDiagnosticFactory((name?: string) => {
|
|
4
|
-
const nameReference = name ? ` '${name}'` : "";
|
|
5
|
-
return `Unable transform static properties for luabind classes${nameReference}.`;
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
export const unsupportedClassDecorator = createErrorDiagnosticFactory((name?: string) => {
|
|
9
|
-
const nameReference = name ? ` '${name}'` : "";
|
|
10
|
-
return `Unable transform class decorators for luabind classes${nameReference}.`;
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export const unsupportedPropertyDecorator = createErrorDiagnosticFactory((name?: string) => {
|
|
14
|
-
const nameReference = name ? ` '${name}'` : "";
|
|
15
|
-
return `Unable transform property decorator for luabind classes${nameReference}.`;
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export const unsupportedParameterDecorator = createErrorDiagnosticFactory((name?: string) => {
|
|
19
|
-
const nameReference = name ? ` '${name}'` : "";
|
|
20
|
-
return `Unable transform parameter decorator for luabind classes${nameReference}.`;
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export const unsupportedMethodDecorator = createErrorDiagnosticFactory((name?: string) => {
|
|
24
|
-
const nameReference = name ? ` '${name}'` : "";
|
|
25
|
-
return `Unable transform method decorator for luabind classes${nameReference}.`;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
export const unsupportedStaticAccessor = createErrorDiagnosticFactory((name?: string) => {
|
|
29
|
-
const nameReference = name ? ` '${name}'` : "";
|
|
30
|
-
return `Unable transform static accessors for luabind classes${nameReference}.`;
|
|
31
|
-
});
|
|
@@ -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
|
-
}
|