@needle-tools/needle-component-compiler 2.4.1-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/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/{src → dist/impl}/blender-compiler.js +69 -80
- 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/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/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
|