@needle-tools/needle-component-compiler 3.0.0 → 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/Changelog.md
CHANGED
|
@@ -4,6 +4,13 @@ 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.1] - 2026-03-04
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
- Fix string enum values being double-quoted in Blender output (e.g. `"\"A\""` instead of `"A"`)
|
|
11
|
+
- Fix user-defined enums whose name collides with a built-in type (e.g. `Color`) being mapped to the built-in type instead of emitting as enum
|
|
12
|
+
- Fix enum registry leaking across compilations, causing stale enum definitions from previous files to affect subsequent compilations
|
|
13
|
+
|
|
7
14
|
## [3.0.0] - 2026-03-04
|
|
8
15
|
|
|
9
16
|
### Changed
|
package/dist/BaseWriter.js
CHANGED
|
@@ -31,6 +31,7 @@ var BaseWriter = /** @class */ (function () {
|
|
|
31
31
|
configurable: true
|
|
32
32
|
});
|
|
33
33
|
BaseWriter.prototype.begin = function (filePath) {
|
|
34
|
+
this._enumRegistry.clear();
|
|
34
35
|
if (!this._currentlyProcessingFiles[filePath]) {
|
|
35
36
|
this._currentlyProcessingFiles[filePath] = [];
|
|
36
37
|
}
|
package/dist/Compiler.js
CHANGED
|
@@ -16,13 +16,13 @@ var Compiler = /** @class */ (function () {
|
|
|
16
16
|
Compiler.prototype.run = function (prog, writer, sourceFile, filePath) {
|
|
17
17
|
var _this = this;
|
|
18
18
|
console.log("Starting compilation of " + filePath);
|
|
19
|
+
writer.begin(filePath);
|
|
19
20
|
// Pre-scan: collect enum declarations so type resolution works for class fields
|
|
20
21
|
ts.forEachChild(sourceFile, function (node) {
|
|
21
22
|
if (ts.isEnumDeclaration(node)) {
|
|
22
23
|
_this.visitEnumDeclaration(node, writer);
|
|
23
24
|
}
|
|
24
25
|
});
|
|
25
|
-
writer.begin(filePath);
|
|
26
26
|
ts.forEachChild(sourceFile, function (node) {
|
|
27
27
|
_this.visit(filePath, node, writer);
|
|
28
28
|
});
|
|
@@ -46,8 +46,12 @@ var Compiler = /** @class */ (function () {
|
|
|
46
46
|
value = parseFloat(ts.tokenToString(member.initializer.operator) + member.initializer.operand.getText());
|
|
47
47
|
nextValue = value + 1;
|
|
48
48
|
}
|
|
49
|
+
else if (ts.isStringLiteral(member.initializer)) {
|
|
50
|
+
// String enum value — use .text to get the raw string without surrounding quotes
|
|
51
|
+
value = member.initializer.text;
|
|
52
|
+
}
|
|
49
53
|
else {
|
|
50
|
-
//
|
|
54
|
+
// Other computed value — store as-is
|
|
51
55
|
value = member.initializer.getText();
|
|
52
56
|
}
|
|
53
57
|
}
|
|
@@ -324,7 +328,8 @@ var Compiler = /** @class */ (function () {
|
|
|
324
328
|
for (var _i = 0, _a = typeNode.types; _i < _a.length; _i++) {
|
|
325
329
|
var member = _a[_i];
|
|
326
330
|
if (member.kind !== ts.SyntaxKind.NullKeyword &&
|
|
327
|
-
member.kind !== ts.SyntaxKind.UndefinedKeyword
|
|
331
|
+
member.kind !== ts.SyntaxKind.UndefinedKeyword &&
|
|
332
|
+
member.kind !== ts.SyntaxKind.VoidKeyword) {
|
|
328
333
|
return this.resolveType(member, writer);
|
|
329
334
|
}
|
|
330
335
|
}
|
|
@@ -333,7 +338,12 @@ var Compiler = /** @class */ (function () {
|
|
|
333
338
|
// TypeReference: use base name only (strips generic args like EventList<void> → EventList)
|
|
334
339
|
if (typeNode.kind === ts.SyntaxKind.TypeReference) {
|
|
335
340
|
var typeReference = typeNode;
|
|
336
|
-
|
|
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);
|
|
337
347
|
}
|
|
338
348
|
return this.resolveTypeFromString(typeNode.getText(), writer);
|
|
339
349
|
};
|
|
@@ -29,6 +29,9 @@ var BlenderWriter = /** @class */ (function (_super) {
|
|
|
29
29
|
typeName = typeName.toLocaleLowerCase();
|
|
30
30
|
if (typeName.startsWith("three."))
|
|
31
31
|
typeName = typeName.substring("three.".length);
|
|
32
|
+
// If the type is a registered enum, return as-is so writeMember handles it
|
|
33
|
+
if (this._enumRegistry.has(typeName))
|
|
34
|
+
return typeName;
|
|
32
35
|
switch (typeName) {
|
|
33
36
|
case "number":
|
|
34
37
|
return "float";
|
|
@@ -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
|
+
}
|