@scriptc/compiler 0.1.1 → 0.1.3
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 +104 -31
- package/ambient/scriptc.d.ts +2 -1
- package/dist/backend/build-cache.js.map +1 -1
- package/dist/backend/c/async.d.ts +5 -0
- package/dist/backend/c/async.js +81 -2
- package/dist/backend/c/async.js.map +1 -1
- package/dist/backend/c/c-emitter.d.ts +25 -10
- package/dist/backend/c/c-emitter.js +74 -22
- package/dist/backend/c/c-emitter.js.map +1 -1
- package/dist/backend/c/exprs.d.ts +8 -1
- package/dist/backend/c/exprs.js +371 -18
- package/dist/backend/c/exprs.js.map +1 -1
- package/dist/backend/c/island.js.map +1 -1
- package/dist/backend/c/may-throw.js.map +1 -1
- package/dist/backend/c/shapes.js +15 -13
- package/dist/backend/c/shapes.js.map +1 -1
- package/dist/backend/c/stmts.d.ts +3 -5
- package/dist/backend/c/stmts.js +58 -17
- package/dist/backend/c/stmts.js.map +1 -1
- package/dist/backend/c/types.d.ts +4 -0
- package/dist/backend/c/types.js +18 -1
- package/dist/backend/c/types.js.map +1 -1
- package/dist/backend/c/types.test.js +8 -1
- package/dist/backend/c/types.test.js.map +1 -1
- package/dist/backend/c/walkers.js +63 -16
- package/dist/backend/c/walkers.js.map +1 -1
- package/dist/backend/external-c.js.map +1 -1
- package/dist/backend/json-literal.d.ts +7 -0
- package/dist/backend/json-literal.js +17 -0
- package/dist/backend/json-literal.js.map +1 -0
- package/dist/backend/json-literal.test.d.ts +1 -0
- package/dist/backend/json-literal.test.js +17 -0
- package/dist/backend/json-literal.test.js.map +1 -0
- package/dist/backend/link-plan.d.ts +1 -1
- package/dist/backend/link-plan.js +5 -1
- package/dist/backend/link-plan.js.map +1 -1
- package/dist/backend/linker.js.map +1 -1
- package/dist/backend/llvm/blocks.js.map +1 -1
- package/dist/backend/llvm/classes.js +8 -7
- package/dist/backend/llvm/classes.js.map +1 -1
- package/dist/backend/llvm/common.d.ts +4 -0
- package/dist/backend/llvm/common.js +6 -0
- package/dist/backend/llvm/common.js.map +1 -1
- package/dist/backend/llvm/common.test.d.ts +1 -0
- package/dist/backend/llvm/common.test.js +9 -0
- package/dist/backend/llvm/common.test.js.map +1 -0
- package/dist/backend/llvm/dyn.d.ts +4 -0
- package/dist/backend/llvm/dyn.js +80 -16
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.js +132 -25
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/expr-async.js +85 -3
- package/dist/backend/llvm/expr-async.js.map +1 -1
- package/dist/backend/llvm/expr-bytes.js.map +1 -1
- package/dist/backend/llvm/expr-calls.js.map +1 -1
- package/dist/backend/llvm/expr-containers.js.map +1 -1
- package/dist/backend/llvm/expr-context.d.ts +5 -0
- package/dist/backend/llvm/expr-control.js.map +1 -1
- package/dist/backend/llvm/expr-dispatch.js.map +1 -1
- package/dist/backend/llvm/expr-dynamic.js +15 -3
- package/dist/backend/llvm/expr-dynamic.js.map +1 -1
- package/dist/backend/llvm/expr-island.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.js +8 -0
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- package/dist/backend/llvm/expr-records.js +3 -3
- package/dist/backend/llvm/expr-records.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.js +222 -10
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
- package/dist/backend/llvm/expr-stream-callbacks.d.ts +3 -0
- package/dist/backend/llvm/expr-stream-callbacks.js +53 -0
- package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
- package/dist/backend/llvm/lib-dispatch.js +24 -0
- package/dist/backend/llvm/lib-dispatch.js.map +1 -1
- package/dist/backend/llvm/lib-process.js +50 -5
- package/dist/backend/llvm/lib-process.js.map +1 -1
- package/dist/backend/llvm/lib-shared.js +64 -0
- package/dist/backend/llvm/lib-shared.js.map +1 -1
- package/dist/backend/llvm/lib-stream.js +6 -3
- package/dist/backend/llvm/lib-stream.js.map +1 -1
- package/dist/backend/llvm/shapes.js +10 -8
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/backend/llvm/split.js.map +1 -1
- package/dist/backend/llvm/unsupported.js.map +1 -1
- package/dist/backend/llvm/walkers.js +7 -5
- package/dist/backend/llvm/walkers.js.map +1 -1
- package/dist/backend/native-codegen.js.map +1 -1
- package/dist/backend/native-codegen.test.js +2 -0
- package/dist/backend/native-codegen.test.js.map +1 -1
- package/dist/backend/native-link-info.d.ts +2 -1
- package/dist/backend/native-link-info.js +4 -0
- package/dist/backend/native-link-info.js.map +1 -1
- package/dist/backend/native-link-info.test.js +24 -1
- package/dist/backend/native-link-info.test.js.map +1 -1
- package/dist/backend/native-toolchain.d.ts +8 -6
- package/dist/backend/native-toolchain.js +28 -13
- package/dist/backend/native-toolchain.js.map +1 -1
- package/dist/backend/native-toolchain.test.js +36 -1
- package/dist/backend/native-toolchain.test.js.map +1 -1
- package/dist/backend/runtime-pack-targets.test.js +1 -1
- package/dist/backend/runtime-pack-targets.test.js.map +1 -1
- package/dist/backend/runtime-pack.js.map +1 -1
- package/dist/backend/runtime-pack.test.js +1 -0
- package/dist/backend/runtime-pack.test.js.map +1 -1
- package/dist/backend/targets.d.ts +5 -0
- package/dist/backend/targets.js +9 -0
- package/dist/backend/targets.js.map +1 -1
- package/dist/backend/targets.test.js +6 -1
- package/dist/backend/targets.test.js.map +1 -1
- package/dist/backend/vendor-archives.js.map +1 -1
- package/dist/compat/fetch-profile.js +4 -2
- package/dist/compat/fetch-profile.js.map +1 -1
- package/dist/coverage/report.js.map +1 -1
- package/dist/coverage/surface-manifest.js +13 -0
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/diagnostics/diagnostic.d.ts +6 -5
- package/dist/diagnostics/diagnostic.js +10 -9
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/diagnostics/render.js.map +1 -1
- package/dist/executable/executable-cache.d.ts +1 -0
- package/dist/executable/executable-cache.js +1 -0
- package/dist/executable/executable-cache.js.map +1 -1
- package/dist/executable/executable-cache.test.js +1 -0
- package/dist/executable/executable-cache.test.js.map +1 -1
- package/dist/ffi/ffi-manifest.js.map +1 -1
- package/dist/frontend/cjs-lexer.js.map +1 -1
- package/dist/frontend/dts-paths.js.map +1 -1
- package/dist/frontend/input-tracker.d.ts +10 -0
- package/dist/frontend/input-tracker.js +26 -3
- package/dist/frontend/input-tracker.js.map +1 -1
- package/dist/frontend/input-tracker.test.js +8 -1
- package/dist/frontend/input-tracker.test.js.map +1 -1
- package/dist/frontend/lib-contract.js.map +1 -1
- package/dist/frontend/lowering/array-values.d.ts +4 -0
- package/dist/frontend/lowering/array-values.js +18 -2
- package/dist/frontend/lowering/array-values.js.map +1 -1
- package/dist/frontend/lowering/callback-arg.js.map +1 -1
- package/dist/frontend/lowering/containers/bytes.d.ts +31 -0
- package/dist/frontend/lowering/containers/bytes.js +1105 -0
- package/dist/frontend/lowering/containers/bytes.js.map +1 -0
- package/dist/frontend/lowering/containers/string-and-regexp.d.ts +17 -0
- package/dist/frontend/lowering/containers/string-and-regexp.js +345 -0
- package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -0
- package/dist/frontend/lowering/expressions/evaluation-safety.d.ts +13 -0
- package/dist/frontend/lowering/expressions/evaluation-safety.js +76 -0
- package/dist/frontend/lowering/expressions/evaluation-safety.js.map +1 -0
- package/dist/frontend/lowering/expressions/object-literals.d.ts +44 -0
- package/dist/frontend/lowering/expressions/object-literals.js +1815 -0
- package/dist/frontend/lowering/expressions/object-literals.js.map +1 -0
- package/dist/frontend/lowering/expressions/optional-chains.d.ts +31 -0
- package/dist/frontend/lowering/expressions/optional-chains.js +382 -0
- package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -0
- package/dist/frontend/lowering/expressions/try-lower-expression.d.ts +7 -0
- package/dist/frontend/lowering/expressions/try-lower-expression.js +26 -0
- package/dist/frontend/lowering/expressions/try-lower-expression.js.map +1 -0
- package/dist/frontend/lowering/lib-boundary.js +7 -2
- package/dist/frontend/lowering/lib-boundary.js.map +1 -1
- package/dist/frontend/lowering/lower-assert.js +16 -10
- package/dist/frontend/lowering/lower-assert.js.map +1 -1
- package/dist/frontend/lowering/lower-async-iteration.d.ts +7 -0
- package/dist/frontend/lowering/lower-async-iteration.js +657 -0
- package/dist/frontend/lowering/lower-async-iteration.js.map +1 -0
- package/dist/frontend/lowering/lower-builtins.d.ts +40 -21
- package/dist/frontend/lowering/lower-builtins.js +611 -115
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.d.ts +21 -10
- package/dist/frontend/lowering/lower-calls.js +516 -75
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.d.ts +7 -13
- package/dist/frontend/lowering/lower-classes.js +128 -35
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-comptime.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.d.ts +1 -47
- package/dist/frontend/lowering/lower-containers.js +147 -1475
- package/dist/frontend/lowering/lower-containers.js.map +1 -1
- package/dist/frontend/lowering/lower-event-emitter.js +51 -5
- package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.d.ts +0 -78
- package/dist/frontend/lowering/lower-exprs.js +503 -2353
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-generators.d.ts +18 -3
- package/dist/frontend/lowering/lower-generators.js +145 -9
- package/dist/frontend/lowering/lower-generators.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.js +10 -3
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-island.d.ts +6 -0
- package/dist/frontend/lowering/lower-island.js +37 -5
- package/dist/frontend/lowering/lower-island.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.js +60 -15
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-node-module.d.ts +18 -0
- package/dist/frontend/lowering/lower-node-module.js +302 -0
- package/dist/frontend/lowering/lower-node-module.js.map +1 -0
- package/dist/frontend/lowering/lower-server.js +1 -1
- package/dist/frontend/lowering/lower-server.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.d.ts +10 -28
- package/dist/frontend/lowering/lower-stmts.js +542 -259
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lower-stream.js +4 -4
- package/dist/frontend/lowering/lower-stream.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +41 -38
- package/dist/frontend/lowering/lowerer.js +148 -62
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/optional-arguments.d.ts +9 -0
- package/dist/frontend/lowering/optional-arguments.js +57 -0
- package/dist/frontend/lowering/optional-arguments.js.map +1 -0
- package/dist/frontend/lowering/surfaces.d.ts +5 -3
- package/dist/frontend/lowering/surfaces.js +33 -13
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/npm-static-declarations.d.ts +35 -0
- package/dist/frontend/npm-static-declarations.js +519 -0
- package/dist/frontend/npm-static-declarations.js.map +1 -0
- package/dist/frontend/npm-static-declarations.test.d.ts +1 -0
- package/dist/frontend/npm-static-declarations.test.js +132 -0
- package/dist/frontend/npm-static-declarations.test.js.map +1 -0
- package/dist/frontend/npm-static.d.ts +2 -0
- package/dist/frontend/npm-static.js +26 -10
- package/dist/frontend/npm-static.js.map +1 -1
- package/dist/frontend/npm.d.ts +60 -0
- package/dist/frontend/npm.js +38 -4
- package/dist/frontend/npm.js.map +1 -1
- package/dist/frontend/npm.test.d.ts +1 -0
- package/dist/frontend/npm.test.js +50 -0
- package/dist/frontend/npm.test.js.map +1 -0
- package/dist/frontend/program.d.ts +3 -2
- package/dist/frontend/program.js +513 -70
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/resolve.d.ts +26 -3
- package/dist/frontend/resolve.js +166 -29
- package/dist/frontend/resolve.js.map +1 -1
- package/dist/frontend/resolve.test.js +24 -1
- package/dist/frontend/resolve.test.js.map +1 -1
- package/dist/frontend/runtime-resolve.d.ts +22 -0
- package/dist/frontend/runtime-resolve.js +101 -0
- package/dist/frontend/runtime-resolve.js.map +1 -0
- package/dist/frontend/runtime-resolve.test.d.ts +1 -0
- package/dist/frontend/runtime-resolve.test.js +18 -0
- package/dist/frontend/runtime-resolve.test.js.map +1 -0
- package/dist/frontend/ts7/adapter.js +12 -13
- package/dist/frontend/ts7/adapter.js.map +1 -1
- package/dist/frontend/ts7/ast.js.map +1 -1
- package/dist/frontend/ts7/census-check.js +3 -3
- package/dist/frontend/ts7/census-check.js.map +1 -1
- package/dist/frontend/ts7/checker.d.ts +3 -0
- package/dist/frontend/ts7/checker.js +12 -3
- package/dist/frontend/ts7/checker.js.map +1 -1
- package/dist/frontend/ts7/enums.js.map +1 -1
- package/dist/frontend/ts7/program-adapter.js +42 -3
- package/dist/frontend/ts7/program-adapter.js.map +1 -1
- package/dist/frontend/type-mapper.js +171 -16
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/dist/ir/analysis.js +1 -0
- package/dist/ir/analysis.js.map +1 -1
- package/dist/ir/ir.d.ts +125 -52
- package/dist/ir/ir.js +136 -7
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/serialize.d.ts +1 -1
- package/dist/ir/serialize.js +1 -1
- package/dist/ir/validate.js +120 -63
- package/dist/ir/validate.js.map +1 -1
- package/dist/library/cache-primitives.js.map +1 -1
- package/dist/library/cache-reset.test.js.map +1 -1
- package/dist/library/compiler-self-identity.js.map +1 -1
- package/dist/library/int-infer.js.map +1 -1
- package/dist/library/int-infer.test.js +4 -4
- package/dist/library/int-infer.test.js.map +1 -1
- package/dist/library/library-cache.d.ts +1 -0
- package/dist/library/library-cache.js +1 -0
- package/dist/library/library-cache.js.map +1 -1
- package/dist/library/library-cache.test.js +18 -5
- package/dist/library/library-cache.test.js.map +1 -1
- package/dist/library/library-profile.js.map +1 -1
- package/dist/library/sidecar-validate.js.map +1 -1
- package/dist/library/sidecar.js.map +1 -1
- package/dist/startup-cache.js.map +1 -1
- package/dist/wasi-paths.js.map +1 -1
- package/package.json +18 -18
- package/surface-manifest.json +91 -20
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { InternalCompilerError } from "../errors.js";
|
|
2
2
|
import * as ts from "./ts7/adapter.js";
|
|
3
|
-
import { arrayOf, BOOL, bytesOf, canConvertToDyn, CHILD_T, DATE_T, DYN, F64, funcOf, isSupportedArrayElem, isSupportedIndexValue, isSupportedMapKey, isSupportedMapValue, isSupportedSetElem, isUnitType, JSVAL, mapOf, NULL_T, PROCSTREAM_T, RUNTIME_EMITTER_CLASS, RUNTIME_ERROR_CLASSES, RUNTIME_STREAM_CLASSES, setOf, STRING, SYMBOL_T, typeEquals, typeKey, UNDEFINED_T, VOID } from "../ir/ir.js";
|
|
3
|
+
import { arrayOf, BOOL, bytesOf, canConvertToDyn, CHILD_T, CRYPTOHASH_T, CRYPTOHMAC_T, DATE_T, DYN, F64, funcOf, isSupportedArrayElem, isSupportedIndexValue, isSupportedMapKey, isSupportedMapValue, isSupportedSetElem, isUnitType, JSVAL, mapOf, NULL_T, PROCSTREAM_T, RUNTIME_EMITTER_CLASS, RUNTIME_ERROR_CLASSES, RUNTIME_STREAM_CLASSES, setOf, STRING, SYMBOL_T, typeEquals, typeKey, UNDEFINED_T, VOID } from "../ir/ir.js";
|
|
4
|
+
import { BIGINT_T } from "../ir/ir.js";
|
|
4
5
|
import { isJsSourceFile, isNodeTypesPath } from "./program.js";
|
|
5
6
|
import { accessorSlotProp } from "../ir/ir.js";
|
|
6
7
|
// typeKey moved to ir/ir.ts (the backend needs it too, for per-type
|
|
@@ -472,6 +473,8 @@ export function formatIrType(t, shapes, unions, seen = new Set()) {
|
|
|
472
473
|
return "URLSearchParams";
|
|
473
474
|
case "symbol":
|
|
474
475
|
return "symbol";
|
|
476
|
+
case "bigint":
|
|
477
|
+
return "bigint";
|
|
475
478
|
case "stats":
|
|
476
479
|
return "Stats";
|
|
477
480
|
case "fileHandle":
|
|
@@ -500,16 +503,22 @@ export function formatIrType(t, shapes, unions, seen = new Set()) {
|
|
|
500
503
|
return "ClientRequest";
|
|
501
504
|
case "secureCtx":
|
|
502
505
|
return "SecureContext";
|
|
506
|
+
case "cryptoHash":
|
|
507
|
+
return "Hash";
|
|
508
|
+
case "cryptoHmac":
|
|
509
|
+
return "Hmac";
|
|
503
510
|
case "fsWatcher":
|
|
504
511
|
return "FSWatcher";
|
|
505
512
|
case "childStream":
|
|
506
513
|
return "Readable";
|
|
514
|
+
case "childWriter":
|
|
515
|
+
return "Writable";
|
|
507
516
|
case "procStream":
|
|
508
517
|
return "WriteStream";
|
|
509
518
|
case "promise":
|
|
510
519
|
return `Promise<${formatIrType(t.inner, shapes, unions, seen)}>`;
|
|
511
520
|
case "generator":
|
|
512
|
-
return
|
|
521
|
+
return `${t.async ? "AsyncGenerator" : "Generator"}<${formatIrType(t.yieldT, shapes, unions, seen)}, ${formatIrType(t.retT, shapes, unions, seen)}, ${formatIrType(t.nextT, shapes, unions, seen)}>`;
|
|
513
522
|
default: {
|
|
514
523
|
const _exhaustive = t;
|
|
515
524
|
void _exhaustive;
|
|
@@ -831,6 +840,8 @@ function mapTypeInner(type, ctx) {
|
|
|
831
840
|
// map to the symbol identity kind.
|
|
832
841
|
if (flags & (ts.TypeFlags.ESSymbol | ts.TypeFlags.UniqueESSymbol))
|
|
833
842
|
return SYMBOL_T;
|
|
843
|
+
if (flags & (ts.TypeFlags.BigInt | ts.TypeFlags.BigIntLiteral))
|
|
844
|
+
return BIGINT_T;
|
|
834
845
|
// STANDALONE undefined (and void) map to VOID: return-type mapping flows
|
|
835
846
|
// through here, and `(): void | undefined` functions must stay void.
|
|
836
847
|
// Inside a union, undefined becomes the undefinedT unit ARM instead (see
|
|
@@ -1070,6 +1081,17 @@ function mapTypeInner(type, ctx) {
|
|
|
1070
1081
|
fields.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
1071
1082
|
return { kind: "record", shapeId: ctx.shapes.intern(fields, true) };
|
|
1072
1083
|
}
|
|
1084
|
+
// BRANDED PRIMITIVES (`string & { readonly __brand: "UserId" }`,
|
|
1085
|
+
// `number & { readonly [tag]: "Meters" }`): the marker object is purely
|
|
1086
|
+
// type-level, so the value rides the primitive's runtime representation.
|
|
1087
|
+
// The recognizer is deliberately narrower than primitive-and-any-object:
|
|
1088
|
+
// runtime-bearing class, callable, indexed, and non-literal data shapes
|
|
1089
|
+
// remain intersections with no representation.
|
|
1090
|
+
if (widened.isIntersectionType()) {
|
|
1091
|
+
const brandedPrimitive = mapBrandedPrimitiveIntersection(widened, ctx);
|
|
1092
|
+
if (brandedPrimitive)
|
|
1093
|
+
return brandedPrimitive;
|
|
1094
|
+
}
|
|
1073
1095
|
// Class instances: the type's symbol is a class declared in the user's
|
|
1074
1096
|
// file. The class NAME as a value has the *constructor* type — same
|
|
1075
1097
|
// REFINED handle intersections — @types/node's idioms: `ServerResponse<
|
|
@@ -1083,7 +1105,7 @@ function mapTypeInner(type, ctx) {
|
|
|
1083
1105
|
// no class identity of its own.
|
|
1084
1106
|
if (widened.isIntersectionType()) {
|
|
1085
1107
|
const HANDLE_KINDS = new Set([
|
|
1086
|
-
"netServer", "netSocket", "httpReq", "httpRes", "httpClientReq", "dgramSocket",
|
|
1108
|
+
"netServer", "netSocket", "httpReq", "httpRes", "httpClientReq", "dgramSocket", "childWriter",
|
|
1087
1109
|
// process.stdout's own type IS the refined intersection
|
|
1088
1110
|
// `WriteStream & { fd: 1 }` — the scalar stream kind rides the same
|
|
1089
1111
|
// refinement rule.
|
|
@@ -1254,6 +1276,20 @@ function mapTypeInner(type, ctx) {
|
|
|
1254
1276
|
// (`x.toString()`) fences at each use site, never silently.
|
|
1255
1277
|
if (isStdlibInterface("Object"))
|
|
1256
1278
|
return DYN;
|
|
1279
|
+
// NodeJS.Module / the shipped fallback's ScriptcModule: a process-lifetime
|
|
1280
|
+
// scalar handle into the compiled CommonJS module registry. Module
|
|
1281
|
+
// identity is numeric identity; its fields are served by the dedicated
|
|
1282
|
+
// module lowering before generic number operations can observe the
|
|
1283
|
+
// representation. The node:module class's merged instance interface is
|
|
1284
|
+
// included, while unrelated user interfaces named Module stay structural.
|
|
1285
|
+
if ((psym?.name === "ScriptcModule" || psym?.name === "Module") &&
|
|
1286
|
+
checker.declarationsOf(psym).some((d) => (ts.isInterfaceDeclaration(d) || ts.isClassDeclaration(d)) &&
|
|
1287
|
+
ctx.isStdlibFile(d.getSourceFile()) &&
|
|
1288
|
+
(psym.name === "ScriptcModule" ||
|
|
1289
|
+
isDeclaredInAmbientNamespace(d, "NodeJS") ||
|
|
1290
|
+
isDeclaredInAmbientModule(d, "module")))) {
|
|
1291
|
+
return F64;
|
|
1292
|
+
}
|
|
1257
1293
|
// events.EventEmitter: the runtime-provided emitter base class (the
|
|
1258
1294
|
// Error-hierarchy precedent — user subclasses resolved through the
|
|
1259
1295
|
// class-instance branch above). Both type layers declare it in the
|
|
@@ -1572,11 +1608,16 @@ function mapTypeInner(type, ctx) {
|
|
|
1572
1608
|
ctx.isStdlibFile(d.getSourceFile()))) {
|
|
1573
1609
|
return { kind: "spawnRes" };
|
|
1574
1610
|
}
|
|
1575
|
-
// child_process.ChildProcess
|
|
1576
|
-
//
|
|
1577
|
-
|
|
1611
|
+
// child_process.ChildProcess and @types/node's stdio-refined return
|
|
1612
|
+
// interfaces: all carry the same runtime child handle; the generic
|
|
1613
|
+
// refinements only tell the checker which stdio properties are null.
|
|
1614
|
+
if (psym !== undefined &&
|
|
1615
|
+
(psym.name === "ChildProcess" ||
|
|
1616
|
+
psym.name === "ChildProcessWithoutNullStreams" ||
|
|
1617
|
+
psym.name === "ChildProcessByStdio") &&
|
|
1578
1618
|
checker.declarationsOf(psym).some((d) => (ts.isInterfaceDeclaration(d) || ts.isClassDeclaration(d)) &&
|
|
1579
|
-
ctx.isStdlibFile(d.getSourceFile())
|
|
1619
|
+
ctx.isStdlibFile(d.getSourceFile()) &&
|
|
1620
|
+
isDeclaredInAmbientModule(d, "child_process"))) {
|
|
1580
1621
|
return { kind: "child" };
|
|
1581
1622
|
}
|
|
1582
1623
|
// net.Server / net.Socket: @types/node's classes or the fallback
|
|
@@ -1613,6 +1654,15 @@ function mapTypeInner(type, ctx) {
|
|
|
1613
1654
|
isDeclaredInAmbientModule(d, "tls"))) {
|
|
1614
1655
|
return { kind: "secureCtx" };
|
|
1615
1656
|
}
|
|
1657
|
+
// crypto.Hash / crypto.Hmac: native incremental digest handles. Keep
|
|
1658
|
+
// provenance module-qualified so user classes with these common names
|
|
1659
|
+
// retain their ordinary structural/class representation.
|
|
1660
|
+
if ((psym?.name === "Hash" || psym?.name === "Hmac") &&
|
|
1661
|
+
checker.declarationsOf(psym).some((d) => (ts.isInterfaceDeclaration(d) || ts.isClassDeclaration(d)) &&
|
|
1662
|
+
ctx.isStdlibFile(d.getSourceFile()) &&
|
|
1663
|
+
isDeclaredInAmbientModule(d, "crypto"))) {
|
|
1664
|
+
return psym.name === "Hash" ? CRYPTOHASH_T : CRYPTOHMAC_T;
|
|
1665
|
+
}
|
|
1616
1666
|
// fs.FSWatcher: the fs.watch handle (scr_watch.c). Module-checked like
|
|
1617
1667
|
// net.Server — @types/node declares `interface FSWatcher extends
|
|
1618
1668
|
// EventEmitter` inside `declare module "fs"`, and the shipped fallback
|
|
@@ -1650,6 +1700,21 @@ function mapTypeInner(type, ctx) {
|
|
|
1650
1700
|
isDeclaredInAmbientNamespace(d, "NodeJS")))) {
|
|
1651
1701
|
return PROCSTREAM_T;
|
|
1652
1702
|
}
|
|
1703
|
+
// A piped child stdin writer. The fallback declarations give it the
|
|
1704
|
+
// dedicated ChildStdin name; @types/node spells the same value as
|
|
1705
|
+
// stream.Writable. As with stream.Readable below, unsupported producers
|
|
1706
|
+
// of the broad @types class fence where they are constructed.
|
|
1707
|
+
if ((psym?.name === "ChildStdin" &&
|
|
1708
|
+
checker.declarationsOf(psym).some((d) => ts.isInterfaceDeclaration(d) &&
|
|
1709
|
+
ctx.isStdlibFile(d.getSourceFile()) &&
|
|
1710
|
+
isDeclaredInAmbientModule(d, "child_process"))) ||
|
|
1711
|
+
(psym?.name === "Writable" &&
|
|
1712
|
+
checker.declarationsOf(psym).some((d) => (ts.isInterfaceDeclaration(d) || ts.isClassDeclaration(d)) &&
|
|
1713
|
+
ctx.isStdlibFile(d.getSourceFile()) &&
|
|
1714
|
+
isNodeTypesPath(d.getSourceFile().fileName) &&
|
|
1715
|
+
isDeclaredInAmbientModule(d, "stream")))) {
|
|
1716
|
+
return { kind: "childWriter" };
|
|
1717
|
+
}
|
|
1653
1718
|
// The static node:stream classes (the shipped fallback declarations —
|
|
1654
1719
|
// NOT @types/node, whose stream.Readable also types child stdio; under
|
|
1655
1720
|
// @types/node the childStream mapping below keeps priority and the
|
|
@@ -1811,9 +1876,9 @@ function mapTypeInner(type, ctx) {
|
|
|
1811
1876
|
return null;
|
|
1812
1877
|
return { kind: "promise", inner };
|
|
1813
1878
|
}
|
|
1814
|
-
// Generator<T, TReturn, TNext
|
|
1815
|
-
// the
|
|
1816
|
-
// generator kind. Channel normalization keeps the runtime honest:
|
|
1879
|
+
// Generator<T, TReturn, TNext>, AsyncGenerator<T, TReturn, TNext> (and
|
|
1880
|
+
// the lib's IterableIterator<T, ...>, the older sync annotation spelling):
|
|
1881
|
+
// the generator kind. Channel normalization keeps the runtime honest:
|
|
1817
1882
|
// yield channel — T must be a real value type (a generator that could
|
|
1818
1883
|
// only yield undefined has no C value form); `never`
|
|
1819
1884
|
// (a generator that never yields) rides the VOID
|
|
@@ -1829,7 +1894,7 @@ function mapTypeInner(type, ctx) {
|
|
|
1829
1894
|
// argument — fenced at the call).
|
|
1830
1895
|
// Mixed dyn/concrete channels stay unmapped: the shared result record's
|
|
1831
1896
|
// value slot would need a dyn union arm, which does not exist.
|
|
1832
|
-
if (isStdlibInterface("Generator") || isStdlibInterface("IterableIterator")) {
|
|
1897
|
+
if (isStdlibInterface("Generator") || isStdlibInterface("AsyncGenerator") || isStdlibInterface("IterableIterator")) {
|
|
1833
1898
|
const args = checker.getTypeArguments(widened);
|
|
1834
1899
|
const channels = genChannels(args[0], args[1], args[2], ctx);
|
|
1835
1900
|
if (!channels)
|
|
@@ -1838,7 +1903,11 @@ function mapTypeInner(type, ctx) {
|
|
|
1838
1903
|
// `.next()` could never answer — mapped generators always resume.
|
|
1839
1904
|
if (!genResultRecord(channels.yieldT, channels.retT, ctx.shapes, unions))
|
|
1840
1905
|
return null;
|
|
1841
|
-
return {
|
|
1906
|
+
return {
|
|
1907
|
+
kind: "generator",
|
|
1908
|
+
...(isStdlibInterface("AsyncGenerator") ? { async: true } : {}),
|
|
1909
|
+
...channels,
|
|
1910
|
+
};
|
|
1842
1911
|
}
|
|
1843
1912
|
// IteratorResult<T, TReturn> — the checker's type of `g.next()` (an
|
|
1844
1913
|
// alias for IteratorYieldResult<T> | IteratorReturnResult<TReturn>):
|
|
@@ -2208,7 +2277,7 @@ function mapTypeInner(type, ctx) {
|
|
|
2208
2277
|
// NgrokChildProcess idiom — `spawn(...) as NgrokChildProcess`, declared
|
|
2209
2278
|
// so tests can hand in mocks): every member is named on the lowered
|
|
2210
2279
|
// ChildProcess surface AND at least two are the handle-defining ones
|
|
2211
|
-
// (kill/on/stdout/stderr/unref/exitCode — a data record like
|
|
2280
|
+
// (kill/on/stdin/stdout/stderr/unref/exitCode — a data record like
|
|
2212
2281
|
// `{ pid: number }` never qualifies). The TYPE maps to the child
|
|
2213
2282
|
// handle: in a compiled program the only VALUE producer is spawn
|
|
2214
2283
|
// itself (a mock object literal in this slot fences at its
|
|
@@ -2222,9 +2291,9 @@ function mapTypeInner(type, ctx) {
|
|
|
2222
2291
|
checker.declarationsOf(psym).every((d) => ts.isInterfaceDeclaration(d) && !ctx.isStdlibFile(d.getSourceFile()))) {
|
|
2223
2292
|
const CHILD_SURFACE = new Set([
|
|
2224
2293
|
"pid", "exitCode", "killed", "kill", "on", "once", "off",
|
|
2225
|
-
"removeListener", "unref", "ref", "stdout", "stderr",
|
|
2294
|
+
"removeListener", "unref", "ref", "stdin", "stdout", "stderr",
|
|
2226
2295
|
]);
|
|
2227
|
-
const CHILD_CORE = new Set(["kill", "on", "stdout", "stderr", "unref", "exitCode"]);
|
|
2296
|
+
const CHILD_CORE = new Set(["kill", "on", "stdin", "stdout", "stderr", "unref", "exitCode"]);
|
|
2228
2297
|
const props = checker.getPropertiesOfType(widened);
|
|
2229
2298
|
let core = 0;
|
|
2230
2299
|
const childShaped = props.length > 0 &&
|
|
@@ -2733,7 +2802,7 @@ export function genResultRecord(yieldT, retT, shapes, unions) {
|
|
|
2733
2802
|
shapeId: shapes.intern([
|
|
2734
2803
|
{ name: "done", type: BOOL },
|
|
2735
2804
|
{ name: "value", type: valueT },
|
|
2736
|
-
]),
|
|
2805
|
+
], false, undefined, ["value", "done"]),
|
|
2737
2806
|
};
|
|
2738
2807
|
}
|
|
2739
2808
|
/** True when a checker type is inhabited ONLY by the unit values —
|
|
@@ -2830,6 +2899,92 @@ function mapHybridCallableIntersection(widened, ctx) {
|
|
|
2830
2899
|
fields.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
2831
2900
|
return { kind: "record", shapeId: shapes.intern(fields, false, undefined, declaredOrder) };
|
|
2832
2901
|
}
|
|
2902
|
+
/** A conventional primitive brand has one runtime-carrying primitive part
|
|
2903
|
+
* and one or more phantom object parts whose fields are literal marker
|
|
2904
|
+
* values. The marker can use a string or unique-symbol key, can be imported
|
|
2905
|
+
* from a declaration file, and can be expressed through a generic alias;
|
|
2906
|
+
* none of those facts changes the runtime value. Empty `{}` refinements are
|
|
2907
|
+
* the marker-free form of the same primitive narrowing.
|
|
2908
|
+
*
|
|
2909
|
+
* Arbitrary primitive/object intersections do not erase here. A companion
|
|
2910
|
+
* with a class identity, call/construct/index signature, accessor, or a
|
|
2911
|
+
* non-literal value field might describe runtime behavior, so it retains the
|
|
2912
|
+
* SC2008 refusal instead of borrowing the primitive representation. */
|
|
2913
|
+
function mapBrandedPrimitiveIntersection(widened, ctx) {
|
|
2914
|
+
if (!widened.isIntersectionType())
|
|
2915
|
+
return null;
|
|
2916
|
+
const { checker, resolveTypeParam, resolveTypeParamTs } = ctx;
|
|
2917
|
+
const primitivePart = (part) => {
|
|
2918
|
+
const base = checker.getBaseTypeOfLiteralType(part);
|
|
2919
|
+
if (base.flags & ts.TypeFlags.Number)
|
|
2920
|
+
return F64;
|
|
2921
|
+
if (base.flags & ts.TypeFlags.String)
|
|
2922
|
+
return STRING;
|
|
2923
|
+
if (base.flags & (ts.TypeFlags.Boolean | ts.TypeFlags.BooleanLiteral))
|
|
2924
|
+
return BOOL;
|
|
2925
|
+
if (base.flags & (ts.TypeFlags.ESSymbol | ts.TypeFlags.UniqueESSymbol))
|
|
2926
|
+
return SYMBOL_T;
|
|
2927
|
+
if (base.flags & (ts.TypeFlags.BigInt | ts.TypeFlags.BigIntLiteral))
|
|
2928
|
+
return BIGINT_T;
|
|
2929
|
+
if (base.flags & ts.TypeFlags.TypeParameter) {
|
|
2930
|
+
const bound = resolveTypeParam?.(base) ?? null;
|
|
2931
|
+
if (bound && (bound.kind === "f64" || bound.kind === "bigint" || bound.kind === "string" || bound.kind === "bool" || bound.kind === "symbol")) {
|
|
2932
|
+
contextResolutions++;
|
|
2933
|
+
return bound;
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2936
|
+
return null;
|
|
2937
|
+
};
|
|
2938
|
+
const markerValue = (value) => {
|
|
2939
|
+
if (value.flags &
|
|
2940
|
+
(ts.TypeFlags.StringLiteral |
|
|
2941
|
+
ts.TypeFlags.NumberLiteral |
|
|
2942
|
+
ts.TypeFlags.BigIntLiteral |
|
|
2943
|
+
ts.TypeFlags.BooleanLiteral |
|
|
2944
|
+
ts.TypeFlags.UniqueESSymbol |
|
|
2945
|
+
ts.TypeFlags.EnumLiteral |
|
|
2946
|
+
ts.TypeFlags.Never |
|
|
2947
|
+
ts.TypeFlags.Undefined |
|
|
2948
|
+
ts.TypeFlags.Void |
|
|
2949
|
+
ts.TypeFlags.Null)) {
|
|
2950
|
+
return true;
|
|
2951
|
+
}
|
|
2952
|
+
if (value.isUnionType())
|
|
2953
|
+
return ts.constituentTypes(value).every(markerValue);
|
|
2954
|
+
if (value.flags & ts.TypeFlags.TypeParameter) {
|
|
2955
|
+
const bound = resolveTypeParamTs?.(value) ?? null;
|
|
2956
|
+
if (bound) {
|
|
2957
|
+
contextResolutions++;
|
|
2958
|
+
return markerValue(bound);
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
return false;
|
|
2962
|
+
};
|
|
2963
|
+
let primitive = null;
|
|
2964
|
+
let markerParts = 0;
|
|
2965
|
+
for (const part of ts.constituentTypes(widened)) {
|
|
2966
|
+
const mappedPrimitive = primitivePart(part);
|
|
2967
|
+
if (mappedPrimitive) {
|
|
2968
|
+
if (primitive && !typeEquals(primitive, mappedPrimitive))
|
|
2969
|
+
return null;
|
|
2970
|
+
primitive = mappedPrimitive;
|
|
2971
|
+
continue;
|
|
2972
|
+
}
|
|
2973
|
+
const partSym = part.getSymbol();
|
|
2974
|
+
const props = checker.getPropertiesOfType(part);
|
|
2975
|
+
if ((part.flags & ts.TypeFlags.Object) === 0 ||
|
|
2976
|
+
checker.getCallSignatures(part).length > 0 ||
|
|
2977
|
+
checker.getConstructSignatures(part).length > 0 ||
|
|
2978
|
+
checker.getIndexInfosOfType(part).length > 0 ||
|
|
2979
|
+
(partSym !== undefined && (partSym.flags & ts.SymbolFlags.Class) !== 0) ||
|
|
2980
|
+
props.some((prop) => (prop.flags & (ts.SymbolFlags.GetAccessor | ts.SymbolFlags.SetAccessor)) !== 0 ||
|
|
2981
|
+
!markerValue(checker.getTypeOfSymbol(prop)))) {
|
|
2982
|
+
return null;
|
|
2983
|
+
}
|
|
2984
|
+
markerParts++;
|
|
2985
|
+
}
|
|
2986
|
+
return primitive && markerParts > 0 ? primitive : null;
|
|
2987
|
+
}
|
|
2833
2988
|
/** True for MAPPED-type results — `Partial<Config>`, `Record<"a", n>`,
|
|
2834
2989
|
* whatever `Pick`/`Omit` reduce to. Their shape is computed by the checker,
|
|
2835
2990
|
* not declared anywhere: the only declaration behind them is the utility
|