@tsonic/emitter 0.0.6 → 0.0.12
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/.tsbuildinfo +1 -1
- package/dist/array.test.js +6 -6
- package/dist/array.test.js.map +1 -1
- package/dist/core/imports.test.js +6 -3
- package/dist/core/imports.test.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/type-compatibility.d.ts +26 -0
- package/dist/core/type-compatibility.d.ts.map +1 -0
- package/dist/core/type-compatibility.js +109 -0
- package/dist/core/type-compatibility.js.map +1 -0
- package/dist/core/type-resolution.d.ts +81 -1
- package/dist/core/type-resolution.d.ts.map +1 -1
- package/dist/core/type-resolution.js +258 -0
- package/dist/core/type-resolution.js.map +1 -1
- package/dist/core/type-resolution.test.js +110 -1
- package/dist/core/type-resolution.test.js.map +1 -1
- package/dist/emitter-types/context.d.ts.map +1 -1
- package/dist/emitter-types/context.js +21 -1
- package/dist/emitter-types/context.js.map +1 -1
- package/dist/emitter-types/core.d.ts +26 -0
- package/dist/emitter-types/core.d.ts.map +1 -1
- package/dist/emitter-types/identifiers.d.ts.map +1 -1
- package/dist/emitter-types/identifiers.js +4 -43
- package/dist/emitter-types/identifiers.js.map +1 -1
- package/dist/emitter-types/index.d.ts +1 -1
- package/dist/emitter-types/index.d.ts.map +1 -1
- package/dist/emitter-types/index.js.map +1 -1
- package/dist/expression-emitter.d.ts.map +1 -1
- package/dist/expression-emitter.js +48 -0
- package/dist/expression-emitter.js.map +1 -1
- package/dist/expressions/access.d.ts.map +1 -1
- package/dist/expressions/access.js +97 -13
- package/dist/expressions/access.js.map +1 -1
- package/dist/expressions/calls.d.ts.map +1 -1
- package/dist/expressions/calls.js +5 -1
- package/dist/expressions/calls.js.map +1 -1
- package/dist/expressions/collections.d.ts +3 -2
- package/dist/expressions/collections.d.ts.map +1 -1
- package/dist/expressions/collections.js +214 -24
- package/dist/expressions/collections.js.map +1 -1
- package/dist/expressions/functions.d.ts +2 -2
- package/dist/expressions/functions.d.ts.map +1 -1
- package/dist/expressions/functions.js +81 -38
- package/dist/expressions/functions.js.map +1 -1
- package/dist/expressions/identifiers.d.ts.map +1 -1
- package/dist/expressions/identifiers.js +27 -7
- package/dist/expressions/identifiers.js.map +1 -1
- package/dist/expressions/index.test.js +189 -4
- package/dist/expressions/index.test.js.map +1 -1
- package/dist/expressions/literals.d.ts +4 -6
- package/dist/expressions/literals.d.ts.map +1 -1
- package/dist/expressions/literals.js +41 -17
- package/dist/expressions/literals.js.map +1 -1
- package/dist/expressions/literals.test.js +41 -0
- package/dist/expressions/literals.test.js.map +1 -1
- package/dist/expressions/operators.d.ts +4 -0
- package/dist/expressions/operators.d.ts.map +1 -1
- package/dist/expressions/operators.js +145 -12
- package/dist/expressions/operators.js.map +1 -1
- package/dist/expressions/other.d.ts.map +1 -1
- package/dist/expressions/other.js +9 -2
- package/dist/expressions/other.js.map +1 -1
- package/dist/generator-exchange.d.ts +1 -1
- package/dist/generator-exchange.d.ts.map +1 -1
- package/dist/generator-exchange.js +15 -4
- package/dist/generator-exchange.js.map +1 -1
- package/dist/generator-wrapper.d.ts +84 -0
- package/dist/generator-wrapper.d.ts.map +1 -0
- package/dist/generator-wrapper.js +312 -0
- package/dist/generator-wrapper.js.map +1 -0
- package/dist/generator-wrapper.test.d.ts +12 -0
- package/dist/generator-wrapper.test.d.ts.map +1 -0
- package/dist/generator-wrapper.test.js +179 -0
- package/dist/generator-wrapper.test.js.map +1 -0
- package/dist/generator.test.js +596 -6
- package/dist/generator.test.js.map +1 -1
- package/dist/golden-tests/config-parser.d.ts.map +1 -1
- package/dist/golden-tests/config-parser.js +81 -11
- package/dist/golden-tests/config-parser.js.map +1 -1
- package/dist/golden-tests/discovery.d.ts.map +1 -1
- package/dist/golden-tests/discovery.js +15 -5
- package/dist/golden-tests/discovery.js.map +1 -1
- package/dist/golden-tests/runner.d.ts.map +1 -1
- package/dist/golden-tests/runner.js +62 -7
- package/dist/golden-tests/runner.js.map +1 -1
- package/dist/golden-tests/types.d.ts +11 -1
- package/dist/golden-tests/types.d.ts.map +1 -1
- package/dist/hierarchical-bindings.test.js +2 -2
- package/dist/hierarchical-bindings.test.js.map +1 -1
- package/dist/integration.test.js +49 -2
- package/dist/integration.test.js.map +1 -1
- package/dist/invariants/emitter-globals-subset.test.d.ts +15 -0
- package/dist/invariants/emitter-globals-subset.test.d.ts.map +1 -0
- package/dist/invariants/emitter-globals-subset.test.js +137 -0
- package/dist/invariants/emitter-globals-subset.test.js.map +1 -0
- package/dist/invariants/numeric-proof-contract.test.d.ts +19 -0
- package/dist/invariants/numeric-proof-contract.test.d.ts.map +1 -0
- package/dist/invariants/numeric-proof-contract.test.js +560 -0
- package/dist/invariants/numeric-proof-contract.test.js.map +1 -0
- package/dist/specialization/generic-functions.test.js +10 -0
- package/dist/specialization/generic-functions.test.js.map +1 -1
- package/dist/specialization/substitution.d.ts.map +1 -1
- package/dist/specialization/substitution.js +7 -0
- package/dist/specialization/substitution.js.map +1 -1
- package/dist/statement-emitter.d.ts.map +1 -1
- package/dist/statement-emitter.js +5 -1
- package/dist/statement-emitter.js.map +1 -1
- package/dist/statements/blocks.d.ts +39 -1
- package/dist/statements/blocks.d.ts.map +1 -1
- package/dist/statements/blocks.js +129 -3
- package/dist/statements/blocks.js.map +1 -1
- package/dist/statements/classes/members/methods.d.ts.map +1 -1
- package/dist/statements/classes/members/methods.js +3 -1
- package/dist/statements/classes/members/methods.js.map +1 -1
- package/dist/statements/control/conditionals.d.ts.map +1 -1
- package/dist/statements/control/conditionals.js +215 -1
- package/dist/statements/control/conditionals.js.map +1 -1
- package/dist/statements/control/loops.d.ts +6 -0
- package/dist/statements/control/loops.d.ts.map +1 -1
- package/dist/statements/control/loops.js +9 -2
- package/dist/statements/control/loops.js.map +1 -1
- package/dist/statements/declarations/classes.d.ts.map +1 -1
- package/dist/statements/declarations/classes.js +13 -5
- package/dist/statements/declarations/classes.js.map +1 -1
- package/dist/statements/declarations/functions.d.ts.map +1 -1
- package/dist/statements/declarations/functions.js +91 -25
- package/dist/statements/declarations/functions.js.map +1 -1
- package/dist/statements/declarations/interfaces.d.ts.map +1 -1
- package/dist/statements/declarations/interfaces.js +11 -1
- package/dist/statements/declarations/interfaces.js.map +1 -1
- package/dist/statements/declarations/type-aliases.d.ts.map +1 -1
- package/dist/statements/declarations/type-aliases.js +11 -1
- package/dist/statements/declarations/type-aliases.js.map +1 -1
- package/dist/statements/index.test.js +165 -3
- package/dist/statements/index.test.js.map +1 -1
- package/dist/types/arrays.d.ts +10 -1
- package/dist/types/arrays.d.ts.map +1 -1
- package/dist/types/arrays.js +16 -1
- package/dist/types/arrays.js.map +1 -1
- package/dist/types/dictionaries.d.ts +3 -2
- package/dist/types/dictionaries.d.ts.map +1 -1
- package/dist/types/dictionaries.js +14 -8
- package/dist/types/dictionaries.js.map +1 -1
- package/dist/types/emitter.d.ts.map +1 -1
- package/dist/types/emitter.js +3 -0
- package/dist/types/emitter.js.map +1 -1
- package/dist/types/index.test.js +5 -2
- package/dist/types/index.test.js.map +1 -1
- package/dist/types/references.d.ts.map +1 -1
- package/dist/types/references.js +128 -29
- package/dist/types/references.js.map +1 -1
- package/dist/types/references.test.d.ts +11 -0
- package/dist/types/references.test.d.ts.map +1 -0
- package/dist/types/references.test.js +384 -0
- package/dist/types/references.test.js.map +1 -0
- package/dist/types/tuples.d.ts +23 -0
- package/dist/types/tuples.d.ts.map +1 -0
- package/dist/types/tuples.js +54 -0
- package/dist/types/tuples.js.map +1 -0
- package/dist/types/unions.test.js +62 -15
- package/dist/types/unions.test.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Reference Type Emission
|
|
3
|
+
*
|
|
4
|
+
* Tests:
|
|
5
|
+
* - bindingsRegistry lookup for CLR types
|
|
6
|
+
* - C# primitive type passthrough
|
|
7
|
+
* - Local type passthrough
|
|
8
|
+
* - Hard failure for unresolved external types
|
|
9
|
+
*/
|
|
10
|
+
import { describe, it } from "mocha";
|
|
11
|
+
import { expect } from "chai";
|
|
12
|
+
import { emitModule } from "../emitter.js";
|
|
13
|
+
/**
|
|
14
|
+
* Helper to create a minimal module with a variable declaration of a given type
|
|
15
|
+
*/
|
|
16
|
+
const createModuleWithType = (varType) => ({
|
|
17
|
+
kind: "module",
|
|
18
|
+
filePath: "/src/test.ts",
|
|
19
|
+
namespace: "Test",
|
|
20
|
+
className: "test",
|
|
21
|
+
isStaticContainer: true,
|
|
22
|
+
imports: [],
|
|
23
|
+
body: [
|
|
24
|
+
{
|
|
25
|
+
kind: "variableDeclaration",
|
|
26
|
+
declarationKind: "const",
|
|
27
|
+
isExported: false,
|
|
28
|
+
declarations: [
|
|
29
|
+
{
|
|
30
|
+
kind: "variableDeclarator",
|
|
31
|
+
name: { kind: "identifierPattern", name: "x" },
|
|
32
|
+
type: varType,
|
|
33
|
+
initializer: { kind: "literal", value: null },
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
exports: [],
|
|
39
|
+
});
|
|
40
|
+
describe("Reference Type Emission", () => {
|
|
41
|
+
describe("C# Primitive Types", () => {
|
|
42
|
+
it("should emit int without qualification", () => {
|
|
43
|
+
const module = createModuleWithType({
|
|
44
|
+
kind: "referenceType",
|
|
45
|
+
name: "int",
|
|
46
|
+
});
|
|
47
|
+
const result = emitModule(module);
|
|
48
|
+
expect(result).to.include("int x");
|
|
49
|
+
});
|
|
50
|
+
it("should emit long without qualification", () => {
|
|
51
|
+
const module = createModuleWithType({
|
|
52
|
+
kind: "referenceType",
|
|
53
|
+
name: "long",
|
|
54
|
+
});
|
|
55
|
+
const result = emitModule(module);
|
|
56
|
+
expect(result).to.include("long x");
|
|
57
|
+
});
|
|
58
|
+
it("should emit double without qualification", () => {
|
|
59
|
+
const module = createModuleWithType({
|
|
60
|
+
kind: "referenceType",
|
|
61
|
+
name: "double",
|
|
62
|
+
});
|
|
63
|
+
const result = emitModule(module);
|
|
64
|
+
expect(result).to.include("double x");
|
|
65
|
+
});
|
|
66
|
+
it("should emit decimal without qualification", () => {
|
|
67
|
+
const module = createModuleWithType({
|
|
68
|
+
kind: "referenceType",
|
|
69
|
+
name: "decimal",
|
|
70
|
+
});
|
|
71
|
+
const result = emitModule(module);
|
|
72
|
+
expect(result).to.include("decimal x");
|
|
73
|
+
});
|
|
74
|
+
it("should emit bool without qualification", () => {
|
|
75
|
+
const module = createModuleWithType({
|
|
76
|
+
kind: "referenceType",
|
|
77
|
+
name: "bool",
|
|
78
|
+
});
|
|
79
|
+
const result = emitModule(module);
|
|
80
|
+
expect(result).to.include("bool x");
|
|
81
|
+
});
|
|
82
|
+
it("should emit nint (native int) without qualification", () => {
|
|
83
|
+
const module = createModuleWithType({
|
|
84
|
+
kind: "referenceType",
|
|
85
|
+
name: "nint",
|
|
86
|
+
});
|
|
87
|
+
const result = emitModule(module);
|
|
88
|
+
expect(result).to.include("nint x");
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe("Known Builtin Types", () => {
|
|
92
|
+
it("should emit Array<T> as List<T>", () => {
|
|
93
|
+
const module = createModuleWithType({
|
|
94
|
+
kind: "referenceType",
|
|
95
|
+
name: "Array",
|
|
96
|
+
typeArguments: [{ kind: "primitiveType", name: "number" }],
|
|
97
|
+
});
|
|
98
|
+
const result = emitModule(module);
|
|
99
|
+
expect(result).to.include("global::System.Collections.Generic.List<double>");
|
|
100
|
+
});
|
|
101
|
+
it("should emit Promise<T> as Task<T>", () => {
|
|
102
|
+
const module = createModuleWithType({
|
|
103
|
+
kind: "referenceType",
|
|
104
|
+
name: "Promise",
|
|
105
|
+
typeArguments: [{ kind: "primitiveType", name: "string" }],
|
|
106
|
+
});
|
|
107
|
+
const result = emitModule(module);
|
|
108
|
+
expect(result).to.include("global::System.Threading.Tasks.Task<string>");
|
|
109
|
+
});
|
|
110
|
+
it("should emit Error as System.Exception in js mode (default)", () => {
|
|
111
|
+
const module = createModuleWithType({
|
|
112
|
+
kind: "referenceType",
|
|
113
|
+
name: "Error",
|
|
114
|
+
});
|
|
115
|
+
// Default runtime is "js"
|
|
116
|
+
const result = emitModule(module);
|
|
117
|
+
expect(result).to.include("global::System.Exception");
|
|
118
|
+
});
|
|
119
|
+
it("should emit Error as System.Exception in js mode (explicit)", () => {
|
|
120
|
+
const module = createModuleWithType({
|
|
121
|
+
kind: "referenceType",
|
|
122
|
+
name: "Error",
|
|
123
|
+
});
|
|
124
|
+
const result = emitModule(module, { runtime: "js" });
|
|
125
|
+
expect(result).to.include("global::System.Exception");
|
|
126
|
+
});
|
|
127
|
+
it("should fail for Error in dotnet mode (not in dotnet-globals)", () => {
|
|
128
|
+
const module = createModuleWithType({
|
|
129
|
+
kind: "referenceType",
|
|
130
|
+
name: "Error",
|
|
131
|
+
});
|
|
132
|
+
// Error is not in dotnet-globals, so it should fail as unresolved
|
|
133
|
+
expect(() => emitModule(module, { runtime: "dotnet" })).to.throw("ICE: Unresolved reference type 'Error'");
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
describe("Pre-resolved CLR Types", () => {
|
|
137
|
+
it("should use resolvedClrType when present", () => {
|
|
138
|
+
const module = createModuleWithType({
|
|
139
|
+
kind: "referenceType",
|
|
140
|
+
name: "Action",
|
|
141
|
+
resolvedClrType: "global::System.Action",
|
|
142
|
+
});
|
|
143
|
+
const result = emitModule(module);
|
|
144
|
+
expect(result).to.include("global::System.Action");
|
|
145
|
+
});
|
|
146
|
+
it("should use resolvedClrType with type arguments", () => {
|
|
147
|
+
const module = createModuleWithType({
|
|
148
|
+
kind: "referenceType",
|
|
149
|
+
name: "Func",
|
|
150
|
+
resolvedClrType: "global::System.Func",
|
|
151
|
+
typeArguments: [
|
|
152
|
+
{ kind: "primitiveType", name: "string" },
|
|
153
|
+
{ kind: "primitiveType", name: "number" },
|
|
154
|
+
],
|
|
155
|
+
});
|
|
156
|
+
const result = emitModule(module);
|
|
157
|
+
expect(result).to.include("global::System.Func<string, double>");
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
describe("Local Types", () => {
|
|
161
|
+
it("should emit local class types without qualification", () => {
|
|
162
|
+
const module = {
|
|
163
|
+
kind: "module",
|
|
164
|
+
filePath: "/src/test.ts",
|
|
165
|
+
namespace: "Test",
|
|
166
|
+
className: "test",
|
|
167
|
+
isStaticContainer: true,
|
|
168
|
+
imports: [],
|
|
169
|
+
body: [
|
|
170
|
+
// Define a local class
|
|
171
|
+
{
|
|
172
|
+
kind: "classDeclaration",
|
|
173
|
+
name: "User",
|
|
174
|
+
isExported: true,
|
|
175
|
+
isStruct: false,
|
|
176
|
+
typeParameters: [],
|
|
177
|
+
implements: [],
|
|
178
|
+
members: [],
|
|
179
|
+
},
|
|
180
|
+
// Use the local class as a type
|
|
181
|
+
{
|
|
182
|
+
kind: "variableDeclaration",
|
|
183
|
+
declarationKind: "const",
|
|
184
|
+
isExported: false,
|
|
185
|
+
declarations: [
|
|
186
|
+
{
|
|
187
|
+
kind: "variableDeclarator",
|
|
188
|
+
name: { kind: "identifierPattern", name: "user" },
|
|
189
|
+
type: { kind: "referenceType", name: "User" },
|
|
190
|
+
initializer: { kind: "literal", value: null },
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
exports: [],
|
|
196
|
+
};
|
|
197
|
+
const result = emitModule(module);
|
|
198
|
+
expect(result).to.include("User user");
|
|
199
|
+
});
|
|
200
|
+
it("should emit local interface types without qualification", () => {
|
|
201
|
+
const module = {
|
|
202
|
+
kind: "module",
|
|
203
|
+
filePath: "/src/test.ts",
|
|
204
|
+
namespace: "Test",
|
|
205
|
+
className: "test",
|
|
206
|
+
isStaticContainer: true,
|
|
207
|
+
imports: [],
|
|
208
|
+
body: [
|
|
209
|
+
// Define a local interface
|
|
210
|
+
{
|
|
211
|
+
kind: "interfaceDeclaration",
|
|
212
|
+
name: "IUser",
|
|
213
|
+
isExported: true,
|
|
214
|
+
isStruct: false,
|
|
215
|
+
typeParameters: [],
|
|
216
|
+
extends: [],
|
|
217
|
+
members: [],
|
|
218
|
+
},
|
|
219
|
+
// Use the local interface as a type
|
|
220
|
+
{
|
|
221
|
+
kind: "variableDeclaration",
|
|
222
|
+
declarationKind: "const",
|
|
223
|
+
isExported: false,
|
|
224
|
+
declarations: [
|
|
225
|
+
{
|
|
226
|
+
kind: "variableDeclarator",
|
|
227
|
+
name: { kind: "identifierPattern", name: "user" },
|
|
228
|
+
type: { kind: "referenceType", name: "IUser" },
|
|
229
|
+
initializer: { kind: "literal", value: null },
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
exports: [],
|
|
235
|
+
};
|
|
236
|
+
const result = emitModule(module);
|
|
237
|
+
expect(result).to.include("IUser user");
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
describe("Runtime Mode Guards", () => {
|
|
241
|
+
it("should NOT emit JSRuntime in dotnet mode for array indexing", () => {
|
|
242
|
+
// This test creates a module with array index access
|
|
243
|
+
// In dotnet mode, it should use native indexer, not JSRuntime.Array.get()
|
|
244
|
+
const module = {
|
|
245
|
+
kind: "module",
|
|
246
|
+
filePath: "/src/test.ts",
|
|
247
|
+
namespace: "Test",
|
|
248
|
+
className: "test",
|
|
249
|
+
isStaticContainer: true,
|
|
250
|
+
imports: [],
|
|
251
|
+
body: [
|
|
252
|
+
{
|
|
253
|
+
kind: "functionDeclaration",
|
|
254
|
+
name: "getFirst",
|
|
255
|
+
isExported: true,
|
|
256
|
+
isAsync: false,
|
|
257
|
+
isGenerator: false,
|
|
258
|
+
parameters: [
|
|
259
|
+
{
|
|
260
|
+
kind: "parameter",
|
|
261
|
+
pattern: { kind: "identifierPattern", name: "arr" },
|
|
262
|
+
type: {
|
|
263
|
+
kind: "arrayType",
|
|
264
|
+
elementType: { kind: "primitiveType", name: "number" },
|
|
265
|
+
},
|
|
266
|
+
isOptional: false,
|
|
267
|
+
isRest: false,
|
|
268
|
+
passing: "value",
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
returnType: { kind: "primitiveType", name: "number" },
|
|
272
|
+
body: {
|
|
273
|
+
kind: "blockStatement",
|
|
274
|
+
statements: [
|
|
275
|
+
{
|
|
276
|
+
kind: "returnStatement",
|
|
277
|
+
expression: {
|
|
278
|
+
kind: "memberAccess",
|
|
279
|
+
object: {
|
|
280
|
+
kind: "identifier",
|
|
281
|
+
name: "arr",
|
|
282
|
+
inferredType: {
|
|
283
|
+
kind: "arrayType",
|
|
284
|
+
elementType: { kind: "primitiveType", name: "number" },
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
property: {
|
|
288
|
+
kind: "literal",
|
|
289
|
+
value: 0,
|
|
290
|
+
// Proof marker: Int32 literal
|
|
291
|
+
inferredType: {
|
|
292
|
+
kind: "primitiveType",
|
|
293
|
+
name: "number",
|
|
294
|
+
numericIntent: "Int32",
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
isComputed: true,
|
|
298
|
+
isOptional: false,
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
],
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
],
|
|
305
|
+
exports: [],
|
|
306
|
+
};
|
|
307
|
+
const result = emitModule(module, { runtime: "dotnet" });
|
|
308
|
+
// In dotnet mode, output should NOT contain JSRuntime
|
|
309
|
+
expect(result).to.not.include("Tsonic.JSRuntime");
|
|
310
|
+
// Should use native indexer (no cast needed with proof marker)
|
|
311
|
+
expect(result).to.include("arr[0]");
|
|
312
|
+
});
|
|
313
|
+
it("should emit JSRuntime in js mode for array indexing", () => {
|
|
314
|
+
// Same module as above but in js mode
|
|
315
|
+
const module = {
|
|
316
|
+
kind: "module",
|
|
317
|
+
filePath: "/src/test.ts",
|
|
318
|
+
namespace: "Test",
|
|
319
|
+
className: "test",
|
|
320
|
+
isStaticContainer: true,
|
|
321
|
+
imports: [],
|
|
322
|
+
body: [
|
|
323
|
+
{
|
|
324
|
+
kind: "functionDeclaration",
|
|
325
|
+
name: "getFirst",
|
|
326
|
+
isExported: true,
|
|
327
|
+
isAsync: false,
|
|
328
|
+
isGenerator: false,
|
|
329
|
+
parameters: [
|
|
330
|
+
{
|
|
331
|
+
kind: "parameter",
|
|
332
|
+
pattern: { kind: "identifierPattern", name: "arr" },
|
|
333
|
+
type: {
|
|
334
|
+
kind: "arrayType",
|
|
335
|
+
elementType: { kind: "primitiveType", name: "number" },
|
|
336
|
+
},
|
|
337
|
+
isOptional: false,
|
|
338
|
+
isRest: false,
|
|
339
|
+
passing: "value",
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
returnType: { kind: "primitiveType", name: "number" },
|
|
343
|
+
body: {
|
|
344
|
+
kind: "blockStatement",
|
|
345
|
+
statements: [
|
|
346
|
+
{
|
|
347
|
+
kind: "returnStatement",
|
|
348
|
+
expression: {
|
|
349
|
+
kind: "memberAccess",
|
|
350
|
+
object: {
|
|
351
|
+
kind: "identifier",
|
|
352
|
+
name: "arr",
|
|
353
|
+
inferredType: {
|
|
354
|
+
kind: "arrayType",
|
|
355
|
+
elementType: { kind: "primitiveType", name: "number" },
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
property: {
|
|
359
|
+
kind: "literal",
|
|
360
|
+
value: 0,
|
|
361
|
+
// Proof marker: Int32 literal
|
|
362
|
+
inferredType: {
|
|
363
|
+
kind: "primitiveType",
|
|
364
|
+
name: "number",
|
|
365
|
+
numericIntent: "Int32",
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
isComputed: true,
|
|
369
|
+
isOptional: false,
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
],
|
|
373
|
+
},
|
|
374
|
+
},
|
|
375
|
+
],
|
|
376
|
+
exports: [],
|
|
377
|
+
};
|
|
378
|
+
const result = emitModule(module, { runtime: "js" });
|
|
379
|
+
// In js mode, output should use JSRuntime.Array.get()
|
|
380
|
+
expect(result).to.include("global::Tsonic.JSRuntime.Array.get");
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
//# sourceMappingURL=references.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"references.test.js","sourceRoot":"","sources":["../../src/types/references.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,OAAe,EAAY,EAAE,CAAC,CAAC;IAC3D,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,cAAc;IACxB,SAAS,EAAE,MAAM;IACjB,SAAS,EAAE,MAAM;IACjB,iBAAiB,EAAE,IAAI;IACvB,OAAO,EAAE,EAAE;IACX,IAAI,EAAE;QACJ;YACE,IAAI,EAAE,qBAAqB;YAC3B,eAAe,EAAE,OAAO;YACxB,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE;gBACZ;oBACE,IAAI,EAAE,oBAAoB;oBAC1B,IAAI,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,GAAG,EAAE;oBAC9C,IAAI,EAAE,OAAO;oBACb,WAAW,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE;iBAC9C;aACF;SACF;KACF;IACD,OAAO,EAAE,EAAE;CACZ,CAAC,CAAC;AAEH,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAClC,EAAE,CAAC,uCA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AC9B,YAAY,EAAE;gDACZ,IAAI,EAAE,eAAe;gDACrB,IAAI,EAAE,QAAQ;gDACd,aAAa,EAAE,OAAO;6CACvB;yCACF;wCACD,UAAU,EAAE,IAAI;wCAChB,UAAU,EAAE,KAAK;qCAClB;iCACF;6BACF;yBACF;qBACF;iBACF;gBACD,OAAO,EAAE,EAAE;aACZ,CAAC;YAEF,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YAErD,sDAAsD;YACtD,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,oCAAoC,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tuple type emission
|
|
3
|
+
*
|
|
4
|
+
* TypeScript tuples are emitted as System.ValueTuple<T1, T2, ...>
|
|
5
|
+
* For tuples with more than 7 elements, .NET requires nesting:
|
|
6
|
+
* ValueTuple<T1..T7, ValueTuple<T8..>> (recursive for 15+, 22+, etc.)
|
|
7
|
+
*/
|
|
8
|
+
import { IrType } from "@tsonic/frontend";
|
|
9
|
+
import { EmitterContext } from "../types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Emit tuple types as global::System.ValueTuple<T1, T2, ...>
|
|
12
|
+
*
|
|
13
|
+
* TypeScript: [string, number, boolean]
|
|
14
|
+
* C#: global::System.ValueTuple<string, double, bool>
|
|
15
|
+
*
|
|
16
|
+
* For 8+ elements, uses .NET's nested TRest pattern:
|
|
17
|
+
* TypeScript: [T1, T2, T3, T4, T5, T6, T7, T8]
|
|
18
|
+
* C#: global::System.ValueTuple<T1, T2, T3, T4, T5, T6, T7, global::System.ValueTuple<T8>>
|
|
19
|
+
*/
|
|
20
|
+
export declare const emitTupleType: (type: Extract<IrType, {
|
|
21
|
+
kind: "tupleType";
|
|
22
|
+
}>, context: EmitterContext) => [string, EmitterContext];
|
|
23
|
+
//# sourceMappingURL=tuples.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tuples.d.ts","sourceRoot":"","sources":["../../src/types/tuples.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAoB7C;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,GACxB,MAAM,OAAO,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC,EAC5C,SAAS,cAAc,KACtB,CAAC,MAAM,EAAE,cAAc,CA8BzB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tuple type emission
|
|
3
|
+
*
|
|
4
|
+
* TypeScript tuples are emitted as System.ValueTuple<T1, T2, ...>
|
|
5
|
+
* For tuples with more than 7 elements, .NET requires nesting:
|
|
6
|
+
* ValueTuple<T1..T7, ValueTuple<T8..>> (recursive for 15+, 22+, etc.)
|
|
7
|
+
*/
|
|
8
|
+
import { emitType } from "./emitter.js";
|
|
9
|
+
/**
|
|
10
|
+
* Helper to emit a list of tuple element types, threading context through.
|
|
11
|
+
*/
|
|
12
|
+
const emitTupleElems = (elems, context) => {
|
|
13
|
+
const out = [];
|
|
14
|
+
let ctx = context;
|
|
15
|
+
for (const t of elems) {
|
|
16
|
+
const [s, next] = emitType(t, ctx);
|
|
17
|
+
out.push(s);
|
|
18
|
+
ctx = next;
|
|
19
|
+
}
|
|
20
|
+
return [out, ctx];
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Emit tuple types as global::System.ValueTuple<T1, T2, ...>
|
|
24
|
+
*
|
|
25
|
+
* TypeScript: [string, number, boolean]
|
|
26
|
+
* C#: global::System.ValueTuple<string, double, bool>
|
|
27
|
+
*
|
|
28
|
+
* For 8+ elements, uses .NET's nested TRest pattern:
|
|
29
|
+
* TypeScript: [T1, T2, T3, T4, T5, T6, T7, T8]
|
|
30
|
+
* C#: global::System.ValueTuple<T1, T2, T3, T4, T5, T6, T7, global::System.ValueTuple<T8>>
|
|
31
|
+
*/
|
|
32
|
+
export const emitTupleType = (type, context) => {
|
|
33
|
+
const elems = type.elementTypes;
|
|
34
|
+
// Empty tuple type [] → ValueTuple (non-generic)
|
|
35
|
+
if (elems.length === 0) {
|
|
36
|
+
return ["global::System.ValueTuple", context];
|
|
37
|
+
}
|
|
38
|
+
// 1-7 elements: direct ValueTuple<T1, ..., Tn>
|
|
39
|
+
if (elems.length <= 7) {
|
|
40
|
+
const [types, ctx] = emitTupleElems(elems, context);
|
|
41
|
+
return [`global::System.ValueTuple<${types.join(", ")}>`, ctx];
|
|
42
|
+
}
|
|
43
|
+
// 8+ elements: nest as ValueTuple<T1..T7, ValueTuple<T8..>>
|
|
44
|
+
const first7 = elems.slice(0, 7);
|
|
45
|
+
const rest = elems.slice(7);
|
|
46
|
+
const [first7Types, ctxAfterFirst7] = emitTupleElems(first7, context);
|
|
47
|
+
// Recursively emit rest as nested tuple (handles 15+, 22+, etc.)
|
|
48
|
+
const [restType, ctxAfterRest] = emitTupleType({ kind: "tupleType", elementTypes: rest }, ctxAfterFirst7);
|
|
49
|
+
return [
|
|
50
|
+
`global::System.ValueTuple<${[...first7Types, restType].join(", ")}>`,
|
|
51
|
+
ctxAfterRest,
|
|
52
|
+
];
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=tuples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tuples.js","sourceRoot":"","sources":["../../src/types/tuples.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC;;GAEG;AACH,MAAM,cAAc,GAAG,CACrB,KAAwB,EACxB,OAAuB,EACK,EAAE;IAC9B,MAA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AAI,EAAE,WAAW,EAAE,YAAY,EAAE,IAAI,EAAE,EACzC,cAAc,CACf,CAAC;IAEF,OAAO;QACL,6BAA6B,CAAC,GAAG,WAAW,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;QACrE,YAAY;KACb,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -73,9 +73,10 @@ describe("Union Type Emission", () => {
|
|
|
73
73
|
],
|
|
74
74
|
};
|
|
75
75
|
const code = emitModule(module);
|
|
76
|
-
// Should use Union<T1, T2>
|
|
77
|
-
expect(code).to.include("Union<string, double> value");
|
|
78
|
-
|
|
76
|
+
// Should use fully-qualified Union<T1, T2>
|
|
77
|
+
expect(code).to.include("global::Tsonic.Runtime.Union<string, double> value");
|
|
78
|
+
// Should NOT include using directives - uses global:: FQN
|
|
79
|
+
expect(code).to.not.include("using Tsonic.Runtime");
|
|
79
80
|
});
|
|
80
81
|
it("should emit function returning union type", () => {
|
|
81
82
|
const module = {
|
|
@@ -114,8 +115,8 @@ describe("Union Type Emission", () => {
|
|
|
114
115
|
],
|
|
115
116
|
};
|
|
116
117
|
const code = emitModule(module);
|
|
117
|
-
// Should return Union<string, double>
|
|
118
|
-
expect(code).to.include("public static Union<string, double> getValue()");
|
|
118
|
+
// Should return Union<string, double> with global:: FQN
|
|
119
|
+
expect(code).to.include("public static global::Tsonic.Runtime.Union<string, double> getValue()");
|
|
119
120
|
});
|
|
120
121
|
it("should emit function parameter with union type", () => {
|
|
121
122
|
const module = {
|
|
@@ -158,8 +159,8 @@ describe("Union Type Emission", () => {
|
|
|
158
159
|
],
|
|
159
160
|
};
|
|
160
161
|
const code = emitModule(module);
|
|
161
|
-
// Should accept Union<string, bool> parameter
|
|
162
|
-
expect(code).to.include("process(Union<string, bool> input)");
|
|
162
|
+
// Should accept Union<string, bool> parameter with global:: FQN
|
|
163
|
+
expect(code).to.include("process(global::Tsonic.Runtime.Union<string, bool> input)");
|
|
163
164
|
});
|
|
164
165
|
it("should handle union with custom types", () => {
|
|
165
166
|
const module = {
|
|
@@ -171,6 +172,25 @@ describe("Union Type Emission", () => {
|
|
|
171
172
|
imports: [],
|
|
172
173
|
exports: [],
|
|
173
174
|
body: [
|
|
175
|
+
// Declare local types for the union
|
|
176
|
+
{
|
|
177
|
+
kind: "interfaceDeclaration",
|
|
178
|
+
name: "User",
|
|
179
|
+
isExported: false,
|
|
180
|
+
isStruct: false,
|
|
181
|
+
typeParameters: [],
|
|
182
|
+
extends: [],
|
|
183
|
+
members: [],
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
kind: "interfaceDeclaration",
|
|
187
|
+
name: "Product",
|
|
188
|
+
isExported: false,
|
|
189
|
+
isStruct: false,
|
|
190
|
+
typeParameters: [],
|
|
191
|
+
extends: [],
|
|
192
|
+
members: [],
|
|
193
|
+
},
|
|
174
194
|
{
|
|
175
195
|
kind: "functionDeclaration",
|
|
176
196
|
name: "getResult",
|
|
@@ -234,9 +254,10 @@ describe("Union Type Emission", () => {
|
|
|
234
254
|
],
|
|
235
255
|
};
|
|
236
256
|
const code = emitModule(module);
|
|
237
|
-
// Should use Union<T1, T2, T3>
|
|
238
|
-
expect(code).to.include("Union<string, double, bool> value");
|
|
239
|
-
|
|
257
|
+
// Should use fully-qualified Union<T1, T2, T3>
|
|
258
|
+
expect(code).to.include("global::Tsonic.Runtime.Union<string, double, bool> value");
|
|
259
|
+
// Should NOT include using directives - uses global:: FQN
|
|
260
|
+
expect(code).to.not.include("using Tsonic.Runtime");
|
|
240
261
|
});
|
|
241
262
|
it("should emit four-type union as Union<T1, T2, T3, T4>", () => {
|
|
242
263
|
const module = {
|
|
@@ -248,6 +269,16 @@ describe("Union Type Emission", () => {
|
|
|
248
269
|
imports: [],
|
|
249
270
|
exports: [],
|
|
250
271
|
body: [
|
|
272
|
+
// Declare local type for the union (Date is not in globals)
|
|
273
|
+
{
|
|
274
|
+
kind: "interfaceDeclaration",
|
|
275
|
+
name: "DateLike",
|
|
276
|
+
isExported: false,
|
|
277
|
+
isStruct: false,
|
|
278
|
+
typeParameters: [],
|
|
279
|
+
extends: [],
|
|
280
|
+
members: [],
|
|
281
|
+
},
|
|
251
282
|
{
|
|
252
283
|
kind: "functionDeclaration",
|
|
253
284
|
name: "process",
|
|
@@ -258,7 +289,7 @@ describe("Union Type Emission", () => {
|
|
|
258
289
|
{ kind: "primitiveType", name: "string" },
|
|
259
290
|
{ kind: "primitiveType", name: "number" },
|
|
260
291
|
{ kind: "primitiveType", name: "boolean" },
|
|
261
|
-
{ kind: "referenceType", name: "
|
|
292
|
+
{ kind: "referenceType", name: "DateLike", typeArguments: [] },
|
|
262
293
|
],
|
|
263
294
|
},
|
|
264
295
|
body: {
|
|
@@ -277,10 +308,20 @@ describe("Union Type Emission", () => {
|
|
|
277
308
|
],
|
|
278
309
|
};
|
|
279
310
|
const code = emitModule(module);
|
|
280
|
-
// Should use Union<T1, T2, T3, T4>
|
|
281
|
-
expect(code).to.include("Union<string, double, bool,
|
|
311
|
+
// Should use Union<T1, T2, T3, T4> with global:: FQN
|
|
312
|
+
expect(code).to.include("global::Tsonic.Runtime.Union<string, double, bool, DateLike> process()");
|
|
282
313
|
});
|
|
283
314
|
it("should emit eight-type union as Union<T1, T2, T3, T4, T5, T6, T7, T8>", () => {
|
|
315
|
+
// Helper to create an interface declaration
|
|
316
|
+
const makeInterface = (name) => ({
|
|
317
|
+
kind: "interfaceDeclaration",
|
|
318
|
+
name,
|
|
319
|
+
isExported: false,
|
|
320
|
+
isStruct: false,
|
|
321
|
+
typeParameters: [],
|
|
322
|
+
extends: [],
|
|
323
|
+
members: [],
|
|
324
|
+
});
|
|
284
325
|
const module = {
|
|
285
326
|
kind: "module",
|
|
286
327
|
filePath: "/test/union8.ts",
|
|
@@ -290,6 +331,12 @@ describe("Union Type Emission", () => {
|
|
|
290
331
|
imports: [],
|
|
291
332
|
exports: [],
|
|
292
333
|
body: [
|
|
334
|
+
// Declare local types for the union
|
|
335
|
+
makeInterface("User"),
|
|
336
|
+
makeInterface("Product"),
|
|
337
|
+
makeInterface("Order"),
|
|
338
|
+
makeInterface("Payment"),
|
|
339
|
+
makeInterface("Invoice"),
|
|
293
340
|
{
|
|
294
341
|
kind: "variableDeclaration",
|
|
295
342
|
declarationKind: "const",
|
|
@@ -318,8 +365,8 @@ describe("Union Type Emission", () => {
|
|
|
318
365
|
],
|
|
319
366
|
};
|
|
320
367
|
const code = emitModule(module);
|
|
321
|
-
// Should use Union<T1, T2, T3, T4, T5, T6, T7, T8>
|
|
322
|
-
expect(code).to.include("Union<string, double, bool, User, Product, Order, Payment, Invoice> value");
|
|
368
|
+
// Should use Union<T1, T2, T3, T4, T5, T6, T7, T8> with global:: FQN
|
|
369
|
+
expect(code).to.include("global::Tsonic.Runtime.Union<string, double, bool, User, Product, Order, Payment, Invoice> value");
|
|
323
370
|
});
|
|
324
371
|
it("should fall back to object for unions with more than 8 types", () => {
|
|
325
372
|
const module = {
|