@needle-tools/needle-component-compiler 1.10.1 → 1.10.3
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 +6 -0
- package/package.json +1 -1
- package/src/component-compiler.js +9 -6
- package/src/component-compiler.ts +10 -6
- package/src/types.js +1 -0
package/Changelog.md
CHANGED
|
@@ -4,6 +4,12 @@ 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
|
+
## [1.10.3] - 2023-09-08
|
|
8
|
+
- Add: Needle Engine type `RGBAColor` is now automatically emitted as `UnityEngine.Color`
|
|
9
|
+
|
|
10
|
+
## [1.10.2] - 2023-09-08
|
|
11
|
+
- Fix: `@type` was not properly applied for `new expression` cases (e.g. `new RGBAColor` should produce a `new Color` when decorated with `@type Color`)
|
|
12
|
+
|
|
7
13
|
## [1.10.1] - 2023-08-02
|
|
8
14
|
- Add: use `@tooltip` to emit a UnityEngine.Tooltip
|
|
9
15
|
- Update Readme
|
package/package.json
CHANGED
|
@@ -333,7 +333,7 @@ function run(program, outputDir, sourceFile) {
|
|
|
333
333
|
// console.log("Unknown assignment:", ts.SyntaxKind[ch.kind]);
|
|
334
334
|
break;
|
|
335
335
|
case ts.SyntaxKind.NewExpression:
|
|
336
|
-
assignment = " = " + getTypeForAssignment(ch);
|
|
336
|
+
assignment = " = " + getTypeForAssignment(ch, typeString);
|
|
337
337
|
break;
|
|
338
338
|
case ts.SyntaxKind.FalseKeyword:
|
|
339
339
|
case ts.SyntaxKind.TrueKeyword:
|
|
@@ -467,7 +467,7 @@ function run(program, outputDir, sourceFile) {
|
|
|
467
467
|
}
|
|
468
468
|
return false;
|
|
469
469
|
}
|
|
470
|
-
function getTypeForAssignment(node) {
|
|
470
|
+
function getTypeForAssignment(node, typeString) {
|
|
471
471
|
// console.log("-------------------\nAssign", ts.SyntaxKind[node.kind]);
|
|
472
472
|
switch (node.kind) {
|
|
473
473
|
case ts.SyntaxKind.FirstLiteralToken:
|
|
@@ -478,7 +478,7 @@ function run(program, outputDir, sourceFile) {
|
|
|
478
478
|
for (var _i = 0, _a = node.getChildren(); _i < _a.length; _i++) {
|
|
479
479
|
var ch = _a[_i];
|
|
480
480
|
var text = ch.getText();
|
|
481
|
-
|
|
481
|
+
console.log("child", ts.SyntaxKind[ch.kind], text);
|
|
482
482
|
switch (ch.kind) {
|
|
483
483
|
case ts.SyntaxKind.Identifier:
|
|
484
484
|
case ts.SyntaxKind.PropertyAccessExpression:
|
|
@@ -489,7 +489,7 @@ function run(program, outputDir, sourceFile) {
|
|
|
489
489
|
var arg = _c[_b];
|
|
490
490
|
if (args === undefined)
|
|
491
491
|
args = "";
|
|
492
|
-
var res = getTypeForAssignment(arg);
|
|
492
|
+
var res = getTypeForAssignment(arg, typeString);
|
|
493
493
|
// handle floats being assigned with "f" suffix
|
|
494
494
|
if (Number.parseFloat(res) >= 0) {
|
|
495
495
|
args += res + "f";
|
|
@@ -505,8 +505,11 @@ function run(program, outputDir, sourceFile) {
|
|
|
505
505
|
}
|
|
506
506
|
if (!args)
|
|
507
507
|
args = "";
|
|
508
|
-
if (type) {
|
|
509
|
-
|
|
508
|
+
if (type || typeString) {
|
|
509
|
+
if (typeString) {
|
|
510
|
+
console.log("Override type", type, typeString);
|
|
511
|
+
type = typeString;
|
|
512
|
+
}
|
|
510
513
|
return "new " + type + "(" + args + ")";
|
|
511
514
|
}
|
|
512
515
|
// const expType = node.getChildren().find(c => c.kind === ts.SyntaxKind.Identifier);
|
|
@@ -366,7 +366,7 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
|
|
|
366
366
|
// console.log("Unknown assignment:", ts.SyntaxKind[ch.kind]);
|
|
367
367
|
break;
|
|
368
368
|
case ts.SyntaxKind.NewExpression:
|
|
369
|
-
assignment = " = " + getTypeForAssignment(ch);
|
|
369
|
+
assignment = " = " + getTypeForAssignment(ch, typeString);
|
|
370
370
|
break;
|
|
371
371
|
case ts.SyntaxKind.FalseKeyword:
|
|
372
372
|
case ts.SyntaxKind.TrueKeyword:
|
|
@@ -493,7 +493,7 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
|
|
|
493
493
|
return false;
|
|
494
494
|
}
|
|
495
495
|
|
|
496
|
-
function getTypeForAssignment(node: ts.Node) {
|
|
496
|
+
function getTypeForAssignment(node: ts.Node, typeString?: string) {
|
|
497
497
|
// console.log("-------------------\nAssign", ts.SyntaxKind[node.kind]);
|
|
498
498
|
switch (node.kind) {
|
|
499
499
|
case ts.SyntaxKind.FirstLiteralToken:
|
|
@@ -503,7 +503,7 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
|
|
|
503
503
|
let args: string | undefined = undefined;
|
|
504
504
|
for (const ch of node.getChildren()) {
|
|
505
505
|
const text = ch.getText();
|
|
506
|
-
|
|
506
|
+
console.log("child", ts.SyntaxKind[ch.kind], text);
|
|
507
507
|
switch (ch.kind) {
|
|
508
508
|
case ts.SyntaxKind.Identifier:
|
|
509
509
|
case ts.SyntaxKind.PropertyAccessExpression:
|
|
@@ -512,7 +512,7 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
|
|
|
512
512
|
case ts.SyntaxKind.SyntaxList:
|
|
513
513
|
for (const arg of ch.getChildren()) {
|
|
514
514
|
if (args === undefined) args = "";
|
|
515
|
-
const res = getTypeForAssignment(arg);
|
|
515
|
+
const res = getTypeForAssignment(arg, typeString);
|
|
516
516
|
// handle floats being assigned with "f" suffix
|
|
517
517
|
if (Number.parseFloat(res) >= 0) {
|
|
518
518
|
args += res + "f";
|
|
@@ -526,13 +526,17 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
|
|
|
526
526
|
}
|
|
527
527
|
}
|
|
528
528
|
if (!args) args = "";
|
|
529
|
-
if (type) {
|
|
530
|
-
|
|
529
|
+
if (type || typeString) {
|
|
530
|
+
if (typeString) {
|
|
531
|
+
console.log("Override type", type, typeString)
|
|
532
|
+
type = typeString;
|
|
533
|
+
}
|
|
531
534
|
return "new " + type + "(" + args + ")";
|
|
532
535
|
}
|
|
533
536
|
// const expType = node.getChildren().find(c => c.kind === ts.SyntaxKind.Identifier);
|
|
534
537
|
break;
|
|
535
538
|
}
|
|
539
|
+
|
|
536
540
|
const str = node.getText();
|
|
537
541
|
if (allowDebugLogs)
|
|
538
542
|
console.log("Unknown assignment:", str, ts.SyntaxKind[node.kind]);
|
package/src/types.js
CHANGED
|
@@ -24,6 +24,7 @@ const dict = {
|
|
|
24
24
|
"AudioSource" : "UnityEngine.AudioSource",
|
|
25
25
|
"THREE.Color" : "UnityEngine.Color",
|
|
26
26
|
"Color" : "UnityEngine.Color",
|
|
27
|
+
"RGBAColor" : "UnityEngine.Color",
|
|
27
28
|
"THREE.Vector2" : "UnityEngine.Vector2",
|
|
28
29
|
"Vector2" : "UnityEngine.Vector2",
|
|
29
30
|
"THREE.Vector3" : "UnityEngine.Vector3",
|