@needle-tools/needle-component-compiler 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog.md +4 -0
- package/DEV.bat +1 -0
- package/{RUNTEST.bat → RUN_MANUAL_TEST.bat} +0 -0
- package/RUN_TESTS.bat +1 -0
- package/package.json +21 -3
- package/src/component-compiler.js +130 -66
- package/src/component-compiler.ts +132 -64
- package/src/test.ts +13 -7
- package/test/codegen/abstract method/expected.cs +14 -0
- package/test/codegen/abstract method/input.js +27 -0
- package/test/codegen/abstract method/input.ts +4 -0
- package/test/codegen/abstract method/output.cs +14 -0
- package/test/codegen/basic/expected.cs +13 -0
- package/test/codegen/basic/input.js +26 -0
- package/test/codegen/basic/input.ts +2 -0
- package/test/codegen/basic/output.cs +13 -0
- package/test/codegen/basic-no-export/expected.cs +0 -0
- package/test/codegen/basic-no-export/input.js +27 -0
- package/test/codegen/basic-no-export/input.ts +4 -0
- package/test/codegen/basic-no-export/output.cs +0 -0
- package/test/codegen/bool/expected.cs +14 -0
- package/test/codegen/bool/input.js +26 -0
- package/test/codegen/bool/input.ts +3 -0
- package/test/codegen/bool/output.cs +14 -0
- package/test/codegen/fields with default values/expected.cs +17 -0
- package/test/codegen/fields with default values/input.js +31 -0
- package/test/codegen/fields with default values/input.ts +6 -0
- package/test/codegen/fields with default values/output.cs +17 -0
- package/test/codegen/method ignore inline type declaration/expected.cs +14 -0
- package/test/codegen/method ignore inline type declaration/input.js +27 -0
- package/test/codegen/method ignore inline type declaration/input.ts +3 -0
- package/test/codegen/method ignore inline type declaration/output.cs +14 -0
- package/test/codegen/nonserialized ignore field/expected.cs +13 -0
- package/test/codegen/nonserialized ignore field/input.js +26 -0
- package/test/codegen/nonserialized ignore field/input.ts +4 -0
- package/test/codegen/nonserialized ignore field/output.cs +13 -0
- package/test/codegen/nonserialized on property does not affect method/expected.cs +14 -0
- package/test/codegen/nonserialized on property does not affect method/input.js +34 -0
- package/test/codegen/nonserialized on property does not affect method/input.ts +8 -0
- package/test/codegen/nonserialized on property does not affect method/output.cs +13 -0
- package/test/codegen/number/expected.cs +14 -0
- package/test/codegen/number/input.js +26 -0
- package/test/codegen/number/input.ts +3 -0
- package/test/codegen/number/output.cs +14 -0
- package/test/codegen/object/expected.cs +14 -0
- package/test/codegen/object/input.js +26 -0
- package/test/codegen/object/input.ts +3 -0
- package/test/codegen/object/output.cs +14 -0
- package/test/codegen/private.methods/expected.cs +13 -0
- package/test/codegen/private.methods/input.js +27 -0
- package/test/codegen/private.methods/input.ts +3 -0
- package/test/codegen/private.methods/output.cs +13 -0
- package/test/codegen/protected.methods/expected.cs +13 -0
- package/test/codegen/protected.methods/input.js +27 -0
- package/test/codegen/protected.methods/input.ts +3 -0
- package/test/codegen/protected.methods/output.cs +13 -0
- package/test/codegen/public method with args/expected.cs +14 -0
- package/test/codegen/public method with args/input.js +27 -0
- package/test/codegen/public method with args/input.ts +3 -0
- package/test/codegen/public method with args/output.cs +14 -0
- package/test/codegen/public method with multiple args/expected.cs +14 -0
- package/test/codegen/public method with multiple args/input.js +27 -0
- package/test/codegen/public method with multiple args/input.ts +3 -0
- package/test/codegen/public method with multiple args/output.cs +14 -0
- package/test/codegen/public.methods/expected.cs +14 -0
- package/test/codegen/public.methods/input.js +27 -0
- package/test/codegen/public.methods/input.ts +3 -0
- package/test/codegen/public.methods/output.cs +14 -0
- package/test/codegen/static method/expected.cs +13 -0
- package/test/codegen/static method/input.js +27 -0
- package/test/codegen/static method/input.ts +3 -0
- package/test/codegen/static method/output.cs +14 -0
- package/test/codegen/string/expected.cs +14 -0
- package/test/codegen/string/input.js +26 -0
- package/test/codegen/string/input.ts +3 -0
- package/test/codegen/string/output.cs +14 -0
- package/test/codegen/stringArray/expected.cs +14 -0
- package/test/codegen/stringArray/input.js +26 -0
- package/test/codegen/stringArray/input.ts +3 -0
- package/test/codegen/stringArray/output.cs +14 -0
- package/test/component.basic.test.ts +52 -0
- package/test/component.methods.test.ts +185 -0
- package/test/component.nonserialized.test.ts +45 -0
- package/test/component.primitives.test.ts +121 -0
- package/test/helpers.ts +72 -0
- package/tsconfig.json +8 -0
- package/workspace.code-workspace +7 -7
|
@@ -4,7 +4,6 @@ import * as fs from "fs";
|
|
|
4
4
|
import * as path from 'path';
|
|
5
5
|
|
|
6
6
|
import * as types from "./types";
|
|
7
|
-
import { type } from "os";
|
|
8
7
|
const dict = types.dict;
|
|
9
8
|
|
|
10
9
|
// add either of these two comments above a class to enforce code gen or disable it for the next class
|
|
@@ -20,24 +19,46 @@ const ifdefPattern = new RegExp("@ifdef ?(?<ifdef>.+)")
|
|
|
20
19
|
const CODEGEN_MARKER_START = "// NEEDLE_CODEGEN_START";
|
|
21
20
|
const CODEGEN_MARKER_END = "// NEEDLE_CODEGEN_END";
|
|
22
21
|
|
|
22
|
+
let allowDebugLogs = true;
|
|
23
|
+
|
|
23
24
|
// will be set to true when e.g. a comment for export is found
|
|
24
25
|
let exportNextClass: boolean = false;
|
|
25
26
|
let dontExportNextClass: boolean = false;
|
|
26
27
|
let serializeField: boolean = false;
|
|
27
28
|
let dontSerialize: boolean = false;
|
|
29
|
+
let typesFileContent: object | undefined | null = undefined;
|
|
30
|
+
|
|
31
|
+
// const exportDir = "../dist";
|
|
32
|
+
const commentStarts: Array<number> = [];
|
|
33
|
+
const contexts: ExportContext[] = [];
|
|
34
|
+
let lastTypeFound: string | null = null;
|
|
35
|
+
let ifdefSections: string[] = [];
|
|
36
|
+
|
|
37
|
+
function resetAllState() {
|
|
38
|
+
exportNextClass = false;
|
|
39
|
+
dontExportNextClass = false;
|
|
40
|
+
serializeField = false;
|
|
41
|
+
dontSerialize = false;
|
|
42
|
+
typesFileContent = undefined;
|
|
43
|
+
|
|
44
|
+
commentStarts.length = 0;
|
|
45
|
+
contexts.length = 0;
|
|
46
|
+
lastTypeFound = null;
|
|
47
|
+
ifdefSections.length = 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
28
50
|
function resetExportNextClass() {
|
|
29
51
|
dontExportNextClass = false;
|
|
30
52
|
exportNextClass = false;
|
|
31
53
|
}
|
|
32
54
|
|
|
33
|
-
|
|
34
|
-
let typesFileContent: object | undefined | null = undefined;
|
|
35
55
|
function tryGetKnownType(str: string): string | null {
|
|
36
56
|
if (typesFileContent === undefined) {
|
|
37
57
|
typesFileContent = null;
|
|
38
58
|
const filePath = path.dirname(__dirname) + "/src/types.json";
|
|
39
59
|
if (fs.existsSync(filePath)) {
|
|
40
|
-
|
|
60
|
+
if (allowDebugLogs)
|
|
61
|
+
console.log("Reading types file");
|
|
41
62
|
const content = fs.readFileSync(filePath, "utf8");
|
|
42
63
|
typesFileContent = JSON.parse(content);
|
|
43
64
|
}
|
|
@@ -45,7 +66,7 @@ function tryGetKnownType(str: string): string | null {
|
|
|
45
66
|
|
|
46
67
|
if (typesFileContent) {
|
|
47
68
|
const fullType = typesFileContent[str];
|
|
48
|
-
if (fullType)
|
|
69
|
+
if (fullType && allowDebugLogs)
|
|
49
70
|
console.log(fullType);
|
|
50
71
|
return fullType;
|
|
51
72
|
}
|
|
@@ -54,17 +75,15 @@ function tryGetKnownType(str: string): string | null {
|
|
|
54
75
|
|
|
55
76
|
// https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API
|
|
56
77
|
|
|
57
|
-
// const exportDir = "../dist";
|
|
58
|
-
const commentStarts: Array<number> = [];
|
|
59
78
|
|
|
60
79
|
class ExportContext {
|
|
61
|
-
outputDir: string;
|
|
80
|
+
outputDir: string | null;
|
|
62
81
|
fileName: string;
|
|
63
82
|
textBuffer: string;
|
|
64
83
|
classEnd: number = -1;
|
|
65
84
|
indentLevel: number = 0;
|
|
66
85
|
|
|
67
|
-
constructor(outputDir: string, fileName: string) {
|
|
86
|
+
constructor(outputDir: string | null, fileName: string) {
|
|
68
87
|
this.outputDir = outputDir;
|
|
69
88
|
this.fileName = fileName;
|
|
70
89
|
this.reset();
|
|
@@ -90,14 +109,20 @@ class ExportContext {
|
|
|
90
109
|
this.append(text + "\n");
|
|
91
110
|
}
|
|
92
111
|
|
|
93
|
-
flush() {
|
|
112
|
+
flush(): string {
|
|
94
113
|
if (this.textBuffer.length <= 0) return;
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
this.
|
|
98
|
-
|
|
99
|
-
|
|
114
|
+
this.textBuffer = CODEGEN_MARKER_START + "\n" + this.textBuffer + "\n" + CODEGEN_MARKER_END;
|
|
115
|
+
const code = this.textBuffer;
|
|
116
|
+
if (this.outputDir !== null) {
|
|
117
|
+
const dir = this.outputDir + "/";
|
|
118
|
+
const path = dir + this.fileName;
|
|
119
|
+
this.replaceGeneratedCodeSection(path);
|
|
120
|
+
if (allowDebugLogs)
|
|
121
|
+
console.log("Write to " + path);
|
|
122
|
+
fs.writeFileSync(path, code);
|
|
123
|
+
}
|
|
100
124
|
this.reset();
|
|
125
|
+
return code;
|
|
101
126
|
}
|
|
102
127
|
|
|
103
128
|
reset() {
|
|
@@ -106,13 +131,13 @@ class ExportContext {
|
|
|
106
131
|
}
|
|
107
132
|
|
|
108
133
|
private replaceGeneratedCodeSection(path: string) {
|
|
109
|
-
this.textBuffer = CODEGEN_MARKER_START + "\n" + this.textBuffer + "\n" + CODEGEN_MARKER_END;
|
|
110
134
|
if (fs.existsSync(path)) {
|
|
111
135
|
const existing = fs.readFileSync(path, "utf8");
|
|
112
136
|
const regex = new RegExp("(?<before>.*?)\/\/ ?NEEDLE_CODEGEN_START.+\/\/ ?NEEDLE_CODEGEN_END(?<after>.*)", "s");
|
|
113
137
|
const matches = regex.exec(existing);
|
|
114
138
|
if (matches?.groups) {
|
|
115
|
-
|
|
139
|
+
if (allowDebugLogs)
|
|
140
|
+
console.log("Found codegen sections")
|
|
116
141
|
const before = matches.groups.before;
|
|
117
142
|
const after = matches.groups.after;
|
|
118
143
|
this.textBuffer = before + this.textBuffer + after;
|
|
@@ -121,18 +146,34 @@ class ExportContext {
|
|
|
121
146
|
}
|
|
122
147
|
}
|
|
123
148
|
|
|
124
|
-
|
|
149
|
+
export function compile(code: string, fileName: string, outputDir: string | null, debugLogs: boolean = true): string[] {
|
|
125
150
|
|
|
126
|
-
|
|
127
|
-
|
|
151
|
+
resetAllState();
|
|
152
|
+
allowDebugLogs = debugLogs;
|
|
153
|
+
|
|
154
|
+
// Parse a file
|
|
155
|
+
const sourceFile = ts.createSourceFile(
|
|
156
|
+
fileName,
|
|
157
|
+
code,
|
|
158
|
+
ts.ScriptTarget.ES2015,
|
|
159
|
+
true, /*setParentNodes */
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const prog = ts.createProgram([fileName], {});
|
|
128
163
|
|
|
129
|
-
|
|
164
|
+
// delint it
|
|
165
|
+
return run(prog, outputDir, sourceFile);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function run(program: ts.Program, outputDir: string | null, sourceFile: ts.SourceFile): string[] {
|
|
130
169
|
|
|
131
|
-
if (!fs.existsSync(outputDir)) {
|
|
170
|
+
if (outputDir !== null && !fs.existsSync(outputDir)) {
|
|
132
171
|
console.error("Output directory does not exist: \"" + outputDir + "\"");
|
|
133
172
|
return;
|
|
134
173
|
}
|
|
135
174
|
|
|
175
|
+
const results: string[] = [];
|
|
176
|
+
|
|
136
177
|
traverseFile(sourceFile);
|
|
137
178
|
function traverseFile(node: ts.Node) {
|
|
138
179
|
|
|
@@ -140,6 +181,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
140
181
|
ts.forEachChild(node, traverseFile);
|
|
141
182
|
}
|
|
142
183
|
|
|
184
|
+
return results;
|
|
185
|
+
|
|
143
186
|
function visit(node: ts.Node) {
|
|
144
187
|
let context: ExportContext | null = contexts.length > 0 ? contexts[contexts.length - 1] : null;
|
|
145
188
|
|
|
@@ -149,12 +192,14 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
149
192
|
context.indentLevel -= 1;
|
|
150
193
|
context.append("}\n");
|
|
151
194
|
}
|
|
152
|
-
context.flush();
|
|
195
|
+
const code = context.flush();
|
|
196
|
+
results.push(code);
|
|
153
197
|
context = null;
|
|
154
198
|
contexts.pop();
|
|
155
199
|
}
|
|
156
200
|
}
|
|
157
|
-
|
|
201
|
+
if (allowDebugLogs)
|
|
202
|
+
console.log("\t", ts.SyntaxKind[node.kind]);
|
|
158
203
|
|
|
159
204
|
const commentRanges = ts.getLeadingCommentRanges(
|
|
160
205
|
sourceFile.getFullText(),
|
|
@@ -186,7 +231,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
186
231
|
// so we remove them
|
|
187
232
|
let type = typeMatch.groups["type"];
|
|
188
233
|
type = type.replace(/\(/, "").replace(/\)/, "");
|
|
189
|
-
|
|
234
|
+
if (allowDebugLogs)
|
|
235
|
+
console.log("Found type: ", type);
|
|
190
236
|
lastTypeFound = type;
|
|
191
237
|
}
|
|
192
238
|
|
|
@@ -226,6 +272,9 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
226
272
|
const meth = node as ts.MethodDeclaration;
|
|
227
273
|
// const isCoroutine = func.asteriskToken;
|
|
228
274
|
if (!skip && meth.name) {
|
|
275
|
+
const pub = isPublic(meth);
|
|
276
|
+
if(!pub) return;
|
|
277
|
+
|
|
229
278
|
let paramsStr = "";
|
|
230
279
|
for (let param of meth.parameters) {
|
|
231
280
|
if (!param || !param.name) continue;
|
|
@@ -234,8 +283,13 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
234
283
|
if (type === undefined) type = "object";
|
|
235
284
|
paramsStr += type + " @" + param.name.getText();
|
|
236
285
|
}
|
|
237
|
-
|
|
286
|
+
let methodName = meth.name.getText();
|
|
287
|
+
switch (methodName) {
|
|
288
|
+
case "onEnable": methodName = "OnEnable"; break;
|
|
289
|
+
case "onDisable": methodName = "OnDisable"; break;
|
|
290
|
+
}
|
|
238
291
|
context.onBeforeMethod(methodName);
|
|
292
|
+
// let visibility = pub ? "public" : "private";
|
|
239
293
|
context.append("public void " + methodName + "(" + paramsStr + "){}\n");
|
|
240
294
|
}
|
|
241
295
|
break;
|
|
@@ -245,7 +299,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
245
299
|
case ts.SyntaxKind.PropertyDeclaration:
|
|
246
300
|
resetExportNextClass();
|
|
247
301
|
if (!context) break;
|
|
248
|
-
|
|
302
|
+
if (allowDebugLogs)
|
|
303
|
+
console.log("Found variable", node.getText());
|
|
249
304
|
const vardec = node as ts.VariableDeclaration;
|
|
250
305
|
|
|
251
306
|
const varName = "@" + vardec.name.getText();
|
|
@@ -254,20 +309,23 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
254
309
|
let isAccessible = pub;
|
|
255
310
|
dontSerialize = false;
|
|
256
311
|
if (serializeField) {
|
|
257
|
-
|
|
312
|
+
if (allowDebugLogs)
|
|
313
|
+
console.log("[SerializeField]");
|
|
258
314
|
context.appendLine("[UnityEngine.SerializeField]");
|
|
259
315
|
isAccessible = true;
|
|
260
316
|
}
|
|
261
|
-
else if(skip)
|
|
317
|
+
else if (skip)
|
|
262
318
|
isAccessible = false;
|
|
263
|
-
|
|
319
|
+
|
|
264
320
|
if (!isAccessible) {
|
|
265
|
-
|
|
321
|
+
if (allowDebugLogs)
|
|
322
|
+
console.log("Skip because not public or serializeable")
|
|
266
323
|
break;
|
|
267
324
|
}
|
|
268
325
|
|
|
269
326
|
const name = vardec.name.getText();
|
|
270
|
-
|
|
327
|
+
if (allowDebugLogs)
|
|
328
|
+
console.log("Variable:", name);
|
|
271
329
|
if (name.startsWith("\"@") || name.startsWith("\"$") || name.startsWith("$")) break;
|
|
272
330
|
let typeString = lastTypeFound ?? tryResolveTypeRecursive(node);
|
|
273
331
|
let postFix = "";
|
|
@@ -317,12 +375,14 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
317
375
|
}
|
|
318
376
|
if (typeString === undefined) typeString = typeName;
|
|
319
377
|
if (typeString === "[]") {
|
|
320
|
-
|
|
378
|
+
if (allowDebugLogs)
|
|
379
|
+
console.log("Unknown array type for \"" + varName + " " + typeName + "\" - your type is probably not known (did you just create it this session?) and you might need to regenerate the Typemap in Unity. Go to \"Needle Engine/Internal/Generate Type Map for component compiler")
|
|
321
380
|
// typeString = "object[]";
|
|
322
381
|
// assignment = " = new object[0]";
|
|
323
382
|
shouldCommentTheLine = true;
|
|
324
383
|
}
|
|
325
|
-
|
|
384
|
+
if (allowDebugLogs)
|
|
385
|
+
console.log("EMIT member: \"" + typeString + "\" " + varName, assignment, "Last type found:", lastTypeFound);
|
|
326
386
|
const prefix = shouldCommentTheLine ? "// " : "";
|
|
327
387
|
context.append(prefix + visibility + " " + typeString + " " + varName + assignment + ";" + postFix + "\n");
|
|
328
388
|
lastTypeFound = null;
|
|
@@ -339,9 +399,11 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
339
399
|
if (!dontExportNextClass && (lastTypeFound || exportNextClass || inheritsComponent)) {
|
|
340
400
|
resetExportNextClass();
|
|
341
401
|
const name = dec.name?.escapedText;
|
|
342
|
-
|
|
402
|
+
if (allowDebugLogs)
|
|
403
|
+
console.log("Found class: ", name);
|
|
343
404
|
const namespace = tryParseNamespace(node) ?? "Needle.Typescript.GeneratedComponents";
|
|
344
|
-
|
|
405
|
+
if (allowDebugLogs)
|
|
406
|
+
console.log("NAMESPACE", namespace);
|
|
345
407
|
const newContext = new ExportContext(outputDir, name + ".cs");
|
|
346
408
|
newContext.appendLine("// auto generated code - do not edit directly");
|
|
347
409
|
newContext.appendLine("");
|
|
@@ -354,14 +416,16 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
354
416
|
let typeName = "UnityEngine.MonoBehaviour";
|
|
355
417
|
if (typeof inheritsComponent === "string") typeName = inheritsComponent;
|
|
356
418
|
if (lastTypeFound) typeName = lastTypeFound;
|
|
357
|
-
|
|
419
|
+
if (allowDebugLogs)
|
|
420
|
+
console.log(name + " inherits " + typeName);
|
|
358
421
|
let modifiers = "";
|
|
359
422
|
if (dec.modifiers) {
|
|
360
423
|
for (const mod of dec.modifiers) {
|
|
361
424
|
switch (mod.getText()) {
|
|
362
425
|
case "abstract":
|
|
363
426
|
modifiers += " abstract";
|
|
364
|
-
|
|
427
|
+
if (allowDebugLogs)
|
|
428
|
+
console.log(name + " is abstract");
|
|
365
429
|
break;
|
|
366
430
|
}
|
|
367
431
|
}
|
|
@@ -374,7 +438,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
374
438
|
contexts.push(newContext);
|
|
375
439
|
}
|
|
376
440
|
else {
|
|
377
|
-
|
|
441
|
+
if (allowDebugLogs)
|
|
442
|
+
console.log("Class type is unknown and will not generate a component: ", dec.name?.escapedText);
|
|
378
443
|
}
|
|
379
444
|
lastTypeFound = null;
|
|
380
445
|
break;
|
|
@@ -431,7 +496,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
431
496
|
break;
|
|
432
497
|
}
|
|
433
498
|
const str = node.getText();
|
|
434
|
-
|
|
499
|
+
if (allowDebugLogs)
|
|
500
|
+
console.log("Unknown assignment:", str, ts.SyntaxKind[node.kind]);
|
|
435
501
|
return str;
|
|
436
502
|
}
|
|
437
503
|
|
|
@@ -439,7 +505,7 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
439
505
|
if (node.kind === ts.SyntaxKind.PublicKeyword) {
|
|
440
506
|
return true;
|
|
441
507
|
}
|
|
442
|
-
else if (node.kind === ts.SyntaxKind.PrivateKeyword) {
|
|
508
|
+
else if (node.kind === ts.SyntaxKind.PrivateKeyword || node.kind === ts.SyntaxKind.ProtectedKeyword) {
|
|
443
509
|
return false;
|
|
444
510
|
}
|
|
445
511
|
|
|
@@ -480,7 +546,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
480
546
|
const separatorIndex = typeName.lastIndexOf(".");
|
|
481
547
|
if (separatorIndex > 0) {
|
|
482
548
|
let newName = typeName.substring(separatorIndex + 1);
|
|
483
|
-
|
|
549
|
+
if (allowDebugLogs)
|
|
550
|
+
console.log("Remove import name from type: \"" + typeName + "\" → \"" + newName + "\"");
|
|
484
551
|
typeName = newName;
|
|
485
552
|
}
|
|
486
553
|
|
|
@@ -541,7 +608,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
541
608
|
case ts.SyntaxKind.TypeReference:
|
|
542
609
|
const typeRef = node as ts.TypeReferenceNode;
|
|
543
610
|
const typeName = typeRef.typeName.getText();
|
|
544
|
-
|
|
611
|
+
if (allowDebugLogs)
|
|
612
|
+
console.log("TypeReference:", typeName);
|
|
545
613
|
switch (typeName) {
|
|
546
614
|
case "Array":
|
|
547
615
|
break;
|
|
@@ -600,7 +668,8 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
600
668
|
const childResult = tryResolveTypeRecursive(child);
|
|
601
669
|
if (childResult !== undefined) {
|
|
602
670
|
if (res === undefined) res = "";
|
|
603
|
-
|
|
671
|
+
if (allowDebugLogs)
|
|
672
|
+
console.log("Child: " + ts.SyntaxKind[child.kind] + " → " + childResult);
|
|
604
673
|
// if the thing is a generic return as generic result
|
|
605
674
|
if (isInGenericDeclaration && !res.includes("[]")) {
|
|
606
675
|
res = "<" + childResult + ">";
|
|
@@ -630,24 +699,23 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
630
699
|
}
|
|
631
700
|
}
|
|
632
701
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
const
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
});
|
|
702
|
+
|
|
703
|
+
if (process) {
|
|
704
|
+
|
|
705
|
+
if (process.argv.length < 4) {
|
|
706
|
+
console.error("Missing args, call with: <output_dir> <input_files>");
|
|
707
|
+
}
|
|
708
|
+
else {
|
|
709
|
+
const outputDir = process.argv[2];
|
|
710
|
+
const fileNames = process.argv.slice(3);
|
|
711
|
+
fileNames.forEach(fileName => {
|
|
712
|
+
if (!fs.existsSync(fileName)) {
|
|
713
|
+
|
|
714
|
+
}
|
|
715
|
+
else {
|
|
716
|
+
const code = readFileSync(fileName).toString();
|
|
717
|
+
compile(code, fileName, outputDir);
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
}
|
|
653
721
|
}
|
package/src/test.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { ThisExpression } from "typescript";
|
|
2
2
|
|
|
3
|
+
export class MyTestComponent extends Behaviour {
|
|
4
|
+
private myMethod(){
|
|
5
|
+
|
|
6
|
+
}
|
|
7
|
+
}
|
|
3
8
|
|
|
4
|
-
|
|
9
|
+
|
|
10
|
+
// export class SkipFieldAndMethod extends Behaviour {
|
|
5
11
|
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
// //@nonSerialized
|
|
13
|
+
// myMethod() {
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
// }
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
// // @nonSerialized
|
|
18
|
+
// myField : string;
|
|
13
19
|
|
|
14
|
-
}
|
|
20
|
+
// }
|
|
15
21
|
|
|
16
22
|
|
|
17
23
|
// export class ComponentWithUnknownType extends Behaviour {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
public void OnDisable(){}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
exports.__esModule = true;
|
|
18
|
+
exports.MyComponent = void 0;
|
|
19
|
+
var MyComponent = /** @class */ (function (_super) {
|
|
20
|
+
__extends(MyComponent, _super);
|
|
21
|
+
function MyComponent() {
|
|
22
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
}
|
|
24
|
+
MyComponent.prototype.onDisable = function () { };
|
|
25
|
+
return MyComponent;
|
|
26
|
+
}(Behaviour));
|
|
27
|
+
exports.MyComponent = MyComponent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
public void OnDisable(){}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class BasicComponet : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
exports.__esModule = true;
|
|
18
|
+
exports.BasicComponet = void 0;
|
|
19
|
+
var BasicComponet = /** @class */ (function (_super) {
|
|
20
|
+
__extends(BasicComponet, _super);
|
|
21
|
+
function BasicComponet() {
|
|
22
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
}
|
|
24
|
+
return BasicComponet;
|
|
25
|
+
}(Behaviour));
|
|
26
|
+
exports.BasicComponet = BasicComponet;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class BasicComponet : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// NEEDLE_CODEGEN_END
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
exports.__esModule = true;
|
|
18
|
+
exports.BasicComponet = void 0;
|
|
19
|
+
//@dont-generate-component
|
|
20
|
+
var BasicComponet = /** @class */ (function (_super) {
|
|
21
|
+
__extends(BasicComponet, _super);
|
|
22
|
+
function BasicComponet() {
|
|
23
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
24
|
+
}
|
|
25
|
+
return BasicComponet;
|
|
26
|
+
}(Behaviour));
|
|
27
|
+
exports.BasicComponet = BasicComponet;
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
public bool @myField;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
exports.__esModule = true;
|
|
18
|
+
exports.MyComponent = void 0;
|
|
19
|
+
var MyComponent = /** @class */ (function (_super) {
|
|
20
|
+
__extends(MyComponent, _super);
|
|
21
|
+
function MyComponent() {
|
|
22
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
}
|
|
24
|
+
return MyComponent;
|
|
25
|
+
}(Behaviour));
|
|
26
|
+
exports.MyComponent = MyComponent;
|