@needle-tools/needle-component-compiler 3.0.1 → 3.0.2-130283d
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/dist/Compiler.js
CHANGED
|
@@ -328,7 +328,8 @@ var Compiler = /** @class */ (function () {
|
|
|
328
328
|
for (var _i = 0, _a = typeNode.types; _i < _a.length; _i++) {
|
|
329
329
|
var member = _a[_i];
|
|
330
330
|
if (member.kind !== ts.SyntaxKind.NullKeyword &&
|
|
331
|
-
member.kind !== ts.SyntaxKind.UndefinedKeyword
|
|
331
|
+
member.kind !== ts.SyntaxKind.UndefinedKeyword &&
|
|
332
|
+
member.kind !== ts.SyntaxKind.VoidKeyword) {
|
|
332
333
|
return this.resolveType(member, writer);
|
|
333
334
|
}
|
|
334
335
|
}
|
|
@@ -337,7 +338,12 @@ var Compiler = /** @class */ (function () {
|
|
|
337
338
|
// TypeReference: use base name only (strips generic args like EventList<void> → EventList)
|
|
338
339
|
if (typeNode.kind === ts.SyntaxKind.TypeReference) {
|
|
339
340
|
var typeReference = typeNode;
|
|
340
|
-
|
|
341
|
+
var typeName = typeReference.typeName.getText();
|
|
342
|
+
// Promise<T> → resolve to void (no C# equivalent for async stubs)
|
|
343
|
+
if (typeName === "Promise") {
|
|
344
|
+
return undefined;
|
|
345
|
+
}
|
|
346
|
+
return this.resolveTypeFromString(typeName, writer);
|
|
341
347
|
}
|
|
342
348
|
return this.resolveTypeFromString(typeNode.getText(), writer);
|
|
343
349
|
};
|
|
@@ -2,6 +2,9 @@ import { Argument, Visibility } from "../base-compiler";
|
|
|
2
2
|
import { BaseWriter } from "../BaseWriter";
|
|
3
3
|
export declare class CSharpWriter extends BaseWriter {
|
|
4
4
|
resolveCSharpTypeName(typescriptTypeName: string): string | void;
|
|
5
|
+
/** Tries to resolve a C# type name; returns undefined if the type is not known.
|
|
6
|
+
* Checks TYPE_MAP keys/values and the enum registry. */
|
|
7
|
+
resolveKnownCSharpTypeName(typeName: string): string | undefined;
|
|
5
8
|
startNewType(filePath: string, typeName: string, baseTypes: string[], comments?: string[]): boolean | void;
|
|
6
9
|
endNewType(filePath: string, typeName: string): void;
|
|
7
10
|
writeMember(visibility: Visibility, name: string, isArray: boolean, type: string, initialValue?: string, comments?: string[]): void;
|
|
@@ -73,6 +73,7 @@ var TYPE_MAP = {
|
|
|
73
73
|
// Physics / Colliders
|
|
74
74
|
"ICollider": "UnityEngine.Collider",
|
|
75
75
|
// UI
|
|
76
|
+
"Button": "UnityEngine.UI.Button",
|
|
76
77
|
"Text": "UnityEngine.UI.Text",
|
|
77
78
|
"Image": "UnityEngine.UI.Image",
|
|
78
79
|
"RawImage": "UnityEngine.UI.RawImage",
|
|
@@ -86,6 +87,8 @@ var TYPE_MAP = {
|
|
|
86
87
|
"Rigidbody": "UnityEngine.Rigidbody",
|
|
87
88
|
"Map": "System.Collections.Generic.Dictionary",
|
|
88
89
|
};
|
|
90
|
+
/** Set of all known C# type names (values from TYPE_MAP) for reverse-lookup */
|
|
91
|
+
var KNOWN_CSHARP_TYPES = new Set(Object.values(TYPE_MAP));
|
|
89
92
|
/** Lifecycle method name mappings: camelCase TS → PascalCase C# */
|
|
90
93
|
var LIFECYCLE_METHODS = {
|
|
91
94
|
"awake": "Awake",
|
|
@@ -130,6 +133,25 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
130
133
|
var stripped = typescriptTypeName.startsWith("THREE.") ? typescriptTypeName.substring(6) : typescriptTypeName;
|
|
131
134
|
return (_b = (_a = TYPE_MAP[typescriptTypeName]) !== null && _a !== void 0 ? _a : TYPE_MAP[stripped]) !== null && _b !== void 0 ? _b : typescriptTypeName;
|
|
132
135
|
};
|
|
136
|
+
/** Tries to resolve a C# type name; returns undefined if the type is not known.
|
|
137
|
+
* Checks TYPE_MAP keys/values and the enum registry. */
|
|
138
|
+
CSharpWriter.prototype.resolveKnownCSharpTypeName = function (typeName) {
|
|
139
|
+
var _a;
|
|
140
|
+
if (!typeName)
|
|
141
|
+
return undefined;
|
|
142
|
+
// Check if it's a TS type name in the map
|
|
143
|
+
var stripped = typeName.startsWith("THREE.") ? typeName.substring(6) : typeName;
|
|
144
|
+
var mapped = (_a = TYPE_MAP[typeName]) !== null && _a !== void 0 ? _a : TYPE_MAP[stripped];
|
|
145
|
+
if (mapped)
|
|
146
|
+
return mapped;
|
|
147
|
+
// Check if it's already a resolved C# type (e.g. "float", "UnityEngine.Vector3")
|
|
148
|
+
if (KNOWN_CSHARP_TYPES.has(typeName))
|
|
149
|
+
return typeName;
|
|
150
|
+
// Check if it's a registered enum type
|
|
151
|
+
if (this._enumRegistry.has(typeName.toLowerCase()))
|
|
152
|
+
return typeName;
|
|
153
|
+
return undefined;
|
|
154
|
+
};
|
|
133
155
|
CSharpWriter.prototype.startNewType = function (filePath, typeName, baseTypes, comments) {
|
|
134
156
|
var _a;
|
|
135
157
|
if (comments === null || comments === void 0 ? void 0 : comments.includes("@dont-generate-component"))
|
|
@@ -247,6 +269,9 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
247
269
|
var _a, _b;
|
|
248
270
|
if (allowDebugLogs)
|
|
249
271
|
console.log("[CSharp] writeMethod", name, returnType);
|
|
272
|
+
// @nonSerialized → skip entirely
|
|
273
|
+
if (comments === null || comments === void 0 ? void 0 : comments.some(function (c) { return c.startsWith("@nonSerialized"); }))
|
|
274
|
+
return;
|
|
250
275
|
// @contextmenu on method → add attribute
|
|
251
276
|
var contextMenuComment = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@contextmenu "); });
|
|
252
277
|
var contextMenu = contextMenuComment ? contextMenuComment.substring("@contextmenu ".length).trim() : null;
|
|
@@ -256,20 +281,20 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
256
281
|
return;
|
|
257
282
|
// Lifecycle methods get PascalCase; regular public methods keep their name as-is
|
|
258
283
|
var methodName = lifecycleName !== null && lifecycleName !== void 0 ? lifecycleName : name;
|
|
259
|
-
// Build parameter list —
|
|
284
|
+
// Build parameter list — unknown/unmapped types resolve to "object"
|
|
260
285
|
var paramList = (_a = args === null || args === void 0 ? void 0 : args.map(function (arg) {
|
|
261
|
-
var _a
|
|
286
|
+
var _a;
|
|
262
287
|
var csharpType;
|
|
263
288
|
if (!arg.type || arg.type.includes("{")) {
|
|
264
289
|
csharpType = "object";
|
|
265
290
|
}
|
|
266
291
|
else {
|
|
267
|
-
csharpType = (
|
|
292
|
+
csharpType = (_a = _this.resolveKnownCSharpTypeName(arg.type)) !== null && _a !== void 0 ? _a : "object";
|
|
268
293
|
}
|
|
269
294
|
return "".concat(csharpType, " @").concat(arg.name);
|
|
270
295
|
}).join(", ")) !== null && _a !== void 0 ? _a : "";
|
|
271
296
|
var csReturnType = returnType
|
|
272
|
-
? ((_b = this.
|
|
297
|
+
? ((_b = this.resolveKnownCSharpTypeName(returnType)) !== null && _b !== void 0 ? _b : "void")
|
|
273
298
|
: "void";
|
|
274
299
|
if (contextMenu)
|
|
275
300
|
this.writer.writeLine("[UnityEngine.ContextMenu(\"".concat(contextMenu, "\")]"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/needle-component-compiler",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2-130283d",
|
|
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
|
-
|
|
61
|
-
|
|
60
|
+
"access": "public",
|
|
61
|
+
"registry": "https://registry.npmjs.org/"
|
|
62
62
|
}
|
|
63
|
-
}
|
|
63
|
+
}
|