@needle-tools/needle-component-compiler 1.7.3 → 1.9.0
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 +8 -0
- package/DEV.bat +1 -0
- package/{RUNTEST.bat → RUN_MANUAL_TEST.bat} +0 -0
- package/RUN_TESTS.bat +1 -0
- package/Readme.md +2 -1
- package/package.json +21 -3
- package/src/component-compiler.js +146 -71
- package/src/component-compiler.ts +147 -67
- package/src/test.ts +27 -3
- package/test/codegen/abstract method/expected.cs +14 -0
- package/test/codegen/abstract method/input.js +27 -0
- package/test/codegen/abstract method/input.ts +4 -0
- package/test/codegen/abstract method/output.cs +14 -0
- package/test/codegen/basic/expected.cs +13 -0
- package/test/codegen/basic/input.js +26 -0
- package/test/codegen/basic/input.ts +2 -0
- package/test/codegen/basic/output.cs +13 -0
- package/test/codegen/basic-no-export/expected.cs +0 -0
- package/test/codegen/basic-no-export/input.js +27 -0
- package/test/codegen/basic-no-export/input.ts +4 -0
- package/test/codegen/basic-no-export/output.cs +0 -0
- package/test/codegen/bool/expected.cs +14 -0
- package/test/codegen/bool/input.js +26 -0
- package/test/codegen/bool/input.ts +3 -0
- package/test/codegen/bool/output.cs +14 -0
- package/test/codegen/fields with default values/expected.cs +17 -0
- package/test/codegen/fields with default values/input.js +31 -0
- package/test/codegen/fields with default values/input.ts +6 -0
- package/test/codegen/fields with default values/output.cs +17 -0
- package/test/codegen/method ignore inline type declaration/expected.cs +14 -0
- package/test/codegen/method ignore inline type declaration/input.js +27 -0
- package/test/codegen/method ignore inline type declaration/input.ts +3 -0
- package/test/codegen/method ignore inline type declaration/output.cs +14 -0
- package/test/codegen/nonserialized ignore field/expected.cs +13 -0
- package/test/codegen/nonserialized ignore field/input.js +26 -0
- package/test/codegen/nonserialized ignore field/input.ts +4 -0
- package/test/codegen/nonserialized ignore field/output.cs +13 -0
- package/test/codegen/nonserialized on property does not affect method/expected.cs +14 -0
- package/test/codegen/nonserialized on property does not affect method/input.js +34 -0
- package/test/codegen/nonserialized on property does not affect method/input.ts +8 -0
- package/test/codegen/nonserialized on property does not affect method/output.cs +13 -0
- package/test/codegen/number/expected.cs +14 -0
- package/test/codegen/number/input.js +26 -0
- package/test/codegen/number/input.ts +3 -0
- package/test/codegen/number/output.cs +14 -0
- package/test/codegen/object/expected.cs +14 -0
- package/test/codegen/object/input.js +26 -0
- package/test/codegen/object/input.ts +3 -0
- package/test/codegen/object/output.cs +14 -0
- package/test/codegen/private.methods/expected.cs +13 -0
- package/test/codegen/private.methods/input.js +27 -0
- package/test/codegen/private.methods/input.ts +3 -0
- package/test/codegen/private.methods/output.cs +13 -0
- package/test/codegen/protected.methods/expected.cs +13 -0
- package/test/codegen/protected.methods/input.js +27 -0
- package/test/codegen/protected.methods/input.ts +3 -0
- package/test/codegen/protected.methods/output.cs +13 -0
- package/test/codegen/public method with args/expected.cs +14 -0
- package/test/codegen/public method with args/input.js +27 -0
- package/test/codegen/public method with args/input.ts +3 -0
- package/test/codegen/public method with args/output.cs +14 -0
- package/test/codegen/public method with multiple args/expected.cs +14 -0
- package/test/codegen/public method with multiple args/input.js +27 -0
- package/test/codegen/public method with multiple args/input.ts +3 -0
- package/test/codegen/public method with multiple args/output.cs +14 -0
- package/test/codegen/public.methods/expected.cs +14 -0
- package/test/codegen/public.methods/input.js +27 -0
- package/test/codegen/public.methods/input.ts +3 -0
- package/test/codegen/public.methods/output.cs +14 -0
- package/test/codegen/static method/expected.cs +13 -0
- package/test/codegen/static method/input.js +27 -0
- package/test/codegen/static method/input.ts +3 -0
- package/test/codegen/static method/output.cs +14 -0
- package/test/codegen/string/expected.cs +14 -0
- package/test/codegen/string/input.js +26 -0
- package/test/codegen/string/input.ts +3 -0
- package/test/codegen/string/output.cs +14 -0
- package/test/codegen/stringArray/expected.cs +14 -0
- package/test/codegen/stringArray/input.js +26 -0
- package/test/codegen/stringArray/input.ts +3 -0
- package/test/codegen/stringArray/output.cs +14 -0
- package/test/component.basic.test.ts +52 -0
- package/test/component.methods.test.ts +185 -0
- package/test/component.nonserialized.test.ts +45 -0
- package/test/component.primitives.test.ts +121 -0
- package/test/helpers.ts +72 -0
- package/tsconfig.json +8 -0
- package/workspace.code-workspace +7 -7
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
public void myMethod(float @myNumber, float @myOtherNumber){}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,27 @@
|
|
|
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.MyComponent = void 0;
|
|
19
|
+
var MyComponent = /** @class */ (function (_super) {
|
|
20
|
+
__extends(MyComponent, _super);
|
|
21
|
+
function MyComponent() {
|
|
22
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
}
|
|
24
|
+
MyComponent.prototype.myMethod = function (myNumber, myOtherNumber) { };
|
|
25
|
+
return MyComponent;
|
|
26
|
+
}(Behaviour));
|
|
27
|
+
exports.MyComponent = MyComponent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
public void myMethod(float @myNumber, float @myOtherNumber){}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
public void myMethod(){}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,27 @@
|
|
|
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.MyComponent = void 0;
|
|
19
|
+
var MyComponent = /** @class */ (function (_super) {
|
|
20
|
+
__extends(MyComponent, _super);
|
|
21
|
+
function MyComponent() {
|
|
22
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
}
|
|
24
|
+
MyComponent.prototype.myMethod = function () { };
|
|
25
|
+
return MyComponent;
|
|
26
|
+
}(Behaviour));
|
|
27
|
+
exports.MyComponent = MyComponent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
public void myMethod(){}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,27 @@
|
|
|
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.MyComponent = void 0;
|
|
19
|
+
var MyComponent = /** @class */ (function (_super) {
|
|
20
|
+
__extends(MyComponent, _super);
|
|
21
|
+
function MyComponent() {
|
|
22
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
}
|
|
24
|
+
MyComponent.myMethod = function () { };
|
|
25
|
+
return MyComponent;
|
|
26
|
+
}(Behaviour));
|
|
27
|
+
exports.MyComponent = MyComponent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
public void myMethod(){}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
public string @myField;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,26 @@
|
|
|
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.MyComponent = void 0;
|
|
19
|
+
var MyComponent = /** @class */ (function (_super) {
|
|
20
|
+
__extends(MyComponent, _super);
|
|
21
|
+
function MyComponent() {
|
|
22
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
}
|
|
24
|
+
return MyComponent;
|
|
25
|
+
}(Behaviour));
|
|
26
|
+
exports.MyComponent = MyComponent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
public string @myField;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
public string[] @myField;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,26 @@
|
|
|
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.MyComponent = void 0;
|
|
19
|
+
var MyComponent = /** @class */ (function (_super) {
|
|
20
|
+
__extends(MyComponent, _super);
|
|
21
|
+
function MyComponent() {
|
|
22
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
}
|
|
24
|
+
return MyComponent;
|
|
25
|
+
}(Behaviour));
|
|
26
|
+
exports.MyComponent = MyComponent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// NEEDLE_CODEGEN_START
|
|
2
|
+
// auto generated code - do not edit directly
|
|
3
|
+
|
|
4
|
+
#pragma warning disable
|
|
5
|
+
|
|
6
|
+
namespace Needle.Typescript.GeneratedComponents
|
|
7
|
+
{
|
|
8
|
+
public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
9
|
+
{
|
|
10
|
+
public string[] @myField;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// NEEDLE_CODEGEN_END
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
});
|