@scriptc/compiler 0.2.1 → 0.2.2
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 +59 -4
- package/dist/backend/llvm/dyn.d.ts +3 -0
- package/dist/backend/llvm/dyn.js +84 -12
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.d.ts +4 -1
- package/dist/backend/llvm/emitter.js +20 -5
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/emitter.test.js +9 -1
- package/dist/backend/llvm/emitter.test.js.map +1 -1
- package/dist/backend/llvm/expr-containers.js +5 -0
- package/dist/backend/llvm/expr-containers.js.map +1 -1
- package/dist/backend/llvm/expr-dynamic.js +30 -5
- package/dist/backend/llvm/expr-dynamic.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.js +70 -9
- 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 +35 -1
- package/dist/backend/llvm/lib-shared.js.map +1 -1
- package/dist/backend/may-throw.js +4 -0
- package/dist/backend/may-throw.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/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/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/containers/bytes.js +17 -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/lower-builtins.d.ts +4 -9
- package/dist/frontend/lowering/lower-builtins.js +291 -51
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +283 -73
- 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 +439 -25
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.d.ts +1 -1
- package/dist/frontend/lowering/lower-containers.js +39 -17
- 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 +294 -129
- 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 +15 -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 +100 -35
- 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-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 +26 -9
- package/dist/frontend/lowering/lowerer.js +218 -27
- 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 +1 -0
- package/dist/frontend/lowering/surfaces.js +24 -12
- 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/program.js +4 -2
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/type-mapper.js +83 -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 +16 -10
- package/dist/index.js.map +1 -1
- package/dist/ir/ir.d.ts +27 -13
- package/dist/ir/ir.js +26 -2
- package/dist/ir/ir.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 +56 -5
- package/dist/ir/validate.js.map +1 -1
- package/dist/ir/validate.test.js +17 -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/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/package.json +20 -20
- package/surface-manifest.json +115 -13
|
@@ -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[] —
|
|
@@ -1882,6 +1901,10 @@ function mapTypeInner(type, ctx) {
|
|
|
1882
1901
|
isDeclaredInAmbientModule(d, "tls"))) {
|
|
1883
1902
|
return { kind: "secureCtx" };
|
|
1884
1903
|
}
|
|
1904
|
+
// Scrypt's runtime options retain property accessors and aliases. Use
|
|
1905
|
+
// checked values so presence probes and repeated getter reads match Node.
|
|
1906
|
+
if (psym?.name === "ScryptOptions" && checker.declarationsOf(psym).some((d) => ts.isInterfaceDeclaration(d) && ctx.isStdlibFile(d.getSourceFile()) && isDeclaredInAmbientModule(d, "crypto")))
|
|
1907
|
+
return DYN;
|
|
1885
1908
|
// crypto.Hash / crypto.Hmac: native incremental digest handles. Keep
|
|
1886
1909
|
// provenance module-qualified so user classes with these common names
|
|
1887
1910
|
// retain their ordinary structural/class representation.
|
|
@@ -2214,28 +2237,53 @@ function mapTypeInner(type, ctx) {
|
|
|
2214
2237
|
], false, undefined, ["address", "family", "port"]),
|
|
2215
2238
|
};
|
|
2216
2239
|
}
|
|
2240
|
+
// Filesystem options are data records. Keep their declared optional fields
|
|
2241
|
+
// instead of allowing arbitrary standard-library interfaces into records.
|
|
2242
|
+
if ((psym?.name === "FileReadOptions" || psym?.name === "ReadOptions" || psym?.name === "ReadOptionsWithBuffer" || psym?.name === "WriteOptions") &&
|
|
2243
|
+
checker.declarationsOf(psym).some((d) => ts.isInterfaceDeclaration(d) && ctx.isStdlibFile(d.getSourceFile()) &&
|
|
2244
|
+
(isDeclaredInAmbientModule(d, "fs/promises") || isDeclaredInAmbientModule(d, "fs")))) {
|
|
2245
|
+
const fields = [];
|
|
2246
|
+
for (const property of checker.getPropertiesOfType(widened)) {
|
|
2247
|
+
if (!["buffer", "offset", "length", "position"].includes(property.name))
|
|
2248
|
+
return null;
|
|
2249
|
+
const type = mapType(checker.getTypeOfSymbol(property), ctx);
|
|
2250
|
+
if (!type)
|
|
2251
|
+
return null;
|
|
2252
|
+
fields.push({ name: property.name, type });
|
|
2253
|
+
}
|
|
2254
|
+
const order = fields.map((field) => field.name);
|
|
2255
|
+
fields.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
2256
|
+
return { kind: "record", shapeId: ctx.shapes.intern(fields, false, undefined, order) };
|
|
2257
|
+
}
|
|
2217
2258
|
// fs/promises FileReadResult<T> / FileWriteResult<T>: the two-field
|
|
2218
2259
|
// null-prototype objects returned by FileHandle.read/write. The native
|
|
2219
2260
|
// record does not model the prototype (unobservable through the lowered
|
|
2220
2261
|
// surface); it preserves the caller buffer/string by reference.
|
|
2221
|
-
if ((psym?.name === "FileReadResult" || psym?.name === "FileWriteResult") &&
|
|
2262
|
+
if ((psym?.name === "FileReadResult" || psym?.name === "FileWriteResult" || psym?.name === "FileReadvResult" || psym?.name === "FileWritevResult" || psym?.name === "ReadVResult" || psym?.name === "WriteVResult") &&
|
|
2222
2263
|
checker.declarationsOf(psym).some((d) => ts.isInterfaceDeclaration(d) &&
|
|
2223
2264
|
ctx.isStdlibFile(d.getSourceFile()) &&
|
|
2224
|
-
isDeclaredInAmbientModule(d, "fs/promises")
|
|
2265
|
+
(isDeclaredInAmbientModule(d, "fs/promises") ||
|
|
2266
|
+
((psym.name === "ReadVResult" || psym.name === "WriteVResult") && isDeclaredInAmbientModule(d, "fs"))))) {
|
|
2225
2267
|
const args = checker.getTypeArguments(widened);
|
|
2226
2268
|
if (args.length !== 1)
|
|
2227
2269
|
return null;
|
|
2228
|
-
const
|
|
2229
|
-
|
|
2270
|
+
const vector = psym.name === "FileReadvResult" || psym.name === "FileWritevResult" || psym.name === "ReadVResult" || psym.name === "WriteVResult";
|
|
2271
|
+
const emptyVector = vector && checker.isArrayType(args[0]) &&
|
|
2272
|
+
(checker.getTypeArguments(args[0])[0].flags & ts.TypeFlags.Never) !== 0;
|
|
2273
|
+
const payload = emptyVector ? arrayOf(bytesOf("u8")) : mapType(args[0], ctx);
|
|
2274
|
+
if (!payload || (vector
|
|
2275
|
+
? !(payload.kind === "array" && payload.elem.kind === "bytes" && payload.elem.elem === "u8")
|
|
2276
|
+
: !(payload.kind === "string" || (payload.kind === "bytes" && payload.elem === "u8")))) {
|
|
2230
2277
|
return null;
|
|
2231
2278
|
}
|
|
2232
|
-
const count = psym.name === "FileReadResult" ? "bytesRead" : "bytesWritten";
|
|
2279
|
+
const count = psym.name === "FileReadResult" || psym.name === "FileReadvResult" || psym.name === "ReadVResult" ? "bytesRead" : "bytesWritten";
|
|
2280
|
+
const payloadName = vector ? "buffers" : "buffer";
|
|
2233
2281
|
return {
|
|
2234
2282
|
kind: "record",
|
|
2235
2283
|
shapeId: ctx.shapes.intern([
|
|
2236
|
-
{ name:
|
|
2284
|
+
{ name: payloadName, type: payload },
|
|
2237
2285
|
{ name: count, type: F64 },
|
|
2238
|
-
], false, undefined, [count,
|
|
2286
|
+
], false, undefined, [count, payloadName]),
|
|
2239
2287
|
};
|
|
2240
2288
|
}
|
|
2241
2289
|
// fs.Dirent (readdirSync's withFileTypes rows): interned explicitly on
|
|
@@ -2469,9 +2517,19 @@ function mapTypeInner(type, ctx) {
|
|
|
2469
2517
|
ts.isParameter(decl) &&
|
|
2470
2518
|
(decl.questionToken !== undefined || decl.initializer !== undefined);
|
|
2471
2519
|
let pt = mapType(checker.getTypeOfSymbol(p), ctx);
|
|
2520
|
+
if (decl && ts.isParameter(decl) && ts.isSetAccessorDeclaration(decl.parent) && isJsSourceFile(decl.getSourceFile()))
|
|
2521
|
+
pt = DYN;
|
|
2472
2522
|
// An inferred JavaScript binding pattern consumes an iterable; it
|
|
2473
2523
|
// does not require the caller's array to have exactly this length.
|
|
2474
|
-
|
|
2524
|
+
const executor = decl && ts.isParameter(decl) ? decl.parent : null;
|
|
2525
|
+
const construction = executor?.parent;
|
|
2526
|
+
const constructorSymbol = construction && ts.isNewExpression(construction)
|
|
2527
|
+
? checker.getSymbolAtLocation(construction.expression) : undefined;
|
|
2528
|
+
const nativeExecutor = executor && (ts.isArrowFunction(executor) || ts.isFunctionExpression(executor)) &&
|
|
2529
|
+
construction && ts.isNewExpression(construction) && construction.arguments?.[0] === executor &&
|
|
2530
|
+
ts.isIdentifier(construction.expression) && construction.expression.text === "Promise" &&
|
|
2531
|
+
constructorSymbol && checker.declarationsOf(constructorSymbol).some((site) => ctx.isStdlibFile(site.getSourceFile()));
|
|
2532
|
+
if (!nativeExecutor && decl && ts.isParameter(decl) && !decl.dotDotDotToken && !ts.isSetAccessorDeclaration(decl.parent) &&
|
|
2475
2533
|
isJsSourceFile(decl.getSourceFile()) && !decl.type &&
|
|
2476
2534
|
!/@(?:param|type)\b/.test(decl.getSourceFile().text.slice(decl.parent?.pos ?? decl.pos, decl.getStart())))
|
|
2477
2535
|
pt = DYN;
|
|
@@ -2510,8 +2568,19 @@ function mapTypeInner(type, ctx) {
|
|
|
2510
2568
|
(retT.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined)) !== 0;
|
|
2511
2569
|
let ret = jsUnitReturn || (!ctx.dynamic && (retT.flags & ts.TypeFlags.Any) !== 0)
|
|
2512
2570
|
? DYN : retT.flags & ts.TypeFlags.Never ? VOID : mapType(retT, ctx);
|
|
2513
|
-
if (sigDecl && isJsSourceFile(sigDecl.getSourceFile())
|
|
2571
|
+
if (sigDecl && ts.isGetAccessorDeclaration(sigDecl) && isJsSourceFile(sigDecl.getSourceFile()))
|
|
2572
|
+
ret = DYN;
|
|
2573
|
+
if (sigDecl && isJsSourceFile(sigDecl.getSourceFile()) && ret?.kind === "array")
|
|
2574
|
+
ret = DYN;
|
|
2575
|
+
if (sigDecl && ts.isFunctionLike(sigDecl) && isJsSourceFile(sigDecl.getSourceFile()) && !sigDecl.type &&
|
|
2576
|
+
!/@returns?\b/.test(sigDecl.getSourceFile().text.slice(sigDecl.pos, sigDecl.getStart())) && ret?.kind === "record")
|
|
2577
|
+
ret = DYN;
|
|
2578
|
+
if (sigDecl && ts.isFunctionLike(sigDecl) && isJsSourceFile(sigDecl.getSourceFile()) && !sigDecl.type &&
|
|
2579
|
+
!/@returns?\b/.test(sigDecl.getSourceFile().text.slice(sigDecl.pos, sigDecl.getStart())) &&
|
|
2580
|
+
(ret?.kind === "date" || ret?.kind === "union" && ctx.unions.get(ret.unionId)?.arms.some((arm) => arm.kind === "func")))
|
|
2514
2581
|
ret = DYN;
|
|
2582
|
+
if (ret && sigDecl && isJsSourceFile(sigDecl.getSourceFile()) && functionCanReturnUndefined(sigDecl))
|
|
2583
|
+
ret = withUndefinedArm(ret, ctx.unions) ?? ret;
|
|
2515
2584
|
if (!ret)
|
|
2516
2585
|
return null;
|
|
2517
2586
|
return typedRest
|