@needle-tools/needle-component-compiler 1.6.2 → 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 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.6.3] - 2022-07-12
8
+ - add warning when class type is unknown
9
+
7
10
  ## [1.6.2] - 2022-07-11
8
11
  - fix ``@type`` for class declaration
9
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/needle-component-compiler",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "Compile mock unity components from typescript",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -38,7 +38,8 @@ function tryGetKnownType(str) {
38
38
  }
39
39
  if (typesFileContent) {
40
40
  var fullType = typesFileContent[str];
41
- console.log(fullType);
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)) {
@@ -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 _f = 0, _g = meth.parameters; _f < _g.length; _f++) {
198
- var param = _g[_f];
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 _h = 0, _j = node.getChildren(); _h < _j.length; _h++) {
232
- var ch = _j[_h];
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:
@@ -302,6 +303,9 @@ function run(program, outputDir, sourceFile) {
302
303
  newContext.classEnd = dec.end;
303
304
  contexts.push(newContext);
304
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
+ }
305
309
  lastTypeFound = null;
306
310
  break;
307
311
  }
@@ -43,7 +43,8 @@ function tryGetKnownType(str: string): string | null {
43
43
 
44
44
  if (typesFileContent) {
45
45
  const fullType = typesFileContent[str];
46
- console.log(fullType);
46
+ if (fullType)
47
+ console.log(fullType);
47
48
  return fullType;
48
49
  }
49
50
  return null;
@@ -314,7 +315,7 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
314
315
  // newContext.appendLine("// source: " + path.resolve(sourceFile.fileName));
315
316
  let typeName = "UnityEngine.MonoBehaviour";
316
317
  if (typeof inheritsComponent === "string") typeName = inheritsComponent;
317
- if(lastTypeFound) typeName = lastTypeFound;
318
+ if (lastTypeFound) typeName = lastTypeFound;
318
319
  console.log(name + " inherits " + typeName);
319
320
  newContext.appendLine("public partial class " + name + " : " + typeName);
320
321
  newContext.appendLine("{");
@@ -322,6 +323,9 @@ export function run(program: ts.Program, outputDir: string, sourceFile: ts.Sourc
322
323
  newContext.classEnd = dec.end;
323
324
  contexts.push(newContext);
324
325
  }
326
+ else {
327
+ console.log("Class type is unknown and will not generate a component: ", dec.name?.escapedText);
328
+ }
325
329
  lastTypeFound = null;
326
330
  break;
327
331
  }
package/src/test.ts CHANGED
@@ -1,9 +1,17 @@
1
- //@type UnityEngine.MonoBehaviour
2
- export class ButtonObject extends Interactable implements IPointerClickHandler, ISerializable {
3
1
 
4
- //@type UnityEngine.Transform[]
5
- myType?: SceneFXWindow;
6
- }
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
+ // }
7
15
 
8
16
  // import { Behaviour } from "needle.tiny.engine/engine-components/Component";
9
17
  // import { RoomEntity } from "./Room";