@needle-tools/needle-component-compiler 2.4.0-pre → 3.0.0-alpha
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 -1
- package/dist/BaseWriter.d.ts +23 -0
- package/dist/BaseWriter.js +90 -0
- package/dist/Compiler.d.ts +20 -0
- package/{src/base-compiler.js → dist/Compiler.js} +99 -194
- package/dist/base-compiler.d.ts +54 -0
- package/dist/base-compiler.js +168 -0
- package/dist/commands.d.ts +3 -0
- package/dist/component-compiler.d.ts +3 -0
- package/{src → dist}/component-compiler.js +5 -0
- package/dist/impl/blender-compiler.d.ts +14 -0
- package/dist/impl/blender-compiler.js +179 -0
- package/dist/impl/csharp-compiler.d.ts +16 -0
- package/dist/impl/csharp-compiler.js +306 -0
- package/dist/impl/react-three-fiber-compiler.d.ts +20 -0
- package/{src → dist/impl}/react-three-fiber-compiler.js +3 -1
- package/dist/register-types.d.ts +8 -0
- package/dist/watcher.d.ts +6 -0
- package/{src → dist}/watcher.js +3 -2
- package/package.json +13 -7
- package/src/blender-compiler.js +0 -180
- package/src/csharp-compiler.js +0 -58
- package/src/test.js +0 -194
- package/src/types.js +0 -51
- package/test/component.basic.test.js +0 -26
- package/test/component.methods.test.js +0 -82
- package/test/component.nonserialized.test.js +0 -20
- package/test/component.primitives.test.js +0 -47
- package/test/helpers.js +0 -54
- /package/{src → dist}/commands.js +0 -0
- /package/{src → dist}/register-types.js +0 -0
package/src/test.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
exports.__esModule = true;
|
|
18
|
-
exports.MyTestComponent = void 0;
|
|
19
|
-
var MyTestComponent = /** @class */ (function (_super) {
|
|
20
|
-
__extends(MyTestComponent, _super);
|
|
21
|
-
function MyTestComponent() {
|
|
22
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
-
_this.myVector2 = new Vector2(1, .5);
|
|
24
|
-
return _this;
|
|
25
|
-
}
|
|
26
|
-
MyTestComponent.prototype.myMethod = function () {
|
|
27
|
-
};
|
|
28
|
-
return MyTestComponent;
|
|
29
|
-
}(Behaviour));
|
|
30
|
-
exports.MyTestComponent = MyTestComponent;
|
|
31
|
-
// export class SkipFieldAndMethod extends Behaviour {
|
|
32
|
-
// //@nonSerialized
|
|
33
|
-
// myMethod() {
|
|
34
|
-
// }
|
|
35
|
-
// // @nonSerialized
|
|
36
|
-
// myField : string;
|
|
37
|
-
// }
|
|
38
|
-
// export class ComponentWithUnknownType extends Behaviour {
|
|
39
|
-
// views: SomeUnknownType;
|
|
40
|
-
// }
|
|
41
|
-
// export class ComponentWithAnimationClip extends Behaviour implements IPointerClickHandler {
|
|
42
|
-
// @serializeable(AnimationClip)
|
|
43
|
-
// animation?: THREE.AnimationClip;
|
|
44
|
-
// }
|
|
45
|
-
// export abstract class MyAbstractComponent extends Behaviour {
|
|
46
|
-
// abstract myMethod();
|
|
47
|
-
// }
|
|
48
|
-
// export class CameraView extends Behaviour {
|
|
49
|
-
// static views: CameraView[] = [];
|
|
50
|
-
// }
|
|
51
|
-
// export class EventComponent extends Behaviour {
|
|
52
|
-
// @serializeable(EventList)
|
|
53
|
-
// roomChanged: EventList = new EventList();
|
|
54
|
-
// }
|
|
55
|
-
// export class SocLoader extends Behaviour {
|
|
56
|
-
// @serializeable(AssetReference)
|
|
57
|
-
// scenes: Array<AssetReference> = [];
|
|
58
|
-
// }
|
|
59
|
-
// // class Test123 {}
|
|
60
|
-
// export class Bla extends Behaviour
|
|
61
|
-
// {
|
|
62
|
-
// myNumber:number = 42;
|
|
63
|
-
// myBool:boolean = true;
|
|
64
|
-
// myString:string = "test";
|
|
65
|
-
// numberArr: number[] = [1,2,3];
|
|
66
|
-
// myColor : THREE.Color = new THREE.Color(255, 0, 0);
|
|
67
|
-
// renderers = new Array<Renderer>();
|
|
68
|
-
// renderers2 : Renderer[] = [];
|
|
69
|
-
// objArr : object[];
|
|
70
|
-
// colArr: THREE.Color[] = [new THREE.Color(1,2,3)];
|
|
71
|
-
// map : Map<string> = new Map<string>();
|
|
72
|
-
// map2 : Map<object> = new Map<object>();
|
|
73
|
-
// private myThing : Test123;
|
|
74
|
-
// }
|
|
75
|
-
// //@type UnityEngine.MonoBehaviour
|
|
76
|
-
// export class ButtonObject extends Interactable implements IPointerClickHandler, ISerializable {
|
|
77
|
-
// //@type UnityEngine.Transform[]
|
|
78
|
-
// myType?: SceneFXWindow;
|
|
79
|
-
// }
|
|
80
|
-
// import { Behaviour } from "needle.tiny.engine/engine-components/Component";
|
|
81
|
-
// import { RoomEntity } from "./Room";
|
|
82
|
-
// import { Behaviour } from "needle.tiny.engine/engine-components/Component";
|
|
83
|
-
// export class MyNewScript extends DriveClient
|
|
84
|
-
// {
|
|
85
|
-
// //@type test
|
|
86
|
-
// texture : RenderTexture;
|
|
87
|
-
// }
|
|
88
|
-
// namespace Hello.World
|
|
89
|
-
// {
|
|
90
|
-
// namespace Deep {
|
|
91
|
-
// export class MyClass extends Behaviour {
|
|
92
|
-
// //@ifdef TEST
|
|
93
|
-
// public myFloat :number;
|
|
94
|
-
// }
|
|
95
|
-
// }
|
|
96
|
-
// }
|
|
97
|
-
// class OtherClass extends Behaviour {
|
|
98
|
-
// }
|
|
99
|
-
//@type (RoomEntity)
|
|
100
|
-
// export class NavigationManager extends RoomEntity {
|
|
101
|
-
// fl:number = 1;
|
|
102
|
-
// nav_forward() {
|
|
103
|
-
// }
|
|
104
|
-
// nav_backward() {
|
|
105
|
-
// }
|
|
106
|
-
// }
|
|
107
|
-
// export abstract class NavComponent extends Behaviour {
|
|
108
|
-
// abstract next();
|
|
109
|
-
// abstract prev();
|
|
110
|
-
// abstract isAtEnd():boolean;
|
|
111
|
-
// }
|
|
112
|
-
// export class PointOfInterest extends Behaviour {
|
|
113
|
-
// myVal:number = 12;
|
|
114
|
-
// // @type(HELLO)
|
|
115
|
-
// myFunction(){
|
|
116
|
-
// }
|
|
117
|
-
// // @type(UnityEngine.Camera)
|
|
118
|
-
// view?:Camera;
|
|
119
|
-
// test:string = "123";
|
|
120
|
-
// // test
|
|
121
|
-
// }
|
|
122
|
-
// export class MaterialColorHandler extends Behaviour {
|
|
123
|
-
// @serializeable(Renderer)
|
|
124
|
-
// renderer?: Renderer[];
|
|
125
|
-
// }
|
|
126
|
-
// export class MyArray extends Behaviour {
|
|
127
|
-
// arr? : Array<number> = [1,2,3];
|
|
128
|
-
// }
|
|
129
|
-
// export class PrivateSerializedField extends Behaviour {
|
|
130
|
-
// //@serializeField
|
|
131
|
-
// private color? : THREE.Color;
|
|
132
|
-
// }
|
|
133
|
-
// export class MyPropertyClass extends Behaviour {
|
|
134
|
-
// set color(col: THREE.Color) {
|
|
135
|
-
// }
|
|
136
|
-
// }
|
|
137
|
-
// export class MyClassWithAFloat extends Behaviour {
|
|
138
|
-
// myfloat:number = .5;
|
|
139
|
-
// private myString : string;
|
|
140
|
-
// }
|
|
141
|
-
// export class GltfExport extends Behaviour {
|
|
142
|
-
// binary: boolean = true;
|
|
143
|
-
// "$serializedTypes" = {
|
|
144
|
-
// url:null
|
|
145
|
-
// }
|
|
146
|
-
// // @contextmenu enable this
|
|
147
|
-
// test(){
|
|
148
|
-
// }
|
|
149
|
-
// }
|
|
150
|
-
// export class SetColor extends Behaviour {
|
|
151
|
-
// "@serializedTypes" = {
|
|
152
|
-
// col: Number,
|
|
153
|
-
// }
|
|
154
|
-
// }
|
|
155
|
-
// class Behaviour {
|
|
156
|
-
// }
|
|
157
|
-
// export class PlatformerMusic extends Behaviour implements IPlaymodeChangeListener {
|
|
158
|
-
// source?: AudioSource;
|
|
159
|
-
// editMode?: string;
|
|
160
|
-
// playMode?: string;
|
|
161
|
-
// onPlaymodeChange(playmode: PlayMode): void {
|
|
162
|
-
// console.log(this);
|
|
163
|
-
// if(!this.source) return;
|
|
164
|
-
// const clip = playmode.isInPlayMode ? this.playMode : this.editMode;
|
|
165
|
-
// console.log("PLAY", clip);
|
|
166
|
-
// this.source.play(clip);
|
|
167
|
-
// }
|
|
168
|
-
// }
|
|
169
|
-
// // TODO: export UnityEvent like this
|
|
170
|
-
// // disable codegen
|
|
171
|
-
// class UnityEvent {
|
|
172
|
-
// methods: Function[] = [];
|
|
173
|
-
// invoke() {
|
|
174
|
-
// for (const m of this.methods) {
|
|
175
|
-
// m();
|
|
176
|
-
// }
|
|
177
|
-
// }
|
|
178
|
-
// }
|
|
179
|
-
// export class MyClass extends Behaviour {
|
|
180
|
-
// myFloat: number = 15;
|
|
181
|
-
// myBool: boolean;
|
|
182
|
-
// // just some default values
|
|
183
|
-
// myArray: number[] = [1, 2, 3];
|
|
184
|
-
// // comment for myString
|
|
185
|
-
// myString: string = "this is a string1";
|
|
186
|
-
// myObject: THREE.Object3D;
|
|
187
|
-
// myBool2: boolean;
|
|
188
|
-
// myFunction() { }
|
|
189
|
-
// myFunctionWithStringParameter(string: string) { }
|
|
190
|
-
// myFunctionWithSomeObjectAndArray(obj: THREE.Object3D, arr: number[]) { }
|
|
191
|
-
// myFunctionWithoutParamTypes(test) { }
|
|
192
|
-
// someOtherStuff: THREE.Object3D[] | null = null;
|
|
193
|
-
// myEvent: UnityEvent;
|
|
194
|
-
// }
|
package/src/types.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.__esModule = true;
|
|
3
|
-
exports.delint = void 0;
|
|
4
|
-
|
|
5
|
-
const dict = {
|
|
6
|
-
"object" : "UnityEngine.Object",
|
|
7
|
-
"number": "float",
|
|
8
|
-
"string": "string",
|
|
9
|
-
"boolean": "bool",
|
|
10
|
-
"Map" : "System.Collections.Generic.HashSet",
|
|
11
|
-
// basic
|
|
12
|
-
"Behaviour" : "UnityEngine.Behaviour",
|
|
13
|
-
"Component" : "UnityEngine.Component",
|
|
14
|
-
"GameObject" : "UnityEngine.GameObject",
|
|
15
|
-
"Object3D" : "UnityEngine.Transform",
|
|
16
|
-
// Addressables
|
|
17
|
-
"AssetReference" : "UnityEngine.Transform",
|
|
18
|
-
// events
|
|
19
|
-
"EventList" : "UnityEngine.Events.UnityEvent",
|
|
20
|
-
// audio
|
|
21
|
-
"AudioClip" : "UnityEngine.AudioClip",
|
|
22
|
-
"THREE.Object3D" : "UnityEngine.Transform",
|
|
23
|
-
"UnityEvent" : "UnityEngine.Events.UnityEvent",
|
|
24
|
-
"AudioSource" : "UnityEngine.AudioSource",
|
|
25
|
-
"THREE.Color" : "UnityEngine.Color",
|
|
26
|
-
"Color" : "UnityEngine.Color",
|
|
27
|
-
"THREE.Vector2" : "UnityEngine.Vector2",
|
|
28
|
-
"Vector2" : "UnityEngine.Vector2",
|
|
29
|
-
"THREE.Vector3" : "UnityEngine.Vector3",
|
|
30
|
-
"Vector3" : "UnityEngine.Vector3",
|
|
31
|
-
"THREE.Vector4" : "UnityEngine.Vector4",
|
|
32
|
-
"Vector4" : "UnityEngine.Vector4",
|
|
33
|
-
// animation
|
|
34
|
-
"Animator" : "UnityEngine.Animator",
|
|
35
|
-
"Animation" : "UnityEngine.Animation",
|
|
36
|
-
"AnimationClip" : "UnityEngine.AnimationClip",
|
|
37
|
-
"SignalAsset" : "UnityEngine.Timeline.SignalAsset",
|
|
38
|
-
"PlayableDirector" : "UnityEngine.Playables.PlayableDirector",
|
|
39
|
-
// Rendering
|
|
40
|
-
"Renderer" : "UnityEngine.Renderer",
|
|
41
|
-
"Material" : "UnityEngine.Material",
|
|
42
|
-
"Mesh" : "UnityEngine.Mesh",
|
|
43
|
-
"Texture" : "UnityEngine.Texture",
|
|
44
|
-
// UI
|
|
45
|
-
"Text" : "UnityEngine.UI.Text",
|
|
46
|
-
"Image" : "UnityEngine.UI.Image",
|
|
47
|
-
"RawImage": "UnityEngine.UI.RawImage",
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
exports.dict = dict;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.__esModule = true;
|
|
3
|
-
var helpers_1 = require("./helpers");
|
|
4
|
-
describe('Basic typescript', function () {
|
|
5
|
-
it('should generate component', function () {
|
|
6
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("basic",
|
|
7
|
-
// INPUT
|
|
8
|
-
"export class BasicComponet extends Behaviour {\n}\n",
|
|
9
|
-
// EXPECTED
|
|
10
|
-
"public partial class BasicComponet : UnityEngine.MonoBehaviour\n\t{\n\t}");
|
|
11
|
-
});
|
|
12
|
-
it('should not generate component', function () {
|
|
13
|
-
(0, helpers_1.compareCodegen)("basic-no-export",
|
|
14
|
-
// INPUT
|
|
15
|
-
"\n //@dont-generate-component\n export class BasicComponet extends Behaviour {\n}\n",
|
|
16
|
-
// EXPECTED
|
|
17
|
-
"");
|
|
18
|
-
});
|
|
19
|
-
it('should ignore abstract type', function () {
|
|
20
|
-
(0, helpers_1.compareCodegen)("basic-no-export",
|
|
21
|
-
// INPUT
|
|
22
|
-
"\n //@dont-generate-component\n export abstract class BasicComponet extends Behaviour {\n}\n",
|
|
23
|
-
// EXPECTED
|
|
24
|
-
"");
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.__esModule = true;
|
|
3
|
-
var helpers_1 = require("./helpers");
|
|
4
|
-
describe('Typescript with public methods', function () {
|
|
5
|
-
it('should generate component with public method', function () {
|
|
6
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("public.methods",
|
|
7
|
-
// INPUT
|
|
8
|
-
"export class MyComponent extends Behaviour {\n public myMethod(): void {}\n}\n",
|
|
9
|
-
// EXPECTED
|
|
10
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public void myMethod(){}\n\t}");
|
|
11
|
-
});
|
|
12
|
-
it('should generate component method and number args', function () {
|
|
13
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("public method with args",
|
|
14
|
-
// INPUT
|
|
15
|
-
"export class MyComponent extends Behaviour {\n public myMethod(myNumber: number): void {}\n}\n",
|
|
16
|
-
// EXPECTED
|
|
17
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public void myMethod(float @myNumber){}\n\t}");
|
|
18
|
-
});
|
|
19
|
-
it('should generate component method and multiple number args', function () {
|
|
20
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("public method with multiple args",
|
|
21
|
-
// INPUT
|
|
22
|
-
"export class MyComponent extends Behaviour {\n public myMethod(myNumber: number, myOtherNumber : number): void {}\n}\n",
|
|
23
|
-
// EXPECTED
|
|
24
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public void myMethod(float @myNumber, float @myOtherNumber){}\n\t}");
|
|
25
|
-
});
|
|
26
|
-
// https://github.com/needle-tools/needle-tiny-component-compiler/issues/11
|
|
27
|
-
it('should generate component method but ignore inline type declaration', function () {
|
|
28
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("method ignore inline type declaration",
|
|
29
|
-
// INPUT
|
|
30
|
-
"export class MyComponent extends Behaviour {\n public myMethod(myNumber: { x : number, y:number, z : number}): void {}\n}\n",
|
|
31
|
-
// EXPECTED
|
|
32
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public void myMethod(object @myNumber){}\n\t}");
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
describe('Typescript with private or protected methods', function () {
|
|
36
|
-
// https://github.com/needle-tools/needle-tiny-component-compiler/issues/13
|
|
37
|
-
it('should ignore private method', function () {
|
|
38
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("private.methods",
|
|
39
|
-
// INPUT
|
|
40
|
-
"export class MyComponent extends Behaviour {\n private myMethod(): void {}\n}\n",
|
|
41
|
-
// EXPECTED
|
|
42
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n\t}");
|
|
43
|
-
});
|
|
44
|
-
// https://github.com/needle-tools/needle-tiny-component-compiler/issues/13
|
|
45
|
-
it('should ignore protected method', function () {
|
|
46
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("protected.methods",
|
|
47
|
-
// INPUT
|
|
48
|
-
"export class MyComponent extends Behaviour {\n protected myMethod(): void {}\n}\n",
|
|
49
|
-
// EXPECTED
|
|
50
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n\t}");
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
describe('Typescript with methods', function () {
|
|
54
|
-
it('should not generate static method', function () {
|
|
55
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("static method",
|
|
56
|
-
// INPUT
|
|
57
|
-
"export class MyComponent extends Behaviour {\n public static myMethod(): void {}\n}\n",
|
|
58
|
-
// EXPECTED
|
|
59
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n\t}");
|
|
60
|
-
});
|
|
61
|
-
it('should not generate abstract method', function () {
|
|
62
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("abstract method",
|
|
63
|
-
// INPUT
|
|
64
|
-
"export class MyComponent extends Behaviour {\n public abstract myMethod(): void {}\n}\n",
|
|
65
|
-
// EXPECTED
|
|
66
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n\t}");
|
|
67
|
-
});
|
|
68
|
-
it('should convert onEnable to OnEnable', function () {
|
|
69
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("abstract method",
|
|
70
|
-
// INPUT
|
|
71
|
-
"export class MyComponent extends Behaviour {\n onEnable() {}\n }\n}\n",
|
|
72
|
-
// EXPECTED
|
|
73
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public void OnEnable(){}\n\t}");
|
|
74
|
-
});
|
|
75
|
-
it('should convert onDisable to OnDisable', function () {
|
|
76
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("abstract method",
|
|
77
|
-
// INPUT
|
|
78
|
-
"export class MyComponent extends Behaviour {\n onDisable() {}\n }\n}\n",
|
|
79
|
-
// EXPECTED
|
|
80
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public void OnDisable(){}\n\t}");
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.__esModule = true;
|
|
3
|
-
var helpers_1 = require("./helpers");
|
|
4
|
-
describe('Typescript with nonSerialized', function () {
|
|
5
|
-
it('should ignore field', function () {
|
|
6
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("nonserialized ignore field",
|
|
7
|
-
// INPUT
|
|
8
|
-
"export class MyComponent extends Behaviour {\n //@nonSerialized\n public myField: number;\n}\n",
|
|
9
|
-
// EXPECTED
|
|
10
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n\t}");
|
|
11
|
-
});
|
|
12
|
-
// https://github.com/needle-tools/needle-tiny-component-compiler/issues/14
|
|
13
|
-
it('should not affect next method', function () {
|
|
14
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("nonserialized on property does not affect method",
|
|
15
|
-
// INPUT
|
|
16
|
-
"export class MyComponent extends Behaviour {\n //@nonSerialized\n public get myField(): number { return 0; }\n\n public myMethod() {\n\n }\n}\n",
|
|
17
|
-
// EXPECTED
|
|
18
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public void myMethod() {}\n\t}");
|
|
19
|
-
});
|
|
20
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.__esModule = true;
|
|
3
|
-
var helpers_1 = require("./helpers");
|
|
4
|
-
describe('Typescript with fields', function () {
|
|
5
|
-
it('should generate component with number', function () {
|
|
6
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("number",
|
|
7
|
-
// INPUT
|
|
8
|
-
"export class MyComponent extends Behaviour {\n public myField: number;\n}\n",
|
|
9
|
-
// EXPECTED
|
|
10
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public float @myField;\n\t}");
|
|
11
|
-
});
|
|
12
|
-
it('should generate component with string', function () {
|
|
13
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("string",
|
|
14
|
-
// INPUT
|
|
15
|
-
"export class MyComponent extends Behaviour {\n public myField: string;\n}\n",
|
|
16
|
-
// EXPECTED
|
|
17
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public string @myField;\n\t}");
|
|
18
|
-
});
|
|
19
|
-
it('should generate component with string array', function () {
|
|
20
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("stringArray",
|
|
21
|
-
// INPUT
|
|
22
|
-
"export class MyComponent extends Behaviour {\n public myField: string[];\n}\n",
|
|
23
|
-
// EXPECTED
|
|
24
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public string[] @myField;\n\t}");
|
|
25
|
-
});
|
|
26
|
-
it('should generate component with boolean', function () {
|
|
27
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("bool",
|
|
28
|
-
// INPUT
|
|
29
|
-
"export class MyComponent extends Behaviour {\n public myField: boolean;\n}\n",
|
|
30
|
-
// EXPECTED
|
|
31
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public bool @myField;\n\t}");
|
|
32
|
-
});
|
|
33
|
-
it('should generate component with object', function () {
|
|
34
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("object",
|
|
35
|
-
// INPUT
|
|
36
|
-
"export class MyComponent extends Behaviour {\n public myField: object;\n}\n",
|
|
37
|
-
// EXPECTED
|
|
38
|
-
"public partial class MyComponent : UnityEngine.MonoBehaviour\n\t{\n public UnityEngine.Object @myField;\n\t}");
|
|
39
|
-
});
|
|
40
|
-
it('should generate component with default values', function () {
|
|
41
|
-
(0, helpers_1.compareCodegenWithDefaultContext)("fields with default values",
|
|
42
|
-
// INPUT
|
|
43
|
-
"export class MyComponent extends Behaviour {\n public myField: number = 42;\n public myField2: string = \"hello\";\n public myField3: boolean = true;\n public myField4: object = null;\n public myVector2: Vector2 = new Vector2(1, .5);\n}\n",
|
|
44
|
-
// EXPECTED
|
|
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
|
-
});
|
|
47
|
-
});
|
package/test/helpers.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.__esModule = true;
|
|
3
|
-
exports.compareCodegenWithDefaultContext = exports.compareCodegen = exports.testCompile = void 0;
|
|
4
|
-
var component_compiler_1 = require("../src/component-compiler");
|
|
5
|
-
var chai_1 = require("chai");
|
|
6
|
-
var fs = require("fs");
|
|
7
|
-
var TestOptions = /** @class */ (function () {
|
|
8
|
-
function TestOptions() {
|
|
9
|
-
this.ignoreWhiteSpace = true;
|
|
10
|
-
}
|
|
11
|
-
return TestOptions;
|
|
12
|
-
}());
|
|
13
|
-
function testCompile(code) {
|
|
14
|
-
var res = (0, component_compiler_1.compile)(code, "test", null, false);
|
|
15
|
-
var output = (res === null || res === void 0 ? void 0 : res.length) > 0 ? res[0] : "";
|
|
16
|
-
return output;
|
|
17
|
-
}
|
|
18
|
-
exports.testCompile = testCompile;
|
|
19
|
-
function compareByLine(output, expected) {
|
|
20
|
-
var splitCode = /\r?\n/;
|
|
21
|
-
if (output == null) {
|
|
22
|
-
(0, chai_1.expect)(expected).to.equal(output);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
var outputLines = output.split(splitCode);
|
|
26
|
-
var expectedLines = expected.split(splitCode);
|
|
27
|
-
for (var i = 0; i < outputLines.length; i++) {
|
|
28
|
-
var outputLine = outputLines[i].trim();
|
|
29
|
-
var expectedLine = expectedLines[i].trim();
|
|
30
|
-
(0, chai_1.expect)(outputLine).to.equal(expectedLine, "Line ".concat(i, " does not match"));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function compareCodegen(id, input, expected) {
|
|
35
|
-
var baseDir = "test/codegen";
|
|
36
|
-
if (!fs.existsSync(baseDir))
|
|
37
|
-
fs.mkdirSync(baseDir);
|
|
38
|
-
var dir = "".concat(baseDir, "/").concat(id);
|
|
39
|
-
if (!fs.existsSync(dir))
|
|
40
|
-
fs.mkdirSync(dir);
|
|
41
|
-
fs.writeFileSync("".concat(dir, "\\input.ts"), input);
|
|
42
|
-
var result = testCompile(input);
|
|
43
|
-
if (result !== null)
|
|
44
|
-
fs.writeFileSync("".concat(dir, "\\output.cs"), result);
|
|
45
|
-
fs.writeFileSync("".concat(dir, "\\expected.cs"), expected);
|
|
46
|
-
compareByLine(result, expected);
|
|
47
|
-
// expect(result).to.equal(expected);
|
|
48
|
-
}
|
|
49
|
-
exports.compareCodegen = compareCodegen;
|
|
50
|
-
function compareCodegenWithDefaultContext(id, input, expected) {
|
|
51
|
-
expected = "// NEEDLE_CODEGEN_START\n // auto generated code - do not edit directly\n \n #pragma warning disable\n \n namespace Needle.Typescript.GeneratedComponents\n {\n \t" + expected + "\n }\n \n // NEEDLE_CODEGEN_END";
|
|
52
|
-
return compareCodegen(id, input, expected);
|
|
53
|
-
}
|
|
54
|
-
exports.compareCodegenWithDefaultContext = compareCodegenWithDefaultContext;
|
|
File without changes
|
|
File without changes
|