@scriptc/compiler 0.0.30 → 0.0.31
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/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/package.json +2 -2
- package/surface-manifest.json +1 -1
|
@@ -1044,6 +1044,15 @@ export declare class Lowerer {
|
|
|
1044
1044
|
/** formatIrType with this Lowerer's registries (records and unions expand
|
|
1045
1045
|
* to their structure in diagnostics). */
|
|
1046
1046
|
fmt(t: IrType): string;
|
|
1047
|
+
/** Whether an IR value has JavaScript Array identity. Homogeneous arrays
|
|
1048
|
+
* use the native array representation; non-empty fixed tuples use a
|
|
1049
|
+
* positional record shape so their slots can keep distinct types, but
|
|
1050
|
+
* Array.isArray must still answer true for both representations. */
|
|
1051
|
+
isArrayValueType(t: IrType): boolean;
|
|
1052
|
+
/** Runtime tags of every JavaScript-array arm in one union. Kept beside
|
|
1053
|
+
* isArrayValueType so Array.isArray's predicate and its narrowing bridge
|
|
1054
|
+
* cannot disagree about fixed tuple arms. */
|
|
1055
|
+
arrayValueTags(unionId: string): number[];
|
|
1047
1056
|
/** isJsonSafeType with this Lowerer's registries — the shared fence for
|
|
1048
1057
|
* what JSON.stringify accepts and what a checked cast can validate. */
|
|
1049
1058
|
jsonSafe(t: IrType): boolean;
|
|
@@ -1067,14 +1076,24 @@ export declare class Lowerer {
|
|
|
1067
1076
|
* arm before the JSON round trip). */
|
|
1068
1077
|
boundaryExitSafe(t: IrType): boolean;
|
|
1069
1078
|
isIslandExpr(node: ts.Expression): boolean;
|
|
1070
|
-
/** True when this node's CHECKER type is `any[]`/`unknown[]
|
|
1071
|
-
*
|
|
1072
|
-
*
|
|
1073
|
-
*
|
|
1074
|
-
*
|
|
1075
|
-
*
|
|
1076
|
-
*
|
|
1079
|
+
/** True when this node's CHECKER type is proven `any[]`/`unknown[]`,
|
|
1080
|
+
* directly or through the intersection tsc builds for a readonly tuple
|
|
1081
|
+
* union (`(Model | readonly [Model, Command]) & any[]`; TS7 distributes
|
|
1082
|
+
* this over the union arms). These are forms of the `arg is any[]`
|
|
1083
|
+
* Array.isArray predicate; the VALUE behind them can still be a real
|
|
1084
|
+
* static array/tuple (maybeNarrow's bridge extracts the union's one
|
|
1085
|
+
* array-valued arm), so receiver-typed dispatch falls back to the LOWERED
|
|
1086
|
+
* type under this test. */
|
|
1077
1087
|
checkerAnyArray(node: ts.Expression): boolean;
|
|
1088
|
+
/** Type-level half of checkerAnyArray, for narrowing sites that already
|
|
1089
|
+
* queried the checker type from a general AST node. */
|
|
1090
|
+
checkerAnyArrayType(t: ts.Type): boolean;
|
|
1091
|
+
/** The lowered static array/tuple value behind checkerAnyArray's
|
|
1092
|
+
* synthetic `any[]` spelling. Array.isArray can leave readonly tuple
|
|
1093
|
+
* unions as intersections that do not map directly, while maybeNarrow
|
|
1094
|
+
* still extracts the runtime-proven array arm from the original union.
|
|
1095
|
+
* Receiver dispatchers use this bridge instead of the synthetic type. */
|
|
1096
|
+
checkerArrayValue(node: ts.Expression): IrExpr | null;
|
|
1078
1097
|
/** Substitutes a bound type parameter anywhere inside mapType's recursion
|
|
1079
1098
|
* (`T`, `T[]`, `{ v: T }`, `(x: T) => T` all resolve). Inert outside
|
|
1080
1099
|
* generic instantiation. */
|
|
@@ -2683,6 +2683,20 @@ export class Lowerer {
|
|
|
2683
2683
|
fmt(t) {
|
|
2684
2684
|
return formatIrType(t, this.shapes, this.unions);
|
|
2685
2685
|
}
|
|
2686
|
+
/** Whether an IR value has JavaScript Array identity. Homogeneous arrays
|
|
2687
|
+
* use the native array representation; non-empty fixed tuples use a
|
|
2688
|
+
* positional record shape so their slots can keep distinct types, but
|
|
2689
|
+
* Array.isArray must still answer true for both representations. */
|
|
2690
|
+
isArrayValueType(t) {
|
|
2691
|
+
return t.kind === "array" || (t.kind === "record" && this.shapes.get(t.shapeId)?.tuple === true);
|
|
2692
|
+
}
|
|
2693
|
+
/** Runtime tags of every JavaScript-array arm in one union. Kept beside
|
|
2694
|
+
* isArrayValueType so Array.isArray's predicate and its narrowing bridge
|
|
2695
|
+
* cannot disagree about fixed tuple arms. */
|
|
2696
|
+
arrayValueTags(unionId) {
|
|
2697
|
+
const def = this.unions.get(unionId);
|
|
2698
|
+
return def ? def.arms.flatMap((arm, tag) => (this.isArrayValueType(arm) ? [tag] : [])) : [];
|
|
2699
|
+
}
|
|
2686
2700
|
/** isJsonSafeType with this Lowerer's registries — the shared fence for
|
|
2687
2701
|
* what JSON.stringify accepts and what a checked cast can validate. */
|
|
2688
2702
|
jsonSafe(t) {
|
|
@@ -2716,18 +2730,49 @@ export class Lowerer {
|
|
|
2716
2730
|
isIslandExpr(node) {
|
|
2717
2731
|
return isIslandExpr(this, node);
|
|
2718
2732
|
}
|
|
2719
|
-
/** True when this node's CHECKER type is `any[]`/`unknown[]
|
|
2720
|
-
*
|
|
2721
|
-
*
|
|
2722
|
-
*
|
|
2723
|
-
*
|
|
2724
|
-
*
|
|
2725
|
-
*
|
|
2733
|
+
/** True when this node's CHECKER type is proven `any[]`/`unknown[]`,
|
|
2734
|
+
* directly or through the intersection tsc builds for a readonly tuple
|
|
2735
|
+
* union (`(Model | readonly [Model, Command]) & any[]`; TS7 distributes
|
|
2736
|
+
* this over the union arms). These are forms of the `arg is any[]`
|
|
2737
|
+
* Array.isArray predicate; the VALUE behind them can still be a real
|
|
2738
|
+
* static array/tuple (maybeNarrow's bridge extracts the union's one
|
|
2739
|
+
* array-valued arm), so receiver-typed dispatch falls back to the LOWERED
|
|
2740
|
+
* type under this test. */
|
|
2726
2741
|
checkerAnyArray(node) {
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2742
|
+
return this.checkerAnyArrayType(this.typeOf(node));
|
|
2743
|
+
}
|
|
2744
|
+
/** Type-level half of checkerAnyArray, for narrowing sites that already
|
|
2745
|
+
* queried the checker type from a general AST node. */
|
|
2746
|
+
checkerAnyArrayType(t) {
|
|
2747
|
+
const isAnyArray = (part) => this.checker.isArrayType(part) &&
|
|
2748
|
+
((this.checker.getTypeArguments(part)[0]?.flags ?? 0) &
|
|
2749
|
+
(ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0;
|
|
2750
|
+
const visit = (part) => {
|
|
2751
|
+
if (isAnyArray(part))
|
|
2752
|
+
return true;
|
|
2753
|
+
// 5.9 leaves `(U) & any[]` as one intersection; 7 distributes it
|
|
2754
|
+
// into `(A & any[]) | (B & any[])`. An intersection is array-proven
|
|
2755
|
+
// when one constituent is; a union is array-proven only when EVERY
|
|
2756
|
+
// arm is, so an ordinary `any[] | string` never qualifies.
|
|
2757
|
+
if ((part.flags & ts.TypeFlags.Intersection) !== 0) {
|
|
2758
|
+
return part.getTypes().some(visit);
|
|
2759
|
+
}
|
|
2760
|
+
if (part.isUnionType())
|
|
2761
|
+
return part.getTypes().every(visit);
|
|
2762
|
+
return false;
|
|
2763
|
+
};
|
|
2764
|
+
return visit(t);
|
|
2765
|
+
}
|
|
2766
|
+
/** The lowered static array/tuple value behind checkerAnyArray's
|
|
2767
|
+
* synthetic `any[]` spelling. Array.isArray can leave readonly tuple
|
|
2768
|
+
* unions as intersections that do not map directly, while maybeNarrow
|
|
2769
|
+
* still extracts the runtime-proven array arm from the original union.
|
|
2770
|
+
* Receiver dispatchers use this bridge instead of the synthetic type. */
|
|
2771
|
+
checkerArrayValue(node) {
|
|
2772
|
+
if (!this.checkerAnyArray(node))
|
|
2773
|
+
return null;
|
|
2774
|
+
const value = this.lowerExpr(node);
|
|
2775
|
+
return this.isArrayValueType(value.type) ? value : null;
|
|
2731
2776
|
}
|
|
2732
2777
|
/** Substitutes a bound type parameter anywhere inside mapType's recursion
|
|
2733
2778
|
* (`T`, `T[]`, `{ v: T }`, `(x: T) => T` all resolve). Inert outside
|