@tsonic/frontend 0.0.1

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 (145) hide show
  1. package/package.json +53 -0
  2. package/src/dependency-graph.ts +18 -0
  3. package/src/dotnet-metadata.ts +121 -0
  4. package/src/graph/builder.ts +81 -0
  5. package/src/graph/circular.ts +58 -0
  6. package/src/graph/extraction/exports.ts +55 -0
  7. package/src/graph/extraction/imports.ts +81 -0
  8. package/src/graph/extraction/index.ts +7 -0
  9. package/src/graph/extraction/orchestrator.ts +99 -0
  10. package/src/graph/extraction.ts +10 -0
  11. package/src/graph/helpers.ts +51 -0
  12. package/src/graph/index.ts +17 -0
  13. package/src/graph/types.ts +13 -0
  14. package/src/index.ts +80 -0
  15. package/src/ir/binding-resolution.test.ts +585 -0
  16. package/src/ir/builder/exports.ts +78 -0
  17. package/src/ir/builder/helpers.ts +27 -0
  18. package/src/ir/builder/imports.ts +153 -0
  19. package/src/ir/builder/index.ts +10 -0
  20. package/src/ir/builder/orchestrator.ts +178 -0
  21. package/src/ir/builder/statements.ts +55 -0
  22. package/src/ir/builder/types.ts +8 -0
  23. package/src/ir/builder/validation.ts +129 -0
  24. package/src/ir/builder.test.ts +581 -0
  25. package/src/ir/builder.ts +14 -0
  26. package/src/ir/converters/expressions/access.ts +99 -0
  27. package/src/ir/converters/expressions/calls.ts +137 -0
  28. package/src/ir/converters/expressions/collections.ts +84 -0
  29. package/src/ir/converters/expressions/functions.ts +62 -0
  30. package/src/ir/converters/expressions/helpers.ts +264 -0
  31. package/src/ir/converters/expressions/index.ts +43 -0
  32. package/src/ir/converters/expressions/literals.ts +22 -0
  33. package/src/ir/converters/expressions/operators.ts +147 -0
  34. package/src/ir/converters/expressions/other.ts +60 -0
  35. package/src/ir/converters/statements/control/blocks.ts +22 -0
  36. package/src/ir/converters/statements/control/conditionals.ts +67 -0
  37. package/src/ir/converters/statements/control/exceptions.ts +43 -0
  38. package/src/ir/converters/statements/control/index.ts +17 -0
  39. package/src/ir/converters/statements/control/loops.ts +99 -0
  40. package/src/ir/converters/statements/control.ts +17 -0
  41. package/src/ir/converters/statements/declarations/classes/constructors.ts +120 -0
  42. package/src/ir/converters/statements/declarations/classes/index.ts +12 -0
  43. package/src/ir/converters/statements/declarations/classes/methods.ts +61 -0
  44. package/src/ir/converters/statements/declarations/classes/orchestrator.ts +166 -0
  45. package/src/ir/converters/statements/declarations/classes/override-detection.ts +116 -0
  46. package/src/ir/converters/statements/declarations/classes/properties.ts +63 -0
  47. package/src/ir/converters/statements/declarations/classes.ts +6 -0
  48. package/src/ir/converters/statements/declarations/enums.ts +29 -0
  49. package/src/ir/converters/statements/declarations/functions.ts +39 -0
  50. package/src/ir/converters/statements/declarations/index.ts +14 -0
  51. package/src/ir/converters/statements/declarations/interfaces.ts +131 -0
  52. package/src/ir/converters/statements/declarations/registry.ts +45 -0
  53. package/src/ir/converters/statements/declarations/type-aliases.ts +25 -0
  54. package/src/ir/converters/statements/declarations/variables.ts +60 -0
  55. package/src/ir/converters/statements/declarations.ts +16 -0
  56. package/src/ir/converters/statements/helpers.ts +174 -0
  57. package/src/ir/converters/statements/index.ts +40 -0
  58. package/src/ir/expression-converter.ts +207 -0
  59. package/src/ir/generic-validator.ts +100 -0
  60. package/src/ir/hierarchical-bindings-e2e.test.ts +163 -0
  61. package/src/ir/index.ts +6 -0
  62. package/src/ir/statement-converter.ts +128 -0
  63. package/src/ir/type-converter/arrays.ts +20 -0
  64. package/src/ir/type-converter/converter.ts +10 -0
  65. package/src/ir/type-converter/functions.ts +22 -0
  66. package/src/ir/type-converter/index.ts +11 -0
  67. package/src/ir/type-converter/inference.ts +122 -0
  68. package/src/ir/type-converter/literals.ts +40 -0
  69. package/src/ir/type-converter/objects.ts +107 -0
  70. package/src/ir/type-converter/orchestrator.ts +85 -0
  71. package/src/ir/type-converter/patterns.ts +73 -0
  72. package/src/ir/type-converter/primitives.ts +57 -0
  73. package/src/ir/type-converter/references.ts +64 -0
  74. package/src/ir/type-converter/unions-intersections.ts +34 -0
  75. package/src/ir/type-converter.ts +13 -0
  76. package/src/ir/types/expressions.ts +215 -0
  77. package/src/ir/types/guards.ts +39 -0
  78. package/src/ir/types/helpers.ts +135 -0
  79. package/src/ir/types/index.ts +108 -0
  80. package/src/ir/types/ir-types.ts +96 -0
  81. package/src/ir/types/module.ts +57 -0
  82. package/src/ir/types/statements.ts +238 -0
  83. package/src/ir/types.ts +97 -0
  84. package/src/metadata/bindings-loader.test.ts +144 -0
  85. package/src/metadata/bindings-loader.ts +357 -0
  86. package/src/metadata/index.ts +15 -0
  87. package/src/metadata/library-loader.ts +153 -0
  88. package/src/metadata/loader.test.ts +156 -0
  89. package/src/metadata/loader.ts +382 -0
  90. package/src/program/bindings.test.ts +512 -0
  91. package/src/program/bindings.ts +253 -0
  92. package/src/program/config.ts +30 -0
  93. package/src/program/creation.ts +249 -0
  94. package/src/program/dependency-graph.ts +245 -0
  95. package/src/program/diagnostics.ts +103 -0
  96. package/src/program/index.ts +19 -0
  97. package/src/program/metadata.ts +68 -0
  98. package/src/program/queries.ts +18 -0
  99. package/src/program/types.ts +38 -0
  100. package/src/program.ts +13 -0
  101. package/src/resolver/dotnet-import-resolver.ts +226 -0
  102. package/src/resolver/import-resolution.ts +177 -0
  103. package/src/resolver/index.ts +18 -0
  104. package/src/resolver/namespace.test.ts +86 -0
  105. package/src/resolver/namespace.ts +42 -0
  106. package/src/resolver/naming.ts +38 -0
  107. package/src/resolver/path-resolution.ts +22 -0
  108. package/src/resolver/types.ts +15 -0
  109. package/src/resolver.test.ts +155 -0
  110. package/src/resolver.ts +14 -0
  111. package/src/symbol-table/builder.ts +114 -0
  112. package/src/symbol-table/creation.ts +42 -0
  113. package/src/symbol-table/helpers.ts +18 -0
  114. package/src/symbol-table/index.ts +13 -0
  115. package/src/symbol-table/queries.ts +42 -0
  116. package/src/symbol-table/types.ts +28 -0
  117. package/src/symbol-table.ts +14 -0
  118. package/src/types/bindings.ts +172 -0
  119. package/src/types/diagnostic.test.ts +164 -0
  120. package/src/types/diagnostic.ts +153 -0
  121. package/src/types/explicit-views.test.ts +113 -0
  122. package/src/types/explicit-views.ts +218 -0
  123. package/src/types/metadata.ts +229 -0
  124. package/src/types/module.ts +99 -0
  125. package/src/types/nested-types.test.ts +194 -0
  126. package/src/types/nested-types.ts +215 -0
  127. package/src/types/parameter-modifiers.ts +173 -0
  128. package/src/types/ref-parameters.test.ts +192 -0
  129. package/src/types/ref-parameters.ts +268 -0
  130. package/src/types/result.test.ts +157 -0
  131. package/src/types/result.ts +48 -0
  132. package/src/types/support-types.test.ts +81 -0
  133. package/src/types/support-types.ts +288 -0
  134. package/src/types/test-harness.ts +180 -0
  135. package/src/validation/exports.ts +98 -0
  136. package/src/validation/features.ts +89 -0
  137. package/src/validation/generics.ts +40 -0
  138. package/src/validation/helpers.ts +31 -0
  139. package/src/validation/imports.ts +97 -0
  140. package/src/validation/index.ts +11 -0
  141. package/src/validation/orchestrator.ts +51 -0
  142. package/src/validation/static-safety.ts +267 -0
  143. package/src/validator.test.ts +468 -0
  144. package/src/validator.ts +15 -0
  145. package/tsconfig.json +13 -0
