@scriptc/compiler 0.1.3 → 0.1.5
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 +275 -62
- package/dist/backend/c/async.d.ts +25 -0
- package/dist/backend/c/async.js +167 -0
- package/dist/backend/c/async.js.map +1 -1
- package/dist/backend/c/c-emitter.d.ts +15 -1
- package/dist/backend/c/c-emitter.js +36 -11
- package/dist/backend/c/c-emitter.js.map +1 -1
- package/dist/backend/c/exprs.d.ts +2 -2
- package/dist/backend/c/exprs.js +556 -71
- package/dist/backend/c/exprs.js.map +1 -1
- package/dist/backend/c/stmts.js +5 -3
- package/dist/backend/c/stmts.js.map +1 -1
- package/dist/backend/c/types.d.ts +2 -3
- package/dist/backend/c/types.js +10 -1
- package/dist/backend/c/types.js.map +1 -1
- package/dist/backend/c/walkers.js +1 -1
- package/dist/backend/c/walkers.js.map +1 -1
- package/dist/backend/link-plan.d.ts +3 -1
- package/dist/backend/link-plan.js +3 -1
- package/dist/backend/link-plan.js.map +1 -1
- package/dist/backend/llvm/dyn.js +1 -1
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.js +42 -12
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/expr-bytes.d.ts +1 -2
- package/dist/backend/llvm/expr-bytes.js +28 -23
- package/dist/backend/llvm/expr-bytes.js.map +1 -1
- package/dist/backend/llvm/expr-callbacks.d.ts +9 -0
- package/dist/backend/llvm/expr-callbacks.js +125 -0
- package/dist/backend/llvm/expr-callbacks.js.map +1 -1
- package/dist/backend/llvm/expr-containers.d.ts +1 -0
- package/dist/backend/llvm/expr-containers.js +32 -4
- package/dist/backend/llvm/expr-containers.js.map +1 -1
- package/dist/backend/llvm/expr-context.d.ts +19 -3
- package/dist/backend/llvm/expr-dispatch.js +1 -0
- package/dist/backend/llvm/expr-dispatch.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.d.ts +1 -1
- package/dist/backend/llvm/expr-primitives.js +49 -13
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.test.d.ts +1 -0
- package/dist/backend/llvm/expr-primitives.test.js +38 -0
- package/dist/backend/llvm/expr-primitives.test.js.map +1 -0
- package/dist/backend/llvm/expr-stream-callbacks.d.ts +3 -0
- package/dist/backend/llvm/expr-stream-callbacks.js +69 -0
- package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
- package/dist/backend/llvm/lib-filesystem.js +80 -10
- package/dist/backend/llvm/lib-filesystem.js.map +1 -1
- package/dist/backend/llvm/lib-network.js +69 -10
- package/dist/backend/llvm/lib-network.js.map +1 -1
- package/dist/backend/llvm/lib-process.js +156 -6
- package/dist/backend/llvm/lib-process.js.map +1 -1
- package/dist/backend/llvm/lib-shared.js +100 -0
- package/dist/backend/llvm/lib-shared.js.map +1 -1
- package/dist/backend/llvm/lib-stream.js +23 -0
- package/dist/backend/llvm/lib-stream.js.map +1 -1
- package/dist/backend/native-toolchain.d.ts +5 -0
- package/dist/backend/native-toolchain.js +4 -1
- package/dist/backend/native-toolchain.js.map +1 -1
- package/dist/backend/runtime-pack.test.js +28 -10
- package/dist/backend/runtime-pack.test.js.map +1 -1
- package/dist/backend/targets.d.ts +7 -0
- package/dist/backend/targets.js +26 -0
- package/dist/backend/targets.js.map +1 -1
- package/dist/backend/targets.test.js +8 -1
- package/dist/backend/targets.test.js.map +1 -1
- package/dist/coverage/surface-manifest.js +14 -4
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/diagnostics/diagnostic.js +1 -1
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/executable/executable-cache.d.ts +4 -0
- package/dist/executable/executable-cache.js +6 -1
- package/dist/executable/executable-cache.js.map +1 -1
- package/dist/executable/executable-cache.test.js +3 -3
- package/dist/executable/executable-cache.test.js.map +1 -1
- package/dist/frontend/fork-target.d.ts +17 -0
- package/dist/frontend/fork-target.js +256 -0
- package/dist/frontend/fork-target.js.map +1 -0
- package/dist/frontend/lowering/abstract-equality.d.ts +6 -0
- package/dist/frontend/lowering/abstract-equality.js +250 -0
- package/dist/frontend/lowering/abstract-equality.js.map +1 -0
- package/dist/frontend/lowering/containers/bytes.d.ts +1 -1
- package/dist/frontend/lowering/containers/bytes.js +6 -5
- package/dist/frontend/lowering/containers/bytes.js.map +1 -1
- package/dist/frontend/lowering/containers/string-and-regexp.d.ts +7 -6
- package/dist/frontend/lowering/containers/string-and-regexp.js +237 -28
- package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
- package/dist/frontend/lowering/expressions/object-literals.js +8 -0
- package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
- package/dist/frontend/lowering/lower-assert.js +71 -2
- package/dist/frontend/lowering/lower-assert.js.map +1 -1
- package/dist/frontend/lowering/lower-builtins.d.ts +54 -28
- package/dist/frontend/lowering/lower-builtins.js +957 -116
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.d.ts +32 -23
- package/dist/frontend/lowering/lower-calls.js +835 -206
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.js +41 -10
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.d.ts +7 -9
- package/dist/frontend/lowering/lower-containers.js +293 -51
- package/dist/frontend/lowering/lower-containers.js.map +1 -1
- package/dist/frontend/lowering/lower-event-emitter.js +212 -21
- package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.d.ts +12 -0
- package/dist/frontend/lowering/lower-exprs.js +263 -93
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.d.ts +4 -0
- package/dist/frontend/lowering/lower-inspect.js +1 -1
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-island.d.ts +6 -3
- package/dist/frontend/lowering/lower-island.js +182 -12
- package/dist/frontend/lowering/lower-island.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.d.ts +6 -0
- package/dist/frontend/lowering/lower-modules.js +184 -38
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-namespaces.js +7 -0
- package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
- package/dist/frontend/lowering/lower-server.d.ts +3 -5
- package/dist/frontend/lowering/lower-server.js +413 -54
- package/dist/frontend/lowering/lower-server.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.js +122 -19
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lower-stream.d.ts +3 -0
- package/dist/frontend/lowering/lower-stream.js +7 -0
- package/dist/frontend/lowering/lower-stream.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +86 -9
- package/dist/frontend/lowering/lowerer.js +449 -74
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/optional-arguments.d.ts +9 -1
- package/dist/frontend/lowering/optional-arguments.js +67 -1
- package/dist/frontend/lowering/optional-arguments.js.map +1 -1
- package/dist/frontend/lowering/pairs-snapshot.d.ts +3 -1
- package/dist/frontend/lowering/pairs-snapshot.js +12 -4
- package/dist/frontend/lowering/pairs-snapshot.js.map +1 -1
- package/dist/frontend/lowering/surfaces.d.ts +34 -14
- package/dist/frontend/lowering/surfaces.js +177 -104
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/npm-static-declarations.d.ts +4 -0
- package/dist/frontend/npm-static-declarations.js +56 -0
- package/dist/frontend/npm-static-declarations.js.map +1 -1
- package/dist/frontend/npm-static-declarations.test.js +23 -2
- package/dist/frontend/npm-static-declarations.test.js.map +1 -1
- package/dist/frontend/npm-static-prune.d.ts +6 -0
- package/dist/frontend/npm-static-prune.js +203 -0
- package/dist/frontend/npm-static-prune.js.map +1 -0
- package/dist/frontend/npm-static-prune.test.d.ts +1 -0
- package/dist/frontend/npm-static-prune.test.js +48 -0
- package/dist/frontend/npm-static-prune.test.js.map +1 -0
- package/dist/frontend/npm-static.js +6 -5
- package/dist/frontend/npm-static.js.map +1 -1
- package/dist/frontend/npm.d.ts +15 -3
- package/dist/frontend/npm.js +87 -14
- package/dist/frontend/npm.js.map +1 -1
- package/dist/frontend/npm.test.js +76 -9
- package/dist/frontend/npm.test.js.map +1 -1
- package/dist/frontend/program.js +107 -14
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/provenance.js +8 -3
- package/dist/frontend/provenance.js.map +1 -1
- package/dist/frontend/resolve.d.ts +6 -0
- package/dist/frontend/resolve.js +7 -4
- package/dist/frontend/resolve.js.map +1 -1
- package/dist/frontend/type-mapper.d.ts +5 -0
- package/dist/frontend/type-mapper.js +80 -29
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +34 -41
- package/dist/index.js.map +1 -1
- package/dist/ir/analysis.d.ts +5 -3
- package/dist/ir/analysis.js +25 -11
- package/dist/ir/analysis.js.map +1 -1
- package/dist/ir/analysis.test.js +50 -2
- package/dist/ir/analysis.test.js.map +1 -1
- package/dist/ir/constant-tables.d.ts +17 -0
- package/dist/ir/constant-tables.js +99 -0
- package/dist/ir/constant-tables.js.map +1 -0
- package/dist/ir/constant-tables.test.d.ts +1 -0
- package/dist/ir/constant-tables.test.js +78 -0
- package/dist/ir/constant-tables.test.js.map +1 -0
- package/dist/ir/integer-ranges.d.ts +13 -0
- package/dist/ir/integer-ranges.js +122 -0
- package/dist/ir/integer-ranges.js.map +1 -0
- package/dist/ir/integer-ranges.test.d.ts +1 -0
- package/dist/ir/integer-ranges.test.js +63 -0
- package/dist/ir/integer-ranges.test.js.map +1 -0
- package/dist/ir/ir.d.ts +130 -76
- package/dist/ir/ir.js +69 -4
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/ir.test.js +20 -1
- package/dist/ir/ir.test.js.map +1 -1
- package/dist/ir/scalar-records.d.ts +8 -0
- package/dist/ir/scalar-records.js +216 -0
- package/dist/ir/scalar-records.js.map +1 -0
- package/dist/ir/scalar-records.test.d.ts +1 -0
- package/dist/ir/scalar-records.test.js +142 -0
- package/dist/ir/scalar-records.test.js.map +1 -0
- package/dist/ir/serialize.d.ts +1 -1
- package/dist/ir/serialize.js +1 -1
- package/dist/ir/serialize.js.map +1 -1
- package/dist/ir/validate.js +256 -20
- package/dist/ir/validate.js.map +1 -1
- package/dist/ir/validate.test.d.ts +1 -0
- package/dist/ir/validate.test.js +31 -0
- package/dist/ir/validate.test.js.map +1 -0
- package/dist/library/cache-primitives.d.ts +1 -1
- package/dist/library/cache-primitives.js +3 -3
- package/dist/library/cache-primitives.js.map +1 -1
- package/dist/library/fence-eval.js +11 -4
- package/dist/library/fence-eval.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.js +0 -1
- package/dist/library/library-cache.js.map +1 -1
- package/dist/library/library-cache.test.js +8 -8
- package/dist/library/library-cache.test.js.map +1 -1
- package/package.json +17 -17
- package/surface-manifest.json +186 -79
|
@@ -8,22 +8,22 @@ import { arrayValueRead, arrayValueStore, arrayValueType } from "./array-values.
|
|
|
8
8
|
import { lowerForAwaitGenerator, lowerForOfGenerator, lowerYieldStarStatement } from "./lower-generators.js";
|
|
9
9
|
import { lowerForAwaitBuiltin } from "./lower-async-iteration.js";
|
|
10
10
|
import { BOOL, BYTES_U8, CAUGHT, DYN, F64, JSVAL, STRING, UNDEFINED_T, VOID, arrayOf, isUnitType, shapeHasAccessorSlots, typeEquals } from "../../ir/ir.js";
|
|
11
|
-
import { PoisonError, boundIdentifiersOf, dynFallbackType, dynUndefinedExpr, importCallHandleType, neverTaintedJsType, stmtUsesIsland, uncheckedOverloadHandleCall } from "./lowerer.js";
|
|
11
|
+
import { PoisonError, boundIdentifiersOf, dynFallbackType, dynUndefinedExpr, importCallHandleType, neverTaintedJsType, staticImportNamespaceType, stmtUsesIsland, uncheckedOverloadHandleCall } from "./lowerer.js";
|
|
12
12
|
import { enforceLibBoundary } from "./lib-boundary.js";
|
|
13
13
|
import { cjsExportAssignmentOf, cjsExportDiscardReason, cjsExportTargetLiteral, isCjsJsFile, isJsSourceFile, locOf, requireSpecOf } from "../program.js";
|
|
14
|
-
import { COMPOUND_ASSIGN_OPS, STR_METHODS, UNSUPPORTED_STMT, isStdlibMember, sideEffectFreeOptionValue, stdlibGlobalAliasDecl, stdlibGlobalNameOf } from "./surfaces.js";
|
|
14
|
+
import { COMPOUND_ASSIGN_OPS, STR_METHODS, UNSUPPORTED_STMT, isStdlibMember, sideEffectFreeOptionValue, stdlibGlobalAliasDecl, stdlibGlobalAliasNameOf, stdlibGlobalNameOf } from "./surfaces.js";
|
|
15
15
|
import { isProvenanceSourceFile } from "../provenance-registry.js";
|
|
16
16
|
import { ambientUndefVarRootOf, lowerImportEquals, nsUndefRead, nsWritableTarget, trapDeclRootOf } from "./lower-namespaces.js";
|
|
17
17
|
import { expandoWritableTarget, lowerExpandoAssignStmt } from "./lower-expando.js";
|
|
18
18
|
import { lowerForOfArrayIter, lowerForOfMap, lowerForOfSearchParams, lowerForOfSet, lowerSafeIndexRead, objectIterOverIndexShape, strCharsCall } from "./lower-containers.js";
|
|
19
|
-
import { bindingContextualGenericFnNodeOf, bindingGenericFnAliasInfoOf, bindingGenericFnInfoOf, bindingGenericFnNodeOf, deadUnmappableBinding, implicitLocalFnInfoOf, implicitLocalFnNodeOf, implicitMethodCallInfersReturn, nullishExprUnitOf, nullishGenericBindingUnitOf, recordKeysArrayCall } from "./lower-calls.js";
|
|
19
|
+
import { bindingContextualGenericFnNodeOf, bindingGenericFnAliasInfoOf, bindingGenericFnInfoOf, bindingGenericFnNodeOf, bindingNeverReassigned, deadUnmappableBinding, implicitLocalFnInfoOf, implicitLocalFnNodeOf, implicitMethodCallInfersReturn, nullishExprUnitOf, nullishGenericBindingUnitOf, recordKeysArrayCall, registerOverloadedCallableAlias } from "./lower-calls.js";
|
|
20
20
|
import { isMixinFnBinding, mixinResultBindingClassOf } from "./lower-mixins.js";
|
|
21
21
|
import { genericIfaceBindingKeepsClass } from "./lower-classes.js";
|
|
22
22
|
import { lowerStreamUnderscoreAssign, streamClassAliasDecl } from "./lower-stream.js";
|
|
23
23
|
import { lowerHttpResPropertyAssignment, lowerHttpServerTimeoutAssignment, lowerServerCloseOverrideAssignment } from "./lower-server.js";
|
|
24
|
-
import { builtinMemberRequireDecl, builtinNamespaceDestructureModuleOf, createRequireBindingDecl, createRequireCalleeFileOf, createRequireNamespaceDecl, textCodecBindingDecl } from "./lower-builtins.js";
|
|
24
|
+
import { builtinMemberRequireDecl, builtinNamespaceDestructureModuleOf, createRequireBindingDecl, createRequireCalleeFileOf, createRequireNamespaceDecl, createRequireProgramModuleDecl, createRequireProgramModuleOf, lowerNodeModuleCall, registerBuiltinCallableAlias, textCodecBindingDecl } from "./lower-builtins.js";
|
|
25
25
|
import { lowerEnumDeclaration } from "./lower-enums.js";
|
|
26
|
-
import { abstractPropertyDeclOf, aliasTypeofNarrows, isMatchSliceType, lowerAbsenceProbe, lowerGroupsProjection, lowerOptionalNumber, matchResultNamedGroupsOf, runtimeOptionalTrueIds, symbolFieldInfo, withRuntimeOptionalNarrowed } from "./lower-exprs.js";
|
|
26
|
+
import { abstractPropertyDeclOf, aliasTypeofNarrows, isMatchSliceType, lowerAbsenceProbe, lowerElementCompound, lowerGroupsProjection, lowerOptionalNumber, matchResultNamedGroupsOf, runtimeOptionalTrueIds, symbolFieldInfo, withRuntimeOptionalNarrowed } from "./lower-exprs.js";
|
|
27
27
|
import { isSafeToRepeat } from "./expressions/evaluation-safety.js";
|
|
28
28
|
import { tryLowerExpression } from "./expressions/try-lower-expression.js";
|
|
29
29
|
import { checkerPanicDiag, isCheckerPanic, requiresDynamicDiag } from "../../diagnostics/diagnostic.js";
|
|
@@ -706,6 +706,9 @@ function varBindingType(lowerer, nameNode) {
|
|
|
706
706
|
(uncheckedOverloadHandleCall(lowerer, nameNode.parent.initializer) ? JSVAL : null) ??
|
|
707
707
|
type;
|
|
708
708
|
}
|
|
709
|
+
if (!lowerer.dynamic && ts.isVariableDeclaration(nameNode.parent) && nameNode.parent.name === nameNode) {
|
|
710
|
+
type = staticImportNamespaceType(lowerer, nameNode.parent.initializer) ?? type;
|
|
711
|
+
}
|
|
709
712
|
if (!type || type.kind === "void")
|
|
710
713
|
return null;
|
|
711
714
|
return type;
|
|
@@ -1123,6 +1126,18 @@ export function lowerVarStatement(lowerer, stmt) {
|
|
|
1123
1126
|
const isConst = (list.flags & ts.NodeFlags.Const) !== 0;
|
|
1124
1127
|
const isLet = (list.flags & ts.NodeFlags.Let) !== 0 || (list.flags & ts.NodeFlags.BlockScoped) === 0;
|
|
1125
1128
|
return list.declarations.flatMap((decl) => {
|
|
1129
|
+
// The canonical ESM bridge to a compiled program module. Like a
|
|
1130
|
+
// top-level CommonJS require declaration, the binding is alias
|
|
1131
|
+
// plumbing while the dependency evaluates at this statement's
|
|
1132
|
+
// exact position through its run-once initializer.
|
|
1133
|
+
if (isConst && createRequireProgramModuleDecl(lowerer, decl.name, decl.initializer)) {
|
|
1134
|
+
if (!ts.isSourceFile(stmt.parent)) {
|
|
1135
|
+
lowerer.unsupported("SC1090", decl, "createRequire program-module bindings outside the module's top level (move the binding to the top of the file; side-effect-only requires may remain nested)");
|
|
1136
|
+
}
|
|
1137
|
+
const target = createRequireProgramModuleOf(lowerer, decl.initializer);
|
|
1138
|
+
const init = lowerer.requireInitStmt(target.spec, decl);
|
|
1139
|
+
return init ? [init] : [];
|
|
1140
|
+
}
|
|
1126
1141
|
// CommonJS require declarations (JS files): at the module's top
|
|
1127
1142
|
// level the BINDINGS are alias plumbing (no storage;
|
|
1128
1143
|
// resolveValueSymbol routes the reads), but the require itself is
|
|
@@ -3304,13 +3319,10 @@ export function lowerVarDecl(lowerer, decl, isLet) {
|
|
|
3304
3319
|
(ts.canHaveModifiers(s) && ts.getModifiers(s)?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) === true))) {
|
|
3305
3320
|
lowerer.unsupported("SC1090", decl.name, `initializer-less top-level declarations named '${decl.name.text}' in an import/export-free file (Node hosts the file as CommonJS, where the wrapper's own binding keeps its value — the declaration reads as the module object there, which has no lowering; rename the variable or give it an initializer)`);
|
|
3306
3321
|
}
|
|
3307
|
-
// `const
|
|
3308
|
-
//
|
|
3309
|
-
//
|
|
3310
|
-
|
|
3311
|
-
// never exists at runtime. collectGlobals skipped registering a
|
|
3312
|
-
// module global for it by the same test.
|
|
3313
|
-
if (lowerer.promisifiedExecFileDecl(decl.name, decl.initializer))
|
|
3322
|
+
// `const asyncFn = promisify(supportedBuiltin)`: the binding registers
|
|
3323
|
+
// a static callable projection; calls route to the target's promise
|
|
3324
|
+
// lowering and the declaration emits no runtime slot.
|
|
3325
|
+
if (lowerer.registerPromisifiedBuiltinDecl(decl.name, decl.initializer))
|
|
3314
3326
|
return null;
|
|
3315
3327
|
// `const inspect = require("util").inspect` — a named import in const
|
|
3316
3328
|
// clothing: builtinImportOf resolves uses through the module tables;
|
|
@@ -3342,7 +3354,16 @@ export function lowerVarDecl(lowerer, decl, isLet) {
|
|
|
3342
3354
|
return null;
|
|
3343
3355
|
// `const process = globalThis.process` — a stdlib-global snapshot:
|
|
3344
3356
|
// alias plumbing (see stdlibGlobalAliasDecl), no storage, no code.
|
|
3345
|
-
|
|
3357
|
+
const stableStdlibAlias = !isLet ||
|
|
3358
|
+
(ts.isVariableDeclarationList(decl.parent) &&
|
|
3359
|
+
(decl.parent.flags & ts.NodeFlags.Let) !== 0 &&
|
|
3360
|
+
ts.isIdentifier(decl.name) &&
|
|
3361
|
+
stdlibGlobalAliasNameOf(lowerer, decl.initializer) !== null &&
|
|
3362
|
+
(() => {
|
|
3363
|
+
const symbol = lowerer.checker.getSymbolAtLocation(decl.name);
|
|
3364
|
+
return symbol !== undefined && bindingNeverReassigned(lowerer, symbol, decl);
|
|
3365
|
+
})());
|
|
3366
|
+
if (stableStdlibAlias && stdlibGlobalAliasDecl(lowerer, decl.name, decl.initializer))
|
|
3346
3367
|
return null;
|
|
3347
3368
|
// `const encoder = new TextEncoder()` and a statically-labelled
|
|
3348
3369
|
// TextDecoder twin: the codec has no general value representation, but calls
|
|
@@ -3373,6 +3394,13 @@ export function lowerVarDecl(lowerer, decl, isLet) {
|
|
|
3373
3394
|
// globals by the same test; block-scoped aliases register here).
|
|
3374
3395
|
if (bindingGenericFnAliasInfoOf(lowerer, decl))
|
|
3375
3396
|
return null;
|
|
3397
|
+
// `const stored = overloadedDeclaration`: no runtime slot is needed;
|
|
3398
|
+
// calls project onto the declaration's implementation ABI and value
|
|
3399
|
+
// reads reuse its interned closure identity.
|
|
3400
|
+
if (!isLet && registerOverloadedCallableAlias(lowerer, decl))
|
|
3401
|
+
return null;
|
|
3402
|
+
if (!isLet && registerBuiltinCallableAlias(lowerer, decl.name, decl.initializer))
|
|
3403
|
+
return null;
|
|
3376
3404
|
// `const knownBy = (cmd) => ...` — an IMPLICIT-ANY function-value
|
|
3377
3405
|
// binding in npm-static JS (function-scope bindings register here, in
|
|
3378
3406
|
// source order before any use can lower; file-scope ones registered at
|
|
@@ -3566,6 +3594,8 @@ export function lowerVarDecl(lowerer, decl, isLet) {
|
|
|
3566
3594
|
// island members).
|
|
3567
3595
|
(lowerer.dynamic && init.type.kind === "dyn" && jsvalFlavoredType(lowerer.mapTypeOf(lowerer.typeOf(decl.name)) ?? DYN) ? DYN : null) ??
|
|
3568
3596
|
(bindingTainted ? null : lowerer.mapTypeOf(lowerer.typeOf(decl.name))) ??
|
|
3597
|
+
staticImportNamespaceType(lowerer, decl.initializer) ??
|
|
3598
|
+
(init.type.kind === "moduleNs" ? init.type : null) ??
|
|
3569
3599
|
(init.type.kind === "dyn" ? DYN : null);
|
|
3570
3600
|
if (lowerer.implicitParamTypes !== null &&
|
|
3571
3601
|
init.type.kind === "dyn" &&
|
|
@@ -4278,7 +4308,7 @@ function lowerCjsExportStatement(lowerer, cjs) {
|
|
|
4278
4308
|
if (discarded !== null)
|
|
4279
4309
|
lowerer.unsupported("SC1090", cjs.expr, discarded);
|
|
4280
4310
|
}
|
|
4281
|
-
const assignExport = (nameNode, value) => {
|
|
4311
|
+
const assignExport = (nameNode, value, root) => {
|
|
4282
4312
|
const symbol = lowerer.checker.getSymbolAtLocation(nameNode) ??
|
|
4283
4313
|
(ts.isIdentifier(nameNode) || ts.isPrivateIdentifier(nameNode)
|
|
4284
4314
|
? lowerer.cjsModuleExportSymbol(cjs.expr.getSourceFile(), nameNode.text)
|
|
@@ -4290,7 +4320,42 @@ function lowerCjsExportStatement(lowerer, cjs) {
|
|
|
4290
4320
|
lowerer.lowerExpr(value);
|
|
4291
4321
|
lowerer.badType(value, lowerer.typeOf(value));
|
|
4292
4322
|
}
|
|
4293
|
-
|
|
4323
|
+
const lowered = lowerer.lowerExprExpecting(value, g.type);
|
|
4324
|
+
if (root?.type.kind !== "dyn" || !ts.isIdentifier(nameNode)) {
|
|
4325
|
+
return { kind: "assign", localId: g.id, value: lowered, loc: locOf(value) };
|
|
4326
|
+
}
|
|
4327
|
+
// A factory whole export is represented by its checked-dynamic root.
|
|
4328
|
+
// A later `module.exports.name = value` mutates THAT same object in
|
|
4329
|
+
// Node; the separate export global exists only so named-import and
|
|
4330
|
+
// lexer-visible member paths have a static snapshot. Evaluate the
|
|
4331
|
+
// RHS once, perform the observable object write first (it may throw
|
|
4332
|
+
// if a factory returned a primitive), then publish the snapshot.
|
|
4333
|
+
const saved = lowerer.declareHiddenLocal("%cjsMember", g.type);
|
|
4334
|
+
const savedRef = () => ({ kind: "varRef", localId: saved.id, type: g.type, loc: locOf(value) });
|
|
4335
|
+
const dynValue = lowerer.coerceInto(value, savedRef(), DYN);
|
|
4336
|
+
return {
|
|
4337
|
+
kind: "block",
|
|
4338
|
+
body: [
|
|
4339
|
+
{ kind: "varDecl", localId: saved.id, init: lowered, loc: locOf(value) },
|
|
4340
|
+
{
|
|
4341
|
+
kind: "exprStmt",
|
|
4342
|
+
expr: {
|
|
4343
|
+
kind: "libCall",
|
|
4344
|
+
fn: "dyn.keySet",
|
|
4345
|
+
args: [
|
|
4346
|
+
{ kind: "varRef", localId: root.id, type: DYN, loc },
|
|
4347
|
+
{ kind: "strLit", value: nameNode.text, type: STRING, loc: locOf(nameNode) },
|
|
4348
|
+
dynValue,
|
|
4349
|
+
],
|
|
4350
|
+
type: VOID,
|
|
4351
|
+
loc,
|
|
4352
|
+
},
|
|
4353
|
+
loc,
|
|
4354
|
+
},
|
|
4355
|
+
{ kind: "assign", localId: g.id, value: savedRef(), loc: locOf(value) },
|
|
4356
|
+
],
|
|
4357
|
+
loc,
|
|
4358
|
+
};
|
|
4294
4359
|
};
|
|
4295
4360
|
if (cjs.kind === "member") {
|
|
4296
4361
|
if (!ts.isIdentifier(cjs.name)) {
|
|
@@ -4352,7 +4417,15 @@ function lowerCjsExportStatement(lowerer, cjs) {
|
|
|
4352
4417
|
return { kind: "block", body: [], loc };
|
|
4353
4418
|
}
|
|
4354
4419
|
}
|
|
4355
|
-
|
|
4420
|
+
const sf = cjs.expr.getSourceFile();
|
|
4421
|
+
let root;
|
|
4422
|
+
for (const stmt of sf.statements) {
|
|
4423
|
+
const whole = cjsExportAssignmentOf(stmt);
|
|
4424
|
+
if (whole?.kind !== "table" || cjsExportDiscardReason(stmt) !== null)
|
|
4425
|
+
continue;
|
|
4426
|
+
root = lowerer.globalsByDeclNode.get(whole.expr);
|
|
4427
|
+
}
|
|
4428
|
+
return assignExport(cjs.name, cjs.value, root);
|
|
4356
4429
|
}
|
|
4357
4430
|
let tableObj = cjs.obj;
|
|
4358
4431
|
let resolvedTarget = false;
|
|
@@ -4576,6 +4649,27 @@ export function lowerExprStatement(lowerer, expr) {
|
|
|
4576
4649
|
ts.isExpressionStatement(stmtNode) &&
|
|
4577
4650
|
ts.isSourceFile(stmtNode.parent) &&
|
|
4578
4651
|
isJsSourceFile(stmtNode.parent);
|
|
4652
|
+
// createRequire's side-effect program-module form uses the same inline
|
|
4653
|
+
// run-once initializer as a CommonJS require statement. The expression
|
|
4654
|
+
// has no represented namespace value in statement position.
|
|
4655
|
+
if (ts.isCallExpression(expr)) {
|
|
4656
|
+
const created = createRequireProgramModuleOf(lowerer, expr);
|
|
4657
|
+
if (created !== null) {
|
|
4658
|
+
return lowerer.requireInitStmt(created.spec, expr) ?? { kind: "block", body: [], loc: locOf(expr) };
|
|
4659
|
+
}
|
|
4660
|
+
// syncBuiltinESMExports() is the other compiler-only statement: the
|
|
4661
|
+
// call validates its zero-argument shape, then emits no code because
|
|
4662
|
+
// the static builtin surface is immutable.
|
|
4663
|
+
const bi = ts.isIdentifier(expr.expression)
|
|
4664
|
+
? lowerer.builtinImportOf(expr.expression)
|
|
4665
|
+
: ts.isPropertyAccessExpression(expr.expression)
|
|
4666
|
+
? lowerer.builtinMemberOf(expr.expression)
|
|
4667
|
+
: null;
|
|
4668
|
+
if (bi?.module === "module" && bi.member === "syncBuiltinESMExports") {
|
|
4669
|
+
lowerNodeModuleCall(lowerer, expr, bi, locOf(expr));
|
|
4670
|
+
return { kind: "block", body: [], loc: locOf(expr) };
|
|
4671
|
+
}
|
|
4672
|
+
}
|
|
4579
4673
|
if (requireSpecOf(expr) !== null &&
|
|
4580
4674
|
ts.isCallExpression(expr) &&
|
|
4581
4675
|
ts.isIdentifier(expr.expression) &&
|
|
@@ -4872,6 +4966,15 @@ export function lowerExprStatement(lowerer, expr) {
|
|
|
4872
4966
|
}
|
|
4873
4967
|
}
|
|
4874
4968
|
}
|
|
4969
|
+
if (!expr.left.questionDotToken && lowerer.stdlibGlobalMember(expr.left, "process") === "exitCode") {
|
|
4970
|
+
const loc = locOf(expr);
|
|
4971
|
+
const value = lowerer.lowerExprExpecting(expr.right, F64);
|
|
4972
|
+
return {
|
|
4973
|
+
kind: "exprStmt",
|
|
4974
|
+
expr: { kind: "libCall", fn: "process.setExitCode", args: [value], type: VOID, loc },
|
|
4975
|
+
loc,
|
|
4976
|
+
};
|
|
4977
|
+
}
|
|
4875
4978
|
// `r._read = fn` / `w._write = fn` (and the other underscore
|
|
4876
4979
|
// methods) on a runtime-stream-rooted receiver: Node's
|
|
4877
4980
|
// own-property shadow of the prototype method — the runtime
|
|
@@ -4969,12 +5072,12 @@ export function lowerExprStatement(lowerer, expr) {
|
|
|
4969
5072
|
// Desugar `x op= e` to `x = x op e` — reads x before e, like JS.
|
|
4970
5073
|
if (ts.isElementAccessExpression(expr.left)) {
|
|
4971
5074
|
// `this[kLimit] += v` — a declared symbol-keyed class field is
|
|
4972
|
-
// the dotted compound in element spelling
|
|
4973
|
-
//
|
|
5075
|
+
// the dotted compound in element spelling. Array and byte-view
|
|
5076
|
+
// elements use the sequenced indexed compound path.
|
|
4974
5077
|
if (symbolFieldInfo(lowerer, expr.left)) {
|
|
4975
5078
|
return lowerer.lowerFieldCompound(expr.left, compound, expr.right, locOf(expr));
|
|
4976
5079
|
}
|
|
4977
|
-
|
|
5080
|
+
return { kind: "exprStmt", expr: lowerElementCompound(lowerer, expr, compound), loc: locOf(expr) };
|
|
4978
5081
|
}
|
|
4979
5082
|
if (ts.isPropertyAccessExpression(expr.left)) {
|
|
4980
5083
|
// `N.x += v` — the namespace-qualified spelling of a module-
|