@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.
Files changed (87) hide show
  1. package/Changelog.md +4 -0
  2. package/DEV.bat +1 -0
  3. package/{RUNTEST.bat → RUN_MANUAL_TEST.bat} +0 -0
  4. package/RUN_TESTS.bat +1 -0
  5. package/package.json +21 -3
  6. package/src/component-compiler.js +130 -66
  7. package/src/component-compiler.ts +132 -64
  8. package/src/test.ts +13 -7
  9. package/test/codegen/abstract method/expected.cs +14 -0
  10. package/test/codegen/abstract method/input.js +27 -0
  11. package/test/codegen/abstract method/input.ts +4 -0
  12. package/test/codegen/abstract method/output.cs +14 -0
  13. package/test/codegen/basic/expected.cs +13 -0
  14. package/test/codegen/basic/input.js +26 -0
  15. package/test/codegen/basic/input.ts +2 -0
  16. package/test/codegen/basic/output.cs +13 -0
  17. package/test/codegen/basic-no-export/expected.cs +0 -0
  18. package/test/codegen/basic-no-export/input.js +27 -0
  19. package/test/codegen/basic-no-export/input.ts +4 -0
  20. package/test/codegen/basic-no-export/output.cs +0 -0
  21. package/test/codegen/bool/expected.cs +14 -0
  22. package/test/codegen/bool/input.js +26 -0
  23. package/test/codegen/bool/input.ts +3 -0
  24. package/test/codegen/bool/output.cs +14 -0
  25. package/test/codegen/fields with default values/expected.cs +17 -0
  26. package/test/codegen/fields with default values/input.js +31 -0
  27. package/test/codegen/fields with default values/input.ts +6 -0
  28. package/test/codegen/fields with default values/output.cs +17 -0
  29. package/test/codegen/method ignore inline type declaration/expected.cs +14 -0
  30. package/test/codegen/method ignore inline type declaration/input.js +27 -0
  31. package/test/codegen/method ignore inline type declaration/input.ts +3 -0
  32. package/test/codegen/method ignore inline type declaration/output.cs +14 -0
  33. package/test/codegen/nonserialized ignore field/expected.cs +13 -0
  34. package/test/codegen/nonserialized ignore field/input.js +26 -0
  35. package/test/codegen/nonserialized ignore field/input.ts +4 -0
  36. package/test/codegen/nonserialized ignore field/output.cs +13 -0
  37. package/test/codegen/nonserialized on property does not affect method/expected.cs +14 -0
  38. package/test/codegen/nonserialized on property does not affect method/input.js +34 -0
  39. package/test/codegen/nonserialized on property does not affect method/input.ts +8 -0
  40. package/test/codegen/nonserialized on property does not affect method/output.cs +13 -0
  41. package/test/codegen/number/expected.cs +14 -0
  42. package/test/codegen/number/input.js +26 -0
  43. package/test/codegen/number/input.ts +3 -0
  44. package/test/codegen/number/output.cs +14 -0
  45. package/test/codegen/object/expected.cs +14 -0
  46. package/test/codegen/object/input.js +26 -0
  47. package/test/codegen/object/input.ts +3 -0
  48. package/test/codegen/object/output.cs +14 -0
  49. package/test/codegen/private.methods/expected.cs +13 -0
  50. package/test/codegen/private.methods/input.js +27 -0
  51. package/test/codegen/private.methods/input.ts +3 -0
  52. package/test/codegen/private.methods/output.cs +13 -0
  53. package/test/codegen/protected.methods/expected.cs +13 -0
  54. package/test/codegen/protected.methods/input.js +27 -0
  55. package/test/codegen/protected.methods/input.ts +3 -0
  56. package/test/codegen/protected.methods/output.cs +13 -0
  57. package/test/codegen/public method with args/expected.cs +14 -0
  58. package/test/codegen/public method with args/input.js +27 -0
  59. package/test/codegen/public method with args/input.ts +3 -0
  60. package/test/codegen/public method with args/output.cs +14 -0
  61. package/test/codegen/public method with multiple args/expected.cs +14 -0
  62. package/test/codegen/public method with multiple args/input.js +27 -0
  63. package/test/codegen/public method with multiple args/input.ts +3 -0
  64. package/test/codegen/public method with multiple args/output.cs +14 -0
  65. package/test/codegen/public.methods/expected.cs +14 -0
  66. package/test/codegen/public.methods/input.js +27 -0
  67. package/test/codegen/public.methods/input.ts +3 -0
  68. package/test/codegen/public.methods/output.cs +14 -0
  69. package/test/codegen/static method/expected.cs +13 -0
  70. package/test/codegen/static method/input.js +27 -0
  71. package/test/codegen/static method/input.ts +3 -0
  72. package/test/codegen/static method/output.cs +14 -0
  73. package/test/codegen/string/expected.cs +14 -0
  74. package/test/codegen/string/input.js +26 -0
  75. package/test/codegen/string/input.ts +3 -0
  76. package/test/codegen/string/output.cs +14 -0
  77. package/test/codegen/stringArray/expected.cs +14 -0
  78. package/test/codegen/stringArray/input.js +26 -0
  79. package/test/codegen/stringArray/input.ts +3 -0
  80. package/test/codegen/stringArray/output.cs +14 -0
  81. package/test/component.basic.test.ts +52 -0
  82. package/test/component.methods.test.ts +185 -0
  83. package/test/component.nonserialized.test.ts +45 -0
  84. package/test/component.primitives.test.ts +121 -0
  85. package/test/helpers.ts +72 -0
  86. package/tsconfig.json +8 -0
  87. package/workspace.code-workspace +7 -7
@@ -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
@@ -0,0 +1,8 @@
1
+ {
2
+ "compilerOptions": {
3
+ "types": [
4
+ "mocha",
5
+ "node"
6
+ ]
7
+ }
8
+ }
@@ -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
  }