@needle-tools/needle-component-compiler 3.0.19 → 3.0.20-next.2ca1149
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 +5 -0
- package/Readme.md +1 -0
- package/dist/BaseWriter.d.ts +1 -1
- package/dist/Compiler.js +5 -2
- package/dist/base-compiler.d.ts +1 -1
- package/dist/impl/blender-compiler.d.ts +1 -1
- package/dist/impl/blender-compiler.js +17 -11
- package/dist/impl/csharp-compiler.d.ts +1 -1
- package/dist/impl/csharp-compiler.js +9 -4
- package/dist/impl/react-three-fiber-compiler.d.ts +1 -1
- package/dist/impl/react-three-fiber-compiler.js +1 -1
- package/package.json +1 -1
package/Changelog.md
CHANGED
|
@@ -4,6 +4,11 @@ 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.20] - 2026-05-05
|
|
8
|
+
### Changed
|
|
9
|
+
- Fields without `@serializable()` decorator (or `//@serializable` / `//@serializeField` comment directive) are no longer emitted in C# or Blender output. This prevents unresolvable types (e.g. `article: Article | undefined = undefined`) from producing compile errors in generated stubs.
|
|
10
|
+
- Blender: component reference types now emit concrete type names (e.g. `Camera`, `Rigidbody`, `AudioSource`) instead of generic `comp`. Added support for: Animation, Animator, Camera, Light, Rigidbody, Renderer, Canvas, VideoPlayer, AudioSource, SphereCollider, MeshCollider, BoxCollider, PlayableDirector, DragControls, Button, Text.
|
|
11
|
+
|
|
7
12
|
## [3.0.19] - 2026-04-28
|
|
8
13
|
### Fixed
|
|
9
14
|
- C#: skip `= undefined` initializers — `undefined` is not valid in C#
|
package/Readme.md
CHANGED
|
@@ -70,6 +70,7 @@ Use `//` comments above classes, fields, or methods to control code generation:
|
|
|
70
70
|
| `@abstract` | Class | Mark the generated class as `abstract` |
|
|
71
71
|
| `@serializeField` | Field | Emit `[UnityEngine.SerializeField]` attribute |
|
|
72
72
|
| `@nonSerialized` | Field / Method | Skip generating C# code for this member |
|
|
73
|
+
| `@header "My text"` | Field | Emit `[UnityEngine.Header("My text")]` (C# only) |
|
|
73
74
|
| `@tooltip "My text"` | Field | Emit `[UnityEngine.Tooltip("My text")]` (C#) or `"description"` (Blender) |
|
|
74
75
|
| `@contextmenu "Label"` | Method | Emit `[UnityEngine.ContextMenu("Label")]` |
|
|
75
76
|
| `@ifdef MY_DEFINE` | Field | Wrap field in `#if MY_DEFINE` / `#endif` |
|
package/dist/BaseWriter.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare abstract class BaseWriter implements IWriter {
|
|
|
8
8
|
/** Enum registry: lowercased enum name → members */
|
|
9
9
|
protected _enumRegistry: Map<string, EnumMember[]>;
|
|
10
10
|
registerEnum(name: string, members: EnumMember[]): void;
|
|
11
|
-
abstract
|
|
11
|
+
abstract resolveNeedleTypeName(typescriptTypeName: string, baseTypes?: string[]): string | void;
|
|
12
12
|
abstract startNewType(filePath: string, typeName: string, baseType: string[], comments?: string[]): boolean | void;
|
|
13
13
|
abstract endNewType(filePath: string, typeName: string): void;
|
|
14
14
|
abstract writeMember(visibility: Visibility, name: string, isArray: boolean, type: string, initialValue?: string, comments?: string[]): void;
|
package/dist/Compiler.js
CHANGED
|
@@ -151,7 +151,10 @@ var Compiler = /** @class */ (function () {
|
|
|
151
151
|
// If the property has a @serializable() decorator, ensure it's in the comments
|
|
152
152
|
// so the writer emits private/protected fields with [SerializeField]
|
|
153
153
|
var hasSerialized = this.hasSerializableDecorator(node);
|
|
154
|
-
|
|
154
|
+
var hasSerializedComment = comments.some(function (c) { return c.startsWith("@serializable") || c.startsWith("@serializeField"); });
|
|
155
|
+
if (!hasSerialized && !hasSerializedComment)
|
|
156
|
+
return; // only emit fields marked with @serializable() or //@serializable or //@serializeField
|
|
157
|
+
if (!comments.some(function (c) { return c.startsWith("@serializable"); })) {
|
|
155
158
|
comments.push("@serializable");
|
|
156
159
|
}
|
|
157
160
|
var flags = [];
|
|
@@ -429,7 +432,7 @@ var Compiler = /** @class */ (function () {
|
|
|
429
432
|
return this.resolveTypeFromString(typeNode.getText(), writer);
|
|
430
433
|
};
|
|
431
434
|
Compiler.prototype.resolveTypeFromString = function (type, writer) {
|
|
432
|
-
var resolved = writer.
|
|
435
|
+
var resolved = writer.resolveNeedleTypeName(type);
|
|
433
436
|
return resolved || type;
|
|
434
437
|
};
|
|
435
438
|
Compiler.prototype.isArrayType = function (typeNode) {
|
package/dist/base-compiler.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export type EnumMember = {
|
|
|
44
44
|
export interface IWriter {
|
|
45
45
|
get outputInfo(): TypeSourceInformation;
|
|
46
46
|
begin(filePath: string | null): void;
|
|
47
|
-
|
|
47
|
+
resolveNeedleTypeName(typescriptTypeName: string, baseTypes?: string[]): string | void;
|
|
48
48
|
end(filePath: string | null): void;
|
|
49
49
|
startNewType(filePath: string | null, typeName: string, baseType: string[], comments?: string[]): void | boolean;
|
|
50
50
|
endNewType(filePath: string | null, typeName: string): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Visibility } from "../base-compiler";
|
|
2
2
|
import { BaseWriter } from "../BaseWriter";
|
|
3
3
|
export declare class BlenderWriter extends BaseWriter {
|
|
4
|
-
|
|
4
|
+
resolveNeedleTypeName(typeName: string, comments?: string[]): string | void;
|
|
5
5
|
startNewType(filePath: string | null, typeName: string, baseTypes: string[], comments?: string[]): void | boolean;
|
|
6
6
|
endNewType(filePath: string | null, typeName: string): void;
|
|
7
7
|
writeMember(visibility: Visibility, name: string, isArray: boolean, type: string, initialValue?: string, comments?: string[]): void;
|
|
@@ -26,7 +26,7 @@ var BlenderWriter = /** @class */ (function (_super) {
|
|
|
26
26
|
function BlenderWriter() {
|
|
27
27
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
28
28
|
}
|
|
29
|
-
BlenderWriter.prototype.
|
|
29
|
+
BlenderWriter.prototype.resolveNeedleTypeName = function (typeName, comments) {
|
|
30
30
|
typeName = typeName.toLocaleLowerCase();
|
|
31
31
|
if (typeName.startsWith("three."))
|
|
32
32
|
typeName = typeName.substring("three.".length);
|
|
@@ -59,17 +59,23 @@ var BlenderWriter = /** @class */ (function (_super) {
|
|
|
59
59
|
case "eventlist":
|
|
60
60
|
return "evt";
|
|
61
61
|
case "behaviour":
|
|
62
|
-
case "animation": // Animation component ref
|
|
63
|
-
case "animator": // Animator component ref
|
|
64
|
-
case "camera":
|
|
65
|
-
case "light":
|
|
66
|
-
case "rigidbody":
|
|
67
|
-
case "renderer": // Renderer component ref
|
|
68
|
-
case "canvas": // Canvas component ref
|
|
69
|
-
case "charactercontroller": // CharacterController component ref
|
|
70
|
-
case "videoplayer": // VideoPlayer component ref
|
|
71
|
-
case "lookatconstraint": // LookAtConstraint component ref
|
|
72
62
|
return "comp";
|
|
63
|
+
case "animation": return "Animation";
|
|
64
|
+
case "animator": return "Animator";
|
|
65
|
+
case "camera": return "Camera";
|
|
66
|
+
case "light": return "Light";
|
|
67
|
+
case "rigidbody": return "Rigidbody";
|
|
68
|
+
case "renderer": return "Renderer";
|
|
69
|
+
case "canvas": return "Canvas";
|
|
70
|
+
case "videoplayer": return "VideoPlayer";
|
|
71
|
+
case "audiosource": return "AudioSource";
|
|
72
|
+
case "spherecollider": return "SphereCollider";
|
|
73
|
+
case "meshcollider": return "MeshCollider";
|
|
74
|
+
case "boxcollider": return "BoxCollider";
|
|
75
|
+
case "playabledirector": return "PlayableDirector";
|
|
76
|
+
case "dragcontrols": return "DragControls";
|
|
77
|
+
case "button": return "Button";
|
|
78
|
+
case "text": return "Text";
|
|
73
79
|
case "texture":
|
|
74
80
|
return "tex";
|
|
75
81
|
case "image":
|
|
@@ -3,7 +3,7 @@ import { BaseWriter } from "../BaseWriter";
|
|
|
3
3
|
export declare class CSharpWriter extends BaseWriter {
|
|
4
4
|
private externalTypes;
|
|
5
5
|
constructor(sink?: ISink, externalTypes?: Record<string, string>);
|
|
6
|
-
|
|
6
|
+
resolveNeedleTypeName(typescriptTypeName: string): string | void;
|
|
7
7
|
/** Tries to resolve a C# type name; returns undefined if the type is not known.
|
|
8
8
|
* Checks TYPE_MAP keys/values and the enum registry. */
|
|
9
9
|
resolveKnownCSharpTypeName(typeName: string): string | undefined;
|
|
@@ -129,7 +129,7 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
129
129
|
_this.externalTypes = externalTypes;
|
|
130
130
|
return _this;
|
|
131
131
|
}
|
|
132
|
-
CSharpWriter.prototype.
|
|
132
|
+
CSharpWriter.prototype.resolveNeedleTypeName = function (typescriptTypeName) {
|
|
133
133
|
var _a, _b, _c, _d, _e;
|
|
134
134
|
if (!typescriptTypeName)
|
|
135
135
|
return undefined;
|
|
@@ -191,7 +191,7 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
191
191
|
}
|
|
192
192
|
else if (baseTypes === null || baseTypes === void 0 ? void 0 : baseTypes.length) {
|
|
193
193
|
var first = baseTypes[0];
|
|
194
|
-
resolvedBase = (_a = this.
|
|
194
|
+
resolvedBase = (_a = this.resolveNeedleTypeName(first)) !== null && _a !== void 0 ? _a : "UnityEngine.MonoBehaviour";
|
|
195
195
|
}
|
|
196
196
|
// Abstract modifier
|
|
197
197
|
var isAbstract = comments === null || comments === void 0 ? void 0 : comments.includes("@abstract");
|
|
@@ -222,7 +222,7 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
222
222
|
var typeOverride = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@type "); });
|
|
223
223
|
var csharpType = typeOverride
|
|
224
224
|
? typeOverride.substring("@type ".length).trim()
|
|
225
|
-
: ((_a = this.
|
|
225
|
+
: ((_a = this.resolveNeedleTypeName(type)) !== null && _a !== void 0 ? _a : type);
|
|
226
226
|
// Determine visibility string
|
|
227
227
|
var vis = "public";
|
|
228
228
|
if (visibility === base_compiler_1.Visibility.Private || visibility === base_compiler_1.Visibility.Protected) {
|
|
@@ -230,6 +230,9 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
230
230
|
}
|
|
231
231
|
// @serializeField → add attribute + force private becomes serialized
|
|
232
232
|
var serializeField = comments === null || comments === void 0 ? void 0 : comments.some(function (c) { return c.startsWith("@serializeField") || c.startsWith("@serializable"); });
|
|
233
|
+
// @header
|
|
234
|
+
var headerComment = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@header "); });
|
|
235
|
+
var header = headerComment ? headerComment.substring("@header ".length).trim().replace(/^["']|["']$/g, "") : null;
|
|
233
236
|
// @tooltip
|
|
234
237
|
var tooltipComment = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@tooltip "); });
|
|
235
238
|
var tooltip = tooltipComment ? tooltipComment.substring("@tooltip ".length).trim().replace(/^["']|["']$/g, "") : null;
|
|
@@ -302,6 +305,8 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
302
305
|
if (needsEditorWrap)
|
|
303
306
|
this.writer.writeLine("#if UNITY_EDITOR");
|
|
304
307
|
// Emit attributes
|
|
308
|
+
if (header)
|
|
309
|
+
this.writer.writeLine("[UnityEngine.Header(\"".concat(header, "\")]"));
|
|
305
310
|
if (tooltip)
|
|
306
311
|
this.writer.writeLine("[UnityEngine.Tooltip(\"".concat(tooltip, "\")]"));
|
|
307
312
|
if (contextMenu)
|
|
@@ -390,7 +395,7 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
390
395
|
if (!match)
|
|
391
396
|
return expr;
|
|
392
397
|
var typeName = match[1], argsStr = match[2];
|
|
393
|
-
var csharpType = (_a = this.
|
|
398
|
+
var csharpType = (_a = this.resolveNeedleTypeName(typeName)) !== null && _a !== void 0 ? _a : typeName;
|
|
394
399
|
// Convert numeric literals to float
|
|
395
400
|
var csharpArgs = argsStr.replace(/(\d+\.?\d*)/g, function (n) {
|
|
396
401
|
return n.includes(".") ? "".concat(n, "f") : "".concat(n, "f");
|
|
@@ -4,7 +4,7 @@ export declare class ReactThreeFiberCompiler implements IWriter {
|
|
|
4
4
|
get outputInfo(): TypeSourceInformation;
|
|
5
5
|
private readonly _typeSourceInformation;
|
|
6
6
|
constructor();
|
|
7
|
-
|
|
7
|
+
resolveNeedleTypeName(typescriptTypeName: string): string | void;
|
|
8
8
|
begin(filePath: string): void;
|
|
9
9
|
end(filePath: string): void;
|
|
10
10
|
startNewType(filePath: string, typeName: string, baseType: string[], comments?: string[]): boolean | void;
|
|
@@ -12,7 +12,7 @@ var ReactThreeFiberCompiler = /** @class */ (function () {
|
|
|
12
12
|
enumerable: false,
|
|
13
13
|
configurable: true
|
|
14
14
|
});
|
|
15
|
-
ReactThreeFiberCompiler.prototype.
|
|
15
|
+
ReactThreeFiberCompiler.prototype.resolveNeedleTypeName = function (typescriptTypeName) {
|
|
16
16
|
return typescriptTypeName;
|
|
17
17
|
};
|
|
18
18
|
ReactThreeFiberCompiler.prototype.begin = function (filePath) {
|
package/package.json
CHANGED