@needle-tools/needle-component-compiler 1.8.0 → 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 +4 -0
- package/DEV.bat +1 -0
- package/{RUNTEST.bat → RUN_MANUAL_TEST.bat} +0 -0
- package/RUN_TESTS.bat +1 -0
- package/package.json +21 -3
- package/src/component-compiler.js +130 -66
- package/src/component-compiler.ts +132 -64
- package/src/test.ts +13 -7
- 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
package/test/helpers.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
}
|
package/tsconfig.json
ADDED
package/workspace.code-workspace
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
{
|
|
2
|
-
"folders": [
|
|
3
|
-
{
|
|
4
|
-
"path": "."
|
|
5
|
-
}
|
|
6
|
-
],
|
|
7
|
-
"settings": {}
|
|
1
|
+
{
|
|
2
|
+
"folders": [
|
|
3
|
+
{
|
|
4
|
+
"path": "."
|
|
5
|
+
}
|
|
6
|
+
],
|
|
7
|
+
"settings": {}
|
|
8
8
|
}
|