@tsonic/emitter 0.0.72 → 0.0.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/core/semantic/imports.js +9 -0
  3. package/dist/core/semantic/imports.js.map +1 -1
  4. package/dist/core/semantic/imports.test.js +43 -0
  5. package/dist/core/semantic/imports.test.js.map +1 -1
  6. package/dist/core/semantic/type-resolution.d.ts +1 -0
  7. package/dist/core/semantic/type-resolution.d.ts.map +1 -1
  8. package/dist/core/semantic/type-resolution.js +167 -5
  9. package/dist/core/semantic/type-resolution.js.map +1 -1
  10. package/dist/core/semantic/type-resolution.test.js +35 -0
  11. package/dist/core/semantic/type-resolution.test.js.map +1 -1
  12. package/dist/emitter-types/core.d.ts +5 -0
  13. package/dist/emitter-types/core.d.ts.map +1 -1
  14. package/dist/expression-emitter.d.ts.map +1 -1
  15. package/dist/expression-emitter.js +801 -2
  16. package/dist/expression-emitter.js.map +1 -1
  17. package/dist/expressions/access.d.ts.map +1 -1
  18. package/dist/expressions/access.js +58 -1
  19. package/dist/expressions/access.js.map +1 -1
  20. package/dist/expressions/calls/call-emitter.d.ts.map +1 -1
  21. package/dist/expressions/calls/call-emitter.js +8 -45
  22. package/dist/expressions/calls/call-emitter.js.map +1 -1
  23. package/dist/expressions/collections.d.ts.map +1 -1
  24. package/dist/expressions/collections.js +211 -3
  25. package/dist/expressions/collections.js.map +1 -1
  26. package/dist/expressions/identifiers.d.ts.map +1 -1
  27. package/dist/expressions/identifiers.js +8 -1
  28. package/dist/expressions/identifiers.js.map +1 -1
  29. package/dist/expressions/index.test.js +117 -0
  30. package/dist/expressions/index.test.js.map +1 -1
  31. package/dist/expressions/operators/binary-emitter.d.ts.map +1 -1
  32. package/dist/expressions/operators/binary-emitter.js +97 -56
  33. package/dist/expressions/operators/binary-emitter.js.map +1 -1
  34. package/dist/expressions/other.d.ts.map +1 -1
  35. package/dist/expressions/other.js +59 -1
  36. package/dist/expressions/other.js.map +1 -1
  37. package/dist/integration.test.js +393 -5
  38. package/dist/integration.test.js.map +1 -1
  39. package/dist/specialization/type-aliases.test.js +8 -0
  40. package/dist/specialization/type-aliases.test.js.map +1 -1
  41. package/dist/statements/classes/members/methods.d.ts.map +1 -1
  42. package/dist/statements/classes/members/methods.js +2 -13
  43. package/dist/statements/classes/members/methods.js.map +1 -1
  44. package/dist/statements/control/conditionals/guard-analysis.d.ts +42 -0
  45. package/dist/statements/control/conditionals/guard-analysis.d.ts.map +1 -1
  46. package/dist/statements/control/conditionals/guard-analysis.js +284 -121
  47. package/dist/statements/control/conditionals/guard-analysis.js.map +1 -1
  48. package/dist/statements/control/conditionals/if-emitter.d.ts.map +1 -1
  49. package/dist/statements/control/conditionals/if-emitter.js +168 -44
  50. package/dist/statements/control/conditionals/if-emitter.js.map +1 -1
  51. package/dist/statements/declarations/functions.d.ts.map +1 -1
  52. package/dist/statements/declarations/functions.js +2 -13
  53. package/dist/statements/declarations/functions.js.map +1 -1
  54. package/dist/statements/declarations/type-aliases.d.ts.map +1 -1
  55. package/dist/statements/declarations/type-aliases.js +2 -1
  56. package/dist/statements/declarations/type-aliases.js.map +1 -1
  57. package/dist/statements/declarations/variables.d.ts.map +1 -1
  58. package/dist/statements/declarations/variables.js +17 -15
  59. package/dist/statements/declarations/variables.js.map +1 -1
  60. package/dist/statements/index.test.js +940 -0
  61. package/dist/statements/index.test.js.map +1 -1
  62. package/dist/types/references.d.ts.map +1 -1
  63. package/dist/types/references.js +12 -8
  64. package/dist/types/references.js.map +1 -1
  65. package/dist/types/references.test.js +112 -0
  66. package/dist/types/references.test.js.map +1 -1
  67. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"methods.js","sourceRoot":"","sources":["../../../../src/statements/classes/members/methods.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAEL,MAAM,EACN,MAAM,EACN,SAAS,EACT,UAAU,GACX,MAAM,m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,CAAC;AAClE,CAAC,CAAC"}
