@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
|
@@ -15,22 +15,24 @@ import { InternalCompilerError } from "../../errors.js";
|
|
|
15
15
|
*/
|
|
16
16
|
import { resolve } from "node:path";
|
|
17
17
|
import { tsgoPath } from "../dts-paths.js";
|
|
18
|
-
import { isRelativeSpecifier } from "../workspace-registry.js";
|
|
19
18
|
import * as ts from "../ts7/adapter.js";
|
|
20
19
|
import { anyOpRequiresDynamicDiag, blockedBindingUseDiag, checkerPanicDiag, componentTypeDiag, isCheckerPanic, genericSignatureTypeDiag, indexSignatureTypeDiag, intersectionTypeDiag, noLoweringDiag, overloadedSignatureTypeDiag, recordShapeMismatchDiag, requiresDynamicApiDiag, requiresDynamicPackageDiag, requiresDynamicTypeDiag, unionMismatchDiag, unsupportedDiag, unsupportedTypeDiag, } from "../../diagnostics/diagnostic.js";
|
|
21
|
-
import { arrayOf, BOOL, canAdaptDynFuncTo, canConvertToDyn, canCrossIslandBoundary, canExitIslandToType, canMarshalTypedFuncIntoIsland, DYN, F64, isJsonSafeType, isJsonStringifySafeType, isUndefinedArmedUnion, isUnitType, JSVAL, RUNTIME_ERROR_CLASSES, STRING, typeEquals, UNDEFINED_T, VOID } from "../../ir/ir.js";
|
|
20
|
+
import { arrayOf, BOOL, canAdaptDynFuncTo, canConvertToDyn, canCrossIslandBoundary, canExitIslandToType, canMarshalTypedFuncIntoIsland, DYN, DYN_HANDLE_KINDS, F64, isDynTypedRefType, isJsonSafeType, isJsonStringifySafeType, isUndefinedArmedUnion, isUnitType, JSVAL, NULL_T, RUNTIME_ERROR_CLASSES, STRING, typeEquals, UNDEFINED_T, VOID } from "../../ir/ir.js";
|
|
22
21
|
import { provenanceActive } from "../provenance-registry.js";
|
|
23
22
|
import { ambientDtsPath, canonicalBuiltinModule, cjsExportAssignmentOf, cjsExportDiscardReason, fallbackDtsPath, isCjsExportTableLiteral, isJsSourceFile, isNodeEsmFile, isNodeTypesPath, locOf, orderedImportsOf, overridesDtsPath, npmStaticDepSf7, requireSpecOf, resolveImport, workspacePackageOfPath, } from "../program.js";
|
|
24
23
|
import { containsRecord, containsUnion, describeComponentBlocker, describeRecordMemberBlocker, formatIrType, ISLAND_AMBIENT_TYPES, isUnitOnlyTsType, mapType, ShapeRegistry, typeKey, UnionRegistry, withUndefinedArm as withUndefinedArmCanonical, } from "../type-mapper.js";
|
|
25
24
|
import { boundaryIntoIslandMsg, boundaryOutOfIslandMsg, builtinConstLit, builtinModuleConstOf, builtinModulesArrayLit, builtinFenceHintOf, builtinModuleFnOf, stdlibMemberFence, isStdlibMember, isStdlibSymbol, isStdlibGlobal, stdlibGlobalMember, nodeTypesOnlySymbol } from "./surfaces.js";
|
|
26
25
|
import { splitFiles, collectProgram, collectNpmImports, collectJsonImports, moduleArtifacts, collectGlobals, declSymbolOf, defaultExportSymbolOf, lowerFileInit, lowerDefaultExport, buildMain, appendDynamicImportModules } from "./lower-modules.js";
|
|
26
|
+
import { prepareCjsModuleGraph } from "./lower-node-module.js";
|
|
27
27
|
import { registerBuiltinErrorClasses, registerBuiltinEmitterClass, registerBuiltinStreamClasses, builtinErrorInfoOf, builtinEmitterInfoOf, builtinStreamInfoOf, analyzeClassDecoration, classIteratorDrainCall, classIteratorNextCall, classIteratorOf, classIteratorOpenCall, classIteratorRestDrainCall, classMemberNameOf, classValueRef, collectClassShape, exactClassOfReceiver, collectClassShapeInner, ctorAbiEquals, findMethodOn, findStaticOn, findGenericMethodOn, findGenericStaticOn, genericClassInstanceType, isSubclassOf, inHierarchy, overrideBelow, staticShadowBelow, upcastTo, lowerClassMembers, lowerClassCtor, lowerClassExpression, lowerClassExpressionInfo, lowerClassMethodMember, lowerClassValueProperty, lowerStaticMethod, throwingSetterFn, fieldInitStmts, lowerStaticFieldInits, lowerStaticFieldRead, lowerDerivedCtorBody, superCallStmt, lowerSuperMethodCall, superThisRef, lowerSuperAccessorRead, lowerSuperAccessorWrite, inheritsBuiltinErrorCtor, inheritsBuiltinEmitterCtor, errorMessageArg, lowerNew, accessorCall } from "./lower-classes.js";
|
|
28
28
|
import { mixinCallClassInfoOf, mixinIntersectionInstanceType } from "./lower-mixins.js";
|
|
29
29
|
import { bindingNeverReassigned, bodyReadsArguments, implicitMonoFile, isThisParameter, paramShape, paramShapes, checkDefaultParamBodyType, completeArgs, wrappedUndefined, undefinedArgFor, requireExactArityValue, bodyReturnType, declaredReturnType, collectSignature, collectSignatureInner, collectGenericSignature, genericFnOf, lowerGenericCall, lowerGenericFnValue, inferTypeParamBindings, lowerGenericInstance, lowerCall, lowerFfiCall, lowerTimersMemberCall, lowerPromiseMethodCall, lowerFilterNarrowCall, isTopLevelFnSymbol, lowerNestedFunctionDecl, lambdaSignature, lowerLambda, lowerFunction, validateFfiImports } from "./lower-calls.js";
|
|
30
|
-
import { lowerArrayMethodCall,
|
|
30
|
+
import { lowerArrayMethodCall, lowerMapMethodCall, lowerMapForEachCall, buildMapForEachFn, lowerRecordOvfCaptureHelper, lowerEnvToPairsHelper, lowerSetMethodCall, lowerSetForEachCall, buildSetForEachFn } from "./lower-containers.js";
|
|
31
|
+
import { lowerBufferStaticCall, lowerBytesMethodCall, lowerBytesNew } from "./containers/bytes.js";
|
|
32
|
+
import { lowerRegexMethodCall, lowerStringMethodCall } from "./containers/string-and-regexp.js";
|
|
31
33
|
import { lowerStreamModuleCall } from "./lower-stream.js";
|
|
32
34
|
import { lowerEmitOverrideSpec } from "./lower-event-emitter.js";
|
|
33
|
-
import { builtinImportOf, createRequireBindingDecl, createRequireNamespaceDecl, createRequireSpecOf, stripTypeCasts, lowerBuiltinModuleCall, lowerFsToUnixTimestampCall, lowerFsLadderCall, lowerChildArgsArg, lowerSpawnSyncCall, lowerSpawnCall, lowerExecSyncCall, recordToEnvPairs, lowerJsonMethodCall, fencedBuiltinImportOf, lowerCryptoComposedCall, lowerUrlMethodCall, lowerSearchParamsMethodCall, lowerStatsMethodCall, lowerChildMethodCall, lowerAtomicsCall, lowerBuiltinExtraProperty, promisifiedExecFileDecl, lowerExecFileAsyncCall, execFileAsyncHelper, lowerStringDecoderMethodCall, strdecHelper, lowerReadlineMethodCall, lowerDcChannelMethodCall, lowerDcChannelProperty, lowerAlsMethodCall, lowerDcTracingChannelMethodCall, lowerDcTracingChannelProperty, lowerJsonProperty, lowerErrorCodeProperty, lowerProcessProperty, isProcessEnv, envValueType, lowerProcessEnvGet, lowerProcessMethodCall, lowerProcessOptionalMethodCall, lowerTimeoutMethodCall, envSnapshotHelper, isConsoleLog, consoleCallMember, lowerNumberStaticCall, lowerNumberStaticProperty, lowerDateCall, lowerTextCodecCall, lowerCryptoModuleCall, lowerFsConstantsProperty, lowerBuiltinConstantsProperty, builtinConstantBindingOf, builtinConstantsDestructureDecl, lowerProcessStreamProperty, lowerStringStaticCall, lowerStringLastIndexOfCall, lowerPromiseStaticCall, textCodecBindingClassOf } from "./lower-builtins.js";
|
|
35
|
+
import { builtinImportOf, createRequireBindingDecl, createRequireNamespaceDecl, createRequireSpecOf, stripTypeCasts, lowerBuiltinModuleCall, lowerTimersPromisesSetInterval, lowerFsToUnixTimestampCall, lowerFsLadderCall, lowerChildArgsArg, lowerSpawnSyncCall, lowerSpawnCall, lowerExecSyncCall, recordToEnvPairs, lowerJsonMethodCall, fencedBuiltinImportOf, lowerCryptoComposedCall, lowerUrlMethodCall, lowerSearchParamsMethodCall, lowerStatsMethodCall, lowerChildMethodCall, lowerAtomicsCall, lowerBuiltinExtraProperty, promisifiedExecFileDecl, lowerExecFileAsyncCall, execFileAsyncHelper, lowerStringDecoderMethodCall, strdecHelper, lowerReadlineMethodCall, lowerDcChannelMethodCall, lowerDcChannelProperty, lowerAlsMethodCall, lowerDcTracingChannelMethodCall, lowerDcTracingChannelProperty, lowerJsonProperty, lowerErrorCodeProperty, lowerProcessProperty, isProcessEnv, envValueType, lowerProcessEnvGet, lowerProcessMethodCall, lowerProcessOptionalMethodCall, lowerTimeoutMethodCall, envSnapshotHelper, isConsoleLog, consoleCallMember, lowerNumberStaticCall, lowerNumberStaticProperty, lowerDateCall, lowerTextCodecCall, lowerCryptoModuleCall, lowerFsConstantsProperty, lowerBuiltinConstantsProperty, builtinConstantBindingOf, builtinConstantsDestructureDecl, lowerProcessStreamProperty, lowerStringStaticCall, lowerStringLastIndexOfCall, lowerPromiseStaticCall, textCodecBindingClassOf } from "./lower-builtins.js";
|
|
34
36
|
import { fenceFetchObjectAssignment, fenceFetchObjectBinding, fenceStaticAbortControllerMemberRead, fenceStaticHeadersIteration, fenceStaticHeadersMember, fenceStaticReadableStreamMember, fenceStaticResponseMember, fenceUnsupportedFetchConstructorMember, isIslandExpr, islandFuncValueFence, islandRegexpOf, jsvalIn, requireDynamicApi, islandGlobalFnOf, lowerAbortControllerNew, lowerDynamicHeadersIteratorCall, lowerDynamicHeadersSpread, lowerDynamicImportCall, lowerFetchCall, lowerFetchElementMethodCall, lowerResponseNew, lowerStaticFetchCompanionCall, lowerStaticAbortControllerCall, lowerStaticAbortSignalListenerCall, lowerStaticReadableStreamCancelCall, lowerStaticReadableStreamControllerCall, lowerStaticReadableStreamNew, lowerStaticReadableStreamReaderCall, lowerStaticResponseCall, lowerIslandMethodCall, lowerMathProperty, npmPackageOf, npmMemberFence, npmPackageOfSymbol } from "./lower-island.js";
|
|
35
37
|
import { lowerHttpHeadersElement, lowerNetModuleCall, lowerServerMethodCall, lowerServerProperty, lowerTlsRootCertificates } from "./lower-server.js";
|
|
36
38
|
import { lowerDgramDnsModuleCall, lowerDgramMethodCall } from "./lower-dgram.js";
|
|
@@ -38,11 +40,14 @@ import { lowerNodeTestModuleCall, lowerTestDirectCall, lowerTestMethodCall, lowe
|
|
|
38
40
|
import { lowerAssertModuleCall, lowerAssertDirectCall } from "./lower-assert.js";
|
|
39
41
|
import { lowerUtilModuleCall } from "./lower-inspect.js";
|
|
40
42
|
import { lowerComptime, comptimeBakeable, rejectComptimeCaptures, comptimeValueToIr } from "./lower-comptime.js";
|
|
41
|
-
import { lowerStmts, noteBlockedBindings, isBlockedBinding, lowerScopedBlock, predeclareForwardCapture, predeclareForwardFnDecl, predeclareForwardVar,
|
|
42
|
-
import {
|
|
43
|
+
import { lowerStmts, noteBlockedBindings, isBlockedBinding, lowerScopedBlock, predeclareForwardCapture, predeclareForwardFnDecl, predeclareForwardVar, lowerStmt, lowerVarStatement, lowerDestructuringDecl, lowerDestructuringAssignParts, lowerBindingPattern, lowerJsvalBindingPattern, checkBindingElement, bindPatternTarget, isParseArgsDynCheckerType, lowerVarDeclList, lowerVarDecl, lowerSwitch, lowerTry, lowerExprStatement, lowerForOf, lowerForStatement } from "./lower-stmts.js";
|
|
44
|
+
import { lowerExpr, maybeNarrow, lowerUnitComparison, lowerNullishCoalesce, lowerCondition, ensureBool, requireTruthyUnion, eqComparableUnion, lowerIntrinsicProperty, lowerArrayLiteral, lowerElementAccess, lowerElementWrite, lowerRecordKeyRead, ensureString, lowerTemplate, lowerAsExpression, lowerPrefixUnary, lowerBinary, lowerCaughtTypeofTest, caughtRead, caughtLocalOf, caughtToString, lowerInstanceOf, lowerRegexLiteral, lowerFieldRead, lowerUnionProperty, fieldTarget, fieldGetExpr, fieldSetStmt, lowerFieldCompound, uniqueSymbolKeyOf } from "./lower-exprs.js";
|
|
45
|
+
import { finishOptionalChain, lowerOptionalChain } from "./expressions/optional-chains.js";
|
|
46
|
+
import { foldedStringKeyOf, lowerDynObjectLiteral, lowerObjectLiteral, lowerShorthandValue, rejectThisInObjectMethod } from "./expressions/object-literals.js";
|
|
43
47
|
import { lowerRecordFieldCall, lowerObjectMethodCall } from "./lower-calls.js";
|
|
44
48
|
import { fenceCrossBlockNsRef, nsPathPrefix } from "./lower-namespaces.js";
|
|
45
49
|
import { numLit, varRef } from "../../ir/build.js";
|
|
50
|
+
import { isSafeToRepeat } from "./expressions/evaluation-safety.js";
|
|
46
51
|
/** Entry function name. '%' cannot appear in a TS identifier, so a user
|
|
47
52
|
* function can never collide with it (mangling is injective per prefix). */
|
|
48
53
|
export const ENTRY_NAME = "%main";
|
|
@@ -464,6 +469,41 @@ export function dynFallbackType(lowerer, node, t) {
|
|
|
464
469
|
// the whole type's own fence.
|
|
465
470
|
return anyPiecedFuncType(lowerer, node, t);
|
|
466
471
|
}
|
|
472
|
+
// JS inference commonly spells a callback field initialized to null as
|
|
473
|
+
// `((value: any) => any) | null`. Preserve the callable arm and its
|
|
474
|
+
// checked-dynamic pieces instead of collapsing the whole slot to dyn.
|
|
475
|
+
// Besides keeping direct calls static, this leaves closure captures
|
|
476
|
+
// visible to the native cycle collector (a dyn-boxed closure edge is
|
|
477
|
+
// intentionally opaque to it).
|
|
478
|
+
if (t.isUnionType()) {
|
|
479
|
+
const arms = [];
|
|
480
|
+
let functions = 0;
|
|
481
|
+
for (const part of ts.constituentTypes(t)) {
|
|
482
|
+
if (part.flags & ts.TypeFlags.Null) {
|
|
483
|
+
arms.push(NULL_T);
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
if (part.flags & (ts.TypeFlags.Undefined | ts.TypeFlags.Void)) {
|
|
487
|
+
arms.push(UNDEFINED_T);
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
const mapped = lowerer.mapTypeOf(part) ?? jsFallbackFunctionType(lowerer, node, part);
|
|
491
|
+
if (mapped?.kind !== "func") {
|
|
492
|
+
functions = -1;
|
|
493
|
+
break;
|
|
494
|
+
}
|
|
495
|
+
functions++;
|
|
496
|
+
arms.push(mapped);
|
|
497
|
+
}
|
|
498
|
+
if (functions === 1 && arms.length > 1) {
|
|
499
|
+
const canonical = [...new Map(arms.map((arm) => [typeKey(arm), arm])).entries()]
|
|
500
|
+
.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)
|
|
501
|
+
.map(([, arm]) => arm);
|
|
502
|
+
return canonical.length === 1
|
|
503
|
+
? canonical[0]
|
|
504
|
+
: { kind: "union", unionId: lowerer.unions.intern(canonical) };
|
|
505
|
+
}
|
|
506
|
+
}
|
|
467
507
|
if (lowerer.checker.isArrayType(t)) {
|
|
468
508
|
const elem = lowerer.checker.getTypeArguments(t)[0];
|
|
469
509
|
const elemTainted = elem !== undefined &&
|
|
@@ -485,18 +525,23 @@ export function dynFallbackType(lowerer, node, t) {
|
|
|
485
525
|
// construct signatures, overloads, and function-with-properties shapes
|
|
486
526
|
// stay out (the whole value falls to dyn below, where every reached
|
|
487
527
|
// use meets its own fence or boxes as-is).
|
|
488
|
-
const
|
|
489
|
-
if (
|
|
490
|
-
|
|
491
|
-
const pt = lowerer.checker.getTypeOfSymbolAtLocation(p, node);
|
|
492
|
-
return lowerer.mapTypeOf(pt) ?? DYN;
|
|
493
|
-
});
|
|
494
|
-
const retT = lowerer.checker.getReturnTypeOfSignature(sig);
|
|
495
|
-
const ret = retT.flags & ts.TypeFlags.Void ? VOID : lowerer.mapTypeOf(retT) ?? DYN;
|
|
496
|
-
return { kind: "func", params, ret };
|
|
497
|
-
}
|
|
528
|
+
const fallbackFunction = jsFallbackFunctionType(lowerer, node, t);
|
|
529
|
+
if (fallbackFunction !== null)
|
|
530
|
+
return fallbackFunction;
|
|
498
531
|
return DYN;
|
|
499
532
|
}
|
|
533
|
+
function jsFallbackFunctionType(lowerer, node, t) {
|
|
534
|
+
const sig = pureSingleCallSignatureOf(lowerer, t);
|
|
535
|
+
if (!sig)
|
|
536
|
+
return null;
|
|
537
|
+
const params = sig.getParameters().map((p) => {
|
|
538
|
+
const pt = lowerer.checker.getTypeOfSymbolAtLocation(p, node);
|
|
539
|
+
return lowerer.mapTypeOf(pt) ?? DYN;
|
|
540
|
+
});
|
|
541
|
+
const retT = lowerer.checker.getReturnTypeOfSignature(sig);
|
|
542
|
+
const ret = retT.flags & ts.TypeFlags.Void ? VOID : lowerer.mapTypeOf(retT) ?? DYN;
|
|
543
|
+
return { kind: "func", params, ret };
|
|
544
|
+
}
|
|
500
545
|
/** The one call signature of a PURE function type — single signature, no
|
|
501
546
|
* properties, no construct signatures, no type parameters, no rest params
|
|
502
547
|
* (declared or synthesized from an `arguments` read). Null for every
|
|
@@ -935,8 +980,9 @@ export class Lowerer {
|
|
|
935
980
|
: null;
|
|
936
981
|
}
|
|
937
982
|
/** A strict property or method receiver over an array-derived optional
|
|
938
|
-
* value.
|
|
939
|
-
* for a unit arm, and extract the
|
|
983
|
+
* value. Reuse a plain read directly or stabilize an effectful receiver
|
|
984
|
+
* once, throw Node's member-read TypeError for a unit arm, and extract the
|
|
985
|
+
* expected present arm otherwise. */
|
|
940
986
|
runtimeOptionalPropertyReceiver(node, value, expected, member) {
|
|
941
987
|
const source = this.runtimeOptionalSourceValue(node, value);
|
|
942
988
|
if (source?.type.kind !== "union")
|
|
@@ -948,8 +994,9 @@ export class Lowerer {
|
|
|
948
994
|
!def.arms.every((arm) => typeEquals(arm, expected) || isUnitType(arm)))
|
|
949
995
|
return null;
|
|
950
996
|
const loc = locOf(node);
|
|
951
|
-
const
|
|
952
|
-
const
|
|
997
|
+
const repeatSource = isSafeToRepeat(source);
|
|
998
|
+
const stable = repeatSource ? null : this.declareHiddenLocal("%propertyRecv", source.type);
|
|
999
|
+
const stableRef = () => repeatSource ? source : varRef(stable.id, source.type, loc);
|
|
953
1000
|
let result = {
|
|
954
1001
|
kind: "unionNarrow",
|
|
955
1002
|
unionId: source.type.unionId,
|
|
@@ -980,6 +1027,8 @@ export class Lowerer {
|
|
|
980
1027
|
loc,
|
|
981
1028
|
};
|
|
982
1029
|
}
|
|
1030
|
+
if (stable === null)
|
|
1031
|
+
return result;
|
|
983
1032
|
return {
|
|
984
1033
|
kind: "seqExpr",
|
|
985
1034
|
stmts: [{ kind: "varDecl", localId: stable.id, init: source, loc }],
|
|
@@ -1265,6 +1314,12 @@ export class Lowerer {
|
|
|
1265
1314
|
* any body lowers: import headers and inline require statements call
|
|
1266
1315
|
* dependency inits by these names. */
|
|
1267
1316
|
initNameOf = new Map();
|
|
1317
|
+
/** CommonJS module objects are scalar handles into the runtime registry.
|
|
1318
|
+
* IDs are assigned in deterministic module order before any body lowers;
|
|
1319
|
+
* the feature gate stays false for programs that never inspect the graph. */
|
|
1320
|
+
cjsModuleIdOf = new Map();
|
|
1321
|
+
cjsModuleFiles = [];
|
|
1322
|
+
cjsModuleGraphEnabled = false;
|
|
1268
1323
|
/** File → the id of its run-once guard global (a bool module global,
|
|
1269
1324
|
* false at program start). Every non-entry module gets one: its %init
|
|
1270
1325
|
* may be called from several importers/requirers, and the guard is what
|
|
@@ -1330,10 +1385,10 @@ export class Lowerer {
|
|
|
1330
1385
|
liftedFns = [];
|
|
1331
1386
|
lambdaCounter = 0;
|
|
1332
1387
|
/** Statement lists currently mid-lowering, innermost last: the forward-
|
|
1333
|
-
* capture machinery
|
|
1334
|
-
*
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1388
|
+
* capture machinery needs to know which later statements of an OPEN list
|
|
1389
|
+
* a symbol's declaration sits in, which scope frame list-level declarations
|
|
1390
|
+
* register into, and where to insert predeclarations before closures or
|
|
1391
|
+
* earlier source statements need them. */
|
|
1337
1392
|
activeStmtLists = [];
|
|
1338
1393
|
/** Forward-captured consts pre-declared as TDZ boxes, keyed by symbol:
|
|
1339
1394
|
* lowerVarDecl consumes the entry when the source declaration arrives and
|
|
@@ -1549,9 +1604,8 @@ export class Lowerer {
|
|
|
1549
1604
|
const spec = requireSpecOf(recvDecl.initializer);
|
|
1550
1605
|
const dep = spec === null
|
|
1551
1606
|
? null
|
|
1552
|
-
:
|
|
1553
|
-
|
|
1554
|
-
: npmStaticDepSf7(this.program, recvDecl.getSourceFile(), spec);
|
|
1607
|
+
: resolveImport(this.program, recvDecl.getSourceFile(), spec) ??
|
|
1608
|
+
npmStaticDepSf7(this.program, recvDecl.getSourceFile(), spec);
|
|
1555
1609
|
if (dep)
|
|
1556
1610
|
symbol = this.cjsModuleExportSymbol(dep, ident.text);
|
|
1557
1611
|
}
|
|
@@ -1687,15 +1741,15 @@ export class Lowerer {
|
|
|
1687
1741
|
return this.externalTypeSpecifierOfSymbol(this.checker.getSymbolAtLocation(value));
|
|
1688
1742
|
}
|
|
1689
1743
|
/** The source file a checker-resolved module-specifier node names. The
|
|
1690
|
-
* checker path
|
|
1691
|
-
*
|
|
1744
|
+
* checker path is preferred; resolveImport is the canonical fallback for
|
|
1745
|
+
* every project-module spelling. */
|
|
1692
1746
|
moduleSourceFileOf(from, spec) {
|
|
1693
1747
|
const moduleSymbol = this.checker.getSymbolAtLocation(spec);
|
|
1694
1748
|
for (const decl of moduleSymbol ? this.checker.declarationsOf(moduleSymbol) : []) {
|
|
1695
1749
|
if (ts.isSourceFile(decl))
|
|
1696
1750
|
return decl;
|
|
1697
1751
|
}
|
|
1698
|
-
return
|
|
1752
|
+
return resolveImport(this.program, from, spec.text);
|
|
1699
1753
|
}
|
|
1700
1754
|
/** Follow one project-module export through the checker's resolved export
|
|
1701
1755
|
* table, then recover its exact external route where alias declarations
|
|
@@ -1937,22 +1991,19 @@ export class Lowerer {
|
|
|
1937
1991
|
return null;
|
|
1938
1992
|
}
|
|
1939
1993
|
const spec = importDecl.moduleSpecifier.text;
|
|
1940
|
-
//
|
|
1941
|
-
//
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
const dep = isRelativeSpecifier(spec)
|
|
1945
|
-
? resolveImport(this.program, importDecl.getSourceFile(), spec)
|
|
1946
|
-
: npmStaticDepSf7(this.program, importDecl.getSourceFile(), spec);
|
|
1994
|
+
// Project aliases/self-references resolve through the same entry point as
|
|
1995
|
+
// relative imports; an opted-in --npm-static package is the fallback.
|
|
1996
|
+
const dep = resolveImport(this.program, importDecl.getSourceFile(), spec) ??
|
|
1997
|
+
npmStaticDepSf7(this.program, importDecl.getSourceFile(), spec);
|
|
1947
1998
|
if (!dep || !isJsSourceFile(dep) || isNodeEsmFile(dep))
|
|
1948
1999
|
return null;
|
|
1949
2000
|
return dep;
|
|
1950
2001
|
}
|
|
1951
2002
|
/** True when `expr` is an identifier bound by a top-level
|
|
1952
|
-
* `const x = require("./local")` of a
|
|
1953
|
-
*
|
|
1954
|
-
* --npm-static package (its CJS entry is a program
|
|
1955
|
-
* binding is the same namespace over the same export table), or by a
|
|
2003
|
+
* `const x = require("./local")` of a project module — relative,
|
|
2004
|
+
* tsconfig-aliased, or package.json-mediated — or of a bare specifier
|
|
2005
|
+
* naming an opted-in --npm-static package (its CJS entry is a program
|
|
2006
|
+
* module, so the binding is the same namespace over the same export table), or by a
|
|
1956
2007
|
* DEFAULT import of a CommonJS JS module (`import d from "./lib.cjs"`:
|
|
1957
2008
|
* Node binds d to module.exports, the same value require answers).
|
|
1958
2009
|
* Member accesses on it resolve through the export table (property
|
|
@@ -1977,7 +2028,7 @@ export class Lowerer {
|
|
|
1977
2028
|
const spec = requireSpecOf(decl.initializer);
|
|
1978
2029
|
if (spec === null)
|
|
1979
2030
|
return false;
|
|
1980
|
-
if (
|
|
2031
|
+
if (resolveImport(this.program, decl.getSourceFile(), spec) === null &&
|
|
1981
2032
|
npmStaticDepSf7(this.program, decl.getSourceFile(), spec) === null) {
|
|
1982
2033
|
return false;
|
|
1983
2034
|
}
|
|
@@ -2197,16 +2248,15 @@ export class Lowerer {
|
|
|
2197
2248
|
* their external dependencies by name). Null for everything else
|
|
2198
2249
|
* (builtins load nothing; the rest kept its preflight fence). */
|
|
2199
2250
|
requireInitStmt(spec, node) {
|
|
2200
|
-
//
|
|
2201
|
-
// a program-module edge
|
|
2202
|
-
//
|
|
2203
|
-
//
|
|
2204
|
-
//
|
|
2251
|
+
// Project requires resolve within the program; another bare require can
|
|
2252
|
+
// be a program-module edge when it names an opted-in --npm-static package
|
|
2253
|
+
// (one package requiring another — the resolution answered its shipped
|
|
2254
|
+
// JS, the file is in the module order, and the reads alias its globals).
|
|
2255
|
+
// Without the guarded %init call at this position
|
|
2205
2256
|
// those globals stay uninitialized: the dep's module body would never
|
|
2206
2257
|
// run.
|
|
2207
|
-
const dep =
|
|
2208
|
-
|
|
2209
|
-
: npmStaticDepSf7(this.program, node.getSourceFile(), spec);
|
|
2258
|
+
const dep = resolveImport(this.program, node.getSourceFile(), spec) ??
|
|
2259
|
+
npmStaticDepSf7(this.program, node.getSourceFile(), spec);
|
|
2210
2260
|
if (!dep || dep.fileName.endsWith(".json"))
|
|
2211
2261
|
return null;
|
|
2212
2262
|
if (this.asyncInitFiles.has(dep)) {
|
|
@@ -2216,11 +2266,33 @@ export class Lowerer {
|
|
|
2216
2266
|
if (initName === undefined)
|
|
2217
2267
|
return null;
|
|
2218
2268
|
const loc = locOf(node);
|
|
2219
|
-
|
|
2269
|
+
const init = {
|
|
2220
2270
|
kind: "exprStmt",
|
|
2221
2271
|
expr: { kind: "call", callee: initName, args: [], type: VOID, loc },
|
|
2222
2272
|
loc,
|
|
2223
2273
|
};
|
|
2274
|
+
const parentModule = this.cjsModuleIdOf.get(node.getSourceFile());
|
|
2275
|
+
const childModule = this.cjsModuleIdOf.get(dep);
|
|
2276
|
+
if (parentModule === undefined || childModule === undefined)
|
|
2277
|
+
return init;
|
|
2278
|
+
return {
|
|
2279
|
+
kind: "block",
|
|
2280
|
+
body: [
|
|
2281
|
+
{
|
|
2282
|
+
kind: "exprStmt",
|
|
2283
|
+
expr: {
|
|
2284
|
+
kind: "libCall",
|
|
2285
|
+
fn: "module.link",
|
|
2286
|
+
args: [numLit(parentModule, loc), numLit(childModule, loc)],
|
|
2287
|
+
type: VOID,
|
|
2288
|
+
loc,
|
|
2289
|
+
},
|
|
2290
|
+
loc,
|
|
2291
|
+
},
|
|
2292
|
+
init,
|
|
2293
|
+
],
|
|
2294
|
+
loc,
|
|
2295
|
+
};
|
|
2224
2296
|
}
|
|
2225
2297
|
/** True when this body should lower: everything with no reachable set,
|
|
2226
2298
|
* the marked bodies in an externally-gated pass, and exactly the
|
|
@@ -2971,6 +3043,7 @@ export class Lowerer {
|
|
|
2971
3043
|
for (const info of this.classes.values())
|
|
2972
3044
|
analyzeClassDecoration(this, info);
|
|
2973
3045
|
this.prepareModuleInits(parts);
|
|
3046
|
+
prepareCjsModuleGraph(this, parts);
|
|
2974
3047
|
const functions = [];
|
|
2975
3048
|
for (const fp of parts) {
|
|
2976
3049
|
for (const decl of fp.fnDecls) {
|
|
@@ -3192,7 +3265,7 @@ export class Lowerer {
|
|
|
3192
3265
|
const module = this.diags.length > 0
|
|
3193
3266
|
? null
|
|
3194
3267
|
: {
|
|
3195
|
-
irVersion:
|
|
3268
|
+
irVersion: 9,
|
|
3196
3269
|
sourceFile: this.entry.fileName,
|
|
3197
3270
|
functions,
|
|
3198
3271
|
classes: artifacts.classes,
|
|
@@ -3342,6 +3415,7 @@ export class Lowerer {
|
|
|
3342
3415
|
for (const info of this.classes.values())
|
|
3343
3416
|
analyzeClassDecoration(this, info);
|
|
3344
3417
|
this.prepareModuleInits(parts);
|
|
3418
|
+
prepareCjsModuleGraph(this, parts);
|
|
3345
3419
|
// Every lowerable body, by emitted-function name. The names double as
|
|
3346
3420
|
// retained-function keys and are deterministic by construction
|
|
3347
3421
|
// (qualified declaration names).
|
|
@@ -4507,10 +4581,18 @@ export class Lowerer {
|
|
|
4507
4581
|
const undefArmedOk = expected.kind === "union" &&
|
|
4508
4582
|
(this.unions
|
|
4509
4583
|
.get(expected.unionId)
|
|
4510
|
-
?.arms.every((a) => a.kind === "undefinedT" ||
|
|
4584
|
+
?.arms.every((a) => a.kind === "undefinedT" ||
|
|
4585
|
+
this.jsonSafe(a) ||
|
|
4586
|
+
isDynTypedRefType(a) ||
|
|
4587
|
+
DYN_HANDLE_KINDS.has(a.kind)) ??
|
|
4511
4588
|
false);
|
|
4512
4589
|
const bytesOk = expected.kind === "bytes" && expected.elem === "u8";
|
|
4513
4590
|
const errorOk = expected.kind === "object" && expected.className === "%Error";
|
|
4591
|
+
// Program and runtime class instances can return only from a
|
|
4592
|
+
// compiler-owned typed-reference capsule. A parsed/plain dyn object
|
|
4593
|
+
// fails the runtime check; an exact capsule unwraps the original
|
|
4594
|
+
// instance and preserves identity.
|
|
4595
|
+
const classOk = isDynTypedRefType(expected);
|
|
4514
4596
|
// ADAPTABLE function targets (the checked-dynamic function
|
|
4515
4597
|
// boundary's OUT direction — `const wrapped: F = mustCall(fn)`):
|
|
4516
4598
|
// check callable-kind, then unwrap an identical boxed signature
|
|
@@ -4518,7 +4600,8 @@ export class Lowerer {
|
|
|
4518
4600
|
// arguments/results per F.
|
|
4519
4601
|
const funcOk = expected.kind === "func" &&
|
|
4520
4602
|
canAdaptDynFuncTo(expected, (id) => this.shapes.get(id), (id) => this.unions.get(id));
|
|
4521
|
-
|
|
4603
|
+
const handleOk = DYN_HANDLE_KINDS.has(expected.kind);
|
|
4604
|
+
if (this.jsonSafe(expected) || undefArmedOk || bytesOk || errorOk || classOk || funcOk || handleOk) {
|
|
4522
4605
|
return { kind: "dynCheck", value: expr, type: expected, loc: expr.loc };
|
|
4523
4606
|
}
|
|
4524
4607
|
return expr;
|
|
@@ -8268,11 +8351,8 @@ export class Lowerer {
|
|
|
8268
8351
|
lowerScopedBlock(stmt) {
|
|
8269
8352
|
return lowerScopedBlock(this, stmt);
|
|
8270
8353
|
}
|
|
8271
|
-
/** Lowers inside a
|
|
8272
|
-
*
|
|
8273
|
-
* break/continue/return crosses. `labels` carries the construct's JS
|
|
8274
|
-
* label names when the source statement was labeled — labeled jumps
|
|
8275
|
-
* resolve against them. */
|
|
8354
|
+
/** Lowers inside a jump-target marker. `labels` carries the construct's
|
|
8355
|
+
* source label names so labeled jumps resolve against them. */
|
|
8276
8356
|
inCtl(kind, fn, labels) {
|
|
8277
8357
|
this.ctx.ctl.push(labels !== undefined && labels.length > 0 ? { kind, labels } : { kind });
|
|
8278
8358
|
try {
|
|
@@ -8293,9 +8373,6 @@ export class Lowerer {
|
|
|
8293
8373
|
this.pendingLabels = null;
|
|
8294
8374
|
return labels ?? undefined;
|
|
8295
8375
|
}
|
|
8296
|
-
rejectJumpCrossingFinally(kw, stmt, label) {
|
|
8297
|
-
return rejectJumpCrossingFinally(this, kw, stmt, label);
|
|
8298
|
-
}
|
|
8299
8376
|
lowerStmt(stmt) {
|
|
8300
8377
|
return lowerStmt(this, stmt);
|
|
8301
8378
|
}
|
|
@@ -8588,6 +8665,12 @@ export class Lowerer {
|
|
|
8588
8665
|
return rejectThisInObjectMethod(this, node);
|
|
8589
8666
|
}
|
|
8590
8667
|
lowerElementAccess(expr) {
|
|
8668
|
+
if (ts.isPropertyAccessExpression(expr.expression) &&
|
|
8669
|
+
ts.isIdentifier(expr.expression.expression) &&
|
|
8670
|
+
expr.expression.expression.text === "require" &&
|
|
8671
|
+
expr.expression.name.text === "cache") {
|
|
8672
|
+
return lowerElementAccess(this, expr);
|
|
8673
|
+
}
|
|
8591
8674
|
const receiver = this.runtimeOptionalIdentifierValue(expr.expression);
|
|
8592
8675
|
const receiverValue = receiver && (receiver.present.kind === "array" || receiver.present.kind === "record")
|
|
8593
8676
|
? (() => {
|
|
@@ -9202,6 +9285,9 @@ export class Lowerer {
|
|
|
9202
9285
|
lowerBuiltinModuleCall(expr, bi, fn, loc) {
|
|
9203
9286
|
return lowerBuiltinModuleCall(this, expr, bi, fn, loc);
|
|
9204
9287
|
}
|
|
9288
|
+
lowerTimersPromisesSetInterval(expr, bi, loc) {
|
|
9289
|
+
return lowerTimersPromisesSetInterval(this, expr, bi, loc);
|
|
9290
|
+
}
|
|
9205
9291
|
lowerFsToUnixTimestampCall(expr, bi, loc) {
|
|
9206
9292
|
return lowerFsToUnixTimestampCall(this, expr, bi, loc);
|
|
9207
9293
|
}
|