@needle-tools/needle-component-compiler 1.12.0-da2e0be → 1.12.1-90184de

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,6 +4,14 @@ 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
8
+ - Fix: Private fields decorated with `@serializable()` should be annotated with `UnityEngine.SerializeField`
9
+ - Fix: Comment for `// @serializeField` should not affect subsequent fields
10
+
11
+
12
+ ## [1.12.0] - 2025-06-02
13
+ - Add: Support to serialize unknown classes when annotated with `// @type object`
14
+
7
15
  ## [1.11.2] - 2023-12-16
8
16
  - Fix: property setter emitting invalid C# code
9
17
 
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@needle-tools/needle-component-compiler",
3
- "version": "1.12.0-da2e0be",
3
+ "version": "1.12.1-90184de",
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
9
  "compile": "tsc src/component-compiler.ts",
10
- "test": "mocha -r ts-node/register test/**/*serializable.test.ts"
10
+ "test": "mocha -r ts-node/register test/**/*.test.ts"
11
11
  },
12
12
  "dependencies": {
13
13
  "typescript": "^4.5.5"
@@ -114,7 +114,8 @@ var ExportContext = /** @class */ (function () {
114
114
  fs.writeFileSync(path_1, code);
115
115
  }
116
116
  else {
117
- console.log("No output dir specified");
117
+ if (allowDebugLogs)
118
+ console.log("No output dir specified");
118
119
  }
119
120
  this.reset();
120
121
  return code;
@@ -189,7 +190,8 @@ function run(program, outputDir, sourceFile) {
189
190
  continue;
190
191
  commentStarts.push(r.pos);
191
192
  var comment = node.getSourceFile().getFullText().slice(r.pos, r.end);
192
- console.log(comment);
193
+ if (allowDebugLogs)
194
+ console.log(comment);
193
195
  if (context) {
194
196
  // https://regex101.com/r/ud4oev/1
195
197
  var emitContextMenu = comment.match("(\/{2,}|\/\*) {0,}@contextmenu {1,}(?<text>[a-zA-Z 0-9]+)?");
@@ -199,7 +201,8 @@ function run(program, outputDir, sourceFile) {
199
201
  // https://regex101.com/r/Sa6Q8T/3
200
202
  var emitTooltip = comment.match("\/{2,} {0,}(@tooltip) *?(?<text>.+)");
201
203
  if (emitTooltip) {
202
- console.log((_c = emitTooltip.groups) === null || _c === void 0 ? void 0 : _c.text);
204
+ if (allowDebugLogs)
205
+ console.log((_c = emitTooltip.groups) === null || _c === void 0 ? void 0 : _c.text);
203
206
  context.emitTooltip = (_e = (_d = emitTooltip.groups) === null || _d === void 0 ? void 0 : _d.text) !== null && _e !== void 0 ? _e : null;
204
207
  }
205
208
  else if (comment.includes(serializeCommand))
@@ -245,6 +248,13 @@ function run(program, outputDir, sourceFile) {
245
248
  // console.log("comment: " + node.getText())
246
249
  // break;
247
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
+ }
248
258
  break;
249
259
  case ts.SyntaxKind.MethodDeclaration:
250
260
  lastTypeFound = null;
@@ -308,24 +318,25 @@ function run(program, outputDir, sourceFile) {
308
318
  var pub = shouldEmitMethod(vardec);
309
319
  var visibility = pub ? "public" : "private";
310
320
  var isAccessible = pub;
311
- dontSerialize = false;
312
321
  if (serializeField) {
313
322
  if (allowDebugLogs)
314
- console.log("[SerializeField]");
323
+ console.log("Emit [UnityEngine.SerializeField]");
315
324
  context.appendLine("[UnityEngine.SerializeField]");
316
325
  isAccessible = true;
317
326
  }
318
327
  else if (skip)
319
328
  isAccessible = false;
329
+ dontSerialize = false;
330
+ serializeField = false;
320
331
  if (!isAccessible) {
321
332
  if (allowDebugLogs)
322
333
  console.log("Skip because not public or serializeable");
323
334
  break;
324
335
  }
325
- var name_1 = vardec.name.getText();
336
+ var name_2 = vardec.name.getText();
326
337
  if (allowDebugLogs)
327
- console.log("Variable:", name_1);
328
- if (name_1.startsWith("\"@") || name_1.startsWith("\"$") || name_1.startsWith("$"))
338
+ console.log("Variable:", name_2);
339
+ if (name_2.startsWith("\"@") || name_2.startsWith("\"$") || name_2.startsWith("$"))
329
340
  break;
330
341
  var typeString = lastTypeFound !== null && lastTypeFound !== void 0 ? lastTypeFound : tryResolveTypeRecursive(node);
331
342
  var postFix = "";
@@ -402,18 +413,19 @@ function run(program, outputDir, sourceFile) {
402
413
  break;
403
414
  case ts.SyntaxKind.ClassDeclaration:
404
415
  serializeField = false;
416
+ dontSerialize = false;
405
417
  var dec = node;
406
418
  // a class must inherit a component
407
419
  var inheritsComponent = testInheritsComponent(node);
408
420
  if (!dontExportNextClass && (lastTypeFound || exportNextClass || inheritsComponent)) {
409
421
  resetExportNextClass();
410
- var name_2 = (_g = dec.name) === null || _g === void 0 ? void 0 : _g.escapedText;
422
+ var name_3 = (_g = dec.name) === null || _g === void 0 ? void 0 : _g.escapedText;
411
423
  if (allowDebugLogs)
412
- console.log("Found class: ", name_2);
424
+ console.log("Found class: ", name_3);
413
425
  var namespace = (_h = tryParseNamespace(node)) !== null && _h !== void 0 ? _h : "Needle.Typescript.GeneratedComponents";
414
426
  if (allowDebugLogs)
415
427
  console.log("NAMESPACE", namespace);
416
- var newContext = new ExportContext(outputDir, name_2 + ".cs");
428
+ var newContext = new ExportContext(outputDir, name_3 + ".cs");
417
429
  newContext.appendLine("// auto generated code - do not edit directly");
418
430
  newContext.appendLine("");
419
431
  newContext.appendLine("#pragma warning disable");
@@ -428,7 +440,7 @@ function run(program, outputDir, sourceFile) {
428
440
  if (lastTypeFound)
429
441
  typeName_1 = lastTypeFound;
430
442
  if (allowDebugLogs)
431
- console.log(name_2 + " inherits " + typeName_1);
443
+ console.log(name_3 + " inherits " + typeName_1);
432
444
  var modifiers = "";
433
445
  if (dec.modifiers) {
434
446
  for (var _p = 0, _q = dec.modifiers; _p < _q.length; _p++) {
@@ -437,7 +449,7 @@ function run(program, outputDir, sourceFile) {
437
449
  case "abstract":
438
450
  modifiers += " abstract";
439
451
  if (allowDebugLogs)
440
- console.log(name_2 + " is abstract");
452
+ console.log(name_3 + " is abstract");
441
453
  break;
442
454
  }
443
455
  }
@@ -447,7 +459,7 @@ function run(program, outputDir, sourceFile) {
447
459
  if (typeName_1 === "object") {
448
460
  newContext.appendLine("[System.Serializable]");
449
461
  }
450
- newContext.appendLine("public " + modifiers.trim() + " class " + name_2 + " : " + typeName_1);
462
+ newContext.appendLine("public " + modifiers.trim() + " class " + name_3 + " : " + typeName_1);
451
463
  newContext.appendLine("{");
452
464
  newContext.indentLevel += 1;
453
465
  newContext.classEnd = dec.end;
@@ -499,7 +511,8 @@ function run(program, outputDir, sourceFile) {
499
511
  for (var _i = 0, _a = node.getChildren(); _i < _a.length; _i++) {
500
512
  var ch = _a[_i];
501
513
  var text = ch.getText();
502
- console.log("child", ts.SyntaxKind[ch.kind], text);
514
+ if (allowDebugLogs)
515
+ console.log("child", ts.SyntaxKind[ch.kind], text);
503
516
  switch (ch.kind) {
504
517
  case ts.SyntaxKind.Identifier:
505
518
  case ts.SyntaxKind.PropertyAccessExpression:
@@ -528,7 +541,8 @@ function run(program, outputDir, sourceFile) {
528
541
  args = "";
529
542
  if (type || typeString) {
530
543
  if (typeString) {
531
- console.log("Override type", type, typeString);
544
+ if (allowDebugLogs)
545
+ console.log("Override type", type, typeString);
532
546
  type = typeString;
533
547
  }
534
548
  return "new " + type + "(" + args + ")";