@needle-tools/needle-component-compiler 1.9.1 → 2.0.0-pre
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 +3 -0
- package/package.json +17 -12
- package/src/base-compiler.js +405 -0
- package/src/blender-compiler.js +141 -0
- package/src/commands.js +11 -0
- package/src/test.js +24 -51
- package/src/watcher.js +72 -0
- package/COMPILE.bat +0 -1
- package/DEV.bat +0 -1
- package/INSTALL.bat +0 -1
- package/PUBLISH.bat +0 -8
- package/RUN_MANUAL_TEST.bat +0 -1
- package/RUN_TESTS.bat +0 -1
- package/src/component-compiler.ts +0 -734
- package/src/test.ts +0 -234
- package/test/component.basic.test.ts +0 -52
- package/test/component.methods.test.ts +0 -185
- package/test/component.nonserialized.test.ts +0 -45
- package/test/component.primitives.test.ts +0 -123
- package/test/helpers.ts +0 -72
package/src/test.ts
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import { ThisExpression } from "typescript";
|
|
2
|
-
|
|
3
|
-
export class MyTestComponent extends Behaviour {
|
|
4
|
-
public myVector2: Vector2 = new Vector2(1, .5);
|
|
5
|
-
private myMethod(){
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// export class SkipFieldAndMethod extends Behaviour {
|
|
12
|
-
|
|
13
|
-
// //@nonSerialized
|
|
14
|
-
// myMethod() {
|
|
15
|
-
|
|
16
|
-
// }
|
|
17
|
-
|
|
18
|
-
// // @nonSerialized
|
|
19
|
-
// myField : string;
|
|
20
|
-
|
|
21
|
-
// }
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// export class ComponentWithUnknownType extends Behaviour {
|
|
25
|
-
// views: SomeUnknownType;
|
|
26
|
-
// }
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// export class ComponentWithAnimationClip extends Behaviour implements IPointerClickHandler {
|
|
30
|
-
|
|
31
|
-
// @serializeable(AnimationClip)
|
|
32
|
-
// animation?: THREE.AnimationClip;
|
|
33
|
-
// }
|
|
34
|
-
|
|
35
|
-
// export abstract class MyAbstractComponent extends Behaviour {
|
|
36
|
-
// abstract myMethod();
|
|
37
|
-
// }
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// export class CameraView extends Behaviour {
|
|
41
|
-
// static views: CameraView[] = [];
|
|
42
|
-
// }
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// export class EventComponent extends Behaviour {
|
|
46
|
-
// @serializeable(EventList)
|
|
47
|
-
// roomChanged: EventList = new EventList();
|
|
48
|
-
// }
|
|
49
|
-
|
|
50
|
-
// export class SocLoader extends Behaviour {
|
|
51
|
-
|
|
52
|
-
// @serializeable(AssetReference)
|
|
53
|
-
// scenes: Array<AssetReference> = [];
|
|
54
|
-
// }
|
|
55
|
-
// // class Test123 {}
|
|
56
|
-
|
|
57
|
-
// export class Bla extends Behaviour
|
|
58
|
-
// {
|
|
59
|
-
// myNumber:number = 42;
|
|
60
|
-
// myBool:boolean = true;
|
|
61
|
-
// myString:string = "test";
|
|
62
|
-
// numberArr: number[] = [1,2,3];
|
|
63
|
-
// myColor : THREE.Color = new THREE.Color(255, 0, 0);
|
|
64
|
-
// renderers = new Array<Renderer>();
|
|
65
|
-
// renderers2 : Renderer[] = [];
|
|
66
|
-
// objArr : object[];
|
|
67
|
-
// colArr: THREE.Color[] = [new THREE.Color(1,2,3)];
|
|
68
|
-
// map : Map<string> = new Map<string>();
|
|
69
|
-
// map2 : Map<object> = new Map<object>();
|
|
70
|
-
// private myThing : Test123;
|
|
71
|
-
// }
|
|
72
|
-
|
|
73
|
-
// //@type UnityEngine.MonoBehaviour
|
|
74
|
-
// export class ButtonObject extends Interactable implements IPointerClickHandler, ISerializable {
|
|
75
|
-
|
|
76
|
-
// //@type UnityEngine.Transform[]
|
|
77
|
-
// myType?: SceneFXWindow;
|
|
78
|
-
// }
|
|
79
|
-
|
|
80
|
-
// import { Behaviour } from "needle.tiny.engine/engine-components/Component";
|
|
81
|
-
// import { RoomEntity } from "./Room";
|
|
82
|
-
|
|
83
|
-
// import { Behaviour } from "needle.tiny.engine/engine-components/Component";
|
|
84
|
-
|
|
85
|
-
// export class MyNewScript extends DriveClient
|
|
86
|
-
// {
|
|
87
|
-
// //@type test
|
|
88
|
-
// texture : RenderTexture;
|
|
89
|
-
// }
|
|
90
|
-
|
|
91
|
-
// namespace Hello.World
|
|
92
|
-
// {
|
|
93
|
-
// namespace Deep {
|
|
94
|
-
// export class MyClass extends Behaviour {
|
|
95
|
-
// //@ifdef TEST
|
|
96
|
-
// public myFloat :number;
|
|
97
|
-
// }
|
|
98
|
-
// }
|
|
99
|
-
// }
|
|
100
|
-
|
|
101
|
-
// class OtherClass extends Behaviour {
|
|
102
|
-
|
|
103
|
-
// }
|
|
104
|
-
|
|
105
|
-
//@type (RoomEntity)
|
|
106
|
-
// export class NavigationManager extends RoomEntity {
|
|
107
|
-
|
|
108
|
-
// fl:number = 1;
|
|
109
|
-
|
|
110
|
-
// nav_forward() {
|
|
111
|
-
|
|
112
|
-
// }
|
|
113
|
-
|
|
114
|
-
// nav_backward() {
|
|
115
|
-
|
|
116
|
-
// }
|
|
117
|
-
// }
|
|
118
|
-
|
|
119
|
-
// export abstract class NavComponent extends Behaviour {
|
|
120
|
-
|
|
121
|
-
// abstract next();
|
|
122
|
-
// abstract prev();
|
|
123
|
-
// abstract isAtEnd():boolean;
|
|
124
|
-
// }
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// export class PointOfInterest extends Behaviour {
|
|
128
|
-
|
|
129
|
-
// myVal:number = 12;
|
|
130
|
-
|
|
131
|
-
// // @type(HELLO)
|
|
132
|
-
// myFunction(){
|
|
133
|
-
|
|
134
|
-
// }
|
|
135
|
-
|
|
136
|
-
// // @type(UnityEngine.Camera)
|
|
137
|
-
// view?:Camera;
|
|
138
|
-
// test:string = "123";
|
|
139
|
-
// // test
|
|
140
|
-
// }
|
|
141
|
-
|
|
142
|
-
// export class MaterialColorHandler extends Behaviour {
|
|
143
|
-
|
|
144
|
-
// @serializeable(Renderer)
|
|
145
|
-
// renderer?: Renderer[];
|
|
146
|
-
// }
|
|
147
|
-
|
|
148
|
-
// export class MyArray extends Behaviour {
|
|
149
|
-
|
|
150
|
-
// arr? : Array<number> = [1,2,3];
|
|
151
|
-
// }
|
|
152
|
-
|
|
153
|
-
// export class PrivateSerializedField extends Behaviour {
|
|
154
|
-
|
|
155
|
-
// //@serializeField
|
|
156
|
-
// private color? : THREE.Color;
|
|
157
|
-
// }
|
|
158
|
-
// export class MyPropertyClass extends Behaviour {
|
|
159
|
-
// set color(col: THREE.Color) {
|
|
160
|
-
// }
|
|
161
|
-
// }
|
|
162
|
-
|
|
163
|
-
// export class MyClassWithAFloat extends Behaviour {
|
|
164
|
-
// myfloat:number = .5;
|
|
165
|
-
// private myString : string;
|
|
166
|
-
// }
|
|
167
|
-
|
|
168
|
-
// export class GltfExport extends Behaviour {
|
|
169
|
-
// binary: boolean = true;
|
|
170
|
-
// "$serializedTypes" = {
|
|
171
|
-
// url:null
|
|
172
|
-
// }
|
|
173
|
-
|
|
174
|
-
// // @contextmenu enable this
|
|
175
|
-
// test(){
|
|
176
|
-
|
|
177
|
-
// }
|
|
178
|
-
// }
|
|
179
|
-
|
|
180
|
-
// export class SetColor extends Behaviour {
|
|
181
|
-
|
|
182
|
-
// "@serializedTypes" = {
|
|
183
|
-
// col: Number,
|
|
184
|
-
// }
|
|
185
|
-
// }
|
|
186
|
-
|
|
187
|
-
// class Behaviour {
|
|
188
|
-
|
|
189
|
-
// }
|
|
190
|
-
|
|
191
|
-
// export class PlatformerMusic extends Behaviour implements IPlaymodeChangeListener {
|
|
192
|
-
// source?: AudioSource;
|
|
193
|
-
// editMode?: string;
|
|
194
|
-
// playMode?: string;
|
|
195
|
-
|
|
196
|
-
// onPlaymodeChange(playmode: PlayMode): void {
|
|
197
|
-
// console.log(this);
|
|
198
|
-
// if(!this.source) return;
|
|
199
|
-
// const clip = playmode.isInPlayMode ? this.playMode : this.editMode;
|
|
200
|
-
// console.log("PLAY", clip);
|
|
201
|
-
// this.source.play(clip);
|
|
202
|
-
// }
|
|
203
|
-
|
|
204
|
-
// }
|
|
205
|
-
|
|
206
|
-
// // TODO: export UnityEvent like this
|
|
207
|
-
// // disable codegen
|
|
208
|
-
// class UnityEvent {
|
|
209
|
-
// methods: Function[] = [];
|
|
210
|
-
// invoke() {
|
|
211
|
-
// for (const m of this.methods) {
|
|
212
|
-
// m();
|
|
213
|
-
// }
|
|
214
|
-
// }
|
|
215
|
-
// }
|
|
216
|
-
|
|
217
|
-
// export class MyClass extends Behaviour {
|
|
218
|
-
// myFloat: number = 15;
|
|
219
|
-
// myBool: boolean;
|
|
220
|
-
// // just some default values
|
|
221
|
-
// myArray: number[] = [1, 2, 3];
|
|
222
|
-
// // comment for myString
|
|
223
|
-
// myString: string = "this is a string1";
|
|
224
|
-
// myObject: THREE.Object3D;
|
|
225
|
-
// myBool2: boolean;
|
|
226
|
-
|
|
227
|
-
// myFunction() { }
|
|
228
|
-
// myFunctionWithStringParameter(string: string) { }
|
|
229
|
-
// myFunctionWithSomeObjectAndArray(obj: THREE.Object3D, arr: number[]) { }
|
|
230
|
-
// myFunctionWithoutParamTypes(test) { }
|
|
231
|
-
|
|
232
|
-
// someOtherStuff: THREE.Object3D[] | null = null;
|
|
233
|
-
// myEvent: UnityEvent;
|
|
234
|
-
// }
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { compareCodegen, compareCodegenWithDefaultContext } from './helpers';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
describe('Basic typescript', () => {
|
|
5
|
-
|
|
6
|
-
it('should generate component', () => {
|
|
7
|
-
compareCodegenWithDefaultContext("basic",
|
|
8
|
-
// INPUT
|
|
9
|
-
`export class BasicComponet extends Behaviour {
|
|
10
|
-
}
|
|
11
|
-
`,
|
|
12
|
-
// EXPECTED
|
|
13
|
-
`public partial class BasicComponet : UnityEngine.MonoBehaviour
|
|
14
|
-
{
|
|
15
|
-
}`
|
|
16
|
-
);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
it('should not generate component', () => {
|
|
22
|
-
compareCodegen("basic-no-export",
|
|
23
|
-
// INPUT
|
|
24
|
-
`
|
|
25
|
-
//@dont-generate-component
|
|
26
|
-
export class BasicComponet extends Behaviour {
|
|
27
|
-
}
|
|
28
|
-
`,
|
|
29
|
-
// EXPECTED
|
|
30
|
-
``
|
|
31
|
-
);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
it('should ignore abstract type', () => {
|
|
38
|
-
compareCodegen("basic-no-export",
|
|
39
|
-
// INPUT
|
|
40
|
-
`
|
|
41
|
-
//@dont-generate-component
|
|
42
|
-
export abstract class BasicComponet extends Behaviour {
|
|
43
|
-
}
|
|
44
|
-
`,
|
|
45
|
-
// EXPECTED
|
|
46
|
-
``
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { compareCodegen, compareCodegenWithDefaultContext } from './helpers';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
describe('Typescript with public methods', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
it('should generate component with public method', () => {
|
|
8
|
-
compareCodegenWithDefaultContext("public.methods",
|
|
9
|
-
// INPUT
|
|
10
|
-
`export class MyComponent extends Behaviour {
|
|
11
|
-
public myMethod(): void {}
|
|
12
|
-
}
|
|
13
|
-
`,
|
|
14
|
-
// EXPECTED
|
|
15
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
16
|
-
{
|
|
17
|
-
public void myMethod(){}
|
|
18
|
-
}`
|
|
19
|
-
);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
it('should generate component method and number args', () => {
|
|
25
|
-
compareCodegenWithDefaultContext("public method with args",
|
|
26
|
-
// INPUT
|
|
27
|
-
`export class MyComponent extends Behaviour {
|
|
28
|
-
public myMethod(myNumber: number): void {}
|
|
29
|
-
}
|
|
30
|
-
`,
|
|
31
|
-
// EXPECTED
|
|
32
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
33
|
-
{
|
|
34
|
-
public void myMethod(float @myNumber){}
|
|
35
|
-
}`
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
it('should generate component method and multiple number args', () => {
|
|
42
|
-
compareCodegenWithDefaultContext("public method with multiple args",
|
|
43
|
-
// INPUT
|
|
44
|
-
`export class MyComponent extends Behaviour {
|
|
45
|
-
public myMethod(myNumber: number, myOtherNumber : number): void {}
|
|
46
|
-
}
|
|
47
|
-
`,
|
|
48
|
-
// EXPECTED
|
|
49
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
50
|
-
{
|
|
51
|
-
public void myMethod(float @myNumber, float @myOtherNumber){}
|
|
52
|
-
}`
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// https://github.com/needle-tools/needle-tiny-component-compiler/issues/11
|
|
59
|
-
it('should generate component method but ignore inline type declaration', () => {
|
|
60
|
-
compareCodegenWithDefaultContext("method ignore inline type declaration",
|
|
61
|
-
// INPUT
|
|
62
|
-
`export class MyComponent extends Behaviour {
|
|
63
|
-
public myMethod(myNumber: { x : number, y:number, z : number}): void {}
|
|
64
|
-
}
|
|
65
|
-
`,
|
|
66
|
-
// EXPECTED
|
|
67
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
68
|
-
{
|
|
69
|
-
public void myMethod(object @myNumber){}
|
|
70
|
-
}`
|
|
71
|
-
);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
describe('Typescript with private or protected methods', () => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// https://github.com/needle-tools/needle-tiny-component-compiler/issues/13
|
|
84
|
-
it('should ignore private method', () => {
|
|
85
|
-
compareCodegenWithDefaultContext("private.methods",
|
|
86
|
-
// INPUT
|
|
87
|
-
`export class MyComponent extends Behaviour {
|
|
88
|
-
private myMethod(): void {}
|
|
89
|
-
}
|
|
90
|
-
`,
|
|
91
|
-
// EXPECTED
|
|
92
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
93
|
-
{
|
|
94
|
-
}`
|
|
95
|
-
);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// https://github.com/needle-tools/needle-tiny-component-compiler/issues/13
|
|
100
|
-
it('should ignore protected method', () => {
|
|
101
|
-
compareCodegenWithDefaultContext("protected.methods",
|
|
102
|
-
// INPUT
|
|
103
|
-
`export class MyComponent extends Behaviour {
|
|
104
|
-
protected myMethod(): void {}
|
|
105
|
-
}
|
|
106
|
-
`,
|
|
107
|
-
// EXPECTED
|
|
108
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
109
|
-
{
|
|
110
|
-
}`
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
describe('Typescript with methods', () => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
it('should not generate static method', () => {
|
|
122
|
-
compareCodegenWithDefaultContext("static method",
|
|
123
|
-
// INPUT
|
|
124
|
-
`export class MyComponent extends Behaviour {
|
|
125
|
-
public static myMethod(): void {}
|
|
126
|
-
}
|
|
127
|
-
`,
|
|
128
|
-
// EXPECTED
|
|
129
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
130
|
-
{
|
|
131
|
-
}`
|
|
132
|
-
);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
it('should not generate abstract method', () => {
|
|
137
|
-
compareCodegenWithDefaultContext("abstract method",
|
|
138
|
-
// INPUT
|
|
139
|
-
`export class MyComponent extends Behaviour {
|
|
140
|
-
public abstract myMethod(): void {}
|
|
141
|
-
}
|
|
142
|
-
`,
|
|
143
|
-
// EXPECTED
|
|
144
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
145
|
-
{
|
|
146
|
-
}`
|
|
147
|
-
);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
it('should convert onEnable to OnEnable', () => {
|
|
153
|
-
compareCodegenWithDefaultContext("abstract method",
|
|
154
|
-
// INPUT
|
|
155
|
-
`export class MyComponent extends Behaviour {
|
|
156
|
-
onEnable() {}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
`,
|
|
160
|
-
// EXPECTED
|
|
161
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
162
|
-
{
|
|
163
|
-
public void OnEnable(){}
|
|
164
|
-
}`
|
|
165
|
-
);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
it('should convert onDisable to OnDisable', () => {
|
|
170
|
-
compareCodegenWithDefaultContext("abstract method",
|
|
171
|
-
// INPUT
|
|
172
|
-
`export class MyComponent extends Behaviour {
|
|
173
|
-
onDisable() {}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
`,
|
|
177
|
-
// EXPECTED
|
|
178
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
179
|
-
{
|
|
180
|
-
public void OnDisable(){}
|
|
181
|
-
}`
|
|
182
|
-
);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { compareCodegen, compareCodegenWithDefaultContext } from './helpers';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
describe('Typescript with nonSerialized', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
it('should ignore field', () => {
|
|
8
|
-
compareCodegenWithDefaultContext("nonserialized ignore field",
|
|
9
|
-
// INPUT
|
|
10
|
-
`export class MyComponent extends Behaviour {
|
|
11
|
-
//@nonSerialized
|
|
12
|
-
public myField: number;
|
|
13
|
-
}
|
|
14
|
-
`,
|
|
15
|
-
// EXPECTED
|
|
16
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
17
|
-
{
|
|
18
|
-
}`
|
|
19
|
-
);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// https://github.com/needle-tools/needle-tiny-component-compiler/issues/14
|
|
24
|
-
it('should not affect next method', () => {
|
|
25
|
-
compareCodegenWithDefaultContext("nonserialized on property does not affect method",
|
|
26
|
-
// INPUT
|
|
27
|
-
`export class MyComponent extends Behaviour {
|
|
28
|
-
//@nonSerialized
|
|
29
|
-
public get myField(): number { return 0; }
|
|
30
|
-
|
|
31
|
-
public myMethod() {
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
`,
|
|
36
|
-
// EXPECTED
|
|
37
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
38
|
-
{
|
|
39
|
-
public void myMethod() {}
|
|
40
|
-
}`
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { compareCodegen, compareCodegenWithDefaultContext } from './helpers';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
describe('Typescript with fields', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
it('should generate component with number', () => {
|
|
8
|
-
compareCodegenWithDefaultContext("number",
|
|
9
|
-
// INPUT
|
|
10
|
-
`export class MyComponent extends Behaviour {
|
|
11
|
-
public myField: number;
|
|
12
|
-
}
|
|
13
|
-
`,
|
|
14
|
-
// EXPECTED
|
|
15
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
16
|
-
{
|
|
17
|
-
public float @myField;
|
|
18
|
-
}`
|
|
19
|
-
);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
it('should generate component with string', () => {
|
|
25
|
-
compareCodegenWithDefaultContext("string",
|
|
26
|
-
// INPUT
|
|
27
|
-
`export class MyComponent extends Behaviour {
|
|
28
|
-
public myField: string;
|
|
29
|
-
}
|
|
30
|
-
`,
|
|
31
|
-
// EXPECTED
|
|
32
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
33
|
-
{
|
|
34
|
-
public string @myField;
|
|
35
|
-
}`
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
it('should generate component with string array', () => {
|
|
43
|
-
compareCodegenWithDefaultContext("stringArray",
|
|
44
|
-
// INPUT
|
|
45
|
-
`export class MyComponent extends Behaviour {
|
|
46
|
-
public myField: string[];
|
|
47
|
-
}
|
|
48
|
-
`,
|
|
49
|
-
// EXPECTED
|
|
50
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
51
|
-
{
|
|
52
|
-
public string[] @myField;
|
|
53
|
-
}`
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
it('should generate component with boolean', () => {
|
|
61
|
-
compareCodegenWithDefaultContext("bool",
|
|
62
|
-
// INPUT
|
|
63
|
-
`export class MyComponent extends Behaviour {
|
|
64
|
-
public myField: boolean;
|
|
65
|
-
}
|
|
66
|
-
`,
|
|
67
|
-
// EXPECTED
|
|
68
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
69
|
-
{
|
|
70
|
-
public bool @myField;
|
|
71
|
-
}`
|
|
72
|
-
);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
it('should generate component with object', () => {
|
|
79
|
-
compareCodegenWithDefaultContext("object",
|
|
80
|
-
// INPUT
|
|
81
|
-
`export class MyComponent extends Behaviour {
|
|
82
|
-
public myField: object;
|
|
83
|
-
}
|
|
84
|
-
`,
|
|
85
|
-
// EXPECTED
|
|
86
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
87
|
-
{
|
|
88
|
-
public UnityEngine.Object @myField;
|
|
89
|
-
}`
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
it('should generate component with default values', () => {
|
|
97
|
-
compareCodegenWithDefaultContext("fields with default values",
|
|
98
|
-
// INPUT
|
|
99
|
-
`export class MyComponent extends Behaviour {
|
|
100
|
-
public myField: number = 42;
|
|
101
|
-
public myField2: string = "hello";
|
|
102
|
-
public myField3: boolean = true;
|
|
103
|
-
public myField4: object = null;
|
|
104
|
-
public myVector2: Vector2 = new Vector2(1, .5);
|
|
105
|
-
}
|
|
106
|
-
`,
|
|
107
|
-
// EXPECTED
|
|
108
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
109
|
-
{
|
|
110
|
-
public float @myField = 42f;
|
|
111
|
-
public string @myField2 = "hello";
|
|
112
|
-
public bool @myField3 = true;
|
|
113
|
-
public UnityEngine.Object @myField4;
|
|
114
|
-
public UnityEngine.Vector2 @myVector2 = new UnityEngine.Vector2(1f, .5f);
|
|
115
|
-
}`
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
package/test/helpers.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { compile } from "../src/component-compiler";
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
import { debuglog } from "util";
|
|
5
|
-
|
|
6
|
-
class TestOptions {
|
|
7
|
-
ignoreWhiteSpace: boolean = true;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function testCompile(code: string): string | null {
|
|
11
|
-
|
|
12
|
-
const res = compile(code, "test", null, false);
|
|
13
|
-
const output = res?.length > 0 ? res[0] : "";
|
|
14
|
-
|
|
15
|
-
return output;
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function compareByLine(output: string, expected: string) {
|
|
20
|
-
const splitCode = /\r?\n/;
|
|
21
|
-
|
|
22
|
-
if (output == null) {
|
|
23
|
-
|
|
24
|
-
expect(expected).to.equal(output);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
|
|
28
|
-
const outputLines = output.split(splitCode);
|
|
29
|
-
const expectedLines = expected.split(splitCode);
|
|
30
|
-
for (let i = 0; i < outputLines.length; i++) {
|
|
31
|
-
const outputLine = outputLines[i].trim();
|
|
32
|
-
const expectedLine = expectedLines[i].trim();
|
|
33
|
-
expect(outputLine).to.equal(expectedLine, `Line ${i} does not match`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function compareCodegen(id: string, input: string, expected: string) {
|
|
40
|
-
const baseDir = "test/codegen";
|
|
41
|
-
if (!fs.existsSync(baseDir))
|
|
42
|
-
fs.mkdirSync(baseDir);
|
|
43
|
-
const dir = `${baseDir}/${id}`;
|
|
44
|
-
if (!fs.existsSync(dir))
|
|
45
|
-
fs.mkdirSync(dir);
|
|
46
|
-
fs.writeFileSync(`${dir}\\input.ts`, input);
|
|
47
|
-
const result = testCompile(input);
|
|
48
|
-
if (result !== null)
|
|
49
|
-
fs.writeFileSync(`${dir}\\output.cs`, result);
|
|
50
|
-
fs.writeFileSync(`${dir}\\expected.cs`, expected);
|
|
51
|
-
|
|
52
|
-
compareByLine(result, expected);
|
|
53
|
-
|
|
54
|
-
// expect(result).to.equal(expected);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function compareCodegenWithDefaultContext(id: string, input: string, expected: string) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
expected = `// NEEDLE_CODEGEN_START
|
|
61
|
-
// auto generated code - do not edit directly
|
|
62
|
-
|
|
63
|
-
#pragma warning disable
|
|
64
|
-
|
|
65
|
-
namespace Needle.Typescript.GeneratedComponents
|
|
66
|
-
{
|
|
67
|
-
\t` + expected + `
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// NEEDLE_CODEGEN_END`;
|
|
71
|
-
return compareCodegen(id, input, expected);
|
|
72
|
-
}
|