@bikky/compiler 0.0.79 → 0.1.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/.idea/copilot.data.migration.agent.xml +6 -0
- package/.idea/copilot.data.migration.ask.xml +6 -0
- package/.idea/copilot.data.migration.ask2agent.xml +6 -0
- package/.idea/copilot.data.migration.edit.xml +6 -0
- package/Libraries/DelayLib.d.mts +34 -2
- package/Libraries/DelayLib.d.mts.map +1 -1
- package/Libraries/DelayLib.mjs +173 -11
- package/Libraries/DelayLib.mjs.map +1 -1
- package/Libraries/DelayLib.mts +219 -14
- package/Libraries/GlobalTypes.d.ts +5 -1
- package/Source/ASTBuilder.d.ts.map +1 -1
- package/Source/ASTHelper.d.ts +1 -1
- package/Source/ASTHelper.d.ts.map +1 -1
- package/Source/ASTHelper.js +22 -4
- package/Source/ASTInterface/Crawler.d.ts +8 -2
- package/Source/ASTInterface/Crawler.d.ts.map +1 -1
- package/Source/ASTInterface/Crawler.js +36 -20
- package/Source/MiscHelpers.d.ts +21 -0
- package/Source/MiscHelpers.d.ts.map +1 -0
- package/Source/MiscHelpers.js +152 -0
- package/Transformers/DelayTransformer.js +52 -0
- package/Transformers/Main.d.ts +2 -1
- package/Transformers/Main.d.ts.map +1 -1
- package/Transformers/Main.js +4 -12
- package/Transformers/ReplicableTransformer.d.ts +2 -0
- package/Transformers/ReplicableTransformer.d.ts.map +1 -0
- package/Transformers/ReplicableTransformer.js +427 -0
- package/package.json +4 -3
- package/tsconfig.build.libs.tsbuildinfo +1 -1
- package/tsconfig.build.src.tsbuildinfo +1 -1
- package/tsconfig.json +4 -5
- package/Transformers/Qdrant.d.ts +0 -18
- package/Transformers/Qdrant.d.ts.map +0 -1
- package/Transformers/Qdrant.js +0 -148
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Crawler_js_1 = require("../Source/ASTInterface/Crawler.js");
|
|
4
|
+
const ts = require("typescript");
|
|
5
|
+
const ASTHelper_js_1 = require("../Source/ASTHelper.js");
|
|
6
|
+
const ts_clone_node_1 = require("ts-clone-node");
|
|
7
|
+
const MiscHelpers_js_1 = require("../Source/MiscHelpers.js");
|
|
8
|
+
var printNode = ASTHelper_js_1.Printer.printNode;
|
|
9
|
+
//RBF = Replication Breakdown File.
|
|
10
|
+
const rbfExt = ".rbf.js";
|
|
11
|
+
const defExt = ".data.d.ts";
|
|
12
|
+
const Klasses = new Map;
|
|
13
|
+
let currentFile = null;
|
|
14
|
+
let allFileImports = new Map();
|
|
15
|
+
let replTypeImports = new Map();
|
|
16
|
+
let currentFileAliases = new Map();
|
|
17
|
+
let rbfImports = new Map();
|
|
18
|
+
let defImports = new Map();
|
|
19
|
+
let rbfContents = [];
|
|
20
|
+
function resolveAliases(name) {
|
|
21
|
+
while (currentFileAliases.has(name)) {
|
|
22
|
+
name = currentFileAliases.get(name);
|
|
23
|
+
}
|
|
24
|
+
return name;
|
|
25
|
+
}
|
|
26
|
+
function makeDataName(name) {
|
|
27
|
+
return name[0].toUpperCase() + name.slice(1);
|
|
28
|
+
}
|
|
29
|
+
function printRBFClass(klass) {
|
|
30
|
+
return `
|
|
31
|
+
Name: ${klass.Name},
|
|
32
|
+
DataName: ${klass.DataName},
|
|
33
|
+
Referenced: ${klass.Referenced},
|
|
34
|
+
Parents: [${klass.Parents.map(p => resolveAliases(p) + "RBF").join(", ")}],
|
|
35
|
+
AllPropertyNames: [],
|
|
36
|
+
OwnPropertyNames: [${klass.OwnPropertyNames.sort().map((e) => `"${e}"`).join(", ")}],
|
|
37
|
+
TypescriptProperties: {${klass.TypescriptProperties.map(p => `
|
|
38
|
+
${p.propertyName}: ${JSON.stringify(p.rbfType)}`).join(",")}
|
|
39
|
+
},
|
|
40
|
+
SerialisedProperties: {${klass.SerialisedProperties.map(p => `
|
|
41
|
+
${p.propertyName}: ${JSON.stringify(p.rbfType)}`).join(",")}
|
|
42
|
+
},
|
|
43
|
+
DataProperties: {${klass.DataProperties.map(p => `
|
|
44
|
+
${p.propertyName}: {
|
|
45
|
+
Type: ${JSON.stringify(p.rbfType)},
|
|
46
|
+
DataName: "${p.dataName}"
|
|
47
|
+
}`).join(",")}
|
|
48
|
+
}`.trim() + "\n";
|
|
49
|
+
}
|
|
50
|
+
const warning = `
|
|
51
|
+
// This file is automatically generated by the bikky compiler.
|
|
52
|
+
`.trim();
|
|
53
|
+
Crawler_js_1.Crawler.OnFile((node) => {
|
|
54
|
+
allFileImports.clear();
|
|
55
|
+
currentFileAliases.clear();
|
|
56
|
+
rbfImports.clear();
|
|
57
|
+
rbfContents = [];
|
|
58
|
+
currentFile = node.ts;
|
|
59
|
+
});
|
|
60
|
+
Crawler_js_1.Crawler.OnFileCompleted((node => {
|
|
61
|
+
if (currentFile) {
|
|
62
|
+
let imports = Array.from(rbfImports.entries()).map(([key, value]) => {
|
|
63
|
+
value = Array.from(new Set(value));
|
|
64
|
+
return `import {${value.join(", ")}} from "${key}";`;
|
|
65
|
+
});
|
|
66
|
+
imports.push(`import { Replicable } from "@bikky/replication";`);
|
|
67
|
+
Crawler_js_1.Crawler.writeSupplementaryFile(currentFile.fileName.slice(0, -3) + rbfExt, imports.join("\n") + "\n\n" + warning + "\n\n" +
|
|
68
|
+
rbfContents.map((e, i) => `export const ${e.Name}RBF = {\n\t${printRBFClass(e)}};\n`
|
|
69
|
+
+ `${e.Name}RBF.AllPropertyNames = ${e.Name}RBF.OwnPropertyNames.concat(${e.Parents.map((e) => `${e}RBF.AllPropertyNames`).join(", ")});\n`
|
|
70
|
+
+ `${e.Name}RBF.AllPropertyNames = Array.from(new Set(${e.Name}RBF.AllPropertyNames)).sort();\n`
|
|
71
|
+
+ `Replicable.registerClass(${e.Name}RBF);`).join("\n\n\n"));
|
|
72
|
+
imports = Array.from(defImports.entries()).map(([key, value]) => {
|
|
73
|
+
value = Array.from(new Set(value));
|
|
74
|
+
return `import {${value.join(", ")}} from "${key}";`;
|
|
75
|
+
});
|
|
76
|
+
Crawler_js_1.Crawler.writeSupplementaryFile(currentFile.fileName.slice(0, -3) + defExt, imports.join("\n") + "\n\n" + warning + "\n\n" +
|
|
77
|
+
rbfContents.map((e) => {
|
|
78
|
+
if (e.Parents.length > 0) {
|
|
79
|
+
return `export interface ${e.Name}Data extends ${e.Parents.map((e) => `Omit<${e + "Data"}, "Class">`).join(", ")} {\n` +
|
|
80
|
+
`\tClass: "${e.Name}";\n` +
|
|
81
|
+
e.DataProperties.map((p) => `\t"${p.dataName}": ${p.defType};`).join(";\n") +
|
|
82
|
+
`\n}\n\n` +
|
|
83
|
+
`export interface ${e.Name}Serialised extends ${e.Parents.map((e) => e + "Serialised").join(", ")} {\n` +
|
|
84
|
+
`\tversion: string;\n` +
|
|
85
|
+
e.SerialisedProperties.map((p) => `\t"${p.propertyName}": ${p.defType};`).join(";\n") +
|
|
86
|
+
`\n}\n\n` +
|
|
87
|
+
`export interface ${e.Name}Construct extends ${e.Parents.map((e) => e + "Construct").join(", ")} {\n` +
|
|
88
|
+
e.TypescriptProperties.map((p) => `\t"${p.dataName}"?: ${p.defType};`).join(";\n") +
|
|
89
|
+
`\n}\n`;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return `export interface ${e.Name}Data {\n` +
|
|
93
|
+
`\tClass: "${e.Name}";\n` +
|
|
94
|
+
e.DataProperties.map((p) => `\t"${p.dataName}": ${p.defType};`).join(";\n") +
|
|
95
|
+
`\n}\n\n` +
|
|
96
|
+
`export interface ${e.Name}Serialised {\n` +
|
|
97
|
+
`\tversion: string;\n` +
|
|
98
|
+
e.SerialisedProperties.map((p) => `\t"${p.propertyName}": ${p.defType};`).join(";\n") +
|
|
99
|
+
`\n}\n\n` +
|
|
100
|
+
`export interface ${e.Name}Construct {\n` +
|
|
101
|
+
e.TypescriptProperties.map((p) => `\t"${p.dataName}"?: ${p.defType};`).join(";\n") +
|
|
102
|
+
`\n}\n`;
|
|
103
|
+
}
|
|
104
|
+
}).join("\n"));
|
|
105
|
+
}
|
|
106
|
+
return node.ts;
|
|
107
|
+
}));
|
|
108
|
+
Crawler_js_1.Crawler.Register((node) => {
|
|
109
|
+
if (ts.isImportDeclaration(node) && node.importClause) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}, (node) => {
|
|
114
|
+
let declaration = node;
|
|
115
|
+
let localPath = declaration.moduleSpecifier.getText().slice(1, -1);
|
|
116
|
+
let rbfpath = (0, MiscHelpers_js_1.joinPaths)((0, MiscHelpers_js_1.getPathDir)(node.getSourceFile().fileName), localPath)
|
|
117
|
+
.replace(/\.ts$/, rbfExt);
|
|
118
|
+
let clause = declaration.importClause;
|
|
119
|
+
if (clause.name) {
|
|
120
|
+
// import name from "module"
|
|
121
|
+
allFileImports.set(clause.name.getText() + "RBF", rbfpath);
|
|
122
|
+
}
|
|
123
|
+
else if (clause.namedBindings) {
|
|
124
|
+
for (let binding of clause.namedBindings.getChildren()) {
|
|
125
|
+
if (ts.isNamedImports(binding)) {
|
|
126
|
+
for (let element of binding.elements) {
|
|
127
|
+
// import { name as alias } from "module"
|
|
128
|
+
if (element.propertyName) {
|
|
129
|
+
currentFileAliases.set(element.propertyName.getText() + "RBF", element.name.getText());
|
|
130
|
+
}
|
|
131
|
+
// import { name } from "module"
|
|
132
|
+
allFileImports.set(element.name.getText() + "RBF", rbfpath);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// import * as name from "module"
|
|
136
|
+
else if (ts.isNamespaceImport(binding)) {
|
|
137
|
+
allFileImports.set(binding.name.getText() + "RBF", rbfpath);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return node;
|
|
142
|
+
});
|
|
143
|
+
//Remember all classes that are marked as InlineClass or AddressableClass.
|
|
144
|
+
Crawler_js_1.Crawler.Register((node) => {
|
|
145
|
+
if (ts.isDecorator(node) && (ts.isClassDeclaration(node.parent) || ts.isClassExpression(node.parent))) {
|
|
146
|
+
let decorator = node;
|
|
147
|
+
let decoratorName = ts.isCallExpression(decorator.expression) ? decorator.expression.expression.getText() : decorator.expression.getText();
|
|
148
|
+
if (decoratorName === "InlineClass" || decoratorName === "AddressableClass") {
|
|
149
|
+
if (ts.isClassDeclaration(node.parent)) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
else if (ts.isClassExpression(node.parent) && "name" in node.parent && node.parent.name) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
(0, ASTHelper_js_1.logError)(node, `Decorator @${decoratorName} can only be applied to named classes.`);
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
}, (node) => {
|
|
164
|
+
var _a, _b, _c, _d, _e, _f;
|
|
165
|
+
let decorator = node;
|
|
166
|
+
let decoratorName = ts.isCallExpression(decorator.expression) ? decorator.expression.expression.getText() : decorator.expression.getText();
|
|
167
|
+
let klassNode = node.parent;
|
|
168
|
+
if (decoratorName === "InlineClass" || decoratorName === "AddressableClass") {
|
|
169
|
+
let klassName = klassNode.name.text;
|
|
170
|
+
let klassExtends = (_b = (_a = klassNode.heritageClauses) === null || _a === void 0 ? void 0 : _a.find(hc => hc.token === ts.SyntaxKind.ExtendsKeyword)) !== null && _b !== void 0 ? _b : null;
|
|
171
|
+
let klassParents = [];
|
|
172
|
+
if (klassExtends) {
|
|
173
|
+
try {
|
|
174
|
+
klassParents = (0, MiscHelpers_js_1.getAllInheritedMixinClassNames)(klassExtends);
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
console.error(e.message);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
for (let value of klassParents) {
|
|
181
|
+
let impo = allFileImports.get(resolveAliases(value));
|
|
182
|
+
if (impo) {
|
|
183
|
+
//Add parents to imports for rbf file.
|
|
184
|
+
let arr = (_c = rbfImports.get(impo.slice(0, -3) + rbfExt)) !== null && _c !== void 0 ? _c : [];
|
|
185
|
+
rbfImports.set(impo.slice(0, -3) + rbfExt, arr);
|
|
186
|
+
arr.push(resolveAliases(value) + "RBF");
|
|
187
|
+
//Add parents to imports for def file.
|
|
188
|
+
arr = (_d = defImports.get(impo.slice(0, -3) + defExt)) !== null && _d !== void 0 ? _d : [];
|
|
189
|
+
defImports.set(impo.slice(0, -3) + defExt, arr);
|
|
190
|
+
arr.push(resolveAliases(value) + "Data");
|
|
191
|
+
arr.push(resolveAliases(value) + "Serialised");
|
|
192
|
+
arr.push(resolveAliases(value) + "Construct");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
let klassGenerics = (_f = (_e = klassNode.typeParameters) === null || _e === void 0 ? void 0 : _e.map(e => e.name.getText())) !== null && _f !== void 0 ? _f : [];
|
|
196
|
+
let klassInfo = {
|
|
197
|
+
Name: klassName,
|
|
198
|
+
DataName: klassName,
|
|
199
|
+
Referenced: decoratorName === "AddressableClass",
|
|
200
|
+
Parents: klassParents,
|
|
201
|
+
Generics: klassGenerics,
|
|
202
|
+
PropertyConfig: {},
|
|
203
|
+
AllPropertyNames: [],
|
|
204
|
+
OwnPropertyNames: [],
|
|
205
|
+
TypescriptProperties: [],
|
|
206
|
+
SerialisedProperties: [],
|
|
207
|
+
DataProperties: [],
|
|
208
|
+
ExposedFunctions: []
|
|
209
|
+
};
|
|
210
|
+
Klasses.set(klassName, klassInfo);
|
|
211
|
+
rbfContents.push(klassInfo);
|
|
212
|
+
}
|
|
213
|
+
//Don't remove the node - Replicable can use it to determine if there's an RBF to be imported.
|
|
214
|
+
return node;
|
|
215
|
+
});
|
|
216
|
+
function recursivelyConvertType(typeNode) {
|
|
217
|
+
if (ts.isUnionTypeNode(typeNode)) {
|
|
218
|
+
return {
|
|
219
|
+
OR: typeNode.types.map(t => recursivelyConvertType(t))
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
else if (ts.isArrayTypeNode(typeNode)) {
|
|
223
|
+
return {
|
|
224
|
+
Is: "Array",
|
|
225
|
+
Containing: [recursivelyConvertType(typeNode.elementType)]
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
else if (ts.isTypeReferenceNode(typeNode)) {
|
|
229
|
+
if (typeNode.typeArguments && typeNode.typeArguments.length > 0) {
|
|
230
|
+
return {
|
|
231
|
+
Is: typeNode.typeName.getText(),
|
|
232
|
+
Containing: typeNode.typeArguments.map(t => recursivelyConvertType(t))
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
Is: typeNode.typeName.getText()
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
else if (typeNode.kind == ts.SyntaxKind.StringKeyword) {
|
|
240
|
+
return {
|
|
241
|
+
Is: "String"
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
else if (typeNode.kind == ts.SyntaxKind.NumberKeyword) {
|
|
245
|
+
return {
|
|
246
|
+
Is: "Number"
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
else if (typeNode.kind == ts.SyntaxKind.BooleanKeyword) {
|
|
250
|
+
return {
|
|
251
|
+
Is: "Boolean"
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
else if (typeNode.kind === ts.SyntaxKind.AnyKeyword) {
|
|
255
|
+
return {
|
|
256
|
+
Is: "Object"
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
else if (typeNode.kind === ts.SyntaxKind.VoidKeyword) {
|
|
260
|
+
return {
|
|
261
|
+
Is: "Void"
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
else if (typeNode.kind === ts.SyntaxKind.NeverKeyword) {
|
|
265
|
+
return {
|
|
266
|
+
Is: "Never"
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
else if (ts.isLiteralTypeNode(typeNode)) {
|
|
270
|
+
if (typeNode.literal.kind === ts.SyntaxKind.NullKeyword) {
|
|
271
|
+
return {
|
|
272
|
+
Is: "Null"
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
else if (typeNode.literal.kind === ts.SyntaxKind.NumberKeyword) {
|
|
276
|
+
return {
|
|
277
|
+
Is: "String",
|
|
278
|
+
RestrictedTo: typeNode.literal.text.includes(".") ?
|
|
279
|
+
parseInt(typeNode.literal.text) : parseFloat(typeNode.literal.text),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
else if (typeNode.literal.kind === ts.SyntaxKind.StringKeyword) {
|
|
283
|
+
return {
|
|
284
|
+
Is: "String",
|
|
285
|
+
RestrictedTo: typeNode.literal.text
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
else if (typeNode.literal.kind === ts.SyntaxKind.TrueKeyword) {
|
|
289
|
+
return {
|
|
290
|
+
Is: "Boolean",
|
|
291
|
+
RestrictedTo: true
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
else if (typeNode.literal.kind === ts.SyntaxKind.FalseKeyword) {
|
|
295
|
+
return {
|
|
296
|
+
Is: "Boolean",
|
|
297
|
+
RestrictedTo: false
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
//Inline JSON.
|
|
302
|
+
else if (ts.isTypeLiteralNode(typeNode)) {
|
|
303
|
+
return {
|
|
304
|
+
Is: "Object"
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
(0, ASTHelper_js_1.logError)(typeNode, `Unsupported type value for @Property, @Get or @Function syntax :${ts.SyntaxKind[typeNode.kind]}`);
|
|
308
|
+
return {
|
|
309
|
+
Is: "Unknown"
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
// Handle @Property, @Setter and @Getter decorators.
|
|
313
|
+
Crawler_js_1.Crawler.Register((node) => {
|
|
314
|
+
if (ts.isDecorator(node) && ts.isPropertyDeclaration(node.parent) && ts.isCallExpression(node.expression) && node.expression.expression.getText() === "Property") {
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
return false;
|
|
318
|
+
}, (node) => {
|
|
319
|
+
let decorator = node;
|
|
320
|
+
let propertyNode = node.parent;
|
|
321
|
+
let klassNode = propertyNode.parent;
|
|
322
|
+
let klassName = klassNode.name.text;
|
|
323
|
+
let klassInfo = Klasses.get(klassName);
|
|
324
|
+
if (!klassInfo) {
|
|
325
|
+
console.error((0, ASTHelper_js_1.logError)(klassNode, `Class ${klassName} is not marked as @InlineClass or @AddressableClass but has a @Property decorator.`));
|
|
326
|
+
return [];
|
|
327
|
+
}
|
|
328
|
+
let propertyName = propertyNode.name.getText();
|
|
329
|
+
let dataName = makeDataName(propertyName);
|
|
330
|
+
let typeChecker = Crawler_js_1.Crawler.GetProgram().ts.getTypeChecker();
|
|
331
|
+
//Use static type if provided, otherwise dynamic type if initialiser is provided, otherwise unknown.
|
|
332
|
+
let valueType;
|
|
333
|
+
if (propertyNode.type) {
|
|
334
|
+
valueType = propertyNode.type;
|
|
335
|
+
}
|
|
336
|
+
else if (propertyNode.initializer) {
|
|
337
|
+
let newType = typeChecker.typeToTypeNode(typeChecker.getTypeAtLocation(propertyNode.initializer), propertyNode, 0);
|
|
338
|
+
if (!newType) {
|
|
339
|
+
(0, ASTHelper_js_1.logError)(propertyNode, `Replicated properties must have a type specified or be initialised to a replicable type.`);
|
|
340
|
+
newType = ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);
|
|
341
|
+
}
|
|
342
|
+
valueType = newType;
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
(0, ASTHelper_js_1.logError)(propertyNode, `Replicated properties must have a type specified or be initialised to a replicable type.`);
|
|
346
|
+
valueType = ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);
|
|
347
|
+
}
|
|
348
|
+
let dataType = valueType;
|
|
349
|
+
let configData;
|
|
350
|
+
if (ts.isCallExpression(decorator.expression) && decorator.expression.arguments.length > 0) {
|
|
351
|
+
configData = decorator.expression.arguments[0];
|
|
352
|
+
}
|
|
353
|
+
if (ts.isCallExpression(decorator.expression) && decorator.expression.typeArguments && decorator.expression.typeArguments.length === 1) {
|
|
354
|
+
dataType = decorator.expression.typeArguments[0];
|
|
355
|
+
}
|
|
356
|
+
function convertTypeToDeclarationFormats(postfix, node) {
|
|
357
|
+
node = (0, ts_clone_node_1.cloneNode)(node, { factory: Crawler_js_1.Crawler.getContext().factory });
|
|
358
|
+
function convertIdentifiers(typeNode) {
|
|
359
|
+
if (ts.isUnionTypeNode(typeNode)) {
|
|
360
|
+
return ts.visitEachChild(typeNode, convertIdentifiers, Crawler_js_1.Crawler.getContext());
|
|
361
|
+
}
|
|
362
|
+
else if (ts.isIdentifier(typeNode)) {
|
|
363
|
+
return postfix.map((e) => {
|
|
364
|
+
var _a;
|
|
365
|
+
let impo = allFileImports.get(typeNode.text);
|
|
366
|
+
if (impo) {
|
|
367
|
+
let arr = (_a = defImports.get(impo)) !== null && _a !== void 0 ? _a : [];
|
|
368
|
+
defImports.set(impo.slice(0, -3) + defExt, arr);
|
|
369
|
+
arr.push(typeNode.text + e);
|
|
370
|
+
}
|
|
371
|
+
if (e === "Serialised") {
|
|
372
|
+
//Definitely an illegal identifier - maybe it'll work anyway and make it easy for us to use?
|
|
373
|
+
return ts.factory.createIdentifier(`["${ts.factory.createIdentifier(typeNode.text + e)}", ${ts.factory.createIdentifier(typeNode.text + e)}]`);
|
|
374
|
+
}
|
|
375
|
+
return ts.factory.createIdentifier(typeNode.text + e);
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
if (postfix.includes("Serialised")) {
|
|
380
|
+
if (postfix.length > 1) {
|
|
381
|
+
return ts.factory.createUnionTypeNode([ts.factory.createTupleTypeNode([ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral("Primitive")), typeNode]),
|
|
382
|
+
(0, ts_clone_node_1.cloneNode)(typeNode)]);
|
|
383
|
+
}
|
|
384
|
+
return ts.factory.createTupleTypeNode([ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral("Primitive")), typeNode]);
|
|
385
|
+
}
|
|
386
|
+
return typeNode;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
let resultType = ts.visitNode(node, convertIdentifiers);
|
|
390
|
+
let resultString = printNode(resultType, Crawler_js_1.Crawler.GetFile().ts, ts.EmitHint.Unspecified);
|
|
391
|
+
return resultString.replace(/(?:\n|\t| {4})/g, "");
|
|
392
|
+
}
|
|
393
|
+
klassInfo.OwnPropertyNames.push(propertyName);
|
|
394
|
+
klassInfo.OwnPropertyNames.sort();
|
|
395
|
+
//Steps:
|
|
396
|
+
if (configData) {
|
|
397
|
+
klassInfo.PropertyConfig[propertyName] = configData;
|
|
398
|
+
}
|
|
399
|
+
klassInfo.DataProperties.push({
|
|
400
|
+
propertyName,
|
|
401
|
+
dataName,
|
|
402
|
+
// 2. Create type that will go in the RBF File, as the data type.
|
|
403
|
+
rbfType: recursivelyConvertType(dataType),
|
|
404
|
+
// 5. Create type that will go in the definition file as the data type.
|
|
405
|
+
defType: convertTypeToDeclarationFormats(["Data"], dataType),
|
|
406
|
+
});
|
|
407
|
+
klassInfo.SerialisedProperties.push({
|
|
408
|
+
propertyName,
|
|
409
|
+
// 1. Create type that will go in the RBF File as the typescript type.
|
|
410
|
+
rbfType: recursivelyConvertType(valueType),
|
|
411
|
+
// 4. Create type that will go in the definition file as the serialised type.
|
|
412
|
+
defType: convertTypeToDeclarationFormats(["Serialised"], valueType),
|
|
413
|
+
});
|
|
414
|
+
klassInfo.TypescriptProperties.push({
|
|
415
|
+
propertyName,
|
|
416
|
+
dataName,
|
|
417
|
+
// 1. Create type that will go in the RBF File as the typescript type.
|
|
418
|
+
rbfType: recursivelyConvertType(valueType),
|
|
419
|
+
// 3. Create type that will go in the definition file as the typescript/construct type.
|
|
420
|
+
defType: convertTypeToDeclarationFormats(["", "Data", "Serialised"], valueType),
|
|
421
|
+
});
|
|
422
|
+
//Remove the decorator.
|
|
423
|
+
return [];
|
|
424
|
+
});
|
|
425
|
+
// Handle @Function decorators.
|
|
426
|
+
// Handle Migration function calls - which allow specifying custom migration logic for old properties/values.
|
|
427
|
+
//# sourceMappingURL=ReplicableTransformer.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bikky/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Typescript modified for compiling space squad",
|
|
5
5
|
"main": "./Libraries/BiscuitLibraries.mjs",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -12,14 +12,15 @@
|
|
|
12
12
|
"bikcserver": "./Execution/bikcserver"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
+
"@bikky/path": "^0.0.18",
|
|
16
|
+
"@bikky/smart-collections": "^0.0.43",
|
|
17
|
+
"ts-clone-node": "^4.0.0",
|
|
15
18
|
"ts-patch": "^3.1.2",
|
|
16
19
|
"typescript": "5.4.5"
|
|
17
20
|
},
|
|
18
21
|
"devDependencies": {
|
|
19
|
-
"@bikky/path": "^0.0.18",
|
|
20
22
|
"@types/node": "^18.0.0",
|
|
21
23
|
"@vitest/coverage-istanbul": "^2.0.0-beta.12",
|
|
22
|
-
"axios": "^1.10.0",
|
|
23
24
|
"vitest": "^2.0.0-beta.12"
|
|
24
25
|
},
|
|
25
26
|
"scripts": {
|