@tsonic/frontend 0.0.12 → 0.0.14
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/ir/converters/expressions/access.d.ts.map +1 -1
- package/dist/ir/converters/expressions/access.js +61 -1
- package/dist/ir/converters/expressions/access.js.map +1 -1
- package/dist/ir/converters/expressions/calls.d.ts +2 -2
- package/dist/ir/converters/expressions/calls.d.ts.map +1 -1
- package/dist/ir/converters/expressions/calls.js +318 -24
- package/dist/ir/converters/expressions/calls.js.map +1 -1
- package/dist/ir/converters/expressions/helpers.js +4 -4
- package/dist/ir/converters/expressions/helpers.js.map +1 -1
- package/dist/ir/converters/expressions/literals.d.ts +14 -0
- package/dist/ir/converters/expressions/literals.d.ts.map +1 -1
- package/dist/ir/converters/expressions/literals.js +22 -2
- package/dist/ir/converters/expressions/literals.js.map +1 -1
- package/dist/ir/converters/expressions/numeric-recovery.test.js +3 -2
- package/dist/ir/converters/expressions/numeric-recovery.test.js.map +1 -1
- package/dist/ir/converters/statements/helpers.d.ts.map +1 -1
- package/dist/ir/converters/statements/helpers.js +10 -4
- package/dist/ir/converters/statements/helpers.js.map +1 -1
- package/dist/ir/expression-converter.d.ts.map +1 -1
- package/dist/ir/expression-converter.js +59 -7
- package/dist/ir/expression-converter.js.map +1 -1
- package/dist/ir/index.d.ts +1 -1
- package/dist/ir/index.d.ts.map +1 -1
- package/dist/ir/index.js +1 -1
- package/dist/ir/index.js.map +1 -1
- package/dist/ir/statement-converter.d.ts.map +1 -1
- package/dist/ir/statement-converter.js +12 -0
- package/dist/ir/statement-converter.js.map +1 -1
- package/dist/ir/type-converter/inference.d.ts.map +1 -1
- package/dist/ir/type-converter/inference.js +50 -7
- package/dist/ir/type-converter/inference.js.map +1 -1
- package/dist/ir/type-converter/primitives.d.ts +26 -4
- package/dist/ir/type-converter/primitives.d.ts.map +1 -1
- package/dist/ir/type-converter/primitives.js +36 -2
- package/dist/ir/type-converter/primitives.js.map +1 -1
- package/dist/ir/type-converter/references.d.ts.map +1 -1
- package/dist/ir/type-converter/references.js +324 -11
- package/dist/ir/type-converter/references.js.map +1 -1
- package/dist/ir/type-converter/utility-types.d.ts +93 -0
- package/dist/ir/type-converter/utility-types.d.ts.map +1 -0
- package/dist/ir/type-converter/utility-types.js +528 -0
- package/dist/ir/type-converter/utility-types.js.map +1 -0
- package/dist/ir/type-converter/utility-types.test.d.ts +10 -0
- package/dist/ir/type-converter/utility-types.test.d.ts.map +1 -0
- package/dist/ir/type-converter/utility-types.test.js +1030 -0
- package/dist/ir/type-converter/utility-types.test.js.map +1 -0
- package/dist/ir/types/expressions.d.ts +87 -3
- package/dist/ir/types/expressions.d.ts.map +1 -1
- package/dist/ir/types/helpers.d.ts +3 -1
- package/dist/ir/types/helpers.d.ts.map +1 -1
- package/dist/ir/types/index.d.ts +3 -2
- package/dist/ir/types/index.d.ts.map +1 -1
- package/dist/ir/types/index.js +2 -0
- package/dist/ir/types/index.js.map +1 -1
- package/dist/ir/types/ir-types.d.ts +69 -11
- package/dist/ir/types/ir-types.d.ts.map +1 -1
- package/dist/ir/types/numeric-helpers.d.ts +46 -0
- package/dist/ir/types/numeric-helpers.d.ts.map +1 -0
- package/dist/ir/types/numeric-helpers.js +105 -0
- package/dist/ir/types/numeric-helpers.js.map +1 -0
- package/dist/ir/types/statements.d.ts +11 -1
- package/dist/ir/types/statements.d.ts.map +1 -1
- package/dist/ir/types.d.ts +2 -2
- package/dist/ir/types.d.ts.map +1 -1
- package/dist/ir/types.js +3 -1
- package/dist/ir/types.js.map +1 -1
- package/dist/ir/validation/anonymous-type-lowering-pass.d.ts +32 -0
- package/dist/ir/validation/anonymous-type-lowering-pass.d.ts.map +1 -0
- package/dist/ir/validation/anonymous-type-lowering-pass.js +868 -0
- package/dist/ir/validation/anonymous-type-lowering-pass.js.map +1 -0
- package/dist/ir/validation/attribute-collection-pass.d.ts +37 -0
- package/dist/ir/validation/attribute-collection-pass.d.ts.map +1 -0
- package/dist/ir/validation/attribute-collection-pass.js +282 -0
- package/dist/ir/validation/attribute-collection-pass.js.map +1 -0
- package/dist/ir/validation/attribute-collection-pass.test.d.ts +5 -0
- package/dist/ir/validation/attribute-collection-pass.test.d.ts.map +1 -0
- package/dist/ir/validation/attribute-collection-pass.test.js +215 -0
- package/dist/ir/validation/attribute-collection-pass.test.js.map +1 -0
- package/dist/ir/validation/index.d.ts +3 -0
- package/dist/ir/validation/index.d.ts.map +1 -1
- package/dist/ir/validation/index.js +3 -0
- package/dist/ir/validation/index.js.map +1 -1
- package/dist/ir/validation/numeric-coercion-pass.d.ts +77 -0
- package/dist/ir/validation/numeric-coercion-pass.d.ts.map +1 -0
- package/dist/ir/validation/numeric-coercion-pass.js +686 -0
- package/dist/ir/validation/numeric-coercion-pass.js.map +1 -0
- package/dist/ir/validation/numeric-invariants.test.js +130 -14
- package/dist/ir/validation/numeric-invariants.test.js.map +1 -1
- package/dist/ir/validation/numeric-proof-pass.d.ts.map +1 -1
- package/dist/ir/validation/numeric-proof-pass.js +68 -108
- package/dist/ir/validation/numeric-proof-pass.js.map +1 -1
- package/dist/ir/validation/soundness-gate.d.ts.map +1 -1
- package/dist/ir/validation/soundness-gate.js +23 -12
- package/dist/ir/validation/soundness-gate.js.map +1 -1
- package/dist/ir/validation/yield-lowering-pass.test.js +21 -12
- package/dist/ir/validation/yield-lowering-pass.test.js.map +1 -1
- package/dist/program/bindings.d.ts +20 -9
- package/dist/program/bindings.d.ts.map +1 -1
- package/dist/program/bindings.js +98 -36
- package/dist/program/bindings.js.map +1 -1
- package/dist/program/bindings.test.js +3 -3
- package/dist/program/dependency-graph.d.ts.map +1 -1
- package/dist/program/dependency-graph.js +31 -5
- package/dist/program/dependency-graph.js.map +1 -1
- package/dist/resolver/import-resolution.d.ts +4 -0
- package/dist/resolver/import-resolution.d.ts.map +1 -1
- package/dist/resolver/import-resolution.js +18 -7
- package/dist/resolver/import-resolution.js.map +1 -1
- package/dist/resolver.test.js +2 -2
- package/dist/resolver.test.js.map +1 -1
- package/dist/types/diagnostic.d.ts +1 -1
- package/dist/types/diagnostic.d.ts.map +1 -1
- package/dist/types/diagnostic.js.map +1 -1
- package/dist/validation/generics.d.ts.map +1 -1
- package/dist/validation/generics.js +133 -1
- package/dist/validation/generics.js.map +1 -1
- package/dist/validation/static-safety.js +13 -0
- package/dist/validation/static-safety.js.map +1 -1
- package/dist/validation/unsupported-utility-types.d.ts +10 -8
- package/dist/validation/unsupported-utility-types.d.ts.map +1 -1
- package/dist/validation/unsupported-utility-types.js +12 -19
- package/dist/validation/unsupported-utility-types.js.map +1 -1
- package/dist/validator.test.js +133 -28
- package/dist/validator.test.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../../../src/ir/type-converter/references.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,
|
|
1
|
+
{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../../../src/ir/type-converter/references.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EACL,MAAM,EAKP,MAAM,aAAa,CAAC;AA2UrB;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAC/B,MAAM,EAAE,CAAC,iBAAiB,EAC1B,SAAS,EAAE,CAAC,WAAW,EACvB,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,KAAK,MAAM,KAClE,MAmIF,CAAC"}
|
|
@@ -2,7 +2,262 @@
|
|
|
2
2
|
* Reference type conversion
|
|
3
3
|
*/
|
|
4
4
|
import * as ts from "typescript";
|
|
5
|
-
import { isPrimitiveTypeName, getPrimitiveType } from "./primitives.js";
|
|
5
|
+
import { isPrimitiveTypeName, getPrimitiveType, isClrPrimitiveTypeName, getClrPrimitiveType, CLR_PRIMITIVE_TYPE_SET, } from "./primitives.js";
|
|
6
|
+
import { isExpandableUtilityType, expandUtilityType, isExpandableConditionalUtilityType, expandConditionalUtilityType, expandRecordType, } from "./utility-types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Cache for structural member extraction to prevent infinite recursion
|
|
9
|
+
* on recursive types like `type Node = { next: Node }`.
|
|
10
|
+
*
|
|
11
|
+
* Key: ts.Type (by identity)
|
|
12
|
+
* Value: extracted members, null (not extractable), or "in-progress" sentinel
|
|
13
|
+
*/
|
|
14
|
+
const structuralMembersCache = new WeakMap();
|
|
15
|
+
/**
|
|
16
|
+
* Check if a type should have structural members extracted.
|
|
17
|
+
*
|
|
18
|
+
* Only extract for:
|
|
19
|
+
* - Interfaces (InterfaceDeclaration)
|
|
20
|
+
* - Type aliases to object types (TypeAliasDeclaration)
|
|
21
|
+
*
|
|
22
|
+
* Do NOT extract for:
|
|
23
|
+
* - Classes (have implementation, not just shape)
|
|
24
|
+
* - Enums, namespaces
|
|
25
|
+
* - Library types (from node_modules or lib.*.d.ts)
|
|
26
|
+
* - CLR interop types
|
|
27
|
+
* - Union/intersection types (ambiguous property semantics)
|
|
28
|
+
*/
|
|
29
|
+
const shouldExtractStructuralMembers = (resolvedType, _checker) => {
|
|
30
|
+
// Don't extract for type parameters
|
|
31
|
+
if (resolvedType.flags & ts.TypeFlags.TypeParameter) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
// Don't extract for union types (ambiguous property semantics)
|
|
35
|
+
if (resolvedType.isUnion()) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
// Don't extract for intersection types (conservative)
|
|
39
|
+
if (resolvedType.isIntersection()) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
// Check the symbol to determine if this is a structural type we should extract
|
|
43
|
+
const symbol = resolvedType.getSymbol();
|
|
44
|
+
if (!symbol) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const declarations = symbol.getDeclarations();
|
|
48
|
+
if (!declarations || declarations.length === 0) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
// Check if ANY declaration is from a library file (node_modules or lib.*.d.ts)
|
|
52
|
+
for (const decl of declarations) {
|
|
53
|
+
const sourceFile = decl.getSourceFile();
|
|
54
|
+
const fileName = sourceFile.fileName;
|
|
55
|
+
// Skip library types
|
|
56
|
+
if (fileName.includes("node_modules") ||
|
|
57
|
+
fileName.includes("lib.") ||
|
|
58
|
+
sourceFile.isDeclarationFile) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Check the first declaration to determine type
|
|
63
|
+
const firstDecl = declarations[0];
|
|
64
|
+
if (!firstDecl) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
// Only extract for interfaces and type aliases
|
|
68
|
+
if (ts.isInterfaceDeclaration(firstDecl)) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (ts.isTypeAliasDeclaration(firstDecl)) {
|
|
72
|
+
// Only extract if the alias resolves to an object-like type
|
|
73
|
+
// (has properties, not a primitive/union/etc)
|
|
74
|
+
const properties = resolvedType.getProperties();
|
|
75
|
+
return properties !== undefined && properties.length > 0;
|
|
76
|
+
}
|
|
77
|
+
// TypeLiteral: When a type alias resolves to an object type like `type Config = { x: number }`,
|
|
78
|
+
// TypeScript's getTypeAtLocation returns the underlying object type, whose declaration is TypeLiteral.
|
|
79
|
+
// We need to extract structural members in this case too.
|
|
80
|
+
if (ts.isTypeLiteralNode(firstDecl)) {
|
|
81
|
+
const properties = resolvedType.getProperties();
|
|
82
|
+
return properties !== undefined && properties.length > 0;
|
|
83
|
+
}
|
|
84
|
+
// Don't extract for classes, enums, etc.
|
|
85
|
+
return false;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Extract structural members from a resolved type.
|
|
89
|
+
*
|
|
90
|
+
* Used to populate structuralMembers on referenceType for interfaces and type aliases.
|
|
91
|
+
* This enables TSN5110 validation for object literal properties against expected types.
|
|
92
|
+
*
|
|
93
|
+
* Safety guards:
|
|
94
|
+
* - Only extracts for interfaces/type-aliases (not classes, enums, lib types)
|
|
95
|
+
* - Uses cache to prevent infinite recursion on recursive types
|
|
96
|
+
* - Skips unsupported keys instead of bailing entirely
|
|
97
|
+
* - Returns undefined for union/intersection (conservative)
|
|
98
|
+
* - Returns undefined for index signatures (can't fully represent)
|
|
99
|
+
*
|
|
100
|
+
* @param resolvedType - The resolved TypeScript type
|
|
101
|
+
* @param node - The enclosing node for type-to-node conversion
|
|
102
|
+
* @param checker - The TypeScript type checker
|
|
103
|
+
* @param convertType - Function to convert nested types
|
|
104
|
+
* @returns Structural members or undefined if extraction fails/skipped
|
|
105
|
+
*/
|
|
106
|
+
const extractStructuralMembers = (resolvedType, node, checker, convertType) => {
|
|
107
|
+
// Check cache first (handles recursion)
|
|
108
|
+
const cached = structuralMembersCache.get(resolvedType);
|
|
109
|
+
if (cached === "in-progress") {
|
|
110
|
+
// Recursive reference - return undefined to break cycle
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
if (cached !== undefined) {
|
|
114
|
+
return cached === null ? undefined : cached;
|
|
115
|
+
}
|
|
116
|
+
// Gate: only extract for structural types we own
|
|
117
|
+
if (!shouldExtractStructuralMembers(resolvedType, checker)) {
|
|
118
|
+
structuralMembersCache.set(resolvedType, null);
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
// Mark as in-progress before recursing.
|
|
122
|
+
// IMPORTANT: Use try/finally to ensure cache is always settled.
|
|
123
|
+
// If typeToTypeNode() or convertType() throws, we must not leave
|
|
124
|
+
// "in-progress" in the cache (would cause future lookups to fail).
|
|
125
|
+
structuralMembersCache.set(resolvedType, "in-progress");
|
|
126
|
+
try {
|
|
127
|
+
// Get properties
|
|
128
|
+
const properties = resolvedType.getProperties();
|
|
129
|
+
if (!properties || properties.length === 0) {
|
|
130
|
+
structuralMembersCache.set(resolvedType, null);
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
// Check for index signatures - can't fully represent these structurally
|
|
134
|
+
const stringIndexType = checker.getIndexInfoOfType(resolvedType, ts.IndexKind.String);
|
|
135
|
+
const numberIndexType = checker.getIndexInfoOfType(resolvedType, ts.IndexKind.Number);
|
|
136
|
+
if (stringIndexType || numberIndexType) {
|
|
137
|
+
structuralMembersCache.set(resolvedType, null);
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
// Extract members
|
|
141
|
+
const members = [];
|
|
142
|
+
for (const prop of properties) {
|
|
143
|
+
const propName = prop.getName();
|
|
144
|
+
// Skip non-string keys (symbols, computed) - don't bail entirely
|
|
145
|
+
if (propName.startsWith("__@") || propName.startsWith("[")) {
|
|
146
|
+
continue; // Skip this property, keep extracting others
|
|
147
|
+
}
|
|
148
|
+
const propType = checker.getTypeOfSymbolAtLocation(prop, node);
|
|
149
|
+
const declarations = prop.getDeclarations();
|
|
150
|
+
// Check optional/readonly
|
|
151
|
+
const isOptional = (prop.flags & ts.SymbolFlags.Optional) !== 0;
|
|
152
|
+
const isReadonly = declarations?.some((decl) => {
|
|
153
|
+
if (ts.isPropertySignature(decl) || ts.isPropertyDeclaration(decl)) {
|
|
154
|
+
return (decl.modifiers?.some((m) => m.kind === ts.SyntaxKind.ReadonlyKeyword) ?? false);
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}) ?? false;
|
|
158
|
+
// Check if it's a method
|
|
159
|
+
const isMethod = declarations?.some((decl) => ts.isMethodSignature(decl) || ts.isMethodDeclaration(decl)) ?? false;
|
|
160
|
+
// IMPORTANT: Check for CLR primitive type aliases BEFORE calling typeToTypeNode.
|
|
161
|
+
// TypeScript eagerly resolves type aliases like `int` to their underlying type `number`
|
|
162
|
+
// when converting to TypeNode. We need to preserve the alias identity for CLR primitives
|
|
163
|
+
// so that TSN5110 correctly validates `int` properties accept `int` values.
|
|
164
|
+
//
|
|
165
|
+
// The propType.aliasSymbol approach doesn't work because getTypeOfSymbolAtLocation
|
|
166
|
+
// returns the resolved type without alias info. Instead, we look at the property
|
|
167
|
+
// declaration's type node directly to see the original type reference.
|
|
168
|
+
//
|
|
169
|
+
// Only preserve alias identity when:
|
|
170
|
+
// 1. The type reference name is a known CLR primitive (e.g., "int")
|
|
171
|
+
// 2. The type reference resolves to @tsonic/core (not a random user alias)
|
|
172
|
+
const propDecl = declarations?.[0];
|
|
173
|
+
if (propDecl &&
|
|
174
|
+
(ts.isPropertySignature(propDecl) || ts.isPropertyDeclaration(propDecl))) {
|
|
175
|
+
const declTypeNode = propDecl.type;
|
|
176
|
+
// Check if the declared type is a type reference to a CLR primitive
|
|
177
|
+
if (declTypeNode && ts.isTypeReferenceNode(declTypeNode)) {
|
|
178
|
+
const typeName = ts.isIdentifier(declTypeNode.typeName)
|
|
179
|
+
? declTypeNode.typeName.text
|
|
180
|
+
: undefined;
|
|
181
|
+
if (typeName && CLR_PRIMITIVE_TYPE_SET.has(typeName)) {
|
|
182
|
+
// Resolve the type reference to check it comes from @tsonic/core
|
|
183
|
+
// For type aliases like `int`, we need to get the symbol from the type name identifier
|
|
184
|
+
// and follow any aliases (imports) to the original declaration
|
|
185
|
+
const typeNameNode = declTypeNode.typeName;
|
|
186
|
+
const typeSymbolRaw = ts.isIdentifier(typeNameNode)
|
|
187
|
+
? checker.getSymbolAtLocation(typeNameNode)
|
|
188
|
+
: undefined;
|
|
189
|
+
// Follow alias chain to get the original symbol (handles re-exports/imports)
|
|
190
|
+
const typeSymbol = typeSymbolRaw
|
|
191
|
+
? checker.getAliasedSymbol(typeSymbolRaw)
|
|
192
|
+
: undefined;
|
|
193
|
+
const refDecl = typeSymbol?.declarations?.[0];
|
|
194
|
+
const refSourceFile = refDecl?.getSourceFile();
|
|
195
|
+
if (refSourceFile?.fileName.includes("@tsonic/core") ||
|
|
196
|
+
refSourceFile?.fileName.includes("@tsonic/types")) {
|
|
197
|
+
// Directly emit the CLR primitive type, bypassing typeToTypeNode
|
|
198
|
+
const propSig = {
|
|
199
|
+
kind: "propertySignature",
|
|
200
|
+
name: propName,
|
|
201
|
+
type: getClrPrimitiveType(typeName),
|
|
202
|
+
isOptional,
|
|
203
|
+
isReadonly,
|
|
204
|
+
};
|
|
205
|
+
members.push(propSig);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const typeNodeFlags = ts.NodeBuilderFlags.NoTruncation;
|
|
212
|
+
const propTypeNode = checker.typeToTypeNode(propType, node, typeNodeFlags);
|
|
213
|
+
if (isMethod && propTypeNode && ts.isFunctionTypeNode(propTypeNode)) {
|
|
214
|
+
// Method signature
|
|
215
|
+
const methSig = {
|
|
216
|
+
kind: "methodSignature",
|
|
217
|
+
name: propName,
|
|
218
|
+
parameters: propTypeNode.parameters.map((param, index) => ({
|
|
219
|
+
kind: "parameter",
|
|
220
|
+
pattern: {
|
|
221
|
+
kind: "identifierPattern",
|
|
222
|
+
name: ts.isIdentifier(param.name)
|
|
223
|
+
? param.name.text
|
|
224
|
+
: `arg${index}`,
|
|
225
|
+
},
|
|
226
|
+
type: param.type ? convertType(param.type, checker) : undefined,
|
|
227
|
+
isOptional: !!param.questionToken,
|
|
228
|
+
isRest: !!param.dotDotDotToken,
|
|
229
|
+
passing: "value",
|
|
230
|
+
})),
|
|
231
|
+
returnType: propTypeNode.type
|
|
232
|
+
? convertType(propTypeNode.type, checker)
|
|
233
|
+
: undefined,
|
|
234
|
+
};
|
|
235
|
+
members.push(methSig);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
// Property signature
|
|
239
|
+
const propSig = {
|
|
240
|
+
kind: "propertySignature",
|
|
241
|
+
name: propName,
|
|
242
|
+
type: propTypeNode
|
|
243
|
+
? convertType(propTypeNode, checker)
|
|
244
|
+
: { kind: "anyType" },
|
|
245
|
+
isOptional,
|
|
246
|
+
isReadonly,
|
|
247
|
+
};
|
|
248
|
+
members.push(propSig);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const result = members.length > 0 ? members : undefined;
|
|
252
|
+
structuralMembersCache.set(resolvedType, result ?? null);
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
// On any error, settle cache to null (not extractable)
|
|
257
|
+
structuralMembersCache.set(resolvedType, null);
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
6
261
|
/**
|
|
7
262
|
* Convert TypeScript type reference to IR type
|
|
8
263
|
* Handles both primitive type names and user-defined types
|
|
@@ -15,6 +270,11 @@ export const convertTypeReference = (node, checker, convertType) => {
|
|
|
15
270
|
if (isPrimitiveTypeName(typeName)) {
|
|
16
271
|
return getPrimitiveType(typeName);
|
|
17
272
|
}
|
|
273
|
+
// Check for CLR primitive type names (e.g., int from @tsonic/core)
|
|
274
|
+
// These are compiler-known types that map to distinct primitives, not referenceType
|
|
275
|
+
if (isClrPrimitiveTypeName(typeName)) {
|
|
276
|
+
return getClrPrimitiveType(typeName);
|
|
277
|
+
}
|
|
18
278
|
// Check for Array<T> utility type → convert to arrayType with explicit origin
|
|
19
279
|
// This ensures Array<T> and T[] are treated identically
|
|
20
280
|
const firstTypeArg = node.typeArguments?.[0];
|
|
@@ -25,34 +285,87 @@ export const convertTypeReference = (node, checker, convertType) => {
|
|
|
25
285
|
origin: "explicit",
|
|
26
286
|
};
|
|
27
287
|
}
|
|
28
|
-
// Check for
|
|
288
|
+
// Check for expandable conditional utility types (NonNullable, Exclude, Extract)
|
|
289
|
+
// These are expanded at compile time by delegating to TypeScript's type checker
|
|
290
|
+
if (isExpandableConditionalUtilityType(typeName) &&
|
|
291
|
+
node.typeArguments?.length) {
|
|
292
|
+
const expanded = expandConditionalUtilityType(node, typeName, checker, convertType);
|
|
293
|
+
if (expanded)
|
|
294
|
+
return expanded;
|
|
295
|
+
// Fall through to referenceType if can't expand (e.g., type parameter)
|
|
296
|
+
}
|
|
297
|
+
// Check for Record<K, V> utility type
|
|
298
|
+
// First try to expand to IrObjectType for finite literal keys
|
|
299
|
+
// Falls back to IrDictionaryType ONLY for string/number keys (not type parameters)
|
|
29
300
|
const typeArgsForRecord = node.typeArguments;
|
|
30
301
|
const keyTypeNode = typeArgsForRecord?.[0];
|
|
31
302
|
const valueTypeNode = typeArgsForRecord?.[1];
|
|
32
303
|
if (typeName === "Record" && keyTypeNode && valueTypeNode) {
|
|
33
|
-
|
|
34
|
-
const
|
|
304
|
+
// Try to expand to IrObjectType for finite literal keys
|
|
305
|
+
const expandedRecord = expandRecordType(node, checker, convertType);
|
|
306
|
+
if (expandedRecord)
|
|
307
|
+
return expandedRecord;
|
|
308
|
+
// Only create dictionary if K is exactly 'string' or 'number'
|
|
309
|
+
// Type parameters should fall through to referenceType
|
|
310
|
+
//
|
|
311
|
+
// NOTE: We check SyntaxKind FIRST because getTypeAtLocation fails on synthesized nodes
|
|
312
|
+
// (from typeToTypeNode). For synthesized nodes like NumberKeyword, getTypeAtLocation
|
|
313
|
+
// returns `any` instead of the correct type. Checking SyntaxKind handles both cases.
|
|
314
|
+
const isStringKey = keyTypeNode.kind === ts.SyntaxKind.StringKeyword ||
|
|
315
|
+
!!(checker.getTypeAtLocation(keyTypeNode).flags & ts.TypeFlags.String);
|
|
316
|
+
const isNumberKey = keyTypeNode.kind === ts.SyntaxKind.NumberKeyword ||
|
|
317
|
+
!!(checker.getTypeAtLocation(keyTypeNode).flags & ts.TypeFlags.Number);
|
|
318
|
+
if (isStringKey || isNumberKey) {
|
|
319
|
+
const keyType = convertType(keyTypeNode, checker);
|
|
320
|
+
const valueType = convertType(valueTypeNode, checker);
|
|
321
|
+
return {
|
|
322
|
+
kind: "dictionaryType",
|
|
323
|
+
keyType,
|
|
324
|
+
valueType,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
// Type parameter or other complex key type - fall through to referenceType
|
|
328
|
+
}
|
|
329
|
+
// Check for expandable utility types (Partial, Required, Readonly, Pick, Omit)
|
|
330
|
+
// These are expanded to IrObjectType at compile time for concrete types
|
|
331
|
+
if (isExpandableUtilityType(typeName) && node.typeArguments?.length) {
|
|
332
|
+
const expanded = expandUtilityType(node, typeName, checker, convertType);
|
|
333
|
+
if (expanded)
|
|
334
|
+
return expanded;
|
|
335
|
+
// Fall through to referenceType if can't expand (e.g., type parameter)
|
|
336
|
+
}
|
|
337
|
+
// Handle parameter passing modifiers: out<T>, ref<T>, inref<T>
|
|
338
|
+
// These are type aliases that should NOT be resolved - we preserve them
|
|
339
|
+
// so the emitter can detect `as out<T>` casts and emit the correct C# prefix.
|
|
340
|
+
if ((typeName === "out" || typeName === "ref" || typeName === "inref") &&
|
|
341
|
+
node.typeArguments &&
|
|
342
|
+
node.typeArguments.length === 1) {
|
|
343
|
+
// Safe: we checked length === 1 above
|
|
344
|
+
const innerTypeArg = node.typeArguments[0];
|
|
345
|
+
if (!innerTypeArg) {
|
|
346
|
+
return { kind: "anyType" };
|
|
347
|
+
}
|
|
35
348
|
return {
|
|
36
|
-
kind: "
|
|
37
|
-
|
|
38
|
-
|
|
349
|
+
kind: "referenceType",
|
|
350
|
+
name: typeName,
|
|
351
|
+
typeArguments: [convertType(innerTypeArg, checker)],
|
|
39
352
|
};
|
|
40
353
|
}
|
|
41
|
-
// NOTE: ref<T>, out<T>, In<T> are no longer supported as types.
|
|
42
|
-
// Parameter modifiers will be expressed via syntax in the future.
|
|
43
|
-
// If someone uses ref<T> etc., it will fall through to referenceType
|
|
44
|
-
// and the validation pass will reject it with a hard error.
|
|
45
354
|
// Check if this is a type parameter reference (e.g., T in Container<T>)
|
|
46
355
|
// Use the type checker to determine if the reference resolves to a type parameter
|
|
47
356
|
const type = checker.getTypeAtLocation(node);
|
|
48
357
|
if (type.flags & ts.TypeFlags.TypeParameter) {
|
|
49
358
|
return { kind: "typeParameterType", name: typeName };
|
|
50
359
|
}
|
|
360
|
+
// Extract structural members for interfaces and type aliases.
|
|
361
|
+
// This enables TSN5110 validation for object literal properties.
|
|
362
|
+
const structuralMembers = extractStructuralMembers(type, node, checker, convertType);
|
|
51
363
|
// Reference type (user-defined or library)
|
|
52
364
|
return {
|
|
53
365
|
kind: "referenceType",
|
|
54
366
|
name: typeName,
|
|
55
367
|
typeArguments: node.typeArguments?.map((t) => convertType(t, checker)),
|
|
368
|
+
structuralMembers,
|
|
56
369
|
};
|
|
57
370
|
};
|
|
58
371
|
//# sourceMappingURL=references.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references.js","sourceRoot":"","sources":["../../../src/ir/type-converter/references.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExE;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,IAA0B,EAC1B,OAAuB,EACvB,WAAmE,EAC3D,EAAE;IACV,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC7C,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI;QACpB,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAE5B,iCAAiC;IACjC,IAAI,mBAAmB,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED,8EAA8E;IAC9E,wDAAwD;IACxD,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7C,IAAI,QAAQ,KAAK,OAAO,IAAI,YAAY,EAAE,CAAC;QACzC,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,WAAW,EAAE,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC;YAC/C,MAAM,EAAE,UAAU;SACnB,CAAC;IACJ,CAAC;IAED,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CAAC,CAAC;QAC3C,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAC7B,CAAC;QACD,OAAO;YACL,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,QAAQ;YACd,aAAa,EAAE,CAAC,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;SACpD,CAAC;IACJ,CAAC;IAED,wEAAwE;IACxE,kFAAkF;IAClF,MAAM,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,CAAC;QAC5C,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACvD,CAAC;IAED,8DAA8D;IAC9D,iEAAiE;IACjE,MAAM,iBAAiB,GAAG,wBAAwB,CAChD,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,WAAW,CACZ,CAAC;IAEF,2CAA2C;IAC3C,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,QAAQ;QACd,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QACtE,iBAAiB;KAClB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility type expansion - Partial, Required, Readonly, Pick, Omit
|
|
3
|
+
*
|
|
4
|
+
* These utility types are expanded at compile time by resolving the type
|
|
5
|
+
* through TypeScript's type checker and converting the result to IrObjectType.
|
|
6
|
+
*/
|
|
7
|
+
import * as ts from "typescript";
|
|
8
|
+
import { IrType, IrObjectType } from "../types.js";
|
|
9
|
+
/**
|
|
10
|
+
* Set of supported mapped utility types that can be expanded
|
|
11
|
+
*/
|
|
12
|
+
export declare const EXPANDABLE_UTILITY_TYPES: Set<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Check if a type name is an expandable utility type
|
|
15
|
+
*/
|
|
16
|
+
export declare const isExpandableUtilityType: (name: string) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Set of supported conditional utility types that can be expanded
|
|
19
|
+
* These delegate to TypeScript's type checker for evaluation.
|
|
20
|
+
*/
|
|
21
|
+
export declare const EXPANDABLE_CONDITIONAL_UTILITY_TYPES: Set<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a type name is an expandable conditional utility type
|
|
24
|
+
*/
|
|
25
|
+
export declare const isExpandableConditionalUtilityType: (name: string) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Expand a mapped utility type to an IrObjectType.
|
|
28
|
+
*
|
|
29
|
+
* This function uses TypeScript's type checker to resolve the utility type
|
|
30
|
+
* and extracts the properties from the resolved type.
|
|
31
|
+
*
|
|
32
|
+
* @param node - The TypeReferenceNode for the utility type
|
|
33
|
+
* @param typeName - The name of the utility type (Partial, Required, etc.)
|
|
34
|
+
* @param checker - The TypeScript type checker
|
|
35
|
+
* @param convertType - Function to convert nested types
|
|
36
|
+
* @returns IrObjectType with the expanded properties, or null if expansion fails
|
|
37
|
+
*/
|
|
38
|
+
export declare const expandUtilityType: (node: ts.TypeReferenceNode, typeName: string, checker: ts.TypeChecker, convertType: (node: ts.TypeNode, checker: ts.TypeChecker) => IrType) => IrObjectType | null;
|
|
39
|
+
/**
|
|
40
|
+
* Expand a conditional utility type (NonNullable, Exclude, Extract) to IR.
|
|
41
|
+
*
|
|
42
|
+
* This function delegates to TypeScript's type checker to evaluate the
|
|
43
|
+
* conditional type, then converts the resolved result to IR.
|
|
44
|
+
*
|
|
45
|
+
* CONCRETE-ONLY EXPANSION RULE:
|
|
46
|
+
* This function ONLY expands utility types when ALL type arguments are concrete
|
|
47
|
+
* (non-generic). If any type argument contains a type parameter, we return null
|
|
48
|
+
* and let the caller fall through to referenceType. This is intentional because:
|
|
49
|
+
*
|
|
50
|
+
* 1. TypeScript's conditional types are distributive over unions, which requires
|
|
51
|
+
* knowing the actual types at compile time.
|
|
52
|
+
* 2. For generic contexts like `function f<T>(x: NonNullable<T>)`, we cannot
|
|
53
|
+
* evaluate the conditional - it must remain as a type reference.
|
|
54
|
+
* 3. This matches TypeScript semantics: deferred evaluation in generic contexts.
|
|
55
|
+
*
|
|
56
|
+
* Gating conditions:
|
|
57
|
+
* - Returns null if any type argument contains type parameters (generic context)
|
|
58
|
+
* - Returns null if TypeScript cannot resolve the type
|
|
59
|
+
*
|
|
60
|
+
* Special handling:
|
|
61
|
+
* - NonNullable<any> → anyType (preserve)
|
|
62
|
+
* - NonNullable<unknown> → unknownType (preserve)
|
|
63
|
+
* - NonNullable<never> → neverType (preserve)
|
|
64
|
+
* - Result is never → neverType
|
|
65
|
+
*
|
|
66
|
+
* @param node - The TypeReferenceNode for the utility type
|
|
67
|
+
* @param typeName - The name of the utility type (NonNullable, Exclude, Extract)
|
|
68
|
+
* @param checker - The TypeScript type checker
|
|
69
|
+
* @param convertType - Function to convert nested types
|
|
70
|
+
* @returns IR type with the expanded result, or null if expansion fails
|
|
71
|
+
*/
|
|
72
|
+
export declare const expandConditionalUtilityType: (node: ts.TypeReferenceNode, typeName: string, checker: ts.TypeChecker, convertType: (node: ts.TypeNode, checker: ts.TypeChecker) => IrType) => IrType | null;
|
|
73
|
+
/**
|
|
74
|
+
* Expand Record<K, T> to IrObjectType when K is a finite set of literal keys.
|
|
75
|
+
*
|
|
76
|
+
* Gating conditions:
|
|
77
|
+
* - Returns null if K contains type parameters (generic context)
|
|
78
|
+
* - Returns null if K is string or number (should remain IrDictionaryType)
|
|
79
|
+
* - Returns null if K contains non-literal types
|
|
80
|
+
*
|
|
81
|
+
* Examples:
|
|
82
|
+
* - Record<"a" | "b", number> → IrObjectType with props {a: number, b: number}
|
|
83
|
+
* - Record<1 | 2, string> → IrObjectType with props {"1": string, "2": string}
|
|
84
|
+
* - Record<string, number> → null (use IrDictionaryType)
|
|
85
|
+
* - Record<K, T> → null (type parameter)
|
|
86
|
+
*
|
|
87
|
+
* @param node - The TypeReferenceNode for Record<K, T>
|
|
88
|
+
* @param checker - The TypeScript type checker
|
|
89
|
+
* @param convertType - Function to convert nested types
|
|
90
|
+
* @returns IrObjectType with the expanded properties, or null if should use dictionary
|
|
91
|
+
*/
|
|
92
|
+
export declare const expandRecordType: (node: ts.TypeReferenceNode, checker: ts.TypeChecker, convertType: (node: ts.TypeNode, checker: ts.TypeChecker) => IrType) => IrObjectType | null;
|
|
93
|
+
//# sourceMappingURL=utility-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility-types.d.ts","sourceRoot":"","sources":["../../../src/ir/type-converter/utility-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EACL,MAAM,EACN,YAAY,EAIb,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,eAAO,MAAM,wBAAwB,aAMnC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAAI,MAAM,MAAM,KAAG,OACnB,CAAC;AAErC;;;GAGG;AACH,eAAO,MAAM,oCAAoC,aAO/C,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,kCAAkC,GAAI,MAAM,MAAM,KAAG,OAClB,CAAC;AAkJjD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,EAAE,CAAC,iBAAiB,EAC1B,UAAU,MAAM,EAChB,SAAS,EAAE,CAAC,WAAW,EACvB,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,KAAK,MAAM,KAClE,YAAY,GAAG,IAuIjB,CAAC;AA4BF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,4BAA4B,GACvC,MAAM,EAA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