@needle-tools/needle-component-compiler 1.12.1 → 1.12.2-b540994

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 CHANGED
@@ -4,11 +4,10 @@ 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.12.1] - 2025-06-06
7
+ ## [1.12.2] - 2025-06-06
8
8
  - Fix: Private fields decorated with `@serializable()` should be annotated with `UnityEngine.SerializeField`
9
9
  - Fix: Comment for `// @serializeField` should not affect subsequent fields
10
10
 
11
-
12
11
  ## [1.12.0] - 2025-06-02
13
12
  - Add: Support to serialize unknown classes when annotated with `// @type object`
14
13
 
package/Readme.md CHANGED
@@ -15,4 +15,13 @@ Please run ``npm install`` first before using.
15
15
  - ``@type MyNamespace.MyType`` decorator for fields or classes, specifiy C# type of field or class
16
16
  - ``@ifdef MY_IFDEF`` field decorator only at the moment
17
17
  - ``@tooltip My Text`` field decorator, generates a Unity `[Tooltip("My Text")]`
18
- - ``@contextmenu MethodName`` method decorator, generates a `[ContextMenu("MethodName")]`
18
+ - ``@contextmenu MethodName`` method decorator, generates a `[ContextMenu("MethodName")]`
19
+
20
+
21
+ # Contact ✒️
22
+ <b>[🌵 Needle](https://needle.tools)</b> •
23
+ [Github](https://github.com/needle-tools) •
24
+ [Twitter](https://twitter.com/NeedleTools) •
25
+ [Discord](https://discord.needle.tools) •
26
+ [Forum](https://forum.needle.tools) •
27
+ [Youtube](https://youtube.com/@needle-tools)
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@needle-tools/needle-component-compiler",
3
- "version": "1.12.1",
3
+ "version": "1.12.2-b540994",
4
4
  "description": "Compile mock unity components from typescript",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "tsc": "tsc",
8
8
  "dev": "npm-watch compile",
9
- "compile" : "tsc src/component-compiler.ts",
10
- "test": "mocha -r ts-node/register test/**/*.test.ts"
9
+ "compile": "tsc src/component-compiler.ts",
10
+ "test": "mocha -r ts-node/register test/**/*.test.ts",
11
+ "test:dev": "mocha -r ts-node/register test/**/*.serializable.test.ts"
11
12
  },
12
13
  "dependencies": {
13
14
  "typescript": "^4.5.5"
@@ -22,13 +23,13 @@
22
23
  "npm-watch": "^0.13.0"
23
24
  },
24
25
  "watch": {
25
- "compile": {
26
- "patterns": [
27
- "src/component-compiler.ts"
28
- ],
29
- "extensions": "ts",
30
- "quiet": false
31
- }
26
+ "compile": {
27
+ "patterns": [
28
+ "src/component-compiler.ts"
29
+ ],
30
+ "extensions": "ts",
31
+ "quiet": false
32
+ }
32
33
  },
33
34
  "author": {
34
35
  "name": "Needle",
@@ -40,7 +41,7 @@
40
41
  "url": "git+https://github.com/needle-tools/needle-tiny-component-compiler.git"
41
42
  },
42
43
  "publishConfig": {
43
- "access": "public",
44
- "registry": "https://registry.npmjs.org/"
44
+ "access": "public",
45
+ "registry": "https://registry.npmjs.org/"
45
46
  }
46
47
  }
@@ -247,15 +247,6 @@ function run(program, outputDir, sourceFile) {
247
247
  // case ts.SyntaxKind.SingleLineCommentTrivia:
248
248
  // console.log("comment: " + node.getText())
249
249
  // break;
250
- case ts.SyntaxKind.Decorator:
251
- {
252
- // If a field is decorated with @serializable then we want to serialize it
253
- var name_1 = node.getText();
254
- if (name_1.startsWith("@serializable(")) {
255
- serializeField = true;
256
- }
257
- }
258
- break;
259
250
  case ts.SyntaxKind.MethodDeclaration:
260
251
  lastTypeFound = null;
261
252
  serializeField = false;
@@ -318,6 +309,8 @@ function run(program, outputDir, sourceFile) {
318
309
  var pub = shouldEmitMethod(vardec);
319
310
  var visibility = pub ? "public" : "private";
320
311
  var isAccessible = pub;
312
+ if (!pub)
313
+ serializeField || (serializeField = testIsMarkedWithSerializable(node));
321
314
  if (serializeField) {
322
315
  if (allowDebugLogs)
323
316
  console.log("Emit [UnityEngine.SerializeField]");
@@ -333,10 +326,10 @@ function run(program, outputDir, sourceFile) {
333
326
  console.log("Skip because not public or serializeable");
334
327
  break;
335
328
  }
336
- var name_2 = vardec.name.getText();
329
+ var name_1 = vardec.name.getText();
337
330
  if (allowDebugLogs)
338
- console.log("Variable:", name_2);
339
- if (name_2.startsWith("\"@") || name_2.startsWith("\"$") || name_2.startsWith("$"))
331
+ console.log("Variable:", name_1);
332
+ if (name_1.startsWith("\"@") || name_1.startsWith("\"$") || name_1.startsWith("$"))
340
333
  break;
341
334
  var typeString = lastTypeFound !== null && lastTypeFound !== void 0 ? lastTypeFound : tryResolveTypeRecursive(node);
342
335
  var postFix = "";
@@ -419,13 +412,13 @@ function run(program, outputDir, sourceFile) {
419
412
  var inheritsComponent = testInheritsComponent(node);
420
413
  if (!dontExportNextClass && (lastTypeFound || exportNextClass || inheritsComponent)) {
421
414
  resetExportNextClass();
422
- var name_3 = (_g = dec.name) === null || _g === void 0 ? void 0 : _g.escapedText;
415
+ var name_2 = (_g = dec.name) === null || _g === void 0 ? void 0 : _g.escapedText;
423
416
  if (allowDebugLogs)
424
- console.log("Found class: ", name_3);
417
+ console.log("Found class: ", name_2);
425
418
  var namespace = (_h = tryParseNamespace(node)) !== null && _h !== void 0 ? _h : "Needle.Typescript.GeneratedComponents";
426
419
  if (allowDebugLogs)
427
420
  console.log("NAMESPACE", namespace);
428
- var newContext = new ExportContext(outputDir, name_3 + ".cs");
421
+ var newContext = new ExportContext(outputDir, name_2 + ".cs");
429
422
  newContext.appendLine("// auto generated code - do not edit directly");
430
423
  newContext.appendLine("");
431
424
  newContext.appendLine("#pragma warning disable");
@@ -440,7 +433,7 @@ function run(program, outputDir, sourceFile) {
440
433
  if (lastTypeFound)
441
434
  typeName_1 = lastTypeFound;
442
435
  if (allowDebugLogs)
443
- console.log(name_3 + " inherits " + typeName_1);
436
+ console.log(name_2 + " inherits " + typeName_1);
444
437
  var modifiers = "";
445
438
  if (dec.modifiers) {
446
439
  for (var _p = 0, _q = dec.modifiers; _p < _q.length; _p++) {
@@ -449,7 +442,7 @@ function run(program, outputDir, sourceFile) {
449
442
  case "abstract":
450
443
  modifiers += " abstract";
451
444
  if (allowDebugLogs)
452
- console.log(name_3 + " is abstract");
445
+ console.log(name_2 + " is abstract");
453
446
  break;
454
447
  }
455
448
  }
@@ -459,7 +452,7 @@ function run(program, outputDir, sourceFile) {
459
452
  if (typeName_1 === "object") {
460
453
  newContext.appendLine("[System.Serializable]");
461
454
  }
462
- newContext.appendLine("public " + modifiers.trim() + " class " + name_3 + " : " + typeName_1);
455
+ newContext.appendLine("public " + modifiers.trim() + " class " + name_2 + " : " + typeName_1);
463
456
  newContext.appendLine("{");
464
457
  newContext.indentLevel += 1;
465
458
  newContext.classEnd = dec.end;
@@ -472,6 +465,22 @@ function run(program, outputDir, sourceFile) {
472
465
  lastTypeFound = null;
473
466
  break;
474
467
  }
468
+ function testIsMarkedWithSerializable(node) {
469
+ if (node.kind === ts.SyntaxKind.Decorator) {
470
+ // If a field is decorated with @serializable then we want to serialize it
471
+ var name_3 = node.getText();
472
+ if (name_3.startsWith("@serializable(")) {
473
+ // if(allowDebugLogs) console.log("Found @serializable decorator");
474
+ return true;
475
+ }
476
+ }
477
+ for (var _i = 0, _a = node.getChildren(); _i < _a.length; _i++) {
478
+ var ch = _a[_i];
479
+ if (testIsMarkedWithSerializable(ch))
480
+ return true;
481
+ }
482
+ return false;
483
+ }
475
484
  function testInheritsComponent(node) {
476
485
  switch (node.kind) {
477
486
  case ts.SyntaxKind.ClassDeclaration:
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "types": [
4
- "mocha",
5
- "node"
6
- ]
7
- }
8
- }
@@ -1,15 +0,0 @@
1
- {
2
- "folders": [
3
- {
4
- "path": "../.github"
5
- },
6
- {
7
- "path": "."
8
- }
9
- ],
10
- "settings": {
11
- "files.exclude": {
12
- "test/*.js": true
13
- }
14
- }
15
- }