@@ -16,6 +16,9 @@ export type GuardInfo = {
16
16
  readonly targetType: IrType;
17
17
  readonly memberN: number;
18
18
  readonly unionArity: number;
19
+ readonly runtimeUnionArity: number;
20
+ readonly candidateMemberNs: readonly number[];
21
+ readonly candidateMembers: readonly IrType[];
19
22
  readonly ctxWithId: EmitterContext;
20
23
  readonly narrowedName: string;
21
24
  readonly escapedOrig: string;
@@ -55,6 +58,9 @@ export type InGuardInfo = {
55
58
  readonly propertyName: string;
56
59
  readonly memberN: number;
57
60
  readonly unionArity: number;
61
+ readonly runtimeUnionArity: number;
62
+ readonly candidateMemberNs: readonly number[];
63
+ readonly candidateMembers: readonly IrType[];
58
64
  readonly ctxWithId: EmitterContext;
59
65
  readonly narrowedName: string;
60
66
  readonly escapedOrig: string;
@@ -83,12 +89,43 @@ export type DiscriminantEqualityGuardInfo = {
83
89
  readonly operator: "===" | "!==" | "==" | "!=";
84
90
  readonly memberN: number;
85
91
  readonly unionArity: number;
92
+ readonly runtimeUnionArity: number;
93
+ readonly candidateMemberNs: readonly number[];
94
+ readonly candidateMembers: readonly IrType[];
86
95
  readonly ctxWithId: EmitterContext;
87
96
  readonly narrowedName: string;
88
97
  readonly escapedOrig: string;
89
98
  readonly escapedNarrow: string;
90
99
  readonly narrowedMap: Map<string, NarrowedBinding>;
91
100
  };
101
+ /**
102
+ * Information extracted from a truthy/falsy property guard:
103
+ * if (result.success) { ... }
104
+ * if (!result.success) { ... }
105
+ *
106
+ * Supports the airplane-grade case where a union member property is definitively
107
+ * truthy or falsy by literal/nullish contract, and exactly one member matches the
108
+ * condition branch.
109
+ */
110
+ export type PropertyTruthinessGuardInfo = {
111
+ readonly originalName: string;
112
+ readonly propertyName: string;
113
+ readonly memberN: number;
114
+ readonly unionArity: number;
115
+ readonly runtimeUnionArity: number;
116
+ readonly candidateMemberNs: readonly number[];
117
+ readonly candidateMembers: readonly IrType[];
118
+ readonly ctxWithId: EmitterContext;
119
+ readonly narrowedName: string;
120
+ readonly escapedOrig: string;
121
+ readonly escapedNarrow: string;
122
+ readonly narrowedMap: Map<string, NarrowedBinding>;
123
+ };
124
+ export type RuntimeUnionFrame = {
125
+ readonly members: readonly IrType[];
126
+ readonly candidateMemberNs: readonly number[];
127
+ readonly runtimeUnionArity: number;
128
+ };
92
129
  /**
93
130
  * Information extracted from a nullable guard condition.
94
131
  * Used to generate .Value access for narrowed nullable value types.
@@ -109,6 +146,11 @@ export type NullableGuardInfo = {
109
146
  * TypeScript flow analysis, by mapping the literal to exactly one union member.
110
147
  */
111
148
  export declare const tryResolveDiscriminantEqualityGuard: (condition: IrExpression, context: EmitterContext) => DiscriminantEqualityGuardInfo | undefined;
149
+ /**
150
+ * Try to extract guard info from `x.prop` / `!x.prop` where the property acts as a
151
+ * boolean-style discriminant over a runtime union.
152
+ */
153
+ export declare const tryResolvePropertyTruthinessGuard: (condition: IrExpression, context: EmitterContext) => PropertyTruthinessGuardInfo | undefined;
112
154
  /**
113
155
  * Try to extract guard info from an `("prop" in x)` binary expression.
114
156
  */
@@ -1 +1 @@
1
- {"version":3,"file":"guard-analysis.d.ts","sourceRoot":"","sources":["../../../../src/statements/control/conditionals/guard-analysis.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EACL,cAAc,EAEd,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAuB3B;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,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;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GACnC,MAAM,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EAC7C,SAAS,cAAc,KACtB,SAAS,GAAG,SAoDd,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,GACpC,WAAW,YAAY,EACvB,SAAS,cAAc,KACtB,mBAAmB,GAAG,SAsCxB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,YAAY,KAAG,OAgBtD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,MAAM,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC,KACpD,MAAM,GAAG,SAmBX,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,6BAA6B,GACxC,WAAW,YAAY,KACtB,iBAAiB,GAAG,SAuDtB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAClC,WAAW,YAAY,EACvB,UAAU,cAAc,KACvB,iBAAiB,GAAG,SAiBtB,CAAC"}
1
+ {"version":3,"file":"guard-analysis.d.ts","sourceRoot":"","sources":["../../../../src/statements/control/conditionals/guard-analysis.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EACL,cAAc,EAEd,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAuB3B;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,Q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iC,GAC5C,WAAW,YAAY,EACvB,SAAS,cAAc,KACtB,2BAA2B,GAAG,SAuIhC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAC5B,WAAW,YAAY,EACvB,SAAS,cAAc,KACtB,WAAW,GAAG,SA0EhB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAAI,MAAM,WAAW,KAAG,OAS3D,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GACnC,MAAM,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EAC7C,SAAS,cAAc,KACtB,SAAS,GAAG,SA0Dd,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,GACpC,WAAW,YAAY,EACvB,SAAS,cAAc,KACtB,mBAAmB,GAAG,SAsCxB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,YAAY,KAAG,OAgBtD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,MAAM,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC,KACpD,MAAM,GAAG,SAmBX,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,6BAA6B,GACxC,WAAW,YAAY,KACtB,iBAAiB,GAAG,SAuDtB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAClC,WAAW,YAAY,EACvB,UAAU,cAAc,KACvB,iBAAiB,GAAG,SAiBtB,CAAC"}
@@ -13,71 +13,37 @@ import { extractCalleeNameFromAst } from "../../../core/format/backend-ast/utils
13
13
  * an identifierExpression. Falls back to extractCalleeNameFromAst for other shapes.
14
14
  */
15
15
  const extractIdentifierText = (ast) => extractCalleeNameFromAst(ast);
16
- import { resolveTypeAlias, stripNullish, findUnionMemberIndex, getPropertyType, getAllPropertySignatures, isDefinitelyValueType, } from "../../../core/semantic/type-resolution.js";
16
+ import { hasDeterministicPropertyMembership, resolveTypeAlias, stripNullish, findUnionMemberIndex, getPropertyType, isDefinitelyValueType, } from "../../../core/semantic/type-resolution.js";
17
17
  import { escapeCSharpIdentifier } from "../../../emitter-types/index.js";
18
18
  import { emitRemappedLocalName } from "../../../core/format/local-names.js";
19
19
  /**
20
20
  * Check if a local nominal type (class/interface) has a property with the given TS name.
21
21
  */
22
- const hasLocalProperty = (type, propertyName, context) => {
23
- if (!context.localTypes)
24
- return false;
25
- const info = context.localTypes.get(type.name);
26
- if (!info)
27
- return false;
28
- if (info.kind === "interface") {
29
- const props = getAllPropertySignatures(type, context);
30
- return props?.some((p) => p.name === propertyName) ?? false;
31
- }
32
- if (info.kind === "class") {
33
- return info.members.some((m) => m.kind === "propertyDeclaration" && m.name === propertyName);
22
+ const getGuardPropertyType = (type, propertyName, context) => {
23
+ if (type.kind === "objectType") {
24
+ const prop = type.members.find((member) => member.kind === "propertySignature" && member.name === propertyName);
25
+ return prop?.type;
34
26
  }
35
- return false;
36
- };
37
- /**
38
- * Check if a nominal type has a property, including cross-module local types.
39
- *
40
- * For same-module types, consult `context.localTypes`.
41
- * For cross-module types, consult the batch `typeMemberIndex` and resolve the
42
- * member's fully-qualified name deterministically.
43
- */
44
- const hasProperty = (type, propertyName, context) => {
45
- if (hasLocalProperty(type, propertyName, context)) {
46
- return true;
47
- }
48
- const index = context.options.typeMemberIndex;
49
- if (!index)
50
- return false;
51
- const stripGlobalPrefix = (name) => name.startsWith("global::") ? name.slice("global::".length) : name;
52
- const candidates = [];
53
- if (type.resolvedClrType) {
54
- candidates.push(stripGlobalPrefix(type.resolvedClrType));
55
- }
56
- else if (type.name.includes(".")) {
57
- candidates.push(type.name);
58
- }
59
- else {
60
- // Resolve by suffix match in the type member index.
61
- const matches = [];
62
- for (const fqn of index.keys()) {
63
- if (fqn.endsWith(`.${type.name}`) ||
64
- fqn.endsWith(`.${type.name}__Alias`)) {
65
- matches.push(fqn);
66
- }
27
+ if (type.kind === "referenceType") {
28
+ if (type.structuralMembers?.length) {
29
+ const prop = type.structuralMembers.find((member) => member.kind === "propertySignature" && member.name === propertyName);
30
+ if (prop)
31
+ return prop.type;
67
32
  }
68
- if (matches.length === 1) {
69
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
70
- candidates.push(matches[0]);
71
- }
72
- else if (matches.length > 1) {
73
- const list = matches.sort().join(", ");
74
- throw new Error(`ICE: Ambiguous union member type '${type.name}' for \`in\` narrowing. Candidates: ${list}`);
33
+ const localTypes = resolveLocalTypesForReference(type, context);
34
+ if (localTypes) {
35
+ const lookupName = type.name.includes(".")
36
+ ? (type.name.split(".").pop() ?? type.name)
37
+ : type.name;
38
+ const localPropType = getPropertyType({ ...type, name: lookupName }, propertyName, { ...context, localTypes });
39
+ if (localPropType)
40
+ return localPropType;
75
41
  }
42
+ const resolvedPropType = getPropertyType(type, propertyName, context);
43
+ if (resolvedPropType)
44
+ return resolvedPropType;
76
45
  }
77
- return candidates.some((fqn) => {
78
- const perType = index.get(fqn);
79
- return perType?.has(propertyName) ?? false;
80
- });
46
+ return undefined;
81
47
  };
82
48
  /**
83
49
  * Resolve a reference type's LocalTypeInfo map (possibly from a different module).
@@ -149,6 +115,90 @@ const tryGetLiteralSet = (type, context) => {
149
115
  }
150
116
  return undefined;
151
117
  };
118
+ const isClrUnionName = (name) => /^Union_[2-8]$/.test(name) || name === "Union" || name.endsWith(".Union");
119
+ const stripGlobalPrefix = (name) => name.startsWith("global::") ? name.slice("global::".length) : name;
120
+ const extractUnionMembers = (type, context) => {
121
+ const resolvedBase = resolveTypeAlias(stripNullish(type), context);
122
+ const resolved = resolvedBase.kind === "intersectionType"
123
+ ? (resolvedBase.types.find((member) => member.kind === "referenceType" && isClrUnionName(member.name)) ?? resolvedBase)
124
+ : resolvedBase;
125
+ if (resolved.kind === "unionType") {
126
+ return resolved.types;
127
+ }
128
+ if (resolved.kind === "referenceType" &&
129
+ isClrUnionName(resolved.name) &&
130
+ resolved.typeArguments &&
131
+ resolved.typeArguments.length >= 2 &&
132
+ resolved.typeArguments.length <= 8) {
133
+ return resolved.typeArguments;
134
+ }
135
+ return undefined;
136
+ };
137
+ const resolveRuntimeUnionFrame = (originalName, unionSourceType, context) => {
138
+ const members = extractUnionMembers(unionSourceType, context);
139
+ if (!members)
140
+ return undefined;
141
+ const narrowed = context.narrowedBindings?.get(originalName);
142
+ if (!narrowed) {
143
+ return {
144
+ members,
145
+ candidateMemberNs: members.map((_, index) => index + 1),
146
+ runtimeUnionArity: members.length,
147
+ };
148
+ }
149
+ if (narrowed.kind !== "runtimeSubset") {
150
+ return undefined;
151
+ }
152
+ if (narrowed.runtimeMemberNs.length !== members.length) {
153
+ return undefined;
154
+ }
155
+ return {
156
+ members,
157
+ candidateMemberNs: [...narrowed.runtimeMemberNs],
158
+ runtimeUnionArity: narrowed.runtimeUnionArity,
159
+ };
160
+ };
161
+ const buildRenameNarrowedMap = (originalName, narrowedName, memberType, ctxWithId) => {
162
+ const narrowedMap = new Map(ctxWithId.narrowedBindings ?? []);
163
+ narrowedMap.set(originalName, {
164
+ kind: "rename",
165
+ name: narrowedName,
166
+ type: memberType,
167
+ });
168
+ return narrowedMap;
169
+ };
170
+ const isDefinitelyTruthyLiteral = (value) => {
171
+ if (typeof value === "string")
172
+ return value.length > 0;
173
+ if (typeof value === "number")
174
+ return value !== 0 && !Number.isNaN(value);
175
+ return value === true;
176
+ };
177
+ const isDefinitelyFalsyType = (type, context) => {
178
+ const resolved = resolveTypeAlias(type, context);
179
+ if (resolved.kind === "literalType") {
180
+ const value = resolved.value;
181
+ return value === false || value === 0 || value === "";
182
+ }
183
+ if (resolved.kind === "primitiveType") {
184
+ return resolved.name === "undefined" || resolved.name === "null";
185
+ }
186
+ if (resolved.kind === "unionType") {
187
+ return resolved.types.every((member) => isDefinitelyFalsyType(member, context));
188
+ }
189
+ return false;
190
+ };
191
+ const isDefinitelyTruthyType = (type, context) => {
192
+ const literals = tryGetLiteralSet(type, context);
193
+ if (literals) {
194
+ return Array.from(literals).every(isDefinitelyTruthyLiteral);
195
+ }
196
+ const resolved = resolveTypeAlias(type, context);
197
+ if (resolved.kind === "unionType") {
198
+ return resolved.types.every((member) => isDefinitelyTruthyType(member, context));
199
+ }
200
+ return false;
201
+ };
152
202
  /**
153
203
  * Try to extract guard info from `x.prop === <literal>` or `x.prop !== <literal>`.
154
204
  *
@@ -211,70 +261,52 @@ export const tryResolveDiscriminantEqualityGuard = (condition, context) => {
211
261
  return undefined;
212
262
  const { receiver, propertyName, literal } = match;
213
263
  const originalName = receiver.name;
214
- // If this identifier is already narrowed (union guard emitted earlier), do NOT try to
215
- // apply another union narrowing rule. This avoids mis-emitting `.IsN()` on a narrowed member type.
216
- if (context.narrowedBindings?.has(originalName))
217
- return undefined;
218
264
  const unionSourceType = receiver.inferredType;
219
265
  if (!unionSourceType)
220
266
  return undefined;
221
- const resolved = resolveTypeAlias(stripNullish(unionSourceType), context);
222
- if (resolved.kind !== "unionType")
267
+ const frame = resolveRuntimeUnionFrame(originalName, unionSourceType, context);
268
+ if (!frame)
223
269
  return undefined;
224
- const unionArity = resolved.types.length;
270
+ const { members, candidateMemberNs, runtimeUnionArity } = frame;
271
+ const unionArity = members.length;
225
272
  if (unionArity < 2 || unionArity > 8)
226
273
  return undefined;
227
274
  // Find which union members have a discriminant property type that includes the literal.
228
- const matchingMembers = [];
229
- for (let i = 0; i < resolved.types.length; i++) {
230
- const member = resolved.types[i];
275
+ const matchingIndices = [];
276
+ const matchingMemberNs = [];
277
+ for (let i = 0; i < members.length; i++) {
278
+ const member = members[i];
231
279
  if (!member)
232
280
  continue;
233
- let propType;
234
- if (member.kind === "objectType") {
235
- const prop = member.members.find((m) => m.kind === "propertySignature" && m.name === propertyName);
236
- propType = prop?.type;
237
- }
238
- else if (member.kind === "referenceType") {
239
- const localTypes = resolveLocalTypesForReference(member, context);
240
- if (!localTypes)
241
- continue;
242
- const lookupName = member.name.includes(".")
243
- ? (member.name.split(".").pop() ?? member.name)
244
- : member.name;
245
- // Use the target module's localTypes for property type resolution.
246
- propType = getPropertyType({ ...member, name: lookupName }, propertyName, { ...context, localTypes });
247
- }
248
- else {
249
- continue;
250
- }
281
+ const propType = getGuardPropertyType(member, propertyName, context);
251
282
  if (!propType)
252
283
  continue;
253
284
  const literals = tryGetLiteralSet(propType, context);
254
285
  if (!literals)
255
286
  continue;
256
287
  if (literals.has(literal)) {
257
- matchingMembers.push(i + 1);
288
+ matchingIndices.push(i);
289
+ matchingMemberNs.push(candidateMemberNs[i] ?? i + 1);
258
290
  }
259
291
  }
260
292
  // Only support the common airplane-grade case: exactly one matching member.
261
- if (matchingMembers.length !== 1)
293
+ if (matchingMemberNs.length !== 1)
262
294
  return undefined;
263
- const memberN = matchingMembers[0];
295
+ const memberN = matchingMemberNs[0];
264
296
  if (!memberN)
265
297
  return undefined;
298
+ const matchingIndex = matchingIndices[0];
299
+ if (matchingIndex === undefined)
300
+ return undefined;
266
301
  const nextId = (context.tempVarId ?? 0) + 1;
267
302
  const ctxWithId = { ...context, tempVarId: nextId };
268
303
  const narrowedName = `${originalName}__${memberN}_${nextId}`;
269
304
  const escapedOrig = emitRemappedLocalName(originalName, context);
270
305
  const escapedNarrow = escapeCSharpIdentifier(narrowedName);
271
- const narrowedMap = new Map(ctxWithId.narrowedBindings ?? []);
272
- const memberType = resolved.types[memberN - 1];
273
- narrowedMap.set(originalName, {
274
- kind: "rename",
275
- name: narrowedName,
276
- type: memberType,
277
- });
306
+ const memberType = members[matchingIndex];
307
+ if (!memberType)
308
+ return undefined;
309
+ const narrowedMap = buildRenameNarrowedMap(originalName, narrowedName, memberType, ctxWithId);
278
310
  return {
279
311
  originalName,
280
312
  propertyName,
@@ -282,6 +314,129 @@ export const tryResolveDiscriminantEqualityGuard = (condition, context) => {
282
314
  operator: condition.operator,
283
315
  memberN,
284
316
  unionArity,
317
+ runtimeUnionArity,
318
+ candidateMemberNs,
319
+ candidateMembers: members,
320
+ ctxWithId,
321
+ narrowedName,
322
+ escapedOrig,
323
+ escapedNarrow,
324
+ narrowedMap,
325
+ };
326
+ };
327
+ /**
328
+ * Try to extract guard info from `x.prop` / `!x.prop` where the property acts as a
329
+ * boolean-style discriminant over a runtime union.
330
+ */
331
+ export const tryResolvePropertyTruthinessGuard = (condition, context) => {
332
+ const extract = (expr) => {
333
+ if (expr.kind === "unary" && expr.operator === "!") {
334
+ const inner = extract(expr.expression);
335
+ return inner ? { ...inner, wantTruthy: !inner.wantTruthy } : undefined;
336
+ }
337
+ if (expr.kind !== "memberAccess")
338
+ return undefined;
339
+ if (expr.isOptional || expr.isComputed)
340
+ return undefined;
341
+ if (expr.object.kind !== "identifier")
342
+ return undefined;
343
+ if (typeof expr.property !== "string")
344
+ return undefined;
345
+ return {
346
+ receiver: expr.object,
347
+ propertyName: expr.property,
348
+ wantTruthy: true,
349
+ bindingType: expr.memberBinding?.type,
350
+ bindingValueTruthiness: expr.inferredType?.kind === "literalType"
351
+ ? isDefinitelyTruthyLiteral(expr.inferredType.value)
352
+ : expr.inferredType?.kind === "primitiveType" &&
353
+ (expr.inferredType.name === "undefined" ||
354
+ expr.inferredType.name === "null")
355
+ ? false
356
+ : undefined,
357
+ };
358
+ };
359
+ const match = extract(condition);
360
+ if (!match)
361
+ return undefined;
362
+ const { receiver, propertyName, wantTruthy, bindingType, bindingValueTruthiness } = match;
363
+ const originalName = receiver.name;
364
+ const unionSourceType = receiver.inferredType;
365
+ if (!unionSourceType)
366
+ return undefined;
367
+ const frame = resolveRuntimeUnionFrame(originalName, unionSourceType, context);
368
+ if (!frame)
369
+ return undefined;
370
+ const { members, candidateMemberNs, runtimeUnionArity } = frame;
371
+ const unionArity = members.length;
372
+ if (unionArity < 2 || unionArity > 8)
373
+ return undefined;
374
+ const matchingIndices = [];
375
+ const matchingMemberNs = [];
376
+ if (bindingType && bindingValueTruthiness !== undefined) {
377
+ const bindingTypeName = stripGlobalPrefix(bindingType);
378
+ const boundMemberIndex = members.findIndex((member) => {
379
+ if (member?.kind !== "referenceType")
380
+ return false;
381
+ const candidateClr = member.resolvedClrType
382
+ ? stripGlobalPrefix(member.resolvedClrType)
383
+ : undefined;
384
+ return candidateClr === bindingTypeName || member.name === bindingTypeName;
385
+ });
386
+ if (boundMemberIndex >= 0) {
387
+ if (wantTruthy === bindingValueTruthiness) {
388
+ matchingIndices.push(boundMemberIndex);
389
+ matchingMemberNs.push(candidateMemberNs[boundMemberIndex] ?? boundMemberIndex + 1);
390
+ }
391
+ else if (unionArity === 2) {
392
+ const otherIndex = boundMemberIndex === 0 ? 1 : 0;
393
+ matchingIndices.push(otherIndex);
394
+ matchingMemberNs.push(candidateMemberNs[otherIndex] ?? otherIndex + 1);
395
+ }
396
+ }
397
+ }
398
+ if (matchingMemberNs.length === 0) {
399
+ for (let i = 0; i < members.length; i++) {
400
+ const member = members[i];
401
+ if (!member)
402
+ continue;
403
+ const propType = getGuardPropertyType(member, propertyName, context);
404
+ if (!propType)
405
+ continue;
406
+ const matches = wantTruthy
407
+ ? isDefinitelyTruthyType(propType, context)
408
+ : isDefinitelyFalsyType(propType, context);
409
+ if (matches) {
410
+ matchingIndices.push(i);
411
+ matchingMemberNs.push(candidateMemberNs[i] ?? i + 1);
412
+ }
413
+ }
414
+ }
415
+ if (matchingMemberNs.length !== 1)
416
+ return undefined;
417
+ const memberN = matchingMemberNs[0];
418
+ if (!memberN)
419
+ return undefined;
420
+ const matchingIndex = matchingIndices[0];
421
+ if (matchingIndex === undefined)
422
+ return undefined;
423
+ const nextId = (context.tempVarId ?? 0) + 1;
424
+ const ctxWithId = { ...context, tempVarId: nextId };
425
+ const narrowedName = `${originalName}__${memberN}_${nextId}`;
426
+ const escapedOrig = emitRemappedLocalName(originalName, context);
427
+ const escapedNarrow = escapeCSharpIdentifier(narrowedName);
428
+ const memberType = members[matchingIndex];
429
+ if (!memberType)
430
+ return undefined;
431
+ const narrowedMap = buildRenameNarrowedMap(originalName, narrowedName, memberType, ctxWithId);
432
+ return {
433
+ originalName,
434
+ propertyName,
435
+ memberN,
436
+ unionArity,
437
+ runtimeUnionArity,
438
+ candidateMemberNs,
439
+ candidateMembers: members,
285
440
  ctxWithId,
286
441
  narrowedName,
287
442
  escapedOrig,
@@ -310,46 +465,52 @@ export const tryResolveInGuard = (condition, context) => {
310
465
  const unionSourceType = condition.right.inferredType;
311
466
  if (!unionSourceType)
312
467
  return undefined;
313
- const resolved = resolveTypeAlias(stripNullish(unionSourceType), context);
314
- if (resolved.kind !== "unionType")
468
+ const frame = resolveRuntimeUnionFrame(originalName, unionSourceType, context);
469
+ if (!frame)
315
470
  return undefined;
316
- const unionArity = resolved.types.length;
471
+ const { members, candidateMemberNs, runtimeUnionArity } = frame;
472
+ const unionArity = members.length;
317
473
  if (unionArity < 2 || unionArity > 8)
318
474
  return undefined;
319
475
  // Find which union members contain the property.
320
- const matchingMembers = [];
321
- for (let i = 0; i < resolved.types.length; i++) {
322
- const member = resolved.types[i];
476
+ const matchingIndices = [];
477
+ const matchingMemberNs = [];
478
+ for (let i = 0; i < members.length; i++) {
479
+ const member = members[i];
323
480
  if (!member || member.kind !== "referenceType")
324
481
  continue;
325
- if (hasProperty(member, propertyName, context)) {
326
- matchingMembers.push(i + 1);
482
+ if (hasDeterministicPropertyMembership(member, propertyName, context) === true) {
483
+ matchingIndices.push(i);
484
+ matchingMemberNs.push(candidateMemberNs[i] ?? i + 1);
327
485
  }
328
486
  }
329
487
  // Only support the common "exactly one matching member" narrowing case.
330
- if (matchingMembers.length !== 1)
488
+ if (matchingMemberNs.length !== 1)
331
489
  return undefined;
332
- const memberN = matchingMembers[0];
490
+ const memberN = matchingMemberNs[0];
333
491
  if (!memberN)
334
492
  return undefined;
493
+ const matchingIndex = matchingIndices[0];
494
+ if (matchingIndex === undefined)
495
+ return undefined;
335
496
  const nextId = (context.tempVarId ?? 0) + 1;
336
497
  const ctxWithId = { ...context, tempVarId: nextId };
337
498
  const narrowedName = `${originalName}__${memberN}_${nextId}`;
338
499
  const [rhsAst] = emitIdentifier(condition.right, context);
339
500
  const escapedOrig = extractIdentifierText(rhsAst);
340
501
  const escapedNarrow = escapeCSharpIdentifier(narrowedName);
341
- const narrowedMap = new Map(ctxWithId.narrowedBindings ?? []);
342
- const memberType = resolved.types[memberN - 1];
343
- narrowedMap.set(originalName, {
344
- kind: "rename",
345
- name: narrowedName,
346
- type: memberType,
347
- });
502
+ const memberType = members[matchingIndex];
503
+ if (!memberType)
504
+ return undefined;
505
+ const narrowedMap = buildRenameNarrowedMap(originalName, narrowedName, memberType, ctxWithId);
348
506
  return {
349
507
  originalName,
350
508
  propertyName,
351
509
  memberN,
352
510
  unionArity,
511
+ runtimeUnionArity,
512
+ candidateMemberNs,
513
+ candidateMembers: members,
353
514
  ctxWithId,
354
515
  narrowedName,
355
516
  escapedOrig,
@@ -395,31 +556,33 @@ export const tryResolvePredicateGuard = (call, context) => {
395
556
  const unionSourceType = arg.inferredType;
396
557
  if (!unionSourceType)
397
558
  return undefined;
398
- const resolved = resolveTypeAlias(stripNullish(unionSourceType), context);
399
- if (resolved.kind !== "unionType")
559
+ const frame = resolveRuntimeUnionFrame(originalName, unionSourceType, context);
560
+ if (!frame)
400
561
  return undefined;
562
+ const resolved = {
563
+ kind: "unionType",
564
+ types: [...frame.members],
565
+ };
401
566
  const idx = findUnionMemberIndex(resolved, narrowing.targetType, context);
402
567
  if (idx === undefined)
403
568
  return undefined;
404
- const memberN = idx + 1;
405
- const unionArity = resolved.types.length;
569
+ const memberN = frame.candidateMemberNs[idx] ?? idx + 1;
570
+ const unionArity = frame.members.length;
406
571
  const nextId = (context.tempVarId ?? 0) + 1;
407
572
  const ctxWithId = { ...context, tempVarId: nextId };
408
573
  const narrowedName = `${originalName}__${memberN}_${nextId}`;
409
574
  const [argAst] = emitIdentifier(arg, context);
410
575
  const escapedOrig = extractIdentifierText(argAst);
411
576
  const escapedNarrow = escapeCSharpIdentifier(narrowedName);
412
- const narrowedMap = new Map(ctxWithId.narrowedBindings ?? []);
413
- narrowedMap.set(originalName, {
414
- kind: "rename",
415
- name: narrowedName,
416
- type: narrowing.targetType,
417
- });
577
+ const narrowedMap = buildRenameNarrowedMap(originalName, narrowedName, narrowing.targetType, ctxWithId);
418
578
  return {
419
579
  originalName,
420
580
  targetType: narrowing.targetType,
421
581
  memberN,
422
582
  unionArity,
583
+ runtimeUnionArity: frame.runtimeUnionArity,
584
+ candidateMemberNs: frame.candidateMemberNs,
585
+ candidateMembers: frame.members,
423
586
  ctxWithId,
424
587
  narrowedName,
425
588
  escapedOrig,