@needle-tools/needle-component-compiler 3.0.15 → 3.0.16

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.16] - 2026-03-24
8
+ ### Fixed
9
+ - Fix array literal initializers (`= []`, `= [1, 2, 3]`) emitting C# 12 collection expressions not supported by Unity
10
+ - Empty arrays: initializer is omitted
11
+ - Non-empty primitive arrays: emit `new float[] { 1f, 2f, 3f }` syntax
12
+ - Non-empty non-primitive arrays: initializer is omitted
13
+
7
14
  ## [3.0.15] - 2026-03-23
8
15
  ### Fixed
9
16
  - Fix non-void method stubs producing uncompilable C# (`CS0161: not all code paths return a value`) by emitting `{ return default; }` instead of `{}`
@@ -245,6 +245,29 @@ var CSharpWriter = /** @class */ (function (_super) {
245
245
  if (initialValue === "null") {
246
246
  // keep null for reference types, skip for value types
247
247
  }
248
+ else if (isArray && initialValue === "[]") {
249
+ // Skip empty array initializers — C# 12 collection expressions (= [])
250
+ // are not supported by Unity's C# version
251
+ }
252
+ else if (isArray && initialValue.startsWith("[")) {
253
+ // Convert [1, 2, 3] → new float[] { 1f, 2f, 3f }
254
+ // Only emit prefilled arrays for primitive types that can be expressed as literals
255
+ if (csharpType === "float" || csharpType === "bool" || csharpType === "string") {
256
+ var inner = initialValue.slice(1, -1);
257
+ var elements = inner.split(",").map(function (e) {
258
+ var v = e.trim();
259
+ if (csharpType === "float")
260
+ return "".concat(v, "f");
261
+ if (csharpType === "bool")
262
+ return v.toLowerCase();
263
+ if (csharpType === "string")
264
+ return "\"".concat(v, "\"");
265
+ return v;
266
+ });
267
+ assignment = " = new ".concat(csharpType, "[] { ").concat(elements.join(", "), " }");
268
+ }
269
+ // For non-primitive types, skip the initializer entirely
270
+ }
248
271
  else if (csharpType === "float") {
249
272
  assignment = " = ".concat(initialValue, "f");
250
273
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/needle-component-compiler",
3
- "version": "3.0.15",
3
+ "version": "3.0.16",
4
4
  "description": "Compile Editor components for Needle Engine for C# and Blender",
5
5
  "main": "dist/index.js",
6
6
  "bin": "dist/cli.js",