@needle-tools/needle-component-compiler 3.0.2 → 3.0.3-f6b855c

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,23 @@ 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
+ ## [3.0.3] - 2026-03-11
8
+
9
+ ### Fixed
10
+ - Fix `Promise<T>` return types passing through as `Promise` instead of resolving to `void`
11
+ - Fix unknown/web-only types (e.g. user-defined interfaces) in method parameters passing through instead of becoming `object`
12
+ - Fix `@nonSerialized` comment directive not being respected on methods (only worked on fields before)
13
+ - Fix `void` in union return types not being filtered out (e.g. `void | boolean` now correctly resolves to `bool`)
14
+ - Fix enum types in method parameters and return types becoming `object` instead of preserving the enum name
15
+
16
+ ### Added
17
+ - `@type` override on methods: `// @type ReturnType` overrides the return type, `// @type paramName ParamType` overrides a specific parameter's type
18
+ - C# enum generation: exported enums are now generated as separate `.cs` files in the `Needle.Typescript.GeneratedComponents` namespace
19
+ - Supports numeric enums (with explicit or auto-incremented values) and string enums
20
+ - Lowercase enum names are automatically PascalCased (e.g. `lightType` → `LightType`)
21
+ - Non-exported enums are registered for type resolution but not generated as files
22
+ - Opt out per enum with `// @dont-generate-enum`
23
+
7
24
  ## [3.0.1] - 2026-03-04
8
25
 
9
26
  ### Fixed
