@scriptc/compiler 0.0.30 → 0.0.32

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.
@@ -1826,9 +1826,7 @@ export function lowerTernary(L, expr, expected) {
1826
1826
  const constituents = t.isUnionType() ? t.getTypes() : [];
1827
1827
  const nonArray = constituents.filter((a) => !L.checker.isArrayType(a) && !L.checker.isTupleType(a));
1828
1828
  const mapped = L.mapTypeOf(t);
1829
- const armCount = mapped?.kind === "union"
1830
- ? (L.unions.get(mapped.unionId)?.arms.filter((a) => a.kind === "array").length ?? 0)
1831
- : 0;
1829
+ const armCount = mapped?.kind === "union" ? L.arrayValueTags(mapped.unionId).length : 0;
1832
1830
  if (sym && nonArray.length === 1 && armCount === 1) {
1833
1831
  falseArmNarrowType = nonArray[0];
1834
1832
  const collect = (n) => {
@@ -2102,25 +2100,20 @@ export function maybeNarrow(L, expr, node) {
2102
2100
  }
2103
2101
  if (expr.type.kind !== "union")
2104
2102
  return expr;
2105
- const narrowed = L.mapTypeOf(L.typeOf(node));
2106
- // `Array.isArray(u)` on a `string | readonly string[]` union: the lib
2107
- // predicate narrows the READONLY arm to `any[]` (tsc's readonly-array
2108
- // quirk), which maps to the island's array-of-handles (or nothing) —
2109
- // but the tag test proved the union's one array arm, so the bridge is
2110
- // the same trusted unionNarrow the mapped case below builds (the
2111
- // certs configuredTlds shape).
2112
- if (!narrowed || (narrowed.kind === "array" && narrowed.elem.kind === "jsval")) {
2113
- const t = L.typeOf(node);
2114
- const anyElem = L.checker.isArrayType(t) &&
2115
- ((L.checker.getTypeArguments(t)[0]?.flags ?? 0) &
2116
- (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0;
2117
- if (anyElem) {
2118
- const def = L.unions.get(expr.type.unionId);
2119
- const arrayTags = def ? def.arms.flatMap((a, i) => (a.kind === "array" ? [i] : [])) : [];
2120
- if (arrayTags.length === 1) {
2121
- const arm = def.arms[arrayTags[0]];
2122
- return { kind: "unionNarrow", unionId: expr.type.unionId, tag: arrayTags[0], value: expr, type: arm, loc: expr.loc };
2123
- }
2103
+ const narrowedTs = L.typeOf(node);
2104
+ const narrowed = L.mapTypeOf(narrowedTs);
2105
+ // `Array.isArray(u)` on a union with one readonly array/tuple arm: the
2106
+ // lib predicate narrows to `any[]`, either directly or intersected
2107
+ // with the original union. That checker type can map to the island's
2108
+ // array-of-handles, nothing, or a synthetic intersection record — but
2109
+ // the tag test proved the union's one array-valued arm, so bridge to it
2110
+ // with the same trusted unionNarrow the mapped case below builds.
2111
+ if (L.checkerAnyArrayType(narrowedTs)) {
2112
+ const def = L.unions.get(expr.type.unionId);
2113
+ const arrayTags = L.arrayValueTags(expr.type.unionId);
2114
+ if (arrayTags.length === 1) {
2115
+ const arm = def.arms[arrayTags[0]];
2116
+ return { kind: "unionNarrow", unionId: expr.type.unionId, tag: arrayTags[0], value: expr, type: arm, loc: expr.loc };
2124
2117
  }
2125
2118
  }
2126
2119
  // A checker type narrowed to a UNIT arm (the `=== undefined` branch)
@@ -5565,9 +5558,17 @@ export function lowerElementAccess(L, expr) {
5565
5558
  // `const cmd = ['pwd', []]`, whose binding lowered checked-dynamic)
5566
5559
  // dispatches as unmapped so the dyn-receiver branch below reads
5567
5560
  // through the checked-dynamic tree instead of dynChecking into never's f64 residue.
5568
- const receiverIr = neverTaintedJsType(L, expr.expression, L.typeOf(expr.expression))
5561
+ let receiverIr = neverTaintedJsType(L, expr.expression, L.typeOf(expr.expression))
5569
5562
  ? null
5570
5563
  : L.mapTypeOf(L.typeOf(expr.expression));
5564
+ // A readonly tuple union under Array.isArray is checker-typed as an
5565
+ // intersection with any[], whose structural mapping is not the tuple
5566
+ // shape. maybeNarrow on the receiver uses the runtime tag proof to
5567
+ // extract the one array-valued arm; dispatch element access from that
5568
+ // lowered representation, like the existing any[] array-method path.
5569
+ const checkerArray = L.checkerArrayValue(expr.expression);
5570
+ if (checkerArray)
5571
+ receiverIr = checkerArray.type;
5571
5572
  if (receiverIr?.kind === "jsval") {
5572
5573
  // Dispatch follows the RUNTIME world (383(d)): a checker-'any'
5573
5574
  // receiver whose value LOWERED checked-dynamic (`bag.list[0]` where
@@ -9350,7 +9351,14 @@ export function lowerFieldRead(L, expr) {
9350
9351
  return L.fieldGetExpr(target, locOf(expr), expr);
9351
9352
  if (expr.questionDotToken)
9352
9353
  return null;
9353
- const receiverIr = L.mapTypeOf(L.typeOf(expr.expression));
9354
+ let receiverIr = L.mapTypeOf(L.typeOf(expr.expression));
9355
+ // The readonly-tuple Array.isArray narrow has no directly mappable
9356
+ // checker type (`Result & any[]`), but maybeNarrow extracted the tuple
9357
+ // record behind it. Route tuple properties such as `.length` from that
9358
+ // lowered value, the element-access bridge's twin.
9359
+ const checkerArray = L.checkerArrayValue(expr.expression);
9360
+ if (checkerArray?.type.kind === "record")
9361
+ receiverIr = checkerArray.type;
9354
9362
  if (receiverIr?.kind === "object" &&
9355
9363
  (L.findMethodOn(L.classes.get(receiverIr.className) ?? null, expr.name.text) ||
9356
9364
  findGenericMethodOn(L, L.classes.get(receiverIr.className) ?? null, expr.name.text))) {