@tsonic/emitter 0.0.3 → 0.0.5
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/adapter-generator.d.ts.map +1 -1
- package/dist/adapter-generator.js +3 -2
- package/dist/adapter-generator.js.map +1 -1
- package/dist/array.test.js +1 -1
- package/dist/array.test.js.map +1 -1
- package/dist/core/imports.d.ts.map +1 -1
- package/dist/core/imports.js +13 -9
- package/dist/core/imports.js.map +1 -1
- package/dist/core/local-types.d.ts +19 -0
- package/dist/core/local-types.d.ts.map +1 -0
- package/dist/core/local-types.js +77 -0
- package/dist/core/local-types.js.map +1 -0
- package/dist/core/module-emitter/orchestrator.d.ts.map +1 -1
- package/dist/core/module-emitter/orchestrator.js +11 -4
- package/dist/core/module-emitter/orchestrator.js.map +1 -1
- package/dist/core/module-emitter/static-container.d.ts +2 -1
- package/dist/core/module-emitter/static-container.d.ts.map +1 -1
- package/dist/core/module-emitter/static-container.js +9 -2
- package/dist/core/module-emitter/static-container.js.map +1 -1
- package/dist/core/module-map.d.ts.map +1 -1
- package/dist/core/module-map.js +6 -0
- package/dist/core/module-map.js.map +1 -1
- package/dist/core/type-resolution.d.ts +47 -0
- package/dist/core/type-resolution.d.ts.map +1 -0
- package/dist/core/type-resolution.js +283 -0
- package/dist/core/type-resolution.js.map +1 -0
- package/dist/core/type-resolution.test.d.ts +5 -0
- package/dist/core/type-resolution.test.d.ts.map +1 -0
- package/dist/core/type-resolution.test.js +271 -0
- package/dist/core/type-resolution.test.js.map +1 -0
- package/dist/emitter-types/context.d.ts +29 -0
- package/dist/emitter-types/context.d.ts.map +1 -1
- package/dist/emitter-types/context.js +39 -0
- package/dist/emitter-types/context.js.map +1 -1
- package/dist/emitter-types/core.d.ts +31 -0
- package/dist/emitter-types/core.d.ts.map +1 -1
- package/dist/emitter-types/identifiers.d.ts +23 -0
- package/dist/emitter-types/identifiers.d.ts.map +1 -0
- package/dist/emitter-types/identifiers.js +164 -0
- package/dist/emitter-types/identifiers.js.map +1 -0
- package/dist/emitter-types/index.d.ts +3 -2
- package/dist/emitter-types/index.d.ts.map +1 -1
- package/dist/emitter-types/index.js +2 -1
- package/dist/emitter-types/index.js.map +1 -1
- package/dist/expression-emitter.d.ts.map +1 -1
- package/dist/expression-emitter.js +5 -5
- package/dist/expression-emitter.js.map +1 -1
- package/dist/expressions/access.d.ts.map +1 -1
- package/dist/expressions/access.js +14 -7
- package/dist/expressions/access.js.map +1 -1
- package/dist/expressions/collections.d.ts +5 -1
- package/dist/expressions/collections.d.ts.map +1 -1
- package/dist/expressions/collections.js +19 -8
- package/dist/expressions/collections.js.map +1 -1
- package/dist/expressions/identifiers.d.ts.map +1 -1
- package/dist/expressions/identifiers.js +3 -2
- package/dist/expressions/identifiers.js.map +1 -1
- package/dist/expressions/literals.d.ts +2 -1
- package/dist/expressions/literals.d.ts.map +1 -1
- package/dist/expressions/literals.js +10 -1
- package/dist/expressions/literals.js.map +1 -1
- package/dist/expressions/literals.test.d.ts +5 -0
- package/dist/expressions/literals.test.d.ts.map +1 -0
- package/dist/expressions/literals.test.js +155 -0
- package/dist/expressions/literals.test.js.map +1 -0
- package/dist/expressions/operators.d.ts +5 -1
- package/dist/expressions/operators.d.ts.map +1 -1
- package/dist/expressions/operators.js +8 -3
- package/dist/expressions/operators.js.map +1 -1
- package/dist/statements/blocks.d.ts +1 -0
- package/dist/statements/blocks.d.ts.map +1 -1
- package/dist/statements/blocks.js +3 -1
- package/dist/statements/blocks.js.map +1 -1
- package/dist/statements/classes/inline-types.d.ts.map +1 -1
- package/dist/statements/classes/inline-types.js +3 -1
- package/dist/statements/classes/inline-types.js.map +1 -1
- package/dist/statements/classes/members/methods.d.ts.map +1 -1
- package/dist/statements/classes/members/methods.js +22 -8
- package/dist/statements/classes/members/methods.js.map +1 -1
- package/dist/statements/classes/members/properties.d.ts.map +1 -1
- package/dist/statements/classes/members/properties.js +3 -2
- package/dist/statements/classes/members/properties.js.map +1 -1
- package/dist/statements/classes/parameters.d.ts.map +1 -1
- package/dist/statements/classes/parameters.js +4 -3
- package/dist/statements/classes/parameters.js.map +1 -1
- package/dist/statements/classes/properties.d.ts.map +1 -1
- package/dist/statements/classes/properties.js +5 -4
- package/dist/statements/classes/properties.js.map +1 -1
- package/dist/statements/control/loops.d.ts.map +1 -1
- package/dist/statements/control/loops.js +5 -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 +14 -7
- package/dist/statements/declarations/classes.js.map +1 -1
- package/dist/statements/declarations/enums.d.ts.map +1 -1
- package/dist/statements/declarations/enums.js +8 -4
- package/dist/statements/declarations/enums.js.map +1 -1
- package/dist/statements/declarations/functions.d.ts.map +1 -1
- package/dist/statements/declarations/functions.js +20 -6
- 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 +2 -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 +3 -2
- package/dist/statements/declarations/type-aliases.js.map +1 -1
- package/dist/statements/declarations/variables.d.ts.map +1 -1
- package/dist/statements/declarations/variables.js +7 -5
- package/dist/statements/declarations/variables.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.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type resolution helpers for generic null/default handling
|
|
3
|
+
*
|
|
4
|
+
* Provides:
|
|
5
|
+
* - containsTypeParameter: Check if type contains any type parameter
|
|
6
|
+
* - substituteTypeArgs: Substitute type arguments into a type
|
|
7
|
+
* - getPropertyType: Look up property type from contextual type
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Check if a type contains any type parameter.
|
|
11
|
+
*
|
|
12
|
+
* Uses both:
|
|
13
|
+
* 1. New IR kind "typeParameterType" (preferred)
|
|
14
|
+
* 2. Legacy detection via typeParams set (compatibility during migration)
|
|
15
|
+
*
|
|
16
|
+
* @param type - The IR type to check
|
|
17
|
+
* @param typeParams - Set of type parameter names in current scope
|
|
18
|
+
* @returns true if the type contains a type parameter
|
|
19
|
+
*/
|
|
20
|
+
export const containsTypeParameter = (type, typeParams) => {
|
|
21
|
+
switch (type.kind) {
|
|
22
|
+
case "typeParameterType":
|
|
23
|
+
// New IR kind - always a type parameter
|
|
24
|
+
return true;
|
|
25
|
+
case "referenceType":
|
|
26
|
+
// Legacy compatibility: check if name is in typeParams set
|
|
27
|
+
if (typeParams.has(type.name)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
// Recurse into type arguments
|
|
31
|
+
if (type.typeArguments) {
|
|
32
|
+
return type.typeArguments.some((arg) => containsTypeParameter(arg, typeParams));
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
case "arrayType":
|
|
36
|
+
return containsTypeParameter(type.elementType, typeParams);
|
|
37
|
+
case "dictionaryType":
|
|
38
|
+
return (containsTypeParameter(type.keyType, typeParams) ||
|
|
39
|
+
containsTypeParameter(type.valueType, typeParams));
|
|
40
|
+
case "unionType":
|
|
41
|
+
case "intersectionType":
|
|
42
|
+
return type.types.some((t) => containsTypeParameter(t, typeParams));
|
|
43
|
+
case "functionType":
|
|
44
|
+
if (containsTypeParameter(type.returnType, typeParams)) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
return type.parameters.some((p) => p.type && containsTypeParameter(p.type, typeParams));
|
|
48
|
+
case "objectType":
|
|
49
|
+
return type.members.some((m) => {
|
|
50
|
+
if (m.kind === "propertySignature") {
|
|
51
|
+
return containsTypeParameter(m.type, typeParams);
|
|
52
|
+
}
|
|
53
|
+
if (m.kind === "methodSignature") {
|
|
54
|
+
if (m.returnType && containsTypeParameter(m.returnType, typeParams)) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return m.parameters.some((p) => p.type && containsTypeParameter(p.type, typeParams));
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
});
|
|
61
|
+
case "primitiveType":
|
|
62
|
+
case "literalType":
|
|
63
|
+
case "anyType":
|
|
64
|
+
case "unknownType":
|
|
65
|
+
case "voidType":
|
|
66
|
+
case "neverType":
|
|
67
|
+
return false;
|
|
68
|
+
default: {
|
|
69
|
+
// Exhaustive check - this will error if a new IR type kind is added
|
|
70
|
+
const exhaustive = type;
|
|
71
|
+
void exhaustive;
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Substitute type arguments into a type.
|
|
78
|
+
*
|
|
79
|
+
* @param type - The type to substitute into
|
|
80
|
+
* @param typeParamNames - List of type parameter names (in order)
|
|
81
|
+
* @param typeArgs - List of type arguments (in order, parallel to typeParamNames)
|
|
82
|
+
* @returns The type with type parameters substituted
|
|
83
|
+
*/
|
|
84
|
+
export const substituteTypeArgs = (type, typeParamNames, typeArgs) => {
|
|
85
|
+
// Build mapping from name to type
|
|
86
|
+
const mapping = new Map();
|
|
87
|
+
for (let i = 0; i < typeParamNames.length && i < typeArgs.length; i++) {
|
|
88
|
+
const name = typeParamNames[i];
|
|
89
|
+
const arg = typeArgs[i];
|
|
90
|
+
if (name !== undefined && arg !== undefined) {
|
|
91
|
+
mapping.set(name, arg);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return substituteType(type, mapping);
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Internal helper for type substitution
|
|
98
|
+
*/
|
|
99
|
+
const substituteType = (type, mapping) => {
|
|
100
|
+
switch (type.kind) {
|
|
101
|
+
case "typeParameterType": {
|
|
102
|
+
const substitution = mapping.get(type.name);
|
|
103
|
+
return substitution ?? type;
|
|
104
|
+
}
|
|
105
|
+
case "referenceType": {
|
|
106
|
+
// Check if this is a type parameter (legacy representation)
|
|
107
|
+
const substitution = mapping.get(type.name);
|
|
108
|
+
if (substitution && !type.typeArguments) {
|
|
109
|
+
return substitution;
|
|
110
|
+
}
|
|
111
|
+
// Recurse into type arguments
|
|
112
|
+
if (type.typeArguments) {
|
|
113
|
+
return {
|
|
114
|
+
...type,
|
|
115
|
+
typeArguments: type.typeArguments.map((arg) => substituteType(arg, mapping)),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return type;
|
|
119
|
+
}
|
|
120
|
+
case "arrayType":
|
|
121
|
+
return {
|
|
122
|
+
...type,
|
|
123
|
+
elementType: substituteType(type.elementType, mapping),
|
|
124
|
+
};
|
|
125
|
+
case "dictionaryType":
|
|
126
|
+
return {
|
|
127
|
+
...type,
|
|
128
|
+
keyType: substituteType(type.keyType, mapping),
|
|
129
|
+
valueType: substituteType(type.valueType, mapping),
|
|
130
|
+
};
|
|
131
|
+
case "unionType":
|
|
132
|
+
return {
|
|
133
|
+
...type,
|
|
134
|
+
types: type.types.map((t) => substituteType(t, mapping)),
|
|
135
|
+
};
|
|
136
|
+
case "intersectionType":
|
|
137
|
+
return {
|
|
138
|
+
...type,
|
|
139
|
+
types: type.types.map((t) => substituteType(t, mapping)),
|
|
140
|
+
};
|
|
141
|
+
case "functionType":
|
|
142
|
+
return {
|
|
143
|
+
...type,
|
|
144
|
+
returnType: substituteType(type.returnType, mapping),
|
|
145
|
+
parameters: type.parameters.map((p) => p.type ? { ...p, type: substituteType(p.type, mapping) } : p),
|
|
146
|
+
};
|
|
147
|
+
case "objectType":
|
|
148
|
+
return {
|
|
149
|
+
...type,
|
|
150
|
+
members: type.members.map((m) => {
|
|
151
|
+
if (m.kind === "propertySignature") {
|
|
152
|
+
return { ...m, type: substituteType(m.type, mapping) };
|
|
153
|
+
}
|
|
154
|
+
if (m.kind === "methodSignature") {
|
|
155
|
+
return {
|
|
156
|
+
...m,
|
|
157
|
+
returnType: m.returnType
|
|
158
|
+
? substituteType(m.returnType, mapping)
|
|
159
|
+
: undefined,
|
|
160
|
+
parameters: m.parameters.map((p) => p.type ? { ...p, type: substituteType(p.type, mapping) } : p),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return m;
|
|
164
|
+
}),
|
|
165
|
+
};
|
|
166
|
+
case "primitiveType":
|
|
167
|
+
case "literalType":
|
|
168
|
+
case "anyType":
|
|
169
|
+
case "unknownType":
|
|
170
|
+
case "voidType":
|
|
171
|
+
case "neverType":
|
|
172
|
+
return type;
|
|
173
|
+
default: {
|
|
174
|
+
const exhaustive = type;
|
|
175
|
+
void exhaustive;
|
|
176
|
+
return type;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Look up property type from a contextual type.
|
|
182
|
+
*
|
|
183
|
+
* This handles:
|
|
184
|
+
* - Local types (class/interface/typeAlias) via localTypes map
|
|
185
|
+
* - Type alias chasing (follows alias.type until reaching a concrete type)
|
|
186
|
+
* - Interface extends resolution (searches base interfaces)
|
|
187
|
+
* - Generic type argument substitution
|
|
188
|
+
*
|
|
189
|
+
* @param contextualType - The contextual type (e.g., Result<T>)
|
|
190
|
+
* @param propertyName - The property name to look up
|
|
191
|
+
* @param context - Emitter context with localTypes
|
|
192
|
+
* @returns The property type after substitution, or undefined if not found
|
|
193
|
+
*/
|
|
194
|
+
export const getPropertyType = (contextualType, propertyName, context) => {
|
|
195
|
+
if (!contextualType || !context.localTypes) {
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
return resolvePropertyType(contextualType, propertyName, context.localTypes, []);
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Internal helper for property type resolution with cycle detection
|
|
202
|
+
*/
|
|
203
|
+
const resolvePropertyType = (type, propertyName, localTypes, visitedTypes) => {
|
|
204
|
+
// Handle reference types (most common case)
|
|
205
|
+
if (type.kind === "referenceType") {
|
|
206
|
+
const typeInfo = localTypes.get(type.name);
|
|
207
|
+
if (!typeInfo) {
|
|
208
|
+
// External type - cannot resolve property type
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
// Prevent cycles
|
|
212
|
+
if (visitedTypes.includes(type.name)) {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
const newVisited = [...visitedTypes, type.name];
|
|
216
|
+
// Chase type alias
|
|
217
|
+
if (typeInfo.kind === "typeAlias") {
|
|
218
|
+
const substituted = type.typeArguments
|
|
219
|
+
? substituteTypeArgs(typeInfo.type, typeInfo.typeParameters, type.typeArguments)
|
|
220
|
+
: typeInfo.type;
|
|
221
|
+
return resolvePropertyType(substituted, propertyName, localTypes, newVisited);
|
|
222
|
+
}
|
|
223
|
+
// Look up property in interface
|
|
224
|
+
if (typeInfo.kind === "interface") {
|
|
225
|
+
// Search own members first
|
|
226
|
+
const prop = findPropertyInMembers(typeInfo.members, propertyName);
|
|
227
|
+
if (prop) {
|
|
228
|
+
return type.typeArguments
|
|
229
|
+
? substituteTypeArgs(prop, typeInfo.typeParameters, type.typeArguments)
|
|
230
|
+
: prop;
|
|
231
|
+
}
|
|
232
|
+
// Search extended interfaces
|
|
233
|
+
for (const base of typeInfo.extends) {
|
|
234
|
+
const baseProp = resolvePropertyType(base, propertyName, localTypes, newVisited);
|
|
235
|
+
if (baseProp) {
|
|
236
|
+
return type.typeArguments
|
|
237
|
+
? substituteTypeArgs(baseProp, typeInfo.typeParameters, type.typeArguments)
|
|
238
|
+
: baseProp;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
// Look up property in class
|
|
244
|
+
if (typeInfo.kind === "class") {
|
|
245
|
+
const prop = findPropertyInClassMembers(typeInfo.members, propertyName);
|
|
246
|
+
if (prop) {
|
|
247
|
+
return type.typeArguments
|
|
248
|
+
? substituteTypeArgs(prop, typeInfo.typeParameters, type.typeArguments)
|
|
249
|
+
: prop;
|
|
250
|
+
}
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
// Handle object types directly
|
|
256
|
+
if (type.kind === "objectType") {
|
|
257
|
+
return findPropertyInMembers(type.members, propertyName);
|
|
258
|
+
}
|
|
259
|
+
return undefined;
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* Find property type in interface members
|
|
263
|
+
*/
|
|
264
|
+
const findPropertyInMembers = (members, propertyName) => {
|
|
265
|
+
for (const member of members) {
|
|
266
|
+
if (member.kind === "propertySignature" && member.name === propertyName) {
|
|
267
|
+
return member.type;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return undefined;
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Find property type in class members
|
|
274
|
+
*/
|
|
275
|
+
const findPropertyInClassMembers = (members, propertyName) => {
|
|
276
|
+
for (const member of members) {
|
|
277
|
+
if (member.kind === "propertyDeclaration" && member.name === propertyName) {
|
|
278
|
+
return member.type;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return undefined;
|
|
282
|
+
};
|
|
283
|
+
//# sourceMappingURL=type-resolution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-resolution.js","sourceRoot":"","sources":["../../src/core/type-resolution.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,IAAY,EACZ,UAA+B,EACtB,EAAE;IACX,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,mBAAmB;YACtB,wCAAwC;YACxC,OAAO,IAAI,CAAC;QAEd,KAAK,eAAe;YAClB,2DAA2D;YAC3D,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC9B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,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,MAAM,CAAC,IAAI,KAAK,qBAAqB,IAAI,MAAM,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAC1E,OAAO,MAAM,CAAC,IAAI,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-resolution.test.d.ts","sourceRoot":"","sources":["../../src/core/type-resolution.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for type resolution helpers
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it } from "mocha";
|
|
5
|
+
import { expect } from "chai";
|
|
6
|
+
import { containsTypeParameter, substituteTypeArgs, getPropertyType, } from "./type-resolution.js";
|
|
7
|
+
describe("type-resolution", () => {
|
|
8
|
+
describe("containsTypeParameter", () => {
|
|
9
|
+
it("returns true for typeParameterType IR kind", () => {
|
|
10
|
+
const type = { kind: "typeParameterType", name: "T" };
|
|
11
|
+
const typeParams = new Set();
|
|
12
|
+
expect(containsTypeParameter(type, typeParams)).to.be.true;
|
|
13
|
+
});
|
|
14
|
+
it("returns true for referenceType matching typeParams set (legacy)", () => {
|
|
15
|
+
const type = { kind: "referenceType", name: "T" };
|
|
16
|
+
const typeParams = new Set(["T"]);
|
|
17
|
+
expect(containsTypeParameter(type, typeParams)).to.be.true;
|
|
18
|
+
});
|
|
19
|
+
it("returns false for referenceType not in typeParams set", () => {
|
|
20
|
+
const type = { kind: "referenceType", name: "string" };
|
|
21
|
+
const typeParams = new Set(["T"]);
|
|
22
|
+
expect(containsTypeParameter(type, typeParams)).to.be.false;
|
|
23
|
+
});
|
|
24
|
+
it("returns true for Array<T> containing type parameter", () => {
|
|
25
|
+
const type = {
|
|
26
|
+
kind: "referenceType",
|
|
27
|
+
name: "Array",
|
|
28
|
+
typeArguments: [{ kind: "typeParameterType", name: "T" }],
|
|
29
|
+
};
|
|
30
|
+
const typeParams = new Set();
|
|
31
|
+
expect(containsTypeParameter(type, typeParams)).to.be.true;
|
|
32
|
+
});
|
|
33
|
+
it("returns false for Array<string> (concrete type)", () => {
|
|
34
|
+
const type = {
|
|
35
|
+
kind: "referenceType",
|
|
36
|
+
name: "Array",
|
|
37
|
+
typeArguments: [{ kind: "primitiveType", name: "string" }],
|
|
38
|
+
};
|
|
39
|
+
const typeParams = new Set();
|
|
40
|
+
expect(containsTypeParameter(type, typeParams)).to.be.false;
|
|
41
|
+
});
|
|
42
|
+
it("returns true for arrayType with type parameter element", () => {
|
|
43
|
+
const type = {
|
|
44
|
+
kind: "arrayType",
|
|
45
|
+
elementType: { kind: "typeParameterType", name: "T" },
|
|
46
|
+
};
|
|
47
|
+
const typeParams = new Set();
|
|
48
|
+
expect(containsTypeParameter(type, typeParams)).to.be.true;
|
|
49
|
+
});
|
|
50
|
+
it("returns true for union type containing type parameter", () => {
|
|
51
|
+
const type = {
|
|
52
|
+
kind: "unionType",
|
|
53
|
+
types: [
|
|
54
|
+
{ kind: "primitiveType", name: "string" },
|
|
55
|
+
{ kind: "typeParameterType", name: "T" },
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
const typeParams = new Set();
|
|
59
|
+
expect(containsTypeParameter(type, typeParams)).to.be.true;
|
|
60
|
+
});
|
|
61
|
+
it("returns false for primitive types", () => {
|
|
62
|
+
const type = { kind: "primitiveType", name: "number" };
|
|
63
|
+
const typeParams = new Set(["T"]);
|
|
64
|
+
expect(containsTypeParameter(type, typeParams)).to.be.false;
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe("substituteTypeArgs", () => {
|
|
68
|
+
it("substitutes simple type parameter", () => {
|
|
69
|
+
const type = { kind: "typeParameterType", name: "T" };
|
|
70
|
+
const typeParamNames = ["T"];
|
|
71
|
+
const typeArgs = [{ kind: "primitiveType", name: "string" }];
|
|
72
|
+
const result = substituteTypeArgs(type, typeParamNames, typeArgs);
|
|
73
|
+
expect(result).to.deep.equal({ kind: "primitiveType", name: "string" });
|
|
74
|
+
});
|
|
75
|
+
it("substitutes type parameter in referenceType (legacy)", () => {
|
|
76
|
+
const type = { kind: "referenceType", name: "T" };
|
|
77
|
+
const typeParamNames = ["T"];
|
|
78
|
+
const typeArgs = [{ kind: "primitiveType", name: "number" }];
|
|
79
|
+
const result = substituteTypeArgs(type, typeParamNames, typeArgs);
|
|
80
|
+
expect(result).to.deep.equal({ kind: "primitiveType", name: "number" });
|
|
81
|
+
});
|
|
82
|
+
it("substitutes type argument in generic reference", () => {
|
|
83
|
+
const type = {
|
|
84
|
+
kind: "referenceType",
|
|
85
|
+
name: "Array",
|
|
86
|
+
typeArguments: [{ kind: "typeParameterType", name: "T" }],
|
|
87
|
+
};
|
|
88
|
+
const typeParamNames = ["T"];
|
|
89
|
+
const typeArgs = [{ kind: "primitiveType", name: "string" }];
|
|
90
|
+
const result = substituteTypeArgs(type, typeParamNames, typeArgs);
|
|
91
|
+
expect(result).to.deep.equal({
|
|
92
|
+
kind: "referenceType",
|
|
93
|
+
name: "Array",
|
|
94
|
+
typeArguments: [{ kind: "primitiveType", name: "string" }],
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
it("substitutes in array element type", () => {
|
|
98
|
+
const type = {
|
|
99
|
+
kind: "arrayType",
|
|
100
|
+
elementType: { kind: "typeParameterType", name: "T" },
|
|
101
|
+
};
|
|
102
|
+
const typeParamNames = ["T"];
|
|
103
|
+
const typeArgs = [{ kind: "primitiveType", name: "boolean" }];
|
|
104
|
+
const result = substituteTypeArgs(type, typeParamNames, typeArgs);
|
|
105
|
+
expect(result).to.deep.equal({
|
|
106
|
+
kind: "arrayType",
|
|
107
|
+
elementType: { kind: "primitiveType", name: "boolean" },
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
it("returns unchanged type when no matching type param", () => {
|
|
111
|
+
const type = { kind: "referenceType", name: "SomeType" };
|
|
112
|
+
const typeParamNames = ["T"];
|
|
113
|
+
const typeArgs = [{ kind: "primitiveType", name: "string" }];
|
|
114
|
+
const result = substituteTypeArgs(type, typeParamNames, typeArgs);
|
|
115
|
+
expect(result).to.deep.equal({ kind: "referenceType", name: "SomeType" });
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe("getPropertyType", () => {
|
|
119
|
+
const defaultOptions = {
|
|
120
|
+
rootNamespace: "Test",
|
|
121
|
+
indent: 4,
|
|
122
|
+
};
|
|
123
|
+
const createContext = (localTypes) => ({
|
|
124
|
+
indentLevel: 0,
|
|
125
|
+
options: defaultOptions,
|
|
126
|
+
isStatic: false,
|
|
127
|
+
isAsync: false,
|
|
128
|
+
localTypes,
|
|
129
|
+
});
|
|
130
|
+
it("returns property type from interface", () => {
|
|
131
|
+
const members = [
|
|
132
|
+
{
|
|
133
|
+
kind: "propertySignature",
|
|
134
|
+
name: "value",
|
|
135
|
+
type: { kind: "typeParameterType", name: "T" },
|
|
136
|
+
isOptional: false,
|
|
137
|
+
isReadonly: false,
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
const localTypes = new Map([
|
|
141
|
+
[
|
|
142
|
+
"Result",
|
|
143
|
+
{
|
|
144
|
+
kind: "interface",
|
|
145
|
+
typeParameters: ["T"],
|
|
146
|
+
members,
|
|
147
|
+
extends: [],
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
]);
|
|
151
|
+
const contextualType = {
|
|
152
|
+
kind: "referenceType",
|
|
153
|
+
name: "Result",
|
|
154
|
+
typeArguments: [{ kind: "primitiveType", name: "string" }],
|
|
155
|
+
};
|
|
156
|
+
const context = createContext(localTypes);
|
|
157
|
+
const result = getPropertyType(contextualType, "value", context);
|
|
158
|
+
// After substitution, T becomes string
|
|
159
|
+
expect(result).to.deep.equal({ kind: "primitiveType", name: "string" });
|
|
160
|
+
});
|
|
161
|
+
it("returns undefined for unknown property", () => {
|
|
162
|
+
const members = [
|
|
163
|
+
{
|
|
164
|
+
kind: "propertySignature",
|
|
165
|
+
name: "value",
|
|
166
|
+
type: { kind: "typeParameterType", name: "T" },
|
|
167
|
+
isOptional: false,
|
|
168
|
+
isReadonly: false,
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
const localTypes = new Map([
|
|
172
|
+
[
|
|
173
|
+
"Result",
|
|
174
|
+
{
|
|
175
|
+
kind: "interface",
|
|
176
|
+
typeParameters: ["T"],
|
|
177
|
+
members,
|
|
178
|
+
extends: [],
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
]);
|
|
182
|
+
const contextualType = {
|
|
183
|
+
kind: "referenceType",
|
|
184
|
+
name: "Result",
|
|
185
|
+
typeArguments: [{ kind: "primitiveType", name: "string" }],
|
|
186
|
+
};
|
|
187
|
+
const context = createContext(localTypes);
|
|
188
|
+
const result = getPropertyType(contextualType, "unknown", context);
|
|
189
|
+
expect(result).to.be.undefined;
|
|
190
|
+
});
|
|
191
|
+
it("returns undefined for unknown type", () => {
|
|
192
|
+
const localTypes = new Map();
|
|
193
|
+
const contextualType = {
|
|
194
|
+
kind: "referenceType",
|
|
195
|
+
name: "ExternalType",
|
|
196
|
+
};
|
|
197
|
+
const context = createContext(localTypes);
|
|
198
|
+
const result = getPropertyType(contextualType, "value", context);
|
|
199
|
+
expect(result).to.be.undefined;
|
|
200
|
+
});
|
|
201
|
+
it("returns unsubstituted type when no type arguments", () => {
|
|
202
|
+
const members = [
|
|
203
|
+
{
|
|
204
|
+
kind: "propertySignature",
|
|
205
|
+
name: "value",
|
|
206
|
+
type: { kind: "typeParameterType", name: "T" },
|
|
207
|
+
isOptional: false,
|
|
208
|
+
isReadonly: false,
|
|
209
|
+
},
|
|
210
|
+
];
|
|
211
|
+
const localTypes = new Map([
|
|
212
|
+
[
|
|
213
|
+
"Result",
|
|
214
|
+
{
|
|
215
|
+
kind: "interface",
|
|
216
|
+
typeParameters: ["T"],
|
|
217
|
+
members,
|
|
218
|
+
extends: [],
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
]);
|
|
222
|
+
const contextualType = {
|
|
223
|
+
kind: "referenceType",
|
|
224
|
+
name: "Result",
|
|
225
|
+
// No typeArguments - using raw generic type
|
|
226
|
+
};
|
|
227
|
+
const context = createContext(localTypes);
|
|
228
|
+
const result = getPropertyType(contextualType, "value", context);
|
|
229
|
+
// Returns unsubstituted T
|
|
230
|
+
expect(result).to.deep.equal({ kind: "typeParameterType", name: "T" });
|
|
231
|
+
});
|
|
232
|
+
it("chases type alias", () => {
|
|
233
|
+
const members = [
|
|
234
|
+
{
|
|
235
|
+
kind: "propertySignature",
|
|
236
|
+
name: "data",
|
|
237
|
+
type: { kind: "primitiveType", name: "string" },
|
|
238
|
+
isOptional: false,
|
|
239
|
+
isReadonly: false,
|
|
240
|
+
},
|
|
241
|
+
];
|
|
242
|
+
const localTypes = new Map([
|
|
243
|
+
[
|
|
244
|
+
"MyAlias",
|
|
245
|
+
{
|
|
246
|
+
kind: "typeAlias",
|
|
247
|
+
typeParameters: [],
|
|
248
|
+
type: { kind: "referenceType", name: "Target" },
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
[
|
|
252
|
+
"Target",
|
|
253
|
+
{
|
|
254
|
+
kind: "interface",
|
|
255
|
+
typeParameters: [],
|
|
256
|
+
members,
|
|
257
|
+
extends: [],
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
]);
|
|
261
|
+
const contextualType = {
|
|
262
|
+
kind: "referenceType",
|
|
263
|
+
name: "MyAlias",
|
|
264
|
+
};
|
|
265
|
+
const context = createContext(localTypes);
|
|
266
|
+
const result = getPropertyType(contextualType, "data", context);
|
|
267
|
+
expect(result).to.deep.equal({ kind: "primitiveType", name: "string" });
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
//# sourceMappingURL=type-resolution.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-resolution.test.js","sourceRoot":"","sources":["../../src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,EAAE,IAAI,EAAE,QAAQ,EAAE;oBAC/C,UAAU,EAAE,KAAK;oBACjB,UAAU,EAAE,KAAK;iBAClB;aACF,CAAC;YAEF,MAAM,UAAU,GAAG,IAAI,GAAG,CAAwB;gBAChD;oBACE,SAAS;oBACT;wBACE,IAAI,EAAE,WAAW;wBACjB,cAAc,EAAE,EAAE;wBAClB,IAAI,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE;qBAChD;iBACF;gBACD;oBACE,QAAQ;oBACR;wBACE,IAAI,EAAE,WAAW;wBACjB,cAAc,EAAE,EAAE;wBAClB,OAAO;wBACP,OAAO,EAAE,EAAE;qBACZ;iBACF;aACF,CAAC,CAAC;YAEH,MAAM,cAAc,GAAW;gBAC7B,IAAI,EAAE,eAAe;gBACrB,IAAI,EAAE,SAAS;aAChB,CAAC;YAEF,MAAM,OAAO,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;YAC1C,MAAM,MAAM,GAAG,eAAe,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YAEhE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -26,4 +26,33 @@ export declare const withAsync: (context: EmitterContext, isAsync: boolean) => E
|
|
|
26
26
|
* Set current class name in context
|
|
27
27
|
*/
|
|
28
28
|
export declare const withClassName: (context: EmitterContext, className: string) => EmitterContext;
|
|
29
|
+
/**
|
|
30
|
+
* Scoped fields that should be restored after emission.
|
|
31
|
+
* These fields define lexical scopes and should not leak to parent scopes.
|
|
32
|
+
*/
|
|
33
|
+
type ScopedFields = Pick<EmitterContext, "typeParameters" | "returnType">;
|
|
34
|
+
/**
|
|
35
|
+
* Execute an emission function with scoped context fields.
|
|
36
|
+
*
|
|
37
|
+
* This helper ensures that scoped fields (typeParameters, returnType) are
|
|
38
|
+
* restored after emission, preventing scope leaks when context is threaded
|
|
39
|
+
* upward via [result, newContext] tuples.
|
|
40
|
+
*
|
|
41
|
+
* Other context mutations (intLoopVars, importBindings, etc.) are preserved
|
|
42
|
+
* and bubbled up correctly.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const [result, finalCtx] = withScoped(
|
|
47
|
+
* context,
|
|
48
|
+
* {
|
|
49
|
+
* typeParameters: new Set([...context.typeParameters ?? [], "T"]),
|
|
50
|
+
* returnType: stmt.returnType
|
|
51
|
+
* },
|
|
52
|
+
* (scopedCtx) => emitFunctionBody(stmt.body, scopedCtx)
|
|
53
|
+
* );
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare const withScoped: <T>(context: EmitterContext, scopedPatch: Partial<ScopedFields>, emit: (ctx: EmitterContext) => [T, EmitterContext]) => [T, EmitterContext];
|
|
57
|
+
export {};
|
|
29
58
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/emitter-types/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAM3D;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,cAAc,KAAG,cA4BvD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,SAAS,cAAc,KAAG,cAG/C,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,SAAS,cAAc,KAAG,cAG/C,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,UAAU,GACrB,SAAS,cAAc,EACvB,UAAU,OAAO,KAChB,cAGD,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,SAAS,GACpB,SAA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