@@ -14,6 +14,8 @@ export declare abstract class BaseWriter implements IWriter {
14
14
  abstract writeMember(visibility: Visibility, name: string, isArray: boolean, type: string, initialValue?: string, comments?: string[]): void;
15
15
  abstract writeMethod(visibility: Visibility, name: string, returnType: string, args: Argument[], comments: string[]): void;
16
16
  abstract writeNewTypeExpression(typeName: string, args?: string[]): void;
17
+ /** Override to generate enum output. Default is no-op. */
18
+ writeEnum(name: string, members: EnumMember[], comments?: string[]): void;
17
19
  private _currentlyProcessingFiles;
18
20
  get outputInfo(): TypeSourceInformation;
19
21
  private _createdSchemesPerFile;
@@ -23,6 +23,10 @@ var BaseWriter = /** @class */ (function () {
23
23
  BaseWriter.prototype.registerEnum = function (name, members) {
24
24
  this._enumRegistry.set(name.toLowerCase(), members);
25
25
  };
26
+ /** Override to generate enum output. Default is no-op. */
27
+ BaseWriter.prototype.writeEnum = function (name, members, comments) {
28
+ // no-op by default — subclasses can override
29
+ };
26
30
  Object.defineProperty(BaseWriter.prototype, "outputInfo", {
27
31
  get: function () {
28
32
  return this._createdSchemesPerFile;
package/dist/Compiler.js CHANGED
@@ -29,11 +29,12 @@ var Compiler = /** @class */ (function () {
29
29
  writer.end(filePath);
30
30
  };
31
31
  Compiler.prototype.visitEnumDeclaration = function (node, writer) {
32
+ var _a;
32
33
  var name = node.name.getText();
33
34
  var members = [];
34
35
  var nextValue = 0;
35
- for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
36
- var member = _a[_i];
36
+ for (var _i = 0, _b = node.members; _i < _b.length; _i++) {
37
+ var member = _b[_i];
37
38
  var memberName = member.name.getText();
38
39
  var value = void 0;
39
40
  if (member.initializer) {
@@ -61,7 +62,13 @@ var Compiler = /** @class */ (function () {
61
62
  members.push({ name: memberName, value: value });
62
63
  }
63
64
  this.debugLog("[COMPILER] ENUM", name, members);
65
+ // Always register for type resolution
64
66
  writer.registerEnum(name, members);
67
+ // Only generate enum file for exported enums
68
+ var isExported = (_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(function (m) { return m.kind === ts.SyntaxKind.ExportKeyword; });
69
+ if (isExported) {
70
+ writer.writeEnum(name, members, this.getComments(node));
71
+ }
65
72
  };
66
73
  Compiler.prototype.visit = function (filePath, node, writer) {
67
74
  var _this = this;
@@ -52,5 +52,6 @@ export interface IWriter {
52
52
  writeMethod(visibility: Visibility, name: string, returnType: string | undefined, args: Argument[], comments: string[]): void;
53
53
  writeNewTypeExpression(typeName: string, args?: string[]): void;
54
54
  registerEnum(name: string, members: EnumMember[]): void;
55
+ writeEnum(name: string, members: EnumMember[], comments?: string[]): void;
55
56
  }
56
57
  export declare function runFromFile(writer: IWriter, path: string): Compiler;
@@ -1,6 +1,9 @@
1
1
  import { Argument, Visibility } from "../base-compiler";
2
2
  import { BaseWriter } from "../BaseWriter";
3
3
  export declare class CSharpWriter extends BaseWriter {
4
+ /** Buffered enum outputs — flushed after all classes in end() */
5
+ private _pendingEnums;
6
+ end(filePath: string | null): void;
4
7
  resolveCSharpTypeName(typescriptTypeName: string): string | void;
5
8
  /** Tries to resolve a C# type name; returns undefined if the type is not known.
6
9
  * Checks TYPE_MAP keys/values and the enum registry. */
@@ -10,6 +13,7 @@ export declare class CSharpWriter extends BaseWriter {
10
13
  writeMember(visibility: Visibility, name: string, isArray: boolean, type: string, initialValue?: string, comments?: string[]): void;
11
14
  writeMethod(visibility: Visibility, name: string, returnType: string, args: Argument[], comments: string[]): void;
12
15
  writeNewTypeExpression(typeName: string, args?: string[]): void;
16
+ writeEnum(name: string, members: import("../base-compiler").EnumMember[], comments?: string[]): void;
13
17
  /** Converts camelCase to PascalCase for method names */
14
18
  private toPascalCase;
15
19
  /** Resolve a "new Type(args)" expression: map TS types to C# qualified types */
@@ -123,8 +123,20 @@ function isEditorType(typeName) {
123
123
  var CSharpWriter = /** @class */ (function (_super) {
124
124
  __extends(CSharpWriter, _super);
125
125
  function CSharpWriter() {
126
- return _super !== null && _super.apply(this, arguments) || this;
126
+ var _this = _super !== null && _super.apply(this, arguments) || this;
127
+ /** Buffered enum outputs — flushed after all classes in end() */
128
+ _this._pendingEnums = [];
129
+ return _this;
127
130
  }
131
+ CSharpWriter.prototype.end = function (filePath) {
132
+ // Flush buffered enums AFTER all class outputs
133
+ for (var _i = 0, _a = this._pendingEnums; _i < _a.length; _i++) {
134
+ var pending = _a[_i];
135
+ this.sink.flush(pending.name + ".cs", pending.content);
136
+ }
137
+ this._pendingEnums.length = 0;
138
+ _super.prototype.end.call(this, filePath);
139
+ };
128
140
  CSharpWriter.prototype.resolveCSharpTypeName = function (typescriptTypeName) {
129
141
  var _a, _b;
130
142
  if (!typescriptTypeName)
@@ -275,6 +287,25 @@ var CSharpWriter = /** @class */ (function (_super) {
275
287
  // @contextmenu on method → add attribute
276
288
  var contextMenuComment = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@contextmenu "); });
277
289
  var contextMenu = contextMenuComment ? contextMenuComment.substring("@contextmenu ".length).trim() : null;
290
+ // @type overrides: "@type ReturnType" for return, "@type paramName ParamType" for params
291
+ var returnTypeOverride;
292
+ var paramTypeOverrides = {};
293
+ if (comments) {
294
+ for (var _i = 0, comments_1 = comments; _i < comments_1.length; _i++) {
295
+ var c = comments_1[_i];
296
+ if (!c.startsWith("@type "))
297
+ continue;
298
+ var parts = c.substring("@type ".length).trim().split(/\s+/);
299
+ if (parts.length >= 2) {
300
+ // "@type paramName Type" → param override
301
+ paramTypeOverrides[parts[0]] = parts.slice(1).join(" ");
302
+ }
303
+ else if (parts.length === 1) {
304
+ // "@type Type" → return type override
305
+ returnTypeOverride = parts[0];
306
+ }
307
+ }
308
+ }
278
309
  // Only emit public methods and lifecycle methods (which are always public)
279
310
  var lifecycleName = LIFECYCLE_METHODS[name];
280
311
  if (visibility !== base_compiler_1.Visibility.Public && !lifecycleName)
@@ -285,7 +316,10 @@ var CSharpWriter = /** @class */ (function (_super) {
285
316
  var paramList = (_a = args === null || args === void 0 ? void 0 : args.map(function (arg) {
286
317
  var _a;
287
318
  var csharpType;
288
- if (!arg.type || arg.type.includes("{")) {
319
+ if (paramTypeOverrides[arg.name]) {
320
+ csharpType = paramTypeOverrides[arg.name];
321
+ }
322
+ else if (!arg.type || arg.type.includes("{")) {
289
323
  csharpType = "object";
290
324
  }
291
325
  else {
@@ -293,9 +327,7 @@ var CSharpWriter = /** @class */ (function (_super) {
293
327
  }
294
328
  return "".concat(csharpType, " @").concat(arg.name);
295
329
  }).join(", ")) !== null && _a !== void 0 ? _a : "";
296
- var csReturnType = returnType
297
- ? ((_b = this.resolveKnownCSharpTypeName(returnType)) !== null && _b !== void 0 ? _b : "void")
298
- : "void";
330
+ var csReturnType = returnTypeOverride !== null && returnTypeOverride !== void 0 ? returnTypeOverride : (returnType ? ((_b = this.resolveKnownCSharpTypeName(returnType)) !== null && _b !== void 0 ? _b : "void") : "void");
299
331
  if (contextMenu)
300
332
  this.writer.writeLine("[UnityEngine.ContextMenu(\"".concat(contextMenu, "\")]"));
301
333
  this.writer.writeLine("public ".concat(csReturnType, " ").concat(methodName, "(").concat(paramList, ") {}"));
@@ -303,6 +335,29 @@ var CSharpWriter = /** @class */ (function (_super) {
303
335
  CSharpWriter.prototype.writeNewTypeExpression = function (typeName, args) {
304
336
  // no-op for C# output
305
337
  };
338
+ CSharpWriter.prototype.writeEnum = function (name, members, comments) {
339
+ // @dont-generate-enum → skip
340
+ if (comments === null || comments === void 0 ? void 0 : comments.some(function (c) { return c.startsWith("@dont-generate-enum"); }))
341
+ return;
342
+ // PascalCase: ensure first letter is uppercase
343
+ var pascalName = name.charAt(0).toUpperCase() + name.slice(1);
344
+ this.writer.beginBlock("namespace Needle.Typescript.GeneratedComponents\n{");
345
+ this.writer.beginBlock("public enum ".concat(pascalName, "\n{"));
346
+ for (var _i = 0, members_1 = members; _i < members_1.length; _i++) {
347
+ var member = members_1[_i];
348
+ if (typeof member.value === "string") {
349
+ // String enums can't have values in C# — emit name only
350
+ this.writer.writeLine("".concat(member.name, ","));
351
+ }
352
+ else {
353
+ this.writer.writeLine("".concat(member.name, " = ").concat(member.value, ","));
354
+ }
355
+ }
356
+ this.writer.endBlock("}");
357
+ this.writer.endBlock("}");
358
+ // Buffer the output — flush after all classes in end()
359
+ this._pendingEnums.push({ name: pascalName, content: this.writer.flush() });
360
+ };
306
361
  // ── Helpers ────────────────────────────────────────────────────────────
307
362
  /** Converts camelCase to PascalCase for method names */
308
363
  CSharpWriter.prototype.toPascalCase = function (name) {
@@ -17,4 +17,5 @@ export declare class ReactThreeFiberCompiler implements IWriter {
17
17
  }[], comments: string[]): void;
18
18
  writeNewTypeExpression(typeName: string, args?: string[]): void;
19
19
  registerEnum(name: string, members: import("../base-compiler").EnumMember[]): void;
20
+ writeEnum(name: string, members: import("../base-compiler").EnumMember[], comments?: string[]): void;
20
21
  }
@@ -31,6 +31,8 @@ var ReactThreeFiberCompiler = /** @class */ (function () {
31
31
  };
32
32
  ReactThreeFiberCompiler.prototype.registerEnum = function (name, members) {
33
33
  };
34
+ ReactThreeFiberCompiler.prototype.writeEnum = function (name, members, comments) {
35
+ };
34
36
  return ReactThreeFiberCompiler;
35
37
  }());
36
38
  exports.ReactThreeFiberCompiler = ReactThreeFiberCompiler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/needle-component-compiler",
3
- "version": "3.0.2",
3
+ "version": "3.0.3-f6b855c",
4
4
  "description": "Compile Editor components for Needle Engine for C# and Blender",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -57,7 +57,7 @@
57
57
  "url": "git+https://github.com/needle-tools/needle-tiny-component-compiler.git"
58
58
  },
59
59
  "publishConfig": {
60
- "access": "public",
61
- "registry": "https://registry.npmjs.org/"
60
+ "access": "public",
61
+ "registry": "https://registry.npmjs.org/"
62
62
  }
63
- }
63
+ }