@@ -0,0 +1,288 @@
1
+ /**
2
+ * Support Types Recognition - Detect and work with _support/types.d.ts marker types.
3
+ *
4
+ * This module provides type guards and helpers to recognize special CLR interop types
5
+ * that don't have JavaScript equivalents: TSByRef, TSUnsafePointer, TSDelegate, etc.
6
+ *
7
+ * @see spec/support-types.md for complete documentation
8
+ */
9
+
10
+ import * as ts from "typescript";
11
+
12
+ /**
13
+ * Support type kind enumeration.
14
+ * Represents the different marker types from _support/types.d.ts.
15
+ */
16
+ export type SupportTypeKind =
17
+ | "TSByRef"
18
+ | "TSUnsafePointer"
19
+ | "TSDelegate"
20
+ | "TSNullable"
21
+ | "TSFixed"
22
+ | "TSStackAlloc";
23
+
24
+ /**
25
+ * Information about a recognized support type.
26
+ */
27
+ export type SupportTypeInfo = {
28
+ readonly kind: SupportTypeKind;
29
+ readonly wrappedType: ts.Type;
30
+ readonly typeArguments: readonly ts.Type[];
31
+ };
32
+
33
+ /**
34
+ * Check if a type is a support type (TSByRef, TSUnsafePointer, etc.).
35
+ *
36
+ * @param type - TypeScript type to check
37
+ * @param checker - TypeScript type checker
38
+ * @returns Support type info if recognized, undefined otherwise
39
+ */
40
+ export const getSupportTypeInfo = (
41
+ type: ts.Type,
42
+ _checker: ts.TypeChecker
43
+ ): SupportTypeInfo | undefined => {
44
+ // Try to get type name from either symbol or aliasSymbol
45
+ const symbol = type.aliasSymbol || type.symbol;
46
+ if (!symbol) {
47
+ return undefined;
48
+ }
49
+
50
+ const typeName = symbol.getName();
51
+
52
+ // Check if it's a recognized support type
53
+ const kind = getSupportTypeKind(typeName);
54
+ if (!kind) {
55
+ return undefined;
56
+ }
57
+
58
+ // Extract type arguments - try alias type arguments first, then regular
59
+ let typeArguments: readonly ts.Type[] = [];
60
+
61
+ // Type aliases have aliasTypeArguments
62
+ if (type.aliasTypeArguments && type.aliasTypeArguments.length > 0) {
63
+ typeArguments = type.aliasTypeArguments;
64
+ }
65
+ // Generic type references have typeArguments through TypeReference interface
66
+ else if (isGenericTypeReference(type)) {
67
+ typeArguments = getTypeArguments(type);
68
+ }
69
+
70
+ if (typeArguments.length === 0) {
71
+ return undefined;
72
+ }
73
+
74
+ const wrappedType = typeArguments[0];
75
+ if (!wrappedType) {
76
+ return undefined;
77
+ }
78
+
79
+ return {
80
+ kind,
81
+ wrappedType,
82
+ typeArguments,
83
+ };
84
+ };
85
+
86
+ /**
87
+ * Get support type kind from type name.
88
+ *
89
+ * @param typeName - Type symbol name
90
+ * @returns Support type kind if recognized, undefined otherwise
91
+ */
92
+ const getSupportTypeKind = (typeName: string): SupportTypeKind | undefined => {
93
+ switch (typeName) {
94
+ case "TSByRef":
95
+ return "TSByRef";
96
+ case "TSUnsafePointer":
97
+ return "TSUnsafePointer";
98
+ case "TSDelegate":
99
+ return "TSDelegate";
100
+ case "TSNullable":
101
+ return "TSNullable";
102
+ case "TSFixed":
103
+ return "TSFixed";
104
+ case "TSStackAlloc":
105
+ return "TSStackAlloc";
106
+ default:
107
+ return undefined;
108
+ }
109
+ };
110
+
111
+ /**
112
+ * Check if a type is TSByRef<T>.
113
+ *
114
+ * @param type - TypeScript type to check
115
+ * @param checker - TypeScript type checker
116
+ * @returns True if type is TSByRef<T>
117
+ */
118
+ export const isTSByRef = (type: ts.Type, checker: ts.TypeChecker): boolean => {
119
+ const info = getSupportTypeInfo(type, checker);
120
+ return info?.kind === "TSByRef";
121
+ };
122
+
123
+ /**
124
+ * Check if a type is TSUnsafePointer<T>.
125
+ *
126
+ * @param type - TypeScript type to check
127
+ * @param checker - TypeScript type checker
128
+ * @returns True if type is TSUnsafePointer<T>
129
+ */
130
+ export const isTSUnsafePointer = (
131
+ type: ts.Type,
132
+ checker: ts.TypeChecker
133
+ ): boolean => {
134
+ const info = getSupportTypeInfo(type, checker);
135
+ return info?.kind === "TSUnsafePointer";
136
+ };
137
+
138
+ /**
139
+ * Check if a type is TSDelegate<TArgs, TReturn>.
140
+ *
141
+ * @param type - TypeScript type to check
142
+ * @param checker - TypeScript type checker
143
+ * @returns True if type is TSDelegate<TArgs, TReturn>
144
+ */
145
+ export const isTSDelegate = (
146
+ type: ts.Type,
147
+ checker: ts.TypeChecker
148
+ ): boolean => {
149
+ const info = getSupportTypeInfo(type, checker);
150
+ return info?.kind === "TSDelegate";
151
+ };
152
+
153
+ /**
154
+ * Check if a type is TSNullable<T>.
155
+ *
156
+ * @param type - TypeScript type to check
157
+ * @param checker - TypeScript type checker
158
+ * @returns True if type is TSNullable<T>
159
+ */
160
+ export const isTSNullable = (
161
+ type: ts.Type,
162
+ checker: ts.TypeChecker
163
+ ): boolean => {
164
+ const info = getSupportTypeInfo(type, checker);
165
+ return info?.kind === "TSNullable";
166
+ };
167
+
168
+ /**
169
+ * Check if a type is TSFixed<T, N>.
170
+ *
171
+ * @param type - TypeScript type to check
172
+ * @param checker - TypeScript type checker
173
+ * @returns True if type is TSFixed<T, N>
174
+ */
175
+ export const isTSFixed = (type: ts.Type, checker: ts.TypeChecker): boolean => {
176
+ const info = getSupportTypeInfo(type, checker);
177
+ return info?.kind === "TSFixed";
178
+ };
179
+
180
+ /**
181
+ * Check if a type is TSStackAlloc<T>.
182
+ *
183
+ * @param type - TypeScript type to check
184
+ * @param checker - TypeScript type checker
185
+ * @returns True if type is TSStackAlloc<T>
186
+ */
187
+ export const isTSStackAlloc = (
188
+ type: ts.Type,
189
+ checker: ts.TypeChecker
190
+ ): boolean => {
191
+ const info = getSupportTypeInfo(type, checker);
192
+ return info?.kind === "TSStackAlloc";
193
+ };
194
+
195
+ /**
196
+ * Extract the wrapped type from TSByRef<T>.
197
+ *
198
+ * @param type - TypeScript type (must be TSByRef<T>)
199
+ * @param checker - TypeScript type checker
200
+ * @returns Wrapped type T, or undefined if not TSByRef
201
+ */
202
+ export const getTSByRefWrappedType = (
203
+ type: ts.Type,
204
+ checker: ts.TypeChecker
205
+ ): ts.Type | undefined => {
206
+ const info = getSupportTypeInfo(type, checker);
207
+ if (info?.kind === "TSByRef") {
208
+ return info.wrappedType;
209
+ }
210
+ return undefined;
211
+ };
212
+
213
+ /**
214
+ * Extract the wrapped type from TSUnsafePointer<T>.
215
+ *
216
+ * @param type - TypeScript type (must be TSUnsafePointer<T>)
217
+ * @param checker - TypeScript type checker
218
+ * @returns Wrapped type T, or undefined if not TSUnsafePointer
219
+ */
220
+ export const getTSUnsafePointerWrappedType = (
221
+ type: ts.Type,
222
+ checker: ts.TypeChecker
223
+ ): ts.Type | undefined => {
224
+ const info = getSupportTypeInfo(type, checker);
225
+ if (info?.kind === "TSUnsafePointer") {
226
+ return info.wrappedType;
227
+ }
228
+ return undefined;
229
+ };
230
+
231
+ /**
232
+ * Check if type is a generic type reference with type arguments.
233
+ *
234
+ * @param type - TypeScript type
235
+ * @returns True if type is a generic type reference
236
+ */
237
+ const isGenericTypeReference = (type: ts.Type): boolean => {
238
+ return (
239
+ (type.flags & ts.TypeFlags.Object) !== 0 &&
240
+ ((type as ts.ObjectType).objectFlags & ts.ObjectFlags.Reference) !== 0
241
+ );
242
+ };
243
+
244
+ /**
245
+ * Get type arguments from a generic type reference.
246
+ *
247
+ * @param type - TypeScript type (must be generic reference)
248
+ * @returns Array of type arguments
249
+ */
250
+ const getTypeArguments = (type: ts.Type): readonly ts.Type[] => {
251
+ const typeRef = type as ts.TypeReference;
252
+ if (!typeRef.typeArguments) {
253
+ return [];
254
+ }
255
+ return typeRef.typeArguments;
256
+ };
257
+
258
+ /**
259
+ * Check if any support type is unsupported (unsafe pointers, fixed buffers, stackalloc).
260
+ *
261
+ * @param type - TypeScript type to check
262
+ * @param checker - TypeScript type checker
263
+ * @returns Error message if unsupported, undefined if supported
264
+ */
265
+ export const checkUnsupportedSupportType = (
266
+ type: ts.Type,
267
+ checker: ts.TypeChecker
268
+ ): string | undefined => {
269
+ const info = getSupportTypeInfo(type, checker);
270
+ if (!info) {
271
+ return undefined;
272
+ }
273
+
274
+ switch (info.kind) {
275
+ case "TSUnsafePointer":
276
+ return "Unsafe pointers are not supported in Tsonic. Use IntPtr for opaque handles.";
277
+ case "TSFixed":
278
+ return "Fixed-size buffers (unsafe feature) are not supported. Use arrays or Span<T> instead.";
279
+ case "TSStackAlloc":
280
+ return "stackalloc is not supported in Tsonic. Use heap-allocated arrays instead.";
281
+ case "TSByRef":
282
+ case "TSDelegate":
283
+ case "TSNullable":
284
+ return undefined; // These are supported
285
+ default:
286
+ return undefined;
287
+ }
288
+ };
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Test harness for support types tests.
3
+ * Creates a real TypeScript program with support type definitions
4
+ * and provides helpers to extract ts.Type objects.
5
+ */
6
+
7
+ import * as ts from "typescript";
8
+ import * as path from "path";
9
+ import * as os from "os";
10
+ import * as fs from "fs";
11
+
12
+ /**
13
+ * Support type definitions (from _support/types.d.ts)
14
+ */
15
+ const SUPPORT_TYPES_DEFS = `
16
+ // Support types for CLR interop
17
+ export type TSByRef<T> = { value: T };
18
+ export type TSUnsafePointer<T> = { __brand: "unsafe-pointer"; __type: T };
19
+ export type TSDelegate<TArgs extends any[], TReturn> = { __brand: "delegate"; __args: TArgs; __return: TReturn };
20
+ export type TSNullable<T> = { __brand: "nullable"; __value: T };
21
+ export type TSFixed<T, N extends number> = { __brand: "fixed"; __type: T; __size: N };
22
+ export type TSStackAlloc<T> = { __brand: "stackalloc"; __type: T };
23
+ `;
24
+
25
+ /**
26
+ * Test code that uses the support types
27
+ */
28
+ const TEST_CODE = `
29
+ import type { TSByRef, TSUnsafePointer, TSDelegate, TSNullable, TSFixed, TSStackAlloc } from "./support-types";
30
+
31
+ // Test variables with support types
32
+ const byRef: TSByRef<number> = { value: 42 };
33
+ const unsafePtr: TSUnsafePointer<string> = null!;
34
+ const delegate: TSDelegate<[string], void> = null!;
35
+ const nullable: TSNullable<number> = null!;
36
+ const fixed: TSFixed<number, 10> = null!;
37
+ const stackAlloc: TSStackAlloc<number> = null!;
38
+ `;
39
+
40
+ export type TestHarness = {
41
+ readonly program: ts.Program;
42
+ readonly checker: ts.TypeChecker;
43
+ readonly sourceFile: ts.SourceFile;
44
+ readonly cleanup: () => void;
45
+ };
46
+
47
+ /**
48
+ * Create a test harness with a real TypeScript program.
49
+ * Returns program, checker, and source file for testing.
50
+ */
51
+ export const createTestHarness = (): TestHarness => {
52
+ // Create temporary directory
53
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "tsonic-test-"));
54
+
55
+ // Write support types definition file
56
+ const supportTypesPath = path.join(tmpDir, "support-types.d.ts");
57
+ fs.writeFileSync(supportTypesPath, SUPPORT_TYPES_DEFS);
58
+
59
+ // Write test code file
60
+ const testCodePath = path.join(tmpDir, "test.ts");
61
+ fs.writeFileSync(testCodePath, TEST_CODE);
62
+
63
+ // Create TypeScript program
64
+ const program = ts.createProgram({
65
+ rootNames: [testCodePath],
66
+ options: {
67
+ target: ts.ScriptTarget.ES2020,
68
+ module: ts.ModuleKind.ES2020,
69
+ moduleResolution: ts.ModuleResolutionKind.Node10,
70
+ strict: true,
71
+ skipLibCheck: true,
72
+ noEmit: true,
73
+ },
74
+ });
75
+
76
+ const checker = program.getTypeChecker();
77
+ const sourceFile = program.getSourceFile(testCodePath);
78
+
79
+ if (!sourceFile) {
80
+ throw new Error("Failed to get source file from test program");
81
+ }
82
+
83
+ const cleanup = () => {
84
+ // Clean up temporary files
85
+ fs.rmSync(tmpDir, { recursive: true, force: true });
86
+ };
87
+
88
+ return {
89
+ program,
90
+ checker,
91
+ sourceFile,
92
+ cleanup,
93
+ };
94
+ };
95
+
96
+ /**
97
+ * Extract the type of a variable declaration by name.
98
+ * Gets the type from the type annotation node, not the inferred type.
99
+ */
100
+ export const getVariableType = (
101
+ sourceFile: ts.SourceFile,
102
+ checker: ts.TypeChecker,
103
+ variableName: string
104
+ ): ts.Type | undefined => {
105
+ let foundType: ts.Type | undefined = undefined;
106
+
107
+ const visit = (node: ts.Node): void => {
108
+ if (ts.isVariableDeclaration(node)) {
109
+ if (ts.isIdentifier(node.name) && node.name.text === variableName) {
110
+ // Get type from type annotation if present
111
+ if (node.type) {
112
+ foundType = checker.getTypeFromTypeNode(node.type);
113
+ } else {
114
+ foundType = checker.getTypeAtLocation(node);
115
+ }
116
+ }
117
+ }
118
+ ts.forEachChild(node, visit);
119
+ };
120
+
121
+ visit(sourceFile);
122
+ return foundType;
123
+ };
124
+
125
+ /**
126
+ * Get all support type instances from the test harness.
127
+ */
128
+ export const getSupportTypes = (
129
+ harness: TestHarness
130
+ ): {
131
+ byRef: ts.Type;
132
+ unsafePointer: ts.Type;
133
+ delegate: ts.Type;
134
+ nullable: ts.Type;
135
+ fixed: ts.Type;
136
+ stackAlloc: ts.Type;
137
+ } => {
138
+ const byRef = getVariableType(harness.sourceFile, harness.checker, "byRef");
139
+ const unsafePointer = getVariableType(
140
+ harness.sourceFile,
141
+ harness.checker,
142
+ "unsafePtr"
143
+ );
144
+ const delegate = getVariableType(
145
+ harness.sourceFile,
146
+ harness.checker,
147
+ "delegate"
148
+ );
149
+ const nullable = getVariableType(
150
+ harness.sourceFile,
151
+ harness.checker,
152
+ "nullable"
153
+ );
154
+ const fixed = getVariableType(harness.sourceFile, harness.checker, "fixed");
155
+ const stackAlloc = getVariableType(
156
+ harness.sourceFile,
157
+ harness.checker,
158
+ "stackAlloc"
159
+ );
160
+
161
+ if (
162
+ !byRef ||
163
+ !unsafePointer ||
164
+ !delegate ||
165
+ !nullable ||
166
+ !fixed ||
167
+ !stackAlloc
168
+ ) {
169
+ throw new Error("Failed to extract all support types from test harness");
170
+ }
171
+
172
+ return {
173
+ byRef,
174
+ unsafePointer,
175
+ delegate,
176
+ nullable,
177
+ fixed,
178
+ stackAlloc,
179
+ };
180
+ };
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Export validation
3
+ */
4
+
5
+ import * as ts from "typescript";
6
+ import { TsonicProgram } from "../program.js";
7
+ import {
8
+ DiagnosticsCollector,
9
+ addDiagnostic,
10
+ createDiagnostic,
11
+ } from "../types/diagnostic.js";
12
+ import { hasExportModifier, getNodeLocation } from "./helpers.js";
13
+
14
+ /**
15
+ * Validate exports (check for duplicates)
16
+ */
17
+ export const validateExports = (
18
+ sourceFile: ts.SourceFile,
19
+ _program: TsonicProgram,
20
+ collector: DiagnosticsCollector
21
+ ): DiagnosticsCollector => {
22
+ const exportedNames = new Set<string>();
23
+
24
+ const visitor = (node: ts.Node): void => {
25
+ if (ts.isExportDeclaration(node) || ts.isExportAssignment(node)) {
26
+ // Validate export syntax
27
+ if (ts.isExportAssignment(node) && !node.isExportEquals) {
28
+ // export default is allowed
29
+ } else if (
30
+ ts.isExportDeclaration(node) &&
31
+ node.exportClause &&
32
+ ts.isNamedExports(node.exportClause)
33
+ ) {
34
+ node.exportClause.elements.forEach((spec) => {
35
+ const name = spec.name.text;
36
+ if (exportedNames.has(name)) {
37
+ collector = addDiagnostic(
38
+ collector,
39
+ createDiagnostic(
40
+ "TSN1005",
41
+ "error",
42
+ `Duplicate export: "${name}"`,
43
+ getNodeLocation(sourceFile, spec)
44
+ )
45
+ );
46
+ }
47
+ exportedNames.add(name);
48
+ });
49
+ }
50
+ }
51
+
52
+ if (ts.isVariableStatement(node) && hasExportModifier(node)) {
53
+ node.declarationList.declarations.forEach((decl) => {
54
+ if (ts.isIdentifier(decl.name)) {
55
+ const name = decl.name.text;
56
+ if (exportedNames.has(name)) {
57
+ collector = addDiagnostic(
58
+ collector,
59
+ createDiagnostic(
60
+ "TSN1005",
61
+ "error",
62
+ `Duplicate export: "${name}"`,
63
+ getNodeLocation(sourceFile, decl)
64
+ )
65
+ );
66
+ }
67
+ exportedNames.add(name);
68
+ }
69
+ });
70
+ }
71
+
72
+ if (
73
+ (ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) &&
74
+ hasExportModifier(node)
75
+ ) {
76
+ const name = node.name?.text;
77
+ if (name) {
78
+ if (exportedNames.has(name)) {
79
+ collector = addDiagnostic(
80
+ collector,
81
+ createDiagnostic(
82
+ "TSN1005",
83
+ "error",
84
+ `Duplicate export: "${name}"`,
85
+ getNodeLocation(sourceFile, node)
86
+ )
87
+ );
88
+ }
89
+ exportedNames.add(name);
90
+ }
91
+ }
92
+
93
+ ts.forEachChild(node, visitor);
94
+ };
95
+
96
+ visitor(sourceFile);
97
+ return collector;
98
+ };
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Unsupported feature validation
3
+ */
4
+
5
+ import * as ts from "typescript";
6
+ import { TsonicProgram } from "../program.js";
7
+ import {
8
+ DiagnosticsCollector,
9
+ addDiagnostic,
10
+ createDiagnostic,
11
+ } from "../types/diagnostic.js";
12
+ import { getNodeLocation } from "./helpers.js";
13
+
14
+ /**
15
+ * Validate that unsupported features are not used
16
+ */
17
+ export const validateUnsupportedFeatures = (
18
+ sourceFile: ts.SourceFile,
19
+ _program: TsonicProgram,
20
+ collector: DiagnosticsCollector
21
+ ): DiagnosticsCollector => {
22
+ const visitor = (node: ts.Node): void => {
23
+ // Check for features we don't support yet
24
+ if (ts.isWithStatement(node)) {
25
+ collector = addDiagnostic(
26
+ collector,
27
+ createDiagnostic(
28
+ "TSN2001",
29
+ "error",
30
+ "'with' statement not supported",
31
+ getNodeLocation(sourceFile, node)
32
+ )
33
+ );
34
+ }
35
+
36
+ if (ts.isMetaProperty(node)) {
37
+ collector = addDiagnostic(
38
+ collector,
39
+ createDiagnostic(
40
+ "TSN2001",
41
+ "error",
42
+ "Meta properties (import.meta) not supported",
43
+ getNodeLocation(sourceFile, node)
44
+ )
45
+ );
46
+ }
47
+
48
+ if (
49
+ ts.isCallExpression(node) &&
50
+ node.expression.kind === ts.SyntaxKind.ImportKeyword
51
+ ) {
52
+ collector = addDiagnostic(
53
+ collector,
54
+ createDiagnostic(
55
+ "TSN2001",
56
+ "error",
57
+ "Dynamic import() not supported",
58
+ getNodeLocation(sourceFile, node),
59
+ "Use static imports"
60
+ )
61
+ );
62
+ }
63
+
64
+ // Check for Promise.then/catch/finally chaining (not supported)
65
+ if (
66
+ ts.isCallExpression(node) &&
67
+ ts.isPropertyAccessExpression(node.expression)
68
+ ) {
69
+ const methodName = node.expression.name.text;
70
+ if (["then", "catch", "finally"].includes(methodName)) {
71
+ collector = addDiagnostic(
72
+ collector,
73
+ createDiagnostic(
74
+ "TSN3011",
75
+ "error",
76
+ `Promise.${methodName}() is not supported`,
77
+ getNodeLocation(sourceFile, node),
78
+ "Use async/await instead of Promise chaining"
79
+ )
80
+ );
81
+ }
82
+ }
83
+
84
+ ts.forEachChild(node, visitor);
85
+ };
86
+
87
+ visitor(sourceFile);
88
+ return collector;
89
+ };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Generic type validation
3
+ */
4
+
5
+ import * as ts from "typescript";
6
+ import { TsonicProgram } from "../program.js";
7
+ import { DiagnosticsCollector, addDiagnostic } from "../types/diagnostic.js";
8
+ import { checkForSymbolIndexSignature } from "../ir/generic-validator.js";
9
+
10
+ /**
11
+ * Validate generic types and constraints
12
+ */
13
+ export const validateGenerics = (
14
+ sourceFile: ts.SourceFile,
15
+ _program: TsonicProgram,
16
+ collector: DiagnosticsCollector
17
+ ): DiagnosticsCollector => {
18
+ const visitor = (node: ts.Node): void => {
19
+ // Only check for truly unsupported features (no static C# mapping)
20
+ // Symbol index signatures - TSN7203
21
+ if (ts.isIndexSignatureDeclaration(node)) {
22
+ const symbolDiag = checkForSymbolIndexSignature(node, sourceFile);
23
+ if (symbolDiag) {
24
+ collector = addDiagnostic(collector, symbolDiag);
25
+ }
26
+ }
27
+
28
+ // Explicitly visit interface and type literal members
29
+ if (ts.isInterfaceDeclaration(node) || ts.isTypeLiteralNode(node)) {
30
+ for (const member of node.members) {
31
+ visitor(member);
32
+ }
33
+ }
34
+
35
+ ts.forEachChild(node, visitor);
36
+ };
37
+
38
+ visitor(sourceFile);
39
+ return collector;
40
+ };