@needle-tools/needle-component-compiler 1.11.1 → 1.12.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 CHANGED
@@ -4,6 +4,9 @@ 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.11.2] - 2023-12-16
8
+ - Fix: property setter emitting invalid C# code
9
+
7
10
  ## [1.11.1] - 2023-12-02
8
11
  - Fix: Use Unity AnimatorController type
9
12
  - Fix: method inline anonymous type declaration (e.g. `myMethod(arg: {x:number})`)
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@needle-tools/needle-component-compiler",
3
- "version": "1.11.1",
3
+ "version": "1.12.0",
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",
10
- "test": "mocha -r ts-node/register test/**.test.ts"
10
+ "test": "mocha -r ts-node/register test/**/*serializable.test.ts"
11
11
  },
12
12
  "dependencies": {
13
13
  "typescript": "^4.5.5"
@@ -19,7 +19,7 @@
19
19
  "chai": "^4.3.6",
20
20
  "mocha": "^10.0.0",
21
21
  "ts-node": "^10.9.1",
22
- "npm-watch": "^0.11.0"
22
+ "npm-watch": "^0.13.0"
23
23
  },
24
24
  "watch": {
25
25
  "compile": {
@@ -38,5 +38,9 @@
38
38
  "repository": {
39
39
  "type": "git",
40
40
  "url": "git+https://github.com/needle-tools/needle-tiny-component-compiler.git"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public",
44
+ "registry": "https://registry.npmjs.org/"
41
45
  }
42
46
  }
@@ -302,7 +302,7 @@ function run(program, outputDir, sourceFile) {
302
302
  if (!context)
303
303
  break;
304
304
  if (allowDebugLogs)
305
- console.log("Found variable", node.getText());
305
+ console.log("Found variable", ts.SyntaxKind[node.kind], "\n", node.getText());
306
306
  var vardec = node;
307
307
  var varName = "@" + vardec.name.getText();
308
308
  var pub = shouldEmitMethod(vardec);
@@ -443,6 +443,10 @@ function run(program, outputDir, sourceFile) {
443
443
  }
444
444
  }
445
445
  modifiers += " partial";
446
+ // If it's a custom class and decorated with @type object then we want to make it serializable
447
+ if (typeName_1 === "object") {
448
+ newContext.appendLine("[System.Serializable]");
449
+ }
446
450
  newContext.appendLine("public " + modifiers.trim() + " class " + name_2 + " : " + typeName_1);
447
451
  newContext.appendLine("{");
448
452
  newContext.indentLevel += 1;
@@ -701,8 +705,14 @@ function run(program, outputDir, sourceFile) {
701
705
  var isInGenericDeclaration = false;
702
706
  for (var _b = 0, _c = node.getChildren(); _b < _c.length; _b++) {
703
707
  var child = _c[_b];
704
- // if (res !== undefined) break;
705
- // console.log("Child type: " + ts.SyntaxKind[child.kind]);
708
+ // Fix https://linear.app/needle/issue/NE-4423
709
+ if (child.kind === ts.SyntaxKind.Block) {
710
+ if (allowDebugLogs)
711
+ console.log("Skip block");
712
+ continue;
713
+ }
714
+ if (allowDebugLogs)
715
+ console.log("Child type: " + ts.SyntaxKind[child.kind]);
706
716
  var isGenericStart = false;
707
717
  var isAssignment = false;
708
718
  switch (child.kind) {
@@ -334,7 +334,7 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
334
334
  resetExportNextClass();
335
335
  if (!context) break;
336
336
  if (allowDebugLogs)
337
- console.log("Found variable", node.getText());
337
+ console.log("Found variable", ts.SyntaxKind[node.kind], "\n", node.getText());
338
338
  const vardec = node as ts.VariableDeclaration;
339
339
 
340
340
  const varName = "@" + vardec.name.getText();
@@ -473,6 +473,10 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
473
473
  }
474
474
  }
475
475
  modifiers += " partial";
476
+ // If it's a custom class and decorated with @type object then we want to make it serializable
477
+ if(typeName === "object") {
478
+ newContext.appendLine("[System.Serializable]")
479
+ }
476
480
  newContext.appendLine("public " + modifiers.trim() + " class " + name + " : " + typeName);
477
481
  newContext.appendLine("{");
478
482
  newContext.indentLevel += 1;
@@ -735,8 +739,15 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
735
739
 
736
740
  let isInGenericDeclaration = false;
737
741
  for (const child of node.getChildren()) {
738
- // if (res !== undefined) break;
739
- // console.log("Child type: " + ts.SyntaxKind[child.kind]);
742
+
743
+
744
+ // Fix https://linear.app/needle/issue/NE-4423
745
+ if (child.kind === ts.SyntaxKind.Block) {
746
+ if(allowDebugLogs) console.log("Skip block");
747
+ continue;
748
+ }
749
+
750
+ if(allowDebugLogs) console.log("Child type: " + ts.SyntaxKind[child.kind]);
740
751
  let isGenericStart = false;
741
752
  let isAssignment = false;
742
753
  switch (child.kind) {