@scriptc/compiler 0.2.1 → 0.2.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 +158 -31
- package/dist/backend/cycle-analysis.js +63 -50
- package/dist/backend/cycle-analysis.js.map +1 -1
- package/dist/backend/cycle-analysis.test.js +51 -0
- package/dist/backend/cycle-analysis.test.js.map +1 -1
- package/dist/backend/llvm/borrowed-receivers.d.ts +9 -0
- package/dist/backend/llvm/borrowed-receivers.js +58 -0
- package/dist/backend/llvm/borrowed-receivers.js.map +1 -0
- package/dist/backend/llvm/call-lifetimes.d.ts +20 -0
- package/dist/backend/llvm/call-lifetimes.js +179 -0
- package/dist/backend/llvm/call-lifetimes.js.map +1 -0
- package/dist/backend/llvm/call-lifetimes.test.d.ts +1 -0
- package/dist/backend/llvm/call-lifetimes.test.js +205 -0
- package/dist/backend/llvm/call-lifetimes.test.js.map +1 -0
- package/dist/backend/llvm/dyn.d.ts +5 -2
- package/dist/backend/llvm/dyn.js +163 -47
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.d.ts +37 -1
- package/dist/backend/llvm/emitter.js +209 -21
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/emitter.test.js +29 -2
- package/dist/backend/llvm/emitter.test.js.map +1 -1
- package/dist/backend/llvm/expr-async.js +1 -1
- package/dist/backend/llvm/expr-async.js.map +1 -1
- package/dist/backend/llvm/expr-calls.js +42 -5
- package/dist/backend/llvm/expr-calls.js.map +1 -1
- package/dist/backend/llvm/expr-containers.js +75 -13
- package/dist/backend/llvm/expr-containers.js.map +1 -1
- package/dist/backend/llvm/expr-dynamic.js +31 -6
- package/dist/backend/llvm/expr-dynamic.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.js +6 -5
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- package/dist/backend/llvm/expr-records.js +1 -1
- package/dist/backend/llvm/expr-records.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.js +75 -19
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
- package/dist/backend/llvm/expr-stream-callbacks.d.ts +2 -2
- package/dist/backend/llvm/expr-stream-callbacks.js +7 -57
- package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
- package/dist/backend/llvm/lib-dispatch.js +41 -3
- package/dist/backend/llvm/lib-dispatch.js.map +1 -1
- package/dist/backend/llvm/lib-filesystem.js +12 -9
- package/dist/backend/llvm/lib-filesystem.js.map +1 -1
- package/dist/backend/llvm/lib-shared.js +70 -2
- package/dist/backend/llvm/lib-shared.js.map +1 -1
- package/dist/backend/llvm/local-array-reads.d.ts +44 -0
- package/dist/backend/llvm/local-array-reads.js +313 -0
- package/dist/backend/llvm/local-array-reads.js.map +1 -0
- package/dist/backend/llvm/local-array-reads.test.d.ts +1 -0
- package/dist/backend/llvm/local-array-reads.test.js +446 -0
- package/dist/backend/llvm/local-array-reads.test.js.map +1 -0
- package/dist/backend/llvm/map-read-lifetimes.d.ts +36 -0
- package/dist/backend/llvm/map-read-lifetimes.js +128 -0
- package/dist/backend/llvm/map-read-lifetimes.js.map +1 -0
- package/dist/backend/llvm/map-read-lifetimes.test.d.ts +1 -0
- package/dist/backend/llvm/map-read-lifetimes.test.js +123 -0
- package/dist/backend/llvm/map-read-lifetimes.test.js.map +1 -0
- package/dist/backend/llvm/shapes.js +1 -0
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/backend/llvm/split.js +15 -5
- package/dist/backend/llvm/split.js.map +1 -1
- package/dist/backend/llvm/split.test.js +17 -0
- package/dist/backend/llvm/split.test.js.map +1 -1
- package/dist/backend/llvm/stack-unions.d.ts +20 -0
- package/dist/backend/llvm/stack-unions.js +61 -0
- package/dist/backend/llvm/stack-unions.js.map +1 -0
- package/dist/backend/llvm/stack-unions.test.d.ts +1 -0
- package/dist/backend/llvm/stack-unions.test.js +241 -0
- package/dist/backend/llvm/stack-unions.test.js.map +1 -0
- package/dist/backend/llvm/string-lifetimes.d.ts +12 -0
- package/dist/backend/llvm/string-lifetimes.js +70 -0
- package/dist/backend/llvm/string-lifetimes.js.map +1 -0
- package/dist/backend/llvm/string-lifetimes.test.d.ts +1 -0
- package/dist/backend/llvm/string-lifetimes.test.js +230 -0
- package/dist/backend/llvm/string-lifetimes.test.js.map +1 -0
- package/dist/backend/mangle.d.ts +2 -0
- package/dist/backend/mangle.js +4 -0
- package/dist/backend/mangle.js.map +1 -1
- package/dist/backend/may-throw.js +71 -29
- package/dist/backend/may-throw.js.map +1 -1
- package/dist/backend/may-throw.test.js +104 -1
- package/dist/backend/may-throw.test.js.map +1 -1
- package/dist/backend/native-codegen.d.ts +1 -1
- package/dist/backend/native-codegen.js +4 -3
- package/dist/backend/native-codegen.js.map +1 -1
- package/dist/backend/native-codegen.test.js +11 -0
- package/dist/backend/native-codegen.test.js.map +1 -1
- package/dist/backend/native-toolchain.d.ts +2 -2
- package/dist/backend/native-toolchain.js +2 -0
- package/dist/backend/native-toolchain.js.map +1 -1
- package/dist/backend/target-diagnostics.d.ts +5 -0
- package/dist/backend/target-diagnostics.js +72 -1
- package/dist/backend/target-diagnostics.js.map +1 -1
- package/dist/backend/target-diagnostics.test.d.ts +1 -0
- package/dist/backend/target-diagnostics.test.js +68 -0
- package/dist/backend/target-diagnostics.test.js.map +1 -0
- package/dist/coverage/surface-manifest.js +5 -3
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/executable/executable-cache.d.ts +7 -3
- package/dist/executable/executable-cache.js +47 -11
- package/dist/executable/executable-cache.js.map +1 -1
- package/dist/executable/executable-cache.test.js +109 -2
- package/dist/executable/executable-cache.test.js.map +1 -1
- package/dist/executable/prepare.js +2 -1
- package/dist/executable/prepare.js.map +1 -1
- package/dist/frontend/builtin-modules.d.ts +1 -1
- package/dist/frontend/builtin-modules.js +1 -1
- package/dist/frontend/builtin-modules.js.map +1 -1
- package/dist/frontend/function-completion.d.ts +6 -0
- package/dist/frontend/function-completion.js +50 -0
- package/dist/frontend/function-completion.js.map +1 -0
- package/dist/frontend/input-tracker.js +3 -3
- package/dist/frontend/input-tracker.js.map +1 -1
- package/dist/frontend/input-tracker.test.js +38 -2
- package/dist/frontend/input-tracker.test.js.map +1 -1
- package/dist/frontend/lowering/abstract-equality.js +5 -1
- package/dist/frontend/lowering/abstract-equality.js.map +1 -1
- package/dist/frontend/lowering/checked-iterable-spread.d.ts +4 -0
- package/dist/frontend/lowering/checked-iterable-spread.js +30 -0
- package/dist/frontend/lowering/checked-iterable-spread.js.map +1 -0
- package/dist/frontend/lowering/checked-promise-all.d.ts +5 -0
- package/dist/frontend/lowering/checked-promise-all.js +31 -0
- package/dist/frontend/lowering/checked-promise-all.js.map +1 -0
- package/dist/frontend/lowering/class-callbacks.d.ts +1 -1
- package/dist/frontend/lowering/class-callbacks.js +7 -6
- package/dist/frontend/lowering/class-callbacks.js.map +1 -1
- package/dist/frontend/lowering/class-construction.d.ts +2 -0
- package/dist/frontend/lowering/class-construction.js +34 -5
- package/dist/frontend/lowering/class-construction.js.map +1 -1
- package/dist/frontend/lowering/class-descriptors.d.ts +1 -1
- package/dist/frontend/lowering/class-descriptors.js +12 -5
- package/dist/frontend/lowering/class-descriptors.js.map +1 -1
- package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +25 -0
- package/dist/frontend/lowering/class-dynamic-dispatch.js +597 -78
- package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
- package/dist/frontend/lowering/class-dynamic-dispatch.test.js +64 -2
- package/dist/frontend/lowering/class-dynamic-dispatch.test.js.map +1 -1
- package/dist/frontend/lowering/class-instance-constructor.d.ts +1 -1
- package/dist/frontend/lowering/class-instance-constructor.js +11 -41
- package/dist/frontend/lowering/class-instance-constructor.js.map +1 -1
- package/dist/frontend/lowering/class-method-values.d.ts +16 -0
- package/dist/frontend/lowering/class-method-values.js +60 -29
- package/dist/frontend/lowering/class-method-values.js.map +1 -1
- package/dist/frontend/lowering/class-prototypes.d.ts +5 -1
- package/dist/frontend/lowering/class-prototypes.js +69 -10
- package/dist/frontend/lowering/class-prototypes.js.map +1 -1
- package/dist/frontend/lowering/class-runtime-statics.d.ts +4 -4
- package/dist/frontend/lowering/class-runtime-statics.js +26 -8
- package/dist/frontend/lowering/class-runtime-statics.js.map +1 -1
- package/dist/frontend/lowering/class-static-data.d.ts +1 -0
- package/dist/frontend/lowering/class-static-data.js +4 -2
- package/dist/frontend/lowering/class-static-data.js.map +1 -1
- package/dist/frontend/lowering/collection-ingestion.d.ts +31 -0
- package/dist/frontend/lowering/collection-ingestion.js +215 -0
- package/dist/frontend/lowering/collection-ingestion.js.map +1 -0
- package/dist/frontend/lowering/containers/bytes.js +19 -4
- package/dist/frontend/lowering/containers/bytes.js.map +1 -1
- package/dist/frontend/lowering/containers/string-and-regexp.js +6 -1
- package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
- package/dist/frontend/lowering/deferred-module-initializers.d.ts +13 -0
- package/dist/frontend/lowering/deferred-module-initializers.js +410 -0
- package/dist/frontend/lowering/deferred-module-initializers.js.map +1 -0
- package/dist/frontend/lowering/deferred-module-initializers.test.d.ts +1 -0
- package/dist/frontend/lowering/deferred-module-initializers.test.js +92 -0
- package/dist/frontend/lowering/deferred-module-initializers.test.js.map +1 -0
- package/dist/frontend/lowering/expressions/object-literals.js +31 -1
- package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
- package/dist/frontend/lowering/expressions/optional-chains.js +3 -3
- package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
- package/dist/frontend/lowering/import-meta.d.ts +10 -0
- package/dist/frontend/lowering/import-meta.js +52 -0
- package/dist/frontend/lowering/import-meta.js.map +1 -0
- package/dist/frontend/lowering/lower-assert.js +105 -41
- package/dist/frontend/lowering/lower-assert.js.map +1 -1
- package/dist/frontend/lowering/lower-builtin-values.d.ts +2 -0
- package/dist/frontend/lowering/lower-builtin-values.js +22 -1
- package/dist/frontend/lowering/lower-builtin-values.js.map +1 -1
- package/dist/frontend/lowering/lower-builtins.d.ts +7 -22
- package/dist/frontend/lowering/lower-builtins.js +439 -95
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +289 -76
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.d.ts +5 -0
- package/dist/frontend/lowering/lower-classes.js +443 -29
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.d.ts +6 -2
- package/dist/frontend/lowering/lower-containers.js +79 -20
- package/dist/frontend/lowering/lower-containers.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.d.ts +10 -6
- package/dist/frontend/lowering/lower-exprs.js +329 -170
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-generators.js +5 -1
- package/dist/frontend/lowering/lower-generators.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.js +58 -1
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-island.js +4 -0
- package/dist/frontend/lowering/lower-island.js.map +1 -1
- package/dist/frontend/lowering/lower-island.test.d.ts +1 -0
- package/dist/frontend/lowering/lower-island.test.js +51 -0
- package/dist/frontend/lowering/lower-island.test.js.map +1 -0
- package/dist/frontend/lowering/lower-modules.d.ts +1 -3
- package/dist/frontend/lowering/lower-modules.js +186 -82
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.test.js +69 -1
- package/dist/frontend/lowering/lower-modules.test.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.js +172 -103
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.test.d.ts +1 -0
- package/dist/frontend/lowering/lower-stmts.test.js +77 -0
- package/dist/frontend/lowering/lower-stmts.test.js.map +1 -0
- package/dist/frontend/lowering/lower-stream.js +2 -0
- package/dist/frontend/lowering/lower-stream.js.map +1 -1
- package/dist/frontend/lowering/lower-system-errors.d.ts +6 -0
- package/dist/frontend/lowering/lower-system-errors.js +29 -0
- package/dist/frontend/lowering/lower-system-errors.js.map +1 -0
- package/dist/frontend/lowering/lower-url.d.ts +2 -1
- package/dist/frontend/lowering/lower-url.js +32 -9
- package/dist/frontend/lowering/lower-url.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +30 -12
- package/dist/frontend/lowering/lowerer.js +268 -49
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/lowerer.test.js +38 -0
- package/dist/frontend/lowering/lowerer.test.js.map +1 -1
- package/dist/frontend/lowering/module-namespace-elements.d.ts +7 -0
- package/dist/frontend/lowering/module-namespace-elements.js +54 -0
- package/dist/frontend/lowering/module-namespace-elements.js.map +1 -0
- package/dist/frontend/lowering/object-factory-new.d.ts +4 -3
- package/dist/frontend/lowering/object-factory-new.js +27 -14
- package/dist/frontend/lowering/object-factory-new.js.map +1 -1
- package/dist/frontend/lowering/surfaces.d.ts +3 -2
- package/dist/frontend/lowering/surfaces.js +93 -33
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/lowering/text-decoder-encoding.js +3 -0
- package/dist/frontend/lowering/text-decoder-encoding.js.map +1 -1
- package/dist/frontend/lowering/text-decoder-encoding.test.js +2 -1
- package/dist/frontend/lowering/text-decoder-encoding.test.js.map +1 -1
- package/dist/frontend/module-syntax.d.ts +1 -1
- package/dist/frontend/module-syntax.js +8 -1
- package/dist/frontend/module-syntax.js.map +1 -1
- package/dist/frontend/module-syntax.test.js +10 -0
- package/dist/frontend/module-syntax.test.js.map +1 -1
- package/dist/frontend/npm.d.ts +4 -0
- package/dist/frontend/npm.js +86 -33
- package/dist/frontend/npm.js.map +1 -1
- package/dist/frontend/npm.test.js +103 -0
- package/dist/frontend/npm.test.js.map +1 -1
- package/dist/frontend/pipeline-native.js +2 -1
- package/dist/frontend/pipeline-native.js.map +1 -1
- package/dist/frontend/program.js +4 -2
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/services-node.js +3 -2
- package/dist/frontend/services-node.js.map +1 -1
- package/dist/frontend/services.d.ts +5 -1
- package/dist/frontend/services.js +9 -1
- package/dist/frontend/services.js.map +1 -1
- package/dist/frontend/services.test.js +21 -0
- package/dist/frontend/services.test.js.map +1 -1
- package/dist/frontend/ts7/ast-node.d.ts +2 -0
- package/dist/frontend/ts7/ast-node.js +30 -4
- package/dist/frontend/ts7/ast-node.js.map +1 -1
- package/dist/frontend/ts7/ast-node.test.js +60 -1
- package/dist/frontend/ts7/ast-node.test.js.map +1 -1
- package/dist/frontend/type-mapper.js +89 -14
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/frontend/union-discriminants.js +22 -7
- package/dist/frontend/union-discriminants.js.map +1 -1
- package/dist/index.js +19 -12
- 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/integer-loops.d.ts +7 -0
- package/dist/ir/integer-loops.js +23 -0
- package/dist/ir/integer-loops.js.map +1 -1
- package/dist/ir/integer-loops.test.d.ts +1 -0
- package/dist/ir/integer-loops.test.js +41 -0
- package/dist/ir/integer-loops.test.js.map +1 -0
- package/dist/ir/ir.d.ts +44 -26
- package/dist/ir/ir.js +69 -11
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/ir.test.js +18 -0
- package/dist/ir/ir.test.js.map +1 -1
- package/dist/ir/serialize.js +21 -1
- package/dist/ir/serialize.js.map +1 -1
- package/dist/ir/serialize.test.js +21 -0
- package/dist/ir/serialize.test.js.map +1 -1
- package/dist/ir/traverse.d.ts +0 -3
- package/dist/ir/traverse.js +33 -20
- package/dist/ir/traverse.js.map +1 -1
- package/dist/ir/validate.js +216 -80
- package/dist/ir/validate.js.map +1 -1
- package/dist/ir/validate.test.js +244 -1
- package/dist/ir/validate.test.js.map +1 -1
- package/dist/library/compiler-self-identity.js +1 -1
- package/dist/library/compiler-self-identity.test.js +2 -2
- package/dist/library/compiler-self-identity.test.js.map +1 -1
- package/dist/library/fence-eval.js +9 -2
- package/dist/library/fence-eval.js.map +1 -1
- package/dist/library/fence-eval.test.d.ts +1 -0
- package/dist/library/fence-eval.test.js +21 -0
- package/dist/library/fence-eval.test.js.map +1 -0
- package/dist/library/int-infer.d.ts +2 -2
- package/dist/library/int-infer.js +10 -7
- package/dist/library/int-infer.js.map +1 -1
- package/dist/library/int-infer.test.js +44 -0
- package/dist/library/int-infer.test.js.map +1 -1
- package/dist/library/prepare.js +2 -1
- package/dist/library/prepare.js.map +1 -1
- package/dist/native/runtime-typescript.d.ts +4 -0
- package/dist/native/runtime-typescript.js +61 -0
- package/dist/native/runtime-typescript.js.map +1 -0
- package/dist/native/runtime-typescript.test.d.ts +1 -0
- package/dist/native/runtime-typescript.test.js +41 -0
- package/dist/native/runtime-typescript.test.js.map +1 -0
- package/package.json +20 -20
- package/surface-manifest.json +385 -29
|
@@ -6,6 +6,7 @@ import { BIGINT_T } from "../ir/ir.js";
|
|
|
6
6
|
import { literalValues } from "./literal-values.js";
|
|
7
7
|
import { remapUnionDiscriminant } from "./union-discriminants.js";
|
|
8
8
|
import { isJsSourceFile, isNodeTypesPath } from "./program.js";
|
|
9
|
+
import { functionCanReturnUndefined } from "./function-completion.js";
|
|
9
10
|
import { accessorSlotProp, recordTextCodecClass } from "../ir/ir.js";
|
|
10
11
|
// typeKey moved to ir/ir.ts (the backend needs it too, for per-type
|
|
11
12
|
// helper interning); re-exported here so frontend call sites keep their
|
|
@@ -19,10 +20,12 @@ export function jsOpenObjectType(decl, type, shapes, unions) {
|
|
|
19
20
|
const arms = type.kind === "union" ? unions.get(type.unionId)?.arms : [type];
|
|
20
21
|
const present = arms?.filter((arm) => arm.kind !== "undefinedT");
|
|
21
22
|
const parameter = ts.isParameter(decl) ? decl : decl.parent && ts.isParameter(decl.parent) ? decl.parent : null;
|
|
22
|
-
//
|
|
23
|
+
// Array parameters in JavaScript also accept typed arrays. Keep
|
|
23
24
|
// their runtime storage at the boundary, including default [] parameters.
|
|
24
25
|
if (parameter && !parameter.dotDotDotToken && present?.length === 1 &&
|
|
25
|
-
present[0].kind === "array"
|
|
26
|
+
present[0].kind === "array")
|
|
27
|
+
return DYN;
|
|
28
|
+
if (parameter && !parameter.dotDotDotToken && present?.length === 1 && present[0].kind === "bytes")
|
|
26
29
|
return DYN;
|
|
27
30
|
// An unannotated JavaScript parameter's object default is a fallback,
|
|
28
31
|
// not a closed class contract. Published code routinely passes another
|
|
@@ -34,6 +37,10 @@ export function jsOpenObjectType(decl, type, shapes, unions) {
|
|
|
34
37
|
if (present?.length !== 1 || present[0].kind !== "record")
|
|
35
38
|
return type;
|
|
36
39
|
const shape = shapes.get(present[0].shapeId);
|
|
40
|
+
// JavaScript dictionaries allow missing keys and inherited properties.
|
|
41
|
+
// A typed index slot cannot represent either of those reads faithfully.
|
|
42
|
+
if (shape?.indexValue && !shape.tuple)
|
|
43
|
+
return DYN;
|
|
37
44
|
const unitOnly = (field) => isUnitType(field) || field.kind === "void" ||
|
|
38
45
|
field.kind === "union" && unions.get(field.unionId)?.arms.every(isUnitType) === true;
|
|
39
46
|
return shape && !shape.tuple && !shape.indexValue &&
|
|
@@ -1534,6 +1541,19 @@ function mapTypeInner(type, ctx) {
|
|
|
1534
1541
|
isDeclaredInAmbientModule(d, "diagnostics_channel"))) {
|
|
1535
1542
|
return F64;
|
|
1536
1543
|
}
|
|
1544
|
+
// Node names this result; the ambient WHATWG declaration uses a type literal.
|
|
1545
|
+
const encodeResult = psym && checker.declarationsOf(psym).some((decl) => {
|
|
1546
|
+
if (!ctx.isStdlibFile(decl.getSourceFile()))
|
|
1547
|
+
return false;
|
|
1548
|
+
if (ts.isInterfaceDeclaration(decl) && decl.name.text === "EncodeIntoResult")
|
|
1549
|
+
return true;
|
|
1550
|
+
const parent = decl.parent;
|
|
1551
|
+
return ts.isTypeLiteralNode(decl) && parent?.kind === ts.SyntaxKind.MethodSignature &&
|
|
1552
|
+
parent.name && ts.isIdentifier(parent.name) && parent.name.text === "encodeInto" &&
|
|
1553
|
+
parent.parent && ts.isInterfaceDeclaration(parent.parent) && parent.parent.name.text === "TextEncoder";
|
|
1554
|
+
});
|
|
1555
|
+
if (encodeResult)
|
|
1556
|
+
return { kind: "record", shapeId: ctx.shapes.intern([{ name: "read", type: F64 }, { name: "written", type: F64 }]) };
|
|
1537
1557
|
// WHATWG codec instances have ordinary reference identity and ownership.
|
|
1538
1558
|
// Their private encoding slot is omitted from enumeration and JSON.
|
|
1539
1559
|
if ((psym?.name === "TextEncoder" || psym?.name === "TextDecoder") &&
|
|
@@ -1720,9 +1740,8 @@ function mapTypeInner(type, ctx) {
|
|
|
1720
1740
|
// ArrayBuffer value exists. The other TypedArray flavors stay
|
|
1721
1741
|
// unmapped (the record path's index-signature check rejects them).
|
|
1722
1742
|
// RegExpMatchArray (s.match's result) IS a string[] here — the honest
|
|
1723
|
-
// slice: [whole match, ...captures]
|
|
1724
|
-
//
|
|
1725
|
-
// member like any other unlowered array property.
|
|
1743
|
+
// slice: [whole match, ...captures]. Nonparticipating captures use the
|
|
1744
|
+
// array's undefined element state; numeric access preserves that state.
|
|
1726
1745
|
if (isStdlibInterface("RegExpMatchArray"))
|
|
1727
1746
|
return arrayOf(STRING);
|
|
1728
1747
|
// TemplateStringsArray (a tag function's first parameter): a string[] —
|
|
@@ -1818,6 +1837,12 @@ function mapTypeInner(type, ctx) {
|
|
|
1818
1837
|
ctx.isStdlibFile(d.getSourceFile()))) {
|
|
1819
1838
|
return { kind: "stats" };
|
|
1820
1839
|
}
|
|
1840
|
+
// Capacity snapshots and options keep their live object representation
|
|
1841
|
+
// across numeric/BigInt overloads, runtime options, and callbacks.
|
|
1842
|
+
if ((psym?.name === "StatsFs" || psym?.name === "BigIntStatsFs" || psym?.name === "StatFsOptions") &&
|
|
1843
|
+
checker.declarationsOf(psym).some((d) => (ts.isInterfaceDeclaration(d) || ts.isClassDeclaration(d)) &&
|
|
1844
|
+
ctx.isStdlibFile(d.getSourceFile()) && isDeclaredInAmbientModule(d, "fs")))
|
|
1845
|
+
return DYN;
|
|
1821
1846
|
// fs/promises.FileHandle: an owned descriptor object. Module provenance
|
|
1822
1847
|
// distinguishes it from user interfaces with the same name; both the
|
|
1823
1848
|
// fallback and @types/node declare it in "fs/promises".
|
|
@@ -1882,6 +1907,10 @@ function mapTypeInner(type, ctx) {
|
|
|
1882
1907
|
isDeclaredInAmbientModule(d, "tls"))) {
|
|
1883
1908
|
return { kind: "secureCtx" };
|
|
1884
1909
|
}
|
|
1910
|
+
// Scrypt's runtime options retain property accessors and aliases. Use
|
|
1911
|
+
// checked values so presence probes and repeated getter reads match Node.
|
|
1912
|
+
if (psym?.name === "ScryptOptions" && checker.declarationsOf(psym).some((d) => ts.isInterfaceDeclaration(d) && ctx.isStdlibFile(d.getSourceFile()) && isDeclaredInAmbientModule(d, "crypto")))
|
|
1913
|
+
return DYN;
|
|
1885
1914
|
// crypto.Hash / crypto.Hmac: native incremental digest handles. Keep
|
|
1886
1915
|
// provenance module-qualified so user classes with these common names
|
|
1887
1916
|
// retain their ordinary structural/class representation.
|
|
@@ -2214,28 +2243,53 @@ function mapTypeInner(type, ctx) {
|
|
|
2214
2243
|
], false, undefined, ["address", "family", "port"]),
|
|
2215
2244
|
};
|
|
2216
2245
|
}
|
|
2246
|
+
// Filesystem options are data records. Keep their declared optional fields
|
|
2247
|
+
// instead of allowing arbitrary standard-library interfaces into records.
|
|
2248
|
+
if ((psym?.name === "FileReadOptions" || psym?.name === "ReadOptions" || psym?.name === "ReadOptionsWithBuffer" || psym?.name === "WriteOptions") &&
|
|
2249
|
+
checker.declarationsOf(psym).some((d) => ts.isInterfaceDeclaration(d) && ctx.isStdlibFile(d.getSourceFile()) &&
|
|
2250
|
+
(isDeclaredInAmbientModule(d, "fs/promises") || isDeclaredInAmbientModule(d, "fs")))) {
|
|
2251
|
+
const fields = [];
|
|
2252
|
+
for (const property of checker.getPropertiesOfType(widened)) {
|
|
2253
|
+
if (!["buffer", "offset", "length", "position"].includes(property.name))
|
|
2254
|
+
return null;
|
|
2255
|
+
const type = mapType(checker.getTypeOfSymbol(property), ctx);
|
|
2256
|
+
if (!type)
|
|
2257
|
+
return null;
|
|
2258
|
+
fields.push({ name: property.name, type });
|
|
2259
|
+
}
|
|
2260
|
+
const order = fields.map((field) => field.name);
|
|
2261
|
+
fields.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
2262
|
+
return { kind: "record", shapeId: ctx.shapes.intern(fields, false, undefined, order) };
|
|
2263
|
+
}
|
|
2217
2264
|
// fs/promises FileReadResult<T> / FileWriteResult<T>: the two-field
|
|
2218
2265
|
// null-prototype objects returned by FileHandle.read/write. The native
|
|
2219
2266
|
// record does not model the prototype (unobservable through the lowered
|
|
2220
2267
|
// surface); it preserves the caller buffer/string by reference.
|
|
2221
|
-
if ((psym?.name === "FileReadResult" || psym?.name === "FileWriteResult") &&
|
|
2268
|
+
if ((psym?.name === "FileReadResult" || psym?.name === "FileWriteResult" || psym?.name === "FileReadvResult" || psym?.name === "FileWritevResult" || psym?.name === "ReadVResult" || psym?.name === "WriteVResult") &&
|
|
2222
2269
|
checker.declarationsOf(psym).some((d) => ts.isInterfaceDeclaration(d) &&
|
|
2223
2270
|
ctx.isStdlibFile(d.getSourceFile()) &&
|
|
2224
|
-
isDeclaredInAmbientModule(d, "fs/promises")
|
|
2271
|
+
(isDeclaredInAmbientModule(d, "fs/promises") ||
|
|
2272
|
+
((psym.name === "ReadVResult" || psym.name === "WriteVResult") && isDeclaredInAmbientModule(d, "fs"))))) {
|
|
2225
2273
|
const args = checker.getTypeArguments(widened);
|
|
2226
2274
|
if (args.length !== 1)
|
|
2227
2275
|
return null;
|
|
2228
|
-
const
|
|
2229
|
-
|
|
2276
|
+
const vector = psym.name === "FileReadvResult" || psym.name === "FileWritevResult" || psym.name === "ReadVResult" || psym.name === "WriteVResult";
|
|
2277
|
+
const emptyVector = vector && checker.isArrayType(args[0]) &&
|
|
2278
|
+
(checker.getTypeArguments(args[0])[0].flags & ts.TypeFlags.Never) !== 0;
|
|
2279
|
+
const payload = emptyVector ? arrayOf(bytesOf("u8")) : mapType(args[0], ctx);
|
|
2280
|
+
if (!payload || (vector
|
|
2281
|
+
? !(payload.kind === "array" && payload.elem.kind === "bytes" && payload.elem.elem === "u8")
|
|
2282
|
+
: !(payload.kind === "string" || (payload.kind === "bytes" && payload.elem === "u8")))) {
|
|
2230
2283
|
return null;
|
|
2231
2284
|
}
|
|
2232
|
-
const count = psym.name === "FileReadResult" ? "bytesRead" : "bytesWritten";
|
|
2285
|
+
const count = psym.name === "FileReadResult" || psym.name === "FileReadvResult" || psym.name === "ReadVResult" ? "bytesRead" : "bytesWritten";
|
|
2286
|
+
const payloadName = vector ? "buffers" : "buffer";
|
|
2233
2287
|
return {
|
|
2234
2288
|
kind: "record",
|
|
2235
2289
|
shapeId: ctx.shapes.intern([
|
|
2236
|
-
{ name:
|
|
2290
|
+
{ name: payloadName, type: payload },
|
|
2237
2291
|
{ name: count, type: F64 },
|
|
2238
|
-
], false, undefined, [count,
|
|
2292
|
+
], false, undefined, [count, payloadName]),
|
|
2239
2293
|
};
|
|
2240
2294
|
}
|
|
2241
2295
|
// fs.Dirent (readdirSync's withFileTypes rows): interned explicitly on
|
|
@@ -2469,9 +2523,19 @@ function mapTypeInner(type, ctx) {
|
|
|
2469
2523
|
ts.isParameter(decl) &&
|
|
2470
2524
|
(decl.questionToken !== undefined || decl.initializer !== undefined);
|
|
2471
2525
|
let pt = mapType(checker.getTypeOfSymbol(p), ctx);
|
|
2526
|
+
if (decl && ts.isParameter(decl) && ts.isSetAccessorDeclaration(decl.parent) && isJsSourceFile(decl.getSourceFile()))
|
|
2527
|
+
pt = DYN;
|
|
2472
2528
|
// An inferred JavaScript binding pattern consumes an iterable; it
|
|
2473
2529
|
// does not require the caller's array to have exactly this length.
|
|
2474
|
-
|
|
2530
|
+
const executor = decl && ts.isParameter(decl) ? decl.parent : null;
|
|
2531
|
+
const construction = executor?.parent;
|
|
2532
|
+
const constructorSymbol = construction && ts.isNewExpression(construction)
|
|
2533
|
+
? checker.getSymbolAtLocation(construction.expression) : undefined;
|
|
2534
|
+
const nativeExecutor = executor && (ts.isArrowFunction(executor) || ts.isFunctionExpression(executor)) &&
|
|
2535
|
+
construction && ts.isNewExpression(construction) && construction.arguments?.[0] === executor &&
|
|
2536
|
+
ts.isIdentifier(construction.expression) && construction.expression.text === "Promise" &&
|
|
2537
|
+
constructorSymbol && checker.declarationsOf(constructorSymbol).some((site) => ctx.isStdlibFile(site.getSourceFile()));
|
|
2538
|
+
if (!nativeExecutor && decl && ts.isParameter(decl) && !decl.dotDotDotToken && !ts.isSetAccessorDeclaration(decl.parent) &&
|
|
2475
2539
|
isJsSourceFile(decl.getSourceFile()) && !decl.type &&
|
|
2476
2540
|
!/@(?:param|type)\b/.test(decl.getSourceFile().text.slice(decl.parent?.pos ?? decl.pos, decl.getStart())))
|
|
2477
2541
|
pt = DYN;
|
|
@@ -2510,8 +2574,19 @@ function mapTypeInner(type, ctx) {
|
|
|
2510
2574
|
(retT.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined)) !== 0;
|
|
2511
2575
|
let ret = jsUnitReturn || (!ctx.dynamic && (retT.flags & ts.TypeFlags.Any) !== 0)
|
|
2512
2576
|
? DYN : retT.flags & ts.TypeFlags.Never ? VOID : mapType(retT, ctx);
|
|
2513
|
-
if (sigDecl && isJsSourceFile(sigDecl.getSourceFile())
|
|
2577
|
+
if (sigDecl && ts.isGetAccessorDeclaration(sigDecl) && isJsSourceFile(sigDecl.getSourceFile()))
|
|
2578
|
+
ret = DYN;
|
|
2579
|
+
if (sigDecl && isJsSourceFile(sigDecl.getSourceFile()) && ret?.kind === "array")
|
|
2580
|
+
ret = DYN;
|
|
2581
|
+
if (sigDecl && ts.isFunctionLike(sigDecl) && isJsSourceFile(sigDecl.getSourceFile()) && !sigDecl.type &&
|
|
2582
|
+
!/@returns?\b/.test(sigDecl.getSourceFile().text.slice(sigDecl.pos, sigDecl.getStart())) && ret?.kind === "record")
|
|
2583
|
+
ret = DYN;
|
|
2584
|
+
if (sigDecl && ts.isFunctionLike(sigDecl) && isJsSourceFile(sigDecl.getSourceFile()) && !sigDecl.type &&
|
|
2585
|
+
!/@returns?\b/.test(sigDecl.getSourceFile().text.slice(sigDecl.pos, sigDecl.getStart())) &&
|
|
2586
|
+
(ret?.kind === "date" || ret?.kind === "union" && ctx.unions.get(ret.unionId)?.arms.some((arm) => arm.kind === "func")))
|
|
2514
2587
|
ret = DYN;
|
|
2588
|
+
if (ret && sigDecl && isJsSourceFile(sigDecl.getSourceFile()) && functionCanReturnUndefined(sigDecl))
|
|
2589
|
+
ret = withUndefinedArm(ret, ctx.unions) ?? ret;
|
|
2515
2590
|
if (!ret)
|
|
2516
2591
|
return null;
|
|
2517
2592
|
return typedRest
|