@needle-tools/needle-component-compiler 1.9.3 → 1.9.4
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 +5 -0
- package/package.json +1 -1
- package/src/component-compiler.js +12 -4
- package/src/component-compiler.ts +12 -4
- package/src/types.js +1 -1
- package/test/component.basic.test.ts +6 -1
- package/test/component.primitives.test.js +14 -0
- package/test/component.primitives.test.ts +35 -0
package/Changelog.md
CHANGED
|
@@ -4,6 +4,11 @@ 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.9.4] - 2023-05-24
|
|
8
|
+
- Change: `Object3D` now emits `GameObject` field instead of `Transform`
|
|
9
|
+
- Fix: ignore `static` methods
|
|
10
|
+
- Fix: ignore `abstract` methods
|
|
11
|
+
|
|
7
12
|
## [1.9.3] - 2022-12-30
|
|
8
13
|
- Add debug logs for when no file or target directory was passed in. Also wrapping core with try catch
|
|
9
14
|
|
package/package.json
CHANGED
|
@@ -242,7 +242,7 @@ function run(program, outputDir, sourceFile) {
|
|
|
242
242
|
var meth = node;
|
|
243
243
|
// const isCoroutine = func.asteriskToken;
|
|
244
244
|
if (!skip && meth.name) {
|
|
245
|
-
var pub_1 =
|
|
245
|
+
var pub_1 = shouldEmitMethod(meth);
|
|
246
246
|
if (!pub_1)
|
|
247
247
|
return;
|
|
248
248
|
var paramsStr = "";
|
|
@@ -280,7 +280,7 @@ function run(program, outputDir, sourceFile) {
|
|
|
280
280
|
console.log("Found variable", node.getText());
|
|
281
281
|
var vardec = node;
|
|
282
282
|
var varName = "@" + vardec.name.getText();
|
|
283
|
-
var pub =
|
|
283
|
+
var pub = shouldEmitMethod(vardec);
|
|
284
284
|
var visibility = pub ? "public" : "private";
|
|
285
285
|
var isAccessible = pub;
|
|
286
286
|
dontSerialize = false;
|
|
@@ -501,16 +501,24 @@ function run(program, outputDir, sourceFile) {
|
|
|
501
501
|
console.log("Unknown assignment:", str, ts.SyntaxKind[node.kind]);
|
|
502
502
|
return str;
|
|
503
503
|
}
|
|
504
|
-
function
|
|
504
|
+
function shouldEmitMethod(node) {
|
|
505
505
|
if (node.kind === ts.SyntaxKind.PublicKeyword) {
|
|
506
506
|
return true;
|
|
507
507
|
}
|
|
508
508
|
else if (node.kind === ts.SyntaxKind.PrivateKeyword || node.kind === ts.SyntaxKind.ProtectedKeyword) {
|
|
509
509
|
return false;
|
|
510
510
|
}
|
|
511
|
+
// check if its static
|
|
512
|
+
else if (node.kind === ts.SyntaxKind.StaticKeyword) {
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
// check if its abstract
|
|
516
|
+
else if (node.kind === ts.SyntaxKind.AbstractKeyword) {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
511
519
|
for (var _i = 0, _a = node.getChildren(); _i < _a.length; _i++) {
|
|
512
520
|
var ch = _a[_i];
|
|
513
|
-
if (!
|
|
521
|
+
if (!shouldEmitMethod(ch))
|
|
514
522
|
return false;
|
|
515
523
|
}
|
|
516
524
|
return true;
|
|
@@ -280,7 +280,7 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
|
|
|
280
280
|
const meth = node as ts.MethodDeclaration;
|
|
281
281
|
// const isCoroutine = func.asteriskToken;
|
|
282
282
|
if (!skip && meth.name) {
|
|
283
|
-
const pub =
|
|
283
|
+
const pub = shouldEmitMethod(meth);
|
|
284
284
|
if (!pub) return;
|
|
285
285
|
|
|
286
286
|
let paramsStr = "";
|
|
@@ -312,7 +312,7 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
|
|
|
312
312
|
const vardec = node as ts.VariableDeclaration;
|
|
313
313
|
|
|
314
314
|
const varName = "@" + vardec.name.getText();
|
|
315
|
-
const pub =
|
|
315
|
+
const pub = shouldEmitMethod(vardec);
|
|
316
316
|
const visibility = pub ? "public" : "private";
|
|
317
317
|
let isAccessible = pub;
|
|
318
318
|
dontSerialize = false;
|
|
@@ -522,16 +522,24 @@ export function run(program: ts.Program, outputDir: string | null, sourceFile: t
|
|
|
522
522
|
return str;
|
|
523
523
|
}
|
|
524
524
|
|
|
525
|
-
function
|
|
525
|
+
function shouldEmitMethod(node: ts.Node): boolean {
|
|
526
526
|
if (node.kind === ts.SyntaxKind.PublicKeyword) {
|
|
527
527
|
return true;
|
|
528
528
|
}
|
|
529
529
|
else if (node.kind === ts.SyntaxKind.PrivateKeyword || node.kind === ts.SyntaxKind.ProtectedKeyword) {
|
|
530
530
|
return false;
|
|
531
531
|
}
|
|
532
|
+
// check if its static
|
|
533
|
+
else if (node.kind === ts.SyntaxKind.StaticKeyword) {
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
// check if its abstract
|
|
537
|
+
else if (node.kind === ts.SyntaxKind.AbstractKeyword) {
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
532
540
|
|
|
533
541
|
for (const ch of node.getChildren()) {
|
|
534
|
-
if (!
|
|
542
|
+
if (!shouldEmitMethod(ch)) return false;
|
|
535
543
|
}
|
|
536
544
|
return true;
|
|
537
545
|
}
|
package/src/types.js
CHANGED
|
@@ -12,7 +12,7 @@ const dict = {
|
|
|
12
12
|
"Behaviour" : "UnityEngine.Behaviour",
|
|
13
13
|
"Component" : "UnityEngine.Component",
|
|
14
14
|
"GameObject" : "UnityEngine.GameObject",
|
|
15
|
-
"Object3D" : "UnityEngine.
|
|
15
|
+
"Object3D" : "UnityEngine.GameObject",
|
|
16
16
|
// Addressables
|
|
17
17
|
"AssetReference" : "UnityEngine.Transform",
|
|
18
18
|
// events
|
|
@@ -33,7 +33,7 @@ describe('Basic typescript', () => {
|
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
it('should ignore abstract type', () => {
|
|
38
38
|
compareCodegen("basic-no-export",
|
|
39
39
|
// INPUT
|
|
@@ -46,6 +46,11 @@ describe('Basic typescript', () => {
|
|
|
46
46
|
``
|
|
47
47
|
);
|
|
48
48
|
});
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
49
54
|
|
|
50
55
|
|
|
51
56
|
});
|
|
@@ -44,4 +44,18 @@ describe('Typescript with fields', function () {
|
|
|
44
44
|
// EXPECTED
|
|
45
45
|
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public float @myField = 42f;\n public string @myField2 = \"hello\";\n public bool @myField3 = true;\n public UnityEngine.Object @myField4;\n\t\tpublic UnityEngine.Vector2 @myVector2 = new UnityEngine.Vector2(1f, .5f);\n\t}");
|
|
46
46
|
});
|
|
47
|
+
it('should generate component with GameObject reference', function () {
|
|
48
|
+
(0, helpers_1.compareCodegenWithDefaultContext)("object",
|
|
49
|
+
// INPUT
|
|
50
|
+
"export class MyComponent extends Behaviour {\n public myObject: Object3D;\n}\n",
|
|
51
|
+
// EXPECTED
|
|
52
|
+
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public UnityEngine.GameObject @myObject;\n\t}");
|
|
53
|
+
});
|
|
54
|
+
it('should generate component with RectTransform reference', function () {
|
|
55
|
+
(0, helpers_1.compareCodegenWithDefaultContext)("object",
|
|
56
|
+
// INPUT
|
|
57
|
+
"export class MyComponent extends Behaviour {\n public myRect: RectTransform;\n}\n",
|
|
58
|
+
// EXPECTED
|
|
59
|
+
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public UnityEngine.RectTransform @myRect;\n\t}");
|
|
60
|
+
});
|
|
47
61
|
});
|
|
@@ -120,4 +120,39 @@ describe('Typescript with fields', () => {
|
|
|
120
120
|
|
|
121
121
|
|
|
122
122
|
|
|
123
|
+
it('should generate component with GameObject reference', () => {
|
|
124
|
+
compareCodegenWithDefaultContext("object",
|
|
125
|
+
// INPUT
|
|
126
|
+
`export class MyComponent extends Behaviour {
|
|
127
|
+
public myObject: Object3D;
|
|
128
|
+
}
|
|
129
|
+
`,
|
|
130
|
+
// EXPECTED
|
|
131
|
+
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
132
|
+
{
|
|
133
|
+
public UnityEngine.GameObject @myObject;
|
|
134
|
+
}`
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
it('should generate component with RectTransform reference', () => {
|
|
142
|
+
compareCodegenWithDefaultContext("object",
|
|
143
|
+
// INPUT
|
|
144
|
+
`export class MyComponent extends Behaviour {
|
|
145
|
+
public myRect: RectTransform;
|
|
146
|
+
}
|
|
147
|
+
`,
|
|
148
|
+
// EXPECTED
|
|
149
|
+
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
150
|
+
{
|
|
151
|
+
public UnityEngine.RectTransform @myRect;
|
|
152
|
+
}`
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
123
158
|
});
|