@scriptc/compiler 0.1.1 → 0.1.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 +45 -17
- package/ambient/scriptc.d.ts +2 -1
- package/dist/backend/build-cache.js.map +1 -1
- package/dist/backend/c/async.js +24 -2
- package/dist/backend/c/async.js.map +1 -1
- package/dist/backend/c/c-emitter.d.ts +22 -10
- package/dist/backend/c/c-emitter.js +60 -15
- package/dist/backend/c/c-emitter.js.map +1 -1
- package/dist/backend/c/exprs.js +220 -10
- 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/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.js.map +1 -1
- package/dist/backend/c/walkers.js +31 -5
- package/dist/backend/c/walkers.js.map +1 -1
- package/dist/backend/external-c.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/dyn.js +56 -3
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.js +98 -19
- 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 +1 -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 +6 -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.map +1 -1
- package/dist/backend/llvm/expr-records.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.js +220 -9
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
- package/dist/backend/llvm/lib-dispatch.js +2 -0
- package/dist/backend/llvm/lib-dispatch.js.map +1 -1
- package/dist/backend/llvm/lib-shared.js +18 -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/split.js.map +1 -1
- package/dist/backend/llvm/unsupported.js.map +1 -1
- 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-toolchain.js.map +1 -1
- package/dist/backend/native-toolchain.test.js.map +1 -1
- package/dist/backend/runtime-pack.js.map +1 -1
- package/dist/backend/targets.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 +12 -0
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/diagnostics/diagnostic.d.ts +6 -5
- package/dist/diagnostics/diagnostic.js +7 -6
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/diagnostics/render.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 +35 -0
- package/dist/frontend/lowering/containers/bytes.js +1021 -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.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 +18 -0
- package/dist/frontend/lowering/lower-builtins.js +219 -48
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.d.ts +13 -4
- package/dist/frontend/lowering/lower-calls.js +407 -64
- 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 +135 -1467
- 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 +402 -2351
- 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 +3 -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 +52 -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 +5 -24
- package/dist/frontend/lowering/lower-stmts.js +519 -253
- 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 +37 -34
- package/dist/frontend/lowering/lowerer.js +143 -57
- 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/npm-static-declarations.d.ts +35 -0
- package/dist/frontend/npm-static-declarations.js +506 -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 +122 -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 +495 -68
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/resolve.d.ts +10 -2
- package/dist/frontend/resolve.js +90 -14
- package/dist/frontend/resolve.js.map +1 -1
- package/dist/frontend/resolve.test.js +4 -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 +120 -7
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/ir/analysis.js.map +1 -1
- package/dist/ir/ir.d.ts +60 -30
- package/dist/ir/ir.js +57 -6
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/validate.js +44 -59
- 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.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 +60 -4
|
@@ -35,10 +35,7 @@ export interface ClassInfo {
|
|
|
35
35
|
ret: IrType;
|
|
36
36
|
abstract?: true;
|
|
37
37
|
async?: true;
|
|
38
|
-
gen?:
|
|
39
|
-
yieldT: IrType;
|
|
40
|
-
nextT: IrType;
|
|
41
|
-
};
|
|
38
|
+
gen?: NonNullable<IrFunction["generator"]>;
|
|
42
39
|
}>;
|
|
43
40
|
/** OWN GENERIC instance methods (own type parameters — `m<T>(x: T)`),
|
|
44
41
|
* monomorphized per call site like top-level generic functions: instance
|
|
@@ -446,7 +443,7 @@ export declare function lowerStaticFieldRead(lowerer: Lowerer, expr: ts.Property
|
|
|
446
443
|
/** A class EXPRESSION's ClassInfo: collection on first encounter (the
|
|
447
444
|
* declaration path over the shared ClassLikeDeclaration machinery, with
|
|
448
445
|
* NamedEvaluation supplying the runtime .name), idempotent per node —
|
|
449
|
-
*
|
|
446
|
+
* tryLowerExpression's speculative visits and the heritage recursion reuse the
|
|
450
447
|
* first collection. The honest v1 boundary is TOP-LEVEL evaluation
|
|
451
448
|
* positions only: each evaluation of a class expression in JS mints a
|
|
452
449
|
* DISTINCT class (fresh identity, fresh statics), and one immortal
|
|
@@ -514,10 +511,7 @@ export declare function findMethodOn(lowerer: Lowerer, info: ClassInfo | null, n
|
|
|
514
511
|
ret: IrType;
|
|
515
512
|
abstract?: true;
|
|
516
513
|
async?: true;
|
|
517
|
-
gen?:
|
|
518
|
-
yieldT: IrType;
|
|
519
|
-
nextT: IrType;
|
|
520
|
-
};
|
|
514
|
+
gen?: NonNullable<IrFunction["generator"]>;
|
|
521
515
|
};
|
|
522
516
|
} | null;
|
|
523
517
|
/** True when `sub` is a STRICT descendant of `sup` in the class graph. */
|
|
@@ -583,10 +577,10 @@ export declare function lowerClassCtor(lowerer: Lowerer, info: ClassInfo): IrFun
|
|
|
583
577
|
* COMPUTED name that folds to one compile-time string
|
|
584
578
|
* (foldedStringKeyOf — the object-literal computed-key machinery
|
|
585
579
|
* applied to method positions; tsc late-bound the member under exactly
|
|
586
|
-
* that name), or
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
580
|
+
* that name), or a reserved `sym:*` slot for the well-known symbols the
|
|
581
|
+
* compiler consumes as language protocols (iterator and explicit
|
|
582
|
+
* resource management). These names are unspellable as user identifiers,
|
|
583
|
+
* like the accessor `get:x` convention. Null for genuinely
|
|
590
584
|
* runtime-keyed names — the computed-member fences stay. */
|
|
591
585
|
export declare function classMemberNameOf(lowerer: Lowerer, name: ts.PropertyName): string | null;
|
|
592
586
|
/** A class type's ITERATOR PROTOCOL shape, statically resolved: the
|
|
@@ -5,13 +5,14 @@ import { InternalCompilerError } from "../../errors.js";
|
|
|
5
5
|
* accessor access, upcasts, `new` expressions, and the builtin Error
|
|
6
6
|
* hierarchy registration. */
|
|
7
7
|
import * as ts from "../ts7/adapter.js";
|
|
8
|
-
import { BOOL, DATE_T, DYN, F64, bytesOf, JSVAL, RUNTIME_EMITTER_CLASS, RUNTIME_ERROR_CLASSES, RUNTIME_STREAM_CLASSES, STRING, UNDEFINED_T, URL_T, VOID, arrayOf, isSupportedMapKey, isUnitType, typeEquals } from "../../ir/ir.js";
|
|
9
|
-
import { MAX_GENERIC_INSTANCES, genericCallInstance, implicitAnyParamSymbolsOf, implicitCallInstance, implicitMonoFile, omittedArgFor } from "./lower-calls.js";
|
|
8
|
+
import { BOOL, DATE_T, DYN, F64, bytesOf, JSVAL, RUNTIME_EMITTER_CLASS, RUNTIME_ERROR_CLASSES, RUNTIME_STREAM_CLASSES, STRING, UNDEFINED_T, URL_T, VOID, arrayOf, isSupportedMapKey, isSupportedMapValue, isSupportedSetElem, isUnitType, typeEquals } from "../../ir/ir.js";
|
|
9
|
+
import { MAX_GENERIC_INSTANCES, appendImplicitUndefinedReturn, generatorMeta, genericCallInstance, implicitAnyParamSymbolsOf, implicitCallInstance, implicitMonoFile, omittedArgFor } from "./lower-calls.js";
|
|
10
10
|
import { isGenericCallableMemberType, typeKey } from "../type-mapper.js";
|
|
11
11
|
import { cjsClassExprWholeExportOf, isCjsJsFile, isJsSourceFile, isModuleExportsAccess, isNodeTypesPath, locOf } from "../program.js";
|
|
12
12
|
import { PoisonError, dynFallbackType, dynUndefinedExpr, newFnCtx, own } from "./lowerer.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { lowerMapSeedArrayNew } from "./lower-containers.js";
|
|
14
|
+
import { bufEncoding } from "./containers/bytes.js";
|
|
15
|
+
import { isSafeToRepeat } from "./expressions/evaluation-safety.js";
|
|
15
16
|
import { lowerSearchParamsNew } from "./lower-builtins.js";
|
|
16
17
|
import { requiresDynamicPackageDiag, unsupportedDiag } from "../../diagnostics/diagnostic.js";
|
|
17
18
|
import { STREAM_API_MEMBERS, STREAM_PROP_MEMBERS, UNDERSCORE_METHODS, lowerStreamNew, lowerStreamSuperCall, streamCtorShape } from "./lower-stream.js";
|
|
@@ -504,6 +505,72 @@ export function collectClassShape(lowerer, decl) {
|
|
|
504
505
|
}
|
|
505
506
|
}
|
|
506
507
|
}
|
|
508
|
+
function inferredEmptyCollectionFieldType(lowerer, decl, field, initializer) {
|
|
509
|
+
if (!ts.isNewExpression(initializer) || (initializer.arguments?.length ?? 0) !== 0 || !ts.isIdentifier(initializer.expression))
|
|
510
|
+
return null;
|
|
511
|
+
const collection = initializer.expression.text;
|
|
512
|
+
if (collection !== "Map" && collection !== "Set")
|
|
513
|
+
return null;
|
|
514
|
+
const symbol = lowerer.checker.getSymbolAtLocation(initializer.expression);
|
|
515
|
+
if (!lowerer.isStdlibSymbol(symbol))
|
|
516
|
+
return null;
|
|
517
|
+
const mapKeys = [];
|
|
518
|
+
const mapValues = [];
|
|
519
|
+
const setElements = [];
|
|
520
|
+
const mappedArgument = (argument) => {
|
|
521
|
+
const type = lowerer.checker.getBaseTypeOfLiteralType(lowerer.typeOf(argument));
|
|
522
|
+
const mapped = lowerer.mapTypeOf(type);
|
|
523
|
+
if (!mapped || mapped.kind === "dyn" || mapped.kind === "jsval" || mapped.kind === "void" || isUnitType(mapped))
|
|
524
|
+
return null;
|
|
525
|
+
return mapped;
|
|
526
|
+
};
|
|
527
|
+
const visit = (node) => {
|
|
528
|
+
if (ts.isFunctionLike(node) && !ts.isArrowFunction(node))
|
|
529
|
+
return "skip";
|
|
530
|
+
if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression))
|
|
531
|
+
return undefined;
|
|
532
|
+
const receiver = node.expression.expression;
|
|
533
|
+
if (!ts.isPropertyAccessExpression(receiver) ||
|
|
534
|
+
receiver.expression.kind !== ts.SyntaxKind.ThisKeyword ||
|
|
535
|
+
receiver.name.text !== field) {
|
|
536
|
+
return undefined;
|
|
537
|
+
}
|
|
538
|
+
if (collection === "Map" && node.expression.name.text === "set" && node.arguments.length === 2) {
|
|
539
|
+
const key = mappedArgument(node.arguments[0]);
|
|
540
|
+
const value = mappedArgument(node.arguments[1]);
|
|
541
|
+
if (key !== null && value !== null && isSupportedMapKey(key) && isSupportedMapValue(value)) {
|
|
542
|
+
mapKeys.push(key);
|
|
543
|
+
mapValues.push(value);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
if (collection === "Set" &&
|
|
547
|
+
(node.expression.name.text === "add" || node.expression.name.text === "has" || node.expression.name.text === "delete") &&
|
|
548
|
+
node.arguments.length === 1) {
|
|
549
|
+
const element = mappedArgument(node.arguments[0]);
|
|
550
|
+
if (element !== null && isSupportedSetElem(element))
|
|
551
|
+
setElements.push(element);
|
|
552
|
+
}
|
|
553
|
+
return undefined;
|
|
554
|
+
};
|
|
555
|
+
for (const member of decl.members) {
|
|
556
|
+
const body = ts.isConstructorDeclaration(member) || ts.isMethodDeclaration(member) || ts.isAccessor(member)
|
|
557
|
+
? member.body
|
|
558
|
+
: undefined;
|
|
559
|
+
if (body !== undefined)
|
|
560
|
+
ts.walkPreorder(body, visit);
|
|
561
|
+
}
|
|
562
|
+
const unique = (types) => {
|
|
563
|
+
const first = types[0];
|
|
564
|
+
return first !== undefined && types.every((type) => typeEquals(type, first)) ? first : null;
|
|
565
|
+
};
|
|
566
|
+
if (collection === "Map") {
|
|
567
|
+
const key = unique(mapKeys);
|
|
568
|
+
const value = unique(mapValues);
|
|
569
|
+
return key !== null && value !== null ? { kind: "map", key, value } : null;
|
|
570
|
+
}
|
|
571
|
+
const element = unique(setElements);
|
|
572
|
+
return element !== null ? { kind: "set", elem: element } : null;
|
|
573
|
+
}
|
|
507
574
|
export function collectClassShapeInner(lowerer, decl, jsNameOverride, inst,
|
|
508
575
|
/** MIXIN instantiation mode (lower-mixins.ts): the class inside a
|
|
509
576
|
* mixin function, collected per call site — `base` is the ARGUMENT
|
|
@@ -1300,23 +1367,15 @@ mixin) {
|
|
|
1300
1367
|
const mName = classMemberNameOf(lowerer, member.name);
|
|
1301
1368
|
if (mName === null)
|
|
1302
1369
|
lowerer.unsupported("SC1090", member, "computed method names");
|
|
1303
|
-
// PUBLIC generator
|
|
1304
|
-
//
|
|
1305
|
-
//
|
|
1306
|
-
//
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
// param 0 — the async-method precedent, generator form.
|
|
1311
|
-
if (member.asteriskToken !== undefined && !ts.isPrivateIdentifier(member.name)) {
|
|
1370
|
+
// Sync PUBLIC generator methods stay fenced because virtualCall
|
|
1371
|
+
// dispatch cannot hold spawn wrappers. Async generator methods
|
|
1372
|
+
// use the existing static async-method dispatch discipline;
|
|
1373
|
+
// overrides fence below. #private generators are always direct.
|
|
1374
|
+
const asyncGenerator = member.asteriskToken !== undefined &&
|
|
1375
|
+
member.modifiers?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword) === true;
|
|
1376
|
+
if (member.asteriskToken !== undefined && !asyncGenerator && !ts.isPrivateIdentifier(member.name)) {
|
|
1312
1377
|
lowerer.unsupported("SC1071", member, "generator methods (a #private generator method compiles — privates never dispatch dynamically; or declare a module-level function* and call it from the method)");
|
|
1313
1378
|
}
|
|
1314
|
-
// An async #private generator (`async *#m()`) is still an async
|
|
1315
|
-
// generator — the blanket SC1071 fence.
|
|
1316
|
-
if (member.asteriskToken !== undefined &&
|
|
1317
|
-
member.modifiers?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword)) {
|
|
1318
|
-
lowerer.unsupported("SC1071", member, "async generators (async function*)");
|
|
1319
|
-
}
|
|
1320
1379
|
// An ABSTRACT method is a signature with no body — type-world,
|
|
1321
1380
|
// except that it declares the vtable slot: calls through
|
|
1322
1381
|
// base-typed receivers are ordinary virtual dispatch, and tsc
|
|
@@ -1466,7 +1525,12 @@ mixin) {
|
|
|
1466
1525
|
if (member.asteriskToken !== undefined) {
|
|
1467
1526
|
if (ft.ret.kind !== "generator")
|
|
1468
1527
|
lowerer.badType(member.name, lowerer.typeOf(member.name));
|
|
1469
|
-
methods.set(mName, {
|
|
1528
|
+
methods.set(mName, {
|
|
1529
|
+
params: shapes,
|
|
1530
|
+
ret: ft.ret,
|
|
1531
|
+
gen: generatorMeta(lowerer, ft.ret),
|
|
1532
|
+
...(asyncMember ? { async: true } : {}),
|
|
1533
|
+
});
|
|
1470
1534
|
}
|
|
1471
1535
|
else {
|
|
1472
1536
|
methods.set(mName, asyncMember ? { params: shapes, ret: ft.ret, async: true } : { params: shapes, ret: ft.ret });
|
|
@@ -1699,6 +1763,7 @@ mixin) {
|
|
|
1699
1763
|
}
|
|
1700
1764
|
const sym = lowerer.checker.getSymbolAtLocation(assign);
|
|
1701
1765
|
const t = sym ? lowerer.checker.getTypeOfSymbol(sym) : undefined;
|
|
1766
|
+
const rhs = stmt.expression.right;
|
|
1702
1767
|
// Implicit-any fields (assigned from UNTYPED ctor params —
|
|
1703
1768
|
// countdown.js's `this.limit = limit`) take the JS checked-
|
|
1704
1769
|
// dynamic fallback like every JS binding: the slot holds a dyn
|
|
@@ -1706,6 +1771,9 @@ mixin) {
|
|
|
1706
1771
|
// TS-annotated `unknown` fields keep their fence (KEEP NARROW
|
|
1707
1772
|
// applies where an annotation could say better).
|
|
1708
1773
|
let type = t ? (lowerer.mapTypeOf(t) ?? dynFallbackType(lowerer, assign, t)) : null;
|
|
1774
|
+
if (type?.kind === "dyn") {
|
|
1775
|
+
type = inferredEmptyCollectionFieldType(lowerer, decl, name, rhs) ?? type;
|
|
1776
|
+
}
|
|
1709
1777
|
if (!type || type.kind === "void")
|
|
1710
1778
|
lowerer.badType(assign, t ?? lowerer.typeOf(assign));
|
|
1711
1779
|
// A JSDoc claim the BODY contradicts (`@type {Command}`
|
|
@@ -1716,7 +1784,7 @@ mixin) {
|
|
|
1716
1784
|
// Trust-but-verify: the claim never silently narrows the
|
|
1717
1785
|
// runtime value.
|
|
1718
1786
|
{
|
|
1719
|
-
const rhsT = lowerer.typeOf(
|
|
1787
|
+
const rhsT = lowerer.typeOf(rhs);
|
|
1720
1788
|
const assignsUndef = (rhsT.flags & ts.TypeFlags.Undefined) !== 0;
|
|
1721
1789
|
const admitsUndef = type.kind === "dyn" ||
|
|
1722
1790
|
isUnitType(type) ||
|
|
@@ -2569,7 +2637,7 @@ function namedEvaluationName(expr) {
|
|
|
2569
2637
|
/** A class EXPRESSION's ClassInfo: collection on first encounter (the
|
|
2570
2638
|
* declaration path over the shared ClassLikeDeclaration machinery, with
|
|
2571
2639
|
* NamedEvaluation supplying the runtime .name), idempotent per node —
|
|
2572
|
-
*
|
|
2640
|
+
* tryLowerExpression's speculative visits and the heritage recursion reuse the
|
|
2573
2641
|
* first collection. The honest v1 boundary is TOP-LEVEL evaluation
|
|
2574
2642
|
* positions only: each evaluation of a class expression in JS mints a
|
|
2575
2643
|
* DISTINCT class (fresh identity, fresh statics), and one immortal
|
|
@@ -3355,10 +3423,10 @@ function lowerClassCtorInner(lowerer, info) {
|
|
|
3355
3423
|
* COMPUTED name that folds to one compile-time string
|
|
3356
3424
|
* (foldedStringKeyOf — the object-literal computed-key machinery
|
|
3357
3425
|
* applied to method positions; tsc late-bound the member under exactly
|
|
3358
|
-
* that name), or
|
|
3359
|
-
*
|
|
3360
|
-
*
|
|
3361
|
-
*
|
|
3426
|
+
* that name), or a reserved `sym:*` slot for the well-known symbols the
|
|
3427
|
+
* compiler consumes as language protocols (iterator and explicit
|
|
3428
|
+
* resource management). These names are unspellable as user identifiers,
|
|
3429
|
+
* like the accessor `get:x` convention. Null for genuinely
|
|
3362
3430
|
* runtime-keyed names — the computed-member fences stay. */
|
|
3363
3431
|
export function classMemberNameOf(lowerer, name) {
|
|
3364
3432
|
if (ts.isIdentifier(name))
|
|
@@ -3372,8 +3440,14 @@ export function classMemberNameOf(lowerer, name) {
|
|
|
3372
3440
|
let e = name.expression;
|
|
3373
3441
|
while (ts.isParenthesizedExpression(e))
|
|
3374
3442
|
e = e.expression;
|
|
3375
|
-
if (ts.isPropertyAccessExpression(e)
|
|
3376
|
-
|
|
3443
|
+
if (ts.isPropertyAccessExpression(e)) {
|
|
3444
|
+
const member = lowerer.stdlibGlobalMember(e, "Symbol");
|
|
3445
|
+
if (member === "iterator" ||
|
|
3446
|
+
member === "asyncIterator" ||
|
|
3447
|
+
member === "dispose" ||
|
|
3448
|
+
member === "asyncDispose") {
|
|
3449
|
+
return `sym:${member}`;
|
|
3450
|
+
}
|
|
3377
3451
|
}
|
|
3378
3452
|
return lowerer.foldedStringKeyOf(name.expression);
|
|
3379
3453
|
}
|
|
@@ -3598,17 +3672,17 @@ function lowerClassMethodMemberInner(lowerer, info, fnLike) {
|
|
|
3598
3672
|
// (callTargetC routes by fn.async; `this` rides as param 0 in the
|
|
3599
3673
|
// spawn's argument pack). Dispatch is static by construction — the
|
|
3600
3674
|
// override fence at collection keeps async methods out of vtables.
|
|
3601
|
-
const isAsync = sig.async === true
|
|
3675
|
+
const isAsync = sig.async === true;
|
|
3602
3676
|
// #PRIVATE GENERATOR methods: the module function is a generator
|
|
3603
3677
|
// IrFunction — the body returns the TReturn channel, yields ride
|
|
3604
3678
|
// ctx.generator, and every call (direct by construction — privates
|
|
3605
3679
|
// never virtualize) enters through the emitted gen-spawn wrapper with
|
|
3606
3680
|
// `this` in the argument pack, answering the suspended generator.
|
|
3607
3681
|
const genCh = sig.gen !== undefined && sig.ret.kind === "generator" ? sig.gen : null;
|
|
3608
|
-
const bodyReturn =
|
|
3609
|
-
? sig.ret
|
|
3610
|
-
:
|
|
3611
|
-
?
|
|
3682
|
+
const bodyReturn = genCh !== null
|
|
3683
|
+
? lowerer.genBodyReturnType(sig.ret)
|
|
3684
|
+
: isAsync && sig.ret.kind === "promise"
|
|
3685
|
+
? sig.ret.inner
|
|
3612
3686
|
: sig.ret;
|
|
3613
3687
|
const fnCtx = newFnCtx(false, null, null, bodyReturn);
|
|
3614
3688
|
fnCtx.isAsync = isAsync;
|
|
@@ -3623,6 +3697,7 @@ function lowerClassMethodMemberInner(lowerer, info, fnLike) {
|
|
|
3623
3697
|
const declared = lowerer.declareParams(fnLike.parameters, sig.params);
|
|
3624
3698
|
params.push(...declared.params);
|
|
3625
3699
|
const body = [...declared.prologue, ...lowerer.lowerStmts(fnLike.body.statements)];
|
|
3700
|
+
appendImplicitUndefinedReturn(lowerer, body, bodyReturn, locOf(fnLike));
|
|
3626
3701
|
const fn = {
|
|
3627
3702
|
name: `%${className}.${mName}`,
|
|
3628
3703
|
params,
|
|
@@ -3666,6 +3741,7 @@ export function lowerStaticMethod(lowerer, info, name) {
|
|
|
3666
3741
|
rejectStaticThis(lowerer, entry.member.body, (keyword) => `'${keyword}' in static methods (it names the RECEIVER class — a dynamic value; reference the class by name instead)`);
|
|
3667
3742
|
const declared = lowerer.declareParams(entry.member.parameters, entry.params);
|
|
3668
3743
|
const body = [...declared.prologue, ...lowerer.lowerStmts(entry.member.body.statements)];
|
|
3744
|
+
appendImplicitUndefinedReturn(lowerer, body, bodyReturn, locOf(entry.member));
|
|
3669
3745
|
const fn = {
|
|
3670
3746
|
name: `%${info.def.name}.static:${name}`,
|
|
3671
3747
|
params: declared.params,
|
|
@@ -4200,6 +4276,17 @@ function lowerProgramClassNew(lowerer, expr, declaredInfo, loc) {
|
|
|
4200
4276
|
loc,
|
|
4201
4277
|
};
|
|
4202
4278
|
}
|
|
4279
|
+
function assignedThisFieldType(lowerer, expr) {
|
|
4280
|
+
const parent = expr.parent;
|
|
4281
|
+
if (!ts.isBinaryExpression(parent) ||
|
|
4282
|
+
parent.operatorToken.kind !== ts.SyntaxKind.EqualsToken ||
|
|
4283
|
+
parent.right !== expr ||
|
|
4284
|
+
!ts.isPropertyAccessExpression(parent.left) ||
|
|
4285
|
+
parent.left.expression.kind !== ts.SyntaxKind.ThisKeyword) {
|
|
4286
|
+
return null;
|
|
4287
|
+
}
|
|
4288
|
+
return lowerer.currentClass?.fields.get(parent.left.name.text) ?? null;
|
|
4289
|
+
}
|
|
4203
4290
|
export function lowerNew(lowerer, expr) {
|
|
4204
4291
|
const loc = locOf(expr);
|
|
4205
4292
|
// `new X(...)` where X is a package-declared class, in a static build:
|
|
@@ -4611,6 +4698,9 @@ export function lowerNew(lowerer, expr) {
|
|
|
4611
4698
|
: null;
|
|
4612
4699
|
let tsType = lowerer.typeOf(expr);
|
|
4613
4700
|
let mapped = lowerer.mapTypeOf(tsType);
|
|
4701
|
+
const fieldType = assignedThisFieldType(lowerer, expr);
|
|
4702
|
+
if (mapped?.kind !== "map" && fieldType?.kind === "map")
|
|
4703
|
+
mapped = fieldType;
|
|
4614
4704
|
// JavaScript's `new Map()` has no type-argument syntax: the no-arg
|
|
4615
4705
|
// constructor overload pins Map<any, any> whatever the JSDoc says
|
|
4616
4706
|
// (`@type` on the declaration types the VARIABLE, not this
|
|
@@ -4691,7 +4781,10 @@ export function lowerNew(lowerer, expr) {
|
|
|
4691
4781
|
}
|
|
4692
4782
|
if (symbol?.name === "Set" && lowerer.isStdlibSymbol(symbol)) {
|
|
4693
4783
|
const tsType = lowerer.typeOf(expr);
|
|
4694
|
-
|
|
4784
|
+
let mapped = lowerer.mapTypeOf(tsType);
|
|
4785
|
+
const fieldType = assignedThisFieldType(lowerer, expr);
|
|
4786
|
+
if (mapped?.kind !== "set" && fieldType?.kind === "set")
|
|
4787
|
+
mapped = fieldType;
|
|
4695
4788
|
if (mapped?.kind === "set" && (expr.arguments?.length ?? 0) === 1) {
|
|
4696
4789
|
const argNode = expr.arguments[0];
|
|
4697
4790
|
// An array LITERAL seed builds element-wise (its contextual type
|
|
@@ -4851,7 +4944,7 @@ export function lowerNew(lowerer, expr) {
|
|
|
4851
4944
|
// observe it before throwing, so dropping it is exact for
|
|
4852
4945
|
// effect-free operands; effectful ones keep the fence.
|
|
4853
4946
|
const enc = lowerer.lowerExpr(expr.arguments[1]);
|
|
4854
|
-
if (enc.kind === "strLit" ||
|
|
4947
|
+
if (enc.kind === "strLit" || isSafeToRepeat(enc)) {
|
|
4855
4948
|
return { kind: "libCall", fn: "buffer.newStringFail", args: [got], type: bytesOf("u8"), loc };
|
|
4856
4949
|
}
|
|
4857
4950
|
}
|