@needle-tools/needle-component-compiler 3.0.0-alpha.7 → 3.0.1

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,10 +4,67 @@ 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.0-alpha.1] - 2026-03-02
8
- - Fix: destructured method parameters (e.g. `{xr}`) now emit as `object @obj` instead of invalid `object @{xr}`
9
- - Fix: `Object3D` type now correctly maps to `UnityEngine.Transform`
10
- - Add: `RectTransform` type mapping to `UnityEngine.RectTransform`
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
+
14
+ ## [3.0.0] - 2026-03-04
15
+
16
+ ### Changed
17
+ - Rewritten compiler architecture with a new `Compiler` (TypeScript walker) + `IWriter` (output backend) design, enabling pluggable output targets
18
+ - CLI interface: `needle-component-compiler <target> <output_dir> <input_files...>` where target is `csharp` or `blender`
19
+
20
+ ### Added
21
+
22
+ #### Architecture
23
+ - New `BaseWriter` / `IWriter` interface allows pluggable output backends (C#, Blender, and future targets like React Three Fiber)
24
+ - New `ISink` / `FileSink` abstraction for output, with `NEEDLE_CODEGEN_START` / `NEEDLE_CODEGEN_END` fence support to preserve hand-written code sections
25
+ - Standalone CLI (`npx @needle-tools/needle-component-compiler`) with `--help` and `--version` flags
26
+
27
+ #### C# Compiler
28
+ - Enum declarations with numeric and string initializers
29
+ - Union type fields (e.g. `field: string | number`) emit as `object` with a doc comment listing the union members
30
+ - Inferred types from initializers (e.g. `speed = 5` infers `float`, `name = "hello"` infers `string`, `new Vector3()` infers `Vector3`)
31
+ - `@dont-generate-component` decorator to skip class generation
32
+ - `@nonSerialized` support for fields (skips serialization)
33
+ - `@type` override decorator for fields and classes
34
+ - `@tooltip` decorator emits `[Tooltip("...")]` attribute
35
+ - `@serializable` / `@serializeField` for private field serialization
36
+ - `@ifdef` / `#if UNITY_EDITOR` wrapping for editor-only fields
37
+ - `NEEDLE_CODEGEN` fences in generated output to preserve manual code sections
38
+ - Static and abstract member handling (static fields skipped, static/abstract methods ignored)
39
+ - Method return type emission (void, primitive types, mapped types)
40
+ - Support for `declare class` with `IComponent` interface
41
+
42
+ #### Blender Compiler
43
+ - Full Blender panel schema generation from TypeScript components
44
+ - Property type mapping: `number` → `FloatProperty`, `string` → `StringProperty`, `boolean` → `BoolProperty`, enums → `EnumProperty`, arrays → `CollectionProperty`
45
+ - Inferred types from initializers (numbers, strings, booleans, `new` expressions)
46
+ - Enum support with `EnumProperty` items generation
47
+ - `@tooltip` decorator maps to Blender `description` field
48
+ - `@nonSerialized` decorator to skip properties
49
+ - `@dont-generate-component` decorator to skip class generation
50
+ - `@type` override decorator
51
+ - Missing/unknown type handling with sensible defaults
52
+ - `register_types` generation for Blender add-on registration
53
+ - File watcher for automatic recompilation on source changes
54
+ - Per-component output files with automatic cleanup on deletion
55
+
56
+ ### Fixed
57
+ - Destructured method parameters (e.g. `{xr}`) now emit as `object @obj` instead of invalid `object @{xr}`
58
+ - `Object3D` type correctly maps to `UnityEngine.GameObject` (not `Transform`)
59
+ - `new` expression type inference for explicit types (e.g. `new RGBAColor()`)
60
+ - `RGBAColor` → `Color` automatic type mapping
61
+ - Method inline anonymous type declarations (e.g. `myMethod(arg: {x: number})`)
62
+ - Codegen no longer deletes manually added code outside of codegen sections
63
+ - Output directory is created automatically if it doesn't exist
64
+
65
+ ### Testing
66
+ - Comprehensive test suite with separate C# and Blender test runners (`npm test`, `npm run test:csharp`, `npm run test:blender`)
67
+ - Test coverage for: basic fields, primitives, enums, unions, tooltips, inferred types, advanced features, codegen fences, methods, and extended type mappings
11
68
 
12
69
  ## [2.4.1-pre] - 2023-04-03
13
70
  # Blender compiler
@@ -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
- // String or computed value — store as-is
54
+ // Other computed value — store as-is
51
55
  value = member.initializer.getText();
52
56
  }
53
57
  }
@@ -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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/needle-component-compiler",
3
- "version": "3.0.0-alpha.7",
3
+ "version": "3.0.1",
4
4
  "description": "Compile Editor components for Needle Engine for C# and Blender",
5
5
  "main": "dist/index.js",
6
6
  "bin": {