@needle-tools/needle-component-compiler 1.6.0 → 1.6.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.
- package/Changelog.md +7 -1
- package/package.json +1 -1
- package/src/component-compiler.js +16 -11
- package/src/component-compiler.ts +10 -5
- package/src/test.ts +20 -5
- package/src/component.cs +0 -1
package/Changelog.md
CHANGED
|
@@ -4,7 +4,13 @@ All notable changes to this package will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
-
## [1.6.
|
|
7
|
+
## [1.6.3] - 2022-07-12
|
|
8
|
+
- add warning when class type is unknown
|
|
9
|
+
|
|
10
|
+
## [1.6.2] - 2022-07-11
|
|
11
|
+
- fix ``@type`` for class declaration
|
|
12
|
+
|
|
13
|
+
## [1.6.1] - 2022-07-10
|
|
8
14
|
- add using ``types.json`` json file that will be generated from Unity
|
|
9
15
|
- change ``@type`` annotiation to only work without braces to be consistent
|
|
10
16
|
|
package/package.json
CHANGED
|
@@ -12,8 +12,8 @@ var exportNextClassCommand = "@generate-component";
|
|
|
12
12
|
var dontExportNextClassCommand = "@dont-generate-component";
|
|
13
13
|
// add above field to add [SerializeField] attribute
|
|
14
14
|
var serializeCommand = "@serializeField";
|
|
15
|
-
// https://regex101.com/r/ltpcKT/
|
|
16
|
-
var typePattern = new RegExp("@type ?(
|
|
15
|
+
// https://regex101.com/r/ltpcKT/2
|
|
16
|
+
var typePattern = new RegExp("@type ?(?<type>.+)");
|
|
17
17
|
var ifdefPattern = new RegExp("@ifdef ?(?<ifdef>.+)");
|
|
18
18
|
var CODEGEN_MARKER_START = "// NEEDLE_CODEGEN_START";
|
|
19
19
|
var CODEGEN_MARKER_END = "// NEEDLE_CODEGEN_END";
|
|
@@ -38,7 +38,8 @@ function tryGetKnownType(str) {
|
|
|
38
38
|
}
|
|
39
39
|
if (typesFileContent) {
|
|
40
40
|
var fullType = typesFileContent[str];
|
|
41
|
-
|
|
41
|
+
if (fullType)
|
|
42
|
+
console.log(fullType);
|
|
42
43
|
return fullType;
|
|
43
44
|
}
|
|
44
45
|
return null;
|
|
@@ -114,7 +115,7 @@ function run(program, outputDir, sourceFile) {
|
|
|
114
115
|
ts.forEachChild(node, traverseFile);
|
|
115
116
|
}
|
|
116
117
|
function visit(node) {
|
|
117
|
-
var _a, _b, _c, _d, _e;
|
|
118
|
+
var _a, _b, _c, _d, _e, _f;
|
|
118
119
|
var context = contexts.length > 0 ? contexts[contexts.length - 1] : null;
|
|
119
120
|
if (context) {
|
|
120
121
|
if ((context === null || context === void 0 ? void 0 : context.classEnd) > 0 && node.pos >= (context === null || context === void 0 ? void 0 : context.classEnd)) {
|
|
@@ -156,7 +157,7 @@ function run(program, outputDir, sourceFile) {
|
|
|
156
157
|
// so we remove them
|
|
157
158
|
var type = typeMatch.groups["type"];
|
|
158
159
|
type = type.replace(/\(/, "").replace(/\)/, "");
|
|
159
|
-
console.log("
|
|
160
|
+
console.log("Found type: ", type);
|
|
160
161
|
lastTypeFound = type;
|
|
161
162
|
}
|
|
162
163
|
var ifdefMatch = ifdefPattern.exec(comment);
|
|
@@ -194,8 +195,8 @@ function run(program, outputDir, sourceFile) {
|
|
|
194
195
|
// const isCoroutine = func.asteriskToken;
|
|
195
196
|
if (meth.name) {
|
|
196
197
|
var paramsStr = "";
|
|
197
|
-
for (var
|
|
198
|
-
var param = _g
|
|
198
|
+
for (var _g = 0, _h = meth.parameters; _g < _h.length; _g++) {
|
|
199
|
+
var param = _h[_g];
|
|
199
200
|
if (!param || !param.name)
|
|
200
201
|
continue;
|
|
201
202
|
if (paramsStr.length > 0)
|
|
@@ -228,8 +229,8 @@ function run(program, outputDir, sourceFile) {
|
|
|
228
229
|
var prefix = typeString === undefined ? "// " : "";
|
|
229
230
|
var assignment = "";
|
|
230
231
|
if (typeString !== undefined) {
|
|
231
|
-
for (var
|
|
232
|
-
var ch = _j
|
|
232
|
+
for (var _j = 0, _k = node.getChildren(); _j < _k.length; _j++) {
|
|
233
|
+
var ch = _k[_j];
|
|
233
234
|
switch (ch.kind) {
|
|
234
235
|
case ts.SyntaxKind.FalseKeyword:
|
|
235
236
|
case ts.SyntaxKind.TrueKeyword:
|
|
@@ -290,9 +291,11 @@ function run(program, outputDir, sourceFile) {
|
|
|
290
291
|
newContext.appendLine("{");
|
|
291
292
|
newContext.indentLevel += 1;
|
|
292
293
|
// newContext.appendLine("// source: " + path.resolve(sourceFile.fileName));
|
|
293
|
-
var typeName =
|
|
294
|
+
var typeName = "UnityEngine.MonoBehaviour";
|
|
294
295
|
if (typeof inheritsComponent === "string")
|
|
295
296
|
typeName = inheritsComponent;
|
|
297
|
+
if (lastTypeFound)
|
|
298
|
+
typeName = lastTypeFound;
|
|
296
299
|
console.log(name_2 + " inherits " + typeName);
|
|
297
300
|
newContext.appendLine("public partial class " + name_2 + " : " + typeName);
|
|
298
301
|
newContext.appendLine("{");
|
|
@@ -300,6 +303,9 @@ function run(program, outputDir, sourceFile) {
|
|
|
300
303
|
newContext.classEnd = dec.end;
|
|
301
304
|
contexts.push(newContext);
|
|
302
305
|
}
|
|
306
|
+
else {
|
|
307
|
+
console.log("Class type is unknown and will not generate a component: ", (_f = dec.name) === null || _f === void 0 ? void 0 : _f.escapedText);
|
|
308
|
+
}
|
|
303
309
|
lastTypeFound = null;
|
|
304
310
|
break;
|
|
305
311
|
}
|
|
@@ -321,7 +327,6 @@ function run(program, outputDir, sourceFile) {
|
|
|
321
327
|
return true;
|
|
322
328
|
if (text === "Behaviour")
|
|
323
329
|
return true;
|
|
324
|
-
console.log(text);
|
|
325
330
|
var known = tryGetKnownType(text);
|
|
326
331
|
if (known)
|
|
327
332
|
return known;
|
|
@@ -11,8 +11,8 @@ const exportNextClassCommand = "@generate-component";
|
|
|
11
11
|
const dontExportNextClassCommand = "@dont-generate-component";
|
|
12
12
|
// add above field to add [SerializeField] attribute
|
|
13
13
|
const serializeCommand = "@serializeField";
|
|
14
|
-
// https://regex101.com/r/ltpcKT/
|
|
15
|
-
const typePattern = new RegExp("@type ?(
|
|
14
|
+
// https://regex101.com/r/ltpcKT/2
|
|
15
|
+
const typePattern = new RegExp("@type ?(?<type>.+)");
|
|
16
16
|
const ifdefPattern = new RegExp("@ifdef ?(?<ifdef>.+)")
|
|
17
17
|
|
|
18
18
|
const CODEGEN_MARKER_START = "// NEEDLE_CODEGEN_START";
|
|
@@ -43,7 +43,8 @@ function tryGetKnownType(str: string): string | null {
|
|
|
43
43
|
|
|
44
44
|
if (typesFileContent) {
|
|
45
45
|
const fullType = typesFileContent[str];
|
|
46
|
-
|
|
46
|
+
if (fullType)
|
|
47
|
+
console.log(fullType);
|
|
47
48
|
return fullType;
|
|
48
49
|
}
|
|
49
50
|
return null;
|
|
@@ -181,7 +182,7 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
181
182
|
// so we remove them
|
|
182
183
|
let type = typeMatch.groups["type"];
|
|
183
184
|
type = type.replace(/\(/, "").replace(/\)/, "");
|
|
184
|
-
console.log("
|
|
185
|
+
console.log("Found type: ", type);
|
|
185
186
|
lastTypeFound = type;
|
|
186
187
|
}
|
|
187
188
|
|
|
@@ -312,8 +313,9 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
312
313
|
newContext.appendLine("{");
|
|
313
314
|
newContext.indentLevel += 1;
|
|
314
315
|
// newContext.appendLine("// source: " + path.resolve(sourceFile.fileName));
|
|
315
|
-
let typeName =
|
|
316
|
+
let typeName = "UnityEngine.MonoBehaviour";
|
|
316
317
|
if (typeof inheritsComponent === "string") typeName = inheritsComponent;
|
|
318
|
+
if (lastTypeFound) typeName = lastTypeFound;
|
|
317
319
|
console.log(name + " inherits " + typeName);
|
|
318
320
|
newContext.appendLine("public partial class " + name + " : " + typeName);
|
|
319
321
|
newContext.appendLine("{");
|
|
@@ -321,6 +323,9 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
|
|
|
321
323
|
newContext.classEnd = dec.end;
|
|
322
324
|
contexts.push(newContext);
|
|
323
325
|
}
|
|
326
|
+
else {
|
|
327
|
+
console.log("Class type is unknown and will not generate a component: ", dec.name?.escapedText);
|
|
328
|
+
}
|
|
324
329
|
lastTypeFound = null;
|
|
325
330
|
break;
|
|
326
331
|
}
|
package/src/test.ts
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
|
|
2
|
+
class Test123 {}
|
|
3
|
+
|
|
4
|
+
export class Bla extends Test123
|
|
5
|
+
{
|
|
6
|
+
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// //@type UnityEngine.MonoBehaviour
|
|
10
|
+
// export class ButtonObject extends Interactable implements IPointerClickHandler, ISerializable {
|
|
11
|
+
|
|
12
|
+
// //@type UnityEngine.Transform[]
|
|
13
|
+
// myType?: SceneFXWindow;
|
|
14
|
+
// }
|
|
15
|
+
|
|
2
16
|
// import { Behaviour } from "needle.tiny.engine/engine-components/Component";
|
|
3
17
|
// import { RoomEntity } from "./Room";
|
|
4
18
|
|
|
5
|
-
import { Behaviour } from "needle.tiny.engine/engine-components/Component";
|
|
19
|
+
// import { Behaviour } from "needle.tiny.engine/engine-components/Component";
|
|
6
20
|
|
|
7
|
-
export class MyNewScript extends DriveClient
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
|
|
21
|
+
// export class MyNewScript extends DriveClient
|
|
22
|
+
// {
|
|
23
|
+
// //@type test
|
|
24
|
+
// texture : RenderTexture;
|
|
25
|
+
// }
|
|
11
26
|
|
|
12
27
|
// namespace Hello.World
|
|
13
28
|
// {
|
package/src/component.cs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
public class MyClass : MonoBehaviour {
|