@scriptc/compiler 0.0.21 → 0.0.22
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 +78 -34
- package/dist/backend/cc-cache.test.d.ts +1 -0
- package/dist/backend/cc-cache.test.js +2507 -0
- package/dist/backend/cc-cache.test.js.map +1 -0
- package/dist/backend/cc.d.ts +69 -11
- package/dist/backend/cc.js +1937 -222
- package/dist/backend/cc.js.map +1 -1
- package/dist/backend/emission/emit-exprs.js +355 -8
- package/dist/backend/emission/emit-exprs.js.map +1 -1
- package/dist/backend/emission/emit-walkers.js +108 -7
- package/dist/backend/emission/emit-walkers.js.map +1 -1
- package/dist/backend/emission/emitter.d.ts +16 -0
- package/dist/backend/emission/emitter.js +23 -2
- package/dist/backend/emission/emitter.js.map +1 -1
- package/dist/backend/llvm/dyn.d.ts +1 -0
- package/dist/backend/llvm/dyn.js +305 -8
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.js +527 -2
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/compat/fetch-profile.d.ts +108 -0
- package/dist/compat/fetch-profile.js +482 -0
- package/dist/compat/fetch-profile.js.map +1 -0
- package/dist/coverage/surface-manifest.js +54 -0
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/frontend/lowering/lower-builtins.d.ts +21 -8
- package/dist/frontend/lowering/lower-builtins.js +137 -14
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +40 -0
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.js +4 -3
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.d.ts +2 -2
- package/dist/frontend/lowering/lower-exprs.js +63 -12
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-island.d.ts +102 -7
- package/dist/frontend/lowering/lower-island.js +1702 -26
- package/dist/frontend/lowering/lower-island.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.js +17 -1
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.js +25 -5
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +39 -0
- package/dist/frontend/lowering/lowerer.js +286 -18
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/surfaces.js +12 -0
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/program.d.ts +16 -0
- package/dist/frontend/program.js +130 -6
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/types.d.ts +14 -7
- package/dist/frontend/types.js +95 -31
- package/dist/frontend/types.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +70 -14
- package/dist/index.js.map +1 -1
- package/dist/ir/nodes.d.ts +32 -16
- package/dist/ir/nodes.js +36 -28
- package/dist/ir/nodes.js.map +1 -1
- package/dist/ir/validate.js +61 -1
- package/dist/ir/validate.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 +80 -0
- package/dist/library/int-infer.test.js.map +1 -1
- package/dist/library/sidecar-validate.js +5 -0
- package/dist/library/sidecar-validate.js.map +1 -1
- package/dist/library/sidecar.d.ts +3 -0
- package/dist/library/sidecar.js.map +1 -1
- package/package.json +2 -2
- package/surface-manifest.json +859 -1
package/dist/frontend/types.js
CHANGED
|
@@ -6,13 +6,28 @@ import { accessorSlotProp } from "../ir/nodes.js";
|
|
|
6
6
|
// helper interning); re-exported here so frontend call sites keep their
|
|
7
7
|
// import path.
|
|
8
8
|
export { typeKey };
|
|
9
|
-
/** The
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
9
|
+
/** The ambient TYPE names of the fetch slice. Under --dynamic their
|
|
10
|
+
* values live in the embedded engine and map to island handles (jsval).
|
|
11
|
+
* Static fetch gives Response, RequestInit, AbortSignal, response
|
|
12
|
+
* Headers, and the readable Web Streams slice native checked-dynamic
|
|
13
|
+
* handle representations. The Headers constructor itself remains
|
|
14
|
+
* dynamic-only even though response.headers is native.
|
|
15
|
+
* Declaration provenance is checked in mapType so user types with the
|
|
16
|
+
* same names keep their ordinary structural representation. */
|
|
17
|
+
export const ISLAND_AMBIENT_TYPES = [
|
|
18
|
+
"Response",
|
|
19
|
+
"RequestInit",
|
|
20
|
+
"Event",
|
|
21
|
+
"EventTarget",
|
|
22
|
+
"AbortSignal",
|
|
23
|
+
"Headers",
|
|
24
|
+
"ReadableStream",
|
|
25
|
+
"ReadableStreamDefaultReader",
|
|
26
|
+
"ReadableStreamDefaultController",
|
|
27
|
+
"ReadableStreamReadResult",
|
|
28
|
+
"ReadableStreamReadValueResult",
|
|
29
|
+
"ReadableStreamReadDoneResult",
|
|
30
|
+
];
|
|
16
31
|
/** The frontend's record-shape interner. Records are monomorphic structural
|
|
17
32
|
* shapes: fields sorted by name form the canonical identity, and two types
|
|
18
33
|
* with the same canonical field list share one shapeId (and later one C
|
|
@@ -729,17 +744,19 @@ function mapTypeInner(type, ctx) {
|
|
|
729
744
|
// rule fires only when the type's own identity is declaration-file-
|
|
730
745
|
// declared — interfaces, classes, type literals, and aliases from the
|
|
731
746
|
// .d.ts. The standard library's declaration files are carved out (their
|
|
732
|
-
// surfaces have static lowerings),
|
|
733
|
-
//
|
|
734
|
-
//
|
|
735
|
-
//
|
|
747
|
+
// surfaces have static lowerings), as are declarations explicitly mapped
|
|
748
|
+
// by --external-types: those describe project-owned structural data while
|
|
749
|
+
// the Lowerer fences their imported runtime bindings. The program's own
|
|
750
|
+
// compiled modules are never declaration files. Without --dynamic this
|
|
751
|
+
// stays unmapped; badType reports the per-package requires-dynamic
|
|
752
|
+
// diagnostic for node_modules types and the generic story otherwise.
|
|
736
753
|
const npmSym = widened.getAliasSymbol() ?? widened.getSymbol();
|
|
737
754
|
const npmDecls = npmSym ? checker.declarationsOf(npmSym) : undefined;
|
|
738
755
|
if (npmDecls &&
|
|
739
756
|
npmDecls.length > 0 &&
|
|
740
757
|
npmDecls.every((d) => {
|
|
741
758
|
const sf = d.getSourceFile();
|
|
742
|
-
return sf.isDeclarationFile && !ctx.isStdlibFile(sf);
|
|
759
|
+
return sf.isDeclarationFile && !ctx.isStdlibFile(sf) && !ctx.isExternalTypeFile(sf);
|
|
743
760
|
})) {
|
|
744
761
|
return ctx.dynamic ? JSVAL : null;
|
|
745
762
|
}
|
|
@@ -1188,23 +1205,57 @@ function mapTypeInner(type, ctx) {
|
|
|
1188
1205
|
// read has its own lowering (errno/syscall/path stay per-member fences).
|
|
1189
1206
|
if (isStdlibInterface("ErrnoException"))
|
|
1190
1207
|
return { kind: "object", className: "%Error" };
|
|
1191
|
-
// The fetch ambient slice
|
|
1192
|
-
//
|
|
1193
|
-
//
|
|
1194
|
-
//
|
|
1195
|
-
//
|
|
1196
|
-
//
|
|
1197
|
-
//
|
|
1198
|
-
//
|
|
1199
|
-
//
|
|
1200
|
-
// for a bare value of the type).
|
|
1208
|
+
// The fetch ambient slice: under --dynamic these are island handles
|
|
1209
|
+
// exactly like npm-declared types. Static fetch has one deliberately
|
|
1210
|
+
// narrower native representation: Response is an opaque checked-
|
|
1211
|
+
// dynamic capsule consumed only by the Response method lowerings, and
|
|
1212
|
+
// RequestInit is a checked-dynamic options object consumed by native
|
|
1213
|
+
// fetch. AbortSignal, response Headers, and the readable Web Streams
|
|
1214
|
+
// slice are native handles carried by that same checked-dynamic
|
|
1215
|
+
// representation. Provenance, not names: a user's own `interface
|
|
1216
|
+
// Response` maps as a record like any other.
|
|
1201
1217
|
// Interface OR class declarations (the shipped fallback declares
|
|
1202
1218
|
// interfaces; @types/node's undici-types declares Response as a class).
|
|
1219
|
+
{
|
|
1220
|
+
const alias = widened.getAliasSymbol();
|
|
1221
|
+
if (!ctx.dynamic &&
|
|
1222
|
+
alias?.name === "ReadableStreamReadResult" &&
|
|
1223
|
+
checker.declarationsOf(alias).some((d) => ts.isTypeAliasDeclaration(d) &&
|
|
1224
|
+
ctx.isStdlibFile(d.getSourceFile()))) {
|
|
1225
|
+
const elemTs = widened.getAliasTypeArguments()?.[0];
|
|
1226
|
+
const elem = elemTs && elemTs.flags & ts.TypeFlags.Any
|
|
1227
|
+
? DYN
|
|
1228
|
+
: elemTs
|
|
1229
|
+
? mapType(elemTs, ctx)
|
|
1230
|
+
: null;
|
|
1231
|
+
if (!elem)
|
|
1232
|
+
return null;
|
|
1233
|
+
return genResultRecord(elem, VOID, ctx.shapes, ctx.unions);
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
if (!ctx.dynamic &&
|
|
1237
|
+
psym &&
|
|
1238
|
+
(psym.name === "ReadableStreamReadValueResult" ||
|
|
1239
|
+
psym.name === "ReadableStreamReadDoneResult") &&
|
|
1240
|
+
checker.declarationsOf(psym).some((d) => ts.isInterfaceDeclaration(d) &&
|
|
1241
|
+
ctx.isStdlibFile(d.getSourceFile()))) {
|
|
1242
|
+
const elemTs = checker.getTypeArguments(widened)[0];
|
|
1243
|
+
const elem = elemTs && elemTs.flags & ts.TypeFlags.Any
|
|
1244
|
+
? DYN
|
|
1245
|
+
: elemTs
|
|
1246
|
+
? mapType(elemTs, ctx)
|
|
1247
|
+
: null;
|
|
1248
|
+
if (!elem)
|
|
1249
|
+
return null;
|
|
1250
|
+
return genResultRecord(elem, VOID, ctx.shapes, ctx.unions);
|
|
1251
|
+
}
|
|
1203
1252
|
if (psym &&
|
|
1204
1253
|
ISLAND_AMBIENT_TYPES.includes(psym.name) &&
|
|
1254
|
+
!(psym.name === "ReadableStream" &&
|
|
1255
|
+
checker.declarationsOf(psym).some((d) => ts.isInterfaceDeclaration(d) && isDeclaredInAmbientNamespace(d, "NodeJS"))) &&
|
|
1205
1256
|
checker.declarationsOf(psym).some((d) => (ts.isInterfaceDeclaration(d) || ts.isClassDeclaration(d)) &&
|
|
1206
1257
|
ctx.isStdlibFile(d.getSourceFile()))) {
|
|
1207
|
-
return ctx.dynamic ? JSVAL :
|
|
1258
|
+
return ctx.dynamic ? JSVAL : DYN;
|
|
1208
1259
|
}
|
|
1209
1260
|
// ReadonlyMap/ReadonlySet are the SAME runtime values as Map/Set — the
|
|
1210
1261
|
// readonly-ness is a checker-only view (no mutating members on the
|
|
@@ -2576,15 +2627,17 @@ function isMappedShape(t) {
|
|
|
2576
2627
|
(t.objectFlags & ts.ObjectFlags.Mapped) !== 0);
|
|
2577
2628
|
}
|
|
2578
2629
|
/** The record path's provenance fence. Declared shapes (object literals,
|
|
2579
|
-
* interfaces, type literals) must come from user code
|
|
2580
|
-
*
|
|
2630
|
+
* interfaces, type literals) must come from user code or an explicitly
|
|
2631
|
+
* mapped external type surface, never an arbitrary .d.ts — the empty
|
|
2632
|
+
* ambient interfaces (Object, Function, Boolean, ...) exist only to
|
|
2581
2633
|
* satisfy tsc and must not become zero-field records. Checker-COMPUTED
|
|
2582
2634
|
* shapes (mapped-type results, intersections) have no user declaration to
|
|
2583
2635
|
* point at: mapped types pass here and get per-MEMBER provenance in the
|
|
2584
2636
|
* field walk instead; an intersection passes when every part is itself an
|
|
2585
2637
|
* ordinary provenance-passing object type (class parts keep their nominal
|
|
2586
2638
|
* identity and never flatten into a struct). */
|
|
2587
|
-
function recordProvenanceOk(t,
|
|
2639
|
+
function recordProvenanceOk(t, ctx) {
|
|
2640
|
+
const { checker } = ctx;
|
|
2588
2641
|
if (t.isIntersectionType()) {
|
|
2589
2642
|
return t.getTypes().every((part) => {
|
|
2590
2643
|
const partSym = part.getSymbol();
|
|
@@ -2592,7 +2645,7 @@ function recordProvenanceOk(t, checker) {
|
|
|
2592
2645
|
!(partSym && partSym.flags & ts.SymbolFlags.Class) &&
|
|
2593
2646
|
checker.getCallSignatures(part).length === 0 &&
|
|
2594
2647
|
checker.getConstructSignatures(part).length === 0 &&
|
|
2595
|
-
recordProvenanceOk(part,
|
|
2648
|
+
recordProvenanceOk(part, ctx);
|
|
2596
2649
|
});
|
|
2597
2650
|
}
|
|
2598
2651
|
if (isMappedShape(t))
|
|
@@ -2601,7 +2654,10 @@ function recordProvenanceOk(t, checker) {
|
|
|
2601
2654
|
const decls = tSym ? checker.declarationsOf(tSym) : undefined;
|
|
2602
2655
|
if (!decls || decls.length === 0)
|
|
2603
2656
|
return false;
|
|
2604
|
-
return !decls.some((d) =>
|
|
2657
|
+
return !decls.some((d) => {
|
|
2658
|
+
const sf = d.getSourceFile();
|
|
2659
|
+
return sf.isDeclarationFile && !ctx.isExternalTypeFile(sf);
|
|
2660
|
+
});
|
|
2605
2661
|
}
|
|
2606
2662
|
/** A GENERIC-callable member type (`m<T>(x: T): T` / `f: <T>(x: T) => T` in
|
|
2607
2663
|
* an object type): pure function-shaped — call signatures only, every one
|
|
@@ -2793,7 +2849,7 @@ function mapRecordTypeInner(widened, ctx) {
|
|
|
2793
2849
|
!widened.isIntersectionType() &&
|
|
2794
2850
|
indexValue === undefined &&
|
|
2795
2851
|
checker.getPropertiesOfType(widened).length === 0;
|
|
2796
|
-
if (!recordProvenanceOk(widened,
|
|
2852
|
+
if (!recordProvenanceOk(widened, ctx) && !pureIndexShape && !anonymousEmpty)
|
|
2797
2853
|
return null;
|
|
2798
2854
|
// Checker-computed shapes (no user declaration) need two extra fences in
|
|
2799
2855
|
// the member walk below; see the comments there.
|
|
@@ -2895,7 +2951,11 @@ function mapRecordTypeInner(widened, ctx) {
|
|
|
2895
2951
|
// lib interface (`Readonly<Date>`) is still the lib's type world, not
|
|
2896
2952
|
// a data shape. Synthesized members (a literal-key Record's) have no
|
|
2897
2953
|
// declarations and pass.
|
|
2898
|
-
if (computed &&
|
|
2954
|
+
if (computed &&
|
|
2955
|
+
checker.declarationsOf(p).some((d) => {
|
|
2956
|
+
const sf = d.getSourceFile();
|
|
2957
|
+
return sf.isDeclarationFile && !ctx.isExternalTypeFile(sf);
|
|
2958
|
+
})) {
|
|
2899
2959
|
return null;
|
|
2900
2960
|
}
|
|
2901
2961
|
const fieldTs = checker.getTypeOfSymbol(p);
|
|
@@ -3192,7 +3252,11 @@ export function describeRecordMemberBlocker(widened, ctx) {
|
|
|
3192
3252
|
// Computed shapes over LIBRARY members (`Readonly<Date>`): the record
|
|
3193
3253
|
// fence there is per-member PROVENANCE (mapRecordTypeInner's rule), not
|
|
3194
3254
|
// any one member's type — that story stays with the residual fence.
|
|
3195
|
-
if (computed &&
|
|
3255
|
+
if (computed &&
|
|
3256
|
+
checker.declarationsOf(p).some((d) => {
|
|
3257
|
+
const sf = d.getSourceFile();
|
|
3258
|
+
return sf.isDeclarationFile && !ctx.isExternalTypeFile(sf);
|
|
3259
|
+
})) {
|
|
3196
3260
|
return null;
|
|
3197
3261
|
}
|
|
3198
3262
|
const fieldTs = checker.getTypeOfSymbol(p);
|