@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.
- package/ambient/scriptc-node-fallback.d.ts +1 -1
- package/dist/backend/cc.d.ts +11 -5
- package/dist/backend/cc.js +38 -7
- package/dist/backend/cc.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +5 -4
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.js +12 -2
- package/dist/frontend/lowering/lower-containers.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.js +32 -24
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.js +3 -2
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +26 -7
- package/dist/frontend/lowering/lowerer.js +56 -11
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/library/int-infer.js +7 -1
- package/dist/library/int-infer.js.map +1 -1
- package/dist/library/int-infer.test.js +69 -0
- package/dist/library/int-infer.test.js.map +1 -1
- package/package.json +2 -2
- package/surface-manifest.json +1 -1
|
@@ -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
|
|
2106
|
-
|
|
2107
|
-
//
|
|
2108
|
-
//
|
|
2109
|
-
//
|
|
2110
|
-
//
|
|
2111
|
-
//
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
const
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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))) {
|