@scriptc/compiler 0.1.2 → 0.1.4
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 +258 -64
- package/dist/backend/c/async.d.ts +30 -0
- package/dist/backend/c/async.js +224 -0
- package/dist/backend/c/async.js.map +1 -1
- package/dist/backend/c/c-emitter.d.ts +13 -0
- package/dist/backend/c/c-emitter.js +28 -9
- 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 +445 -60
- package/dist/backend/c/exprs.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/types.d.ts +4 -0
- package/dist/backend/c/types.js +20 -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 +32 -11
- package/dist/backend/c/walkers.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 +2 -1
- package/dist/backend/link-plan.js +6 -1
- package/dist/backend/link-plan.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 +24 -13
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.js +54 -12
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/expr-bytes.d.ts +1 -1
- package/dist/backend/llvm/expr-bytes.js +8 -8
- 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-context.d.ts +18 -2
- package/dist/backend/llvm/expr-dispatch.js +1 -0
- package/dist/backend/llvm/expr-dispatch.js.map +1 -1
- package/dist/backend/llvm/expr-dynamic.js +9 -0
- package/dist/backend/llvm/expr-dynamic.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.d.ts +1 -1
- package/dist/backend/llvm/expr-primitives.js +38 -9
- 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-records.js +3 -3
- package/dist/backend/llvm/expr-records.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.js +2 -1
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
- package/dist/backend/llvm/expr-stream-callbacks.d.ts +6 -0
- package/dist/backend/llvm/expr-stream-callbacks.js +122 -0
- package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
- package/dist/backend/llvm/lib-dispatch.js +22 -0
- package/dist/backend/llvm/lib-dispatch.js.map +1 -1
- package/dist/backend/llvm/lib-filesystem.js +68 -10
- package/dist/backend/llvm/lib-filesystem.js.map +1 -1
- package/dist/backend/llvm/lib-network.js +18 -2
- package/dist/backend/llvm/lib-network.js.map +1 -1
- package/dist/backend/llvm/lib-process.js +206 -11
- package/dist/backend/llvm/lib-process.js.map +1 -1
- package/dist/backend/llvm/lib-shared.js +82 -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/llvm/shapes.js +10 -8
- package/dist/backend/llvm/shapes.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-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 +11 -6
- package/dist/backend/native-toolchain.js +30 -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.test.js +29 -10
- package/dist/backend/runtime-pack.test.js.map +1 -1
- package/dist/backend/targets.d.ts +9 -0
- package/dist/backend/targets.js +22 -0
- package/dist/backend/targets.js.map +1 -1
- package/dist/backend/targets.test.js +13 -1
- package/dist/backend/targets.test.js.map +1 -1
- package/dist/coverage/surface-manifest.js +9 -0
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/diagnostics/diagnostic.js +4 -4
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/executable/executable-cache.d.ts +3 -0
- package/dist/executable/executable-cache.js +4 -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/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 +0 -4
- package/dist/frontend/lowering/containers/bytes.js +112 -28
- package/dist/frontend/lowering/containers/bytes.js.map +1 -1
- package/dist/frontend/lowering/lower-assert.js +87 -12
- package/dist/frontend/lowering/lower-assert.js.map +1 -1
- package/dist/frontend/lowering/lower-builtins.d.ts +72 -44
- package/dist/frontend/lowering/lower-builtins.js +1323 -165
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.d.ts +37 -27
- package/dist/frontend/lowering/lower-calls.js +682 -132
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.js +39 -8
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.js +162 -8
- 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.js +238 -87
- 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 +8 -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 +165 -6
- 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 +192 -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 +1 -1
- package/dist/frontend/lowering/lower-server.js +130 -27
- package/dist/frontend/lowering/lower-server.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.d.ts +5 -4
- package/dist/frontend/lowering/lower-stmts.js +141 -21
- 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 +90 -13
- package/dist/frontend/lowering/lowerer.js +416 -76
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/surfaces.d.ts +31 -3
- package/dist/frontend/lowering/surfaces.js +173 -90
- 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 +83 -14
- package/dist/frontend/npm-static-declarations.js.map +1 -1
- package/dist/frontend/npm-static-declarations.test.js +33 -2
- package/dist/frontend/npm-static-declarations.test.js.map +1 -1
- 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 +80 -8
- 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 +110 -12
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/resolve.d.ts +28 -7
- package/dist/frontend/resolve.js +90 -26
- package/dist/frontend/resolve.js.map +1 -1
- package/dist/frontend/resolve.test.js +21 -1
- package/dist/frontend/resolve.test.js.map +1 -1
- package/dist/frontend/type-mapper.d.ts +5 -0
- package/dist/frontend/type-mapper.js +115 -33
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +30 -3
- 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 +155 -66
- package/dist/ir/ir.js +143 -6
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/ir.test.js +14 -1
- package/dist/ir/ir.test.js.map +1 -1
- 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 +242 -18
- package/dist/ir/validate.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/package.json +17 -17
- package/surface-manifest.json +163 -54
|
@@ -45,10 +45,11 @@ export declare function predeclareForwardCapture(lowerer: Lowerer, symbol: ts.Sy
|
|
|
45
45
|
/** The FUNCTION-DECLARATION twin of predeclareForwardCapture: JS hoists a
|
|
46
46
|
* nested `function f() {}` to scope entry — the binding is LIVE from the
|
|
47
47
|
* first statement, so a reference lexically above the declaration in the
|
|
48
|
-
* SAME function lowers the declaration eagerly at the reference (
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
48
|
+
* SAME function lowers the declaration eagerly at the reference (storage
|
|
49
|
+
* declaration and initializing assignment are pushed before the current
|
|
50
|
+
* statement's IR, registered in the list's scope frame) and the statement
|
|
51
|
+
* loop skips the source statement when it arrives
|
|
52
|
+
* (lowerer.hoistedFnDecls). Same-function only: the declaration's own
|
|
52
53
|
* lowering runs under the ctx that owns its statement list, and a
|
|
53
54
|
* cross-function early capture would need lowering under a DIFFERENT
|
|
54
55
|
* ctx than the one currently open — that shape keeps the honest fence. */
|
|
@@ -8,20 +8,20 @@ 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
26
|
import { abstractPropertyDeclOf, aliasTypeofNarrows, isMatchSliceType, lowerAbsenceProbe, lowerGroupsProjection, lowerOptionalNumber, matchResultNamedGroupsOf, runtimeOptionalTrueIds, symbolFieldInfo, withRuntimeOptionalNarrowed } from "./lower-exprs.js";
|
|
27
27
|
import { isSafeToRepeat } from "./expressions/evaluation-safety.js";
|
|
@@ -518,7 +518,7 @@ const TDZ_KINDS = new Set([
|
|
|
518
518
|
// shape is the const's own initializer capturing the const:
|
|
519
519
|
// `const server = http.createServer(h).listen(0, done)` with `done`
|
|
520
520
|
// reading `server` — a TDZ read until the assign completes, JS exactly.
|
|
521
|
-
"child", "childStream", "netServer", "netSocket", "dgramSocket", "testCtx",
|
|
521
|
+
"child", "childStream", "childWriter", "netServer", "netSocket", "dgramSocket", "testCtx",
|
|
522
522
|
"httpReq", "httpRes", "httpClientReq",
|
|
523
523
|
// The h2 handles — `const client = http2.connect(url, mustCall(() =>
|
|
524
524
|
// ...client...))` is the suite's canonical self-capturing const.
|
|
@@ -594,10 +594,11 @@ export function predeclareForwardCapture(lowerer, symbol) {
|
|
|
594
594
|
/** The FUNCTION-DECLARATION twin of predeclareForwardCapture: JS hoists a
|
|
595
595
|
* nested `function f() {}` to scope entry — the binding is LIVE from the
|
|
596
596
|
* first statement, so a reference lexically above the declaration in the
|
|
597
|
-
* SAME function lowers the declaration eagerly at the reference (
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
597
|
+
* SAME function lowers the declaration eagerly at the reference (storage
|
|
598
|
+
* declaration and initializing assignment are pushed before the current
|
|
599
|
+
* statement's IR, registered in the list's scope frame) and the statement
|
|
600
|
+
* loop skips the source statement when it arrives
|
|
601
|
+
* (lowerer.hoistedFnDecls). Same-function only: the declaration's own
|
|
601
602
|
* lowering runs under the ctx that owns its statement list, and a
|
|
602
603
|
* cross-function early capture would need lowering under a DIFFERENT
|
|
603
604
|
* ctx than the one currently open — that shape keeps the honest fence. */
|
|
@@ -705,6 +706,9 @@ function varBindingType(lowerer, nameNode) {
|
|
|
705
706
|
(uncheckedOverloadHandleCall(lowerer, nameNode.parent.initializer) ? JSVAL : null) ??
|
|
706
707
|
type;
|
|
707
708
|
}
|
|
709
|
+
if (!lowerer.dynamic && ts.isVariableDeclaration(nameNode.parent) && nameNode.parent.name === nameNode) {
|
|
710
|
+
type = staticImportNamespaceType(lowerer, nameNode.parent.initializer) ?? type;
|
|
711
|
+
}
|
|
708
712
|
if (!type || type.kind === "void")
|
|
709
713
|
return null;
|
|
710
714
|
return type;
|
|
@@ -1086,7 +1090,8 @@ export function lowerStmt(lowerer, stmt) {
|
|
|
1086
1090
|
return null;
|
|
1087
1091
|
if (ts.isFunctionDeclaration(stmt)) {
|
|
1088
1092
|
// Already lowered eagerly by the forward-hoisting machinery
|
|
1089
|
-
// (predeclareForwardFnDecl) —
|
|
1093
|
+
// (predeclareForwardFnDecl) — its declaration and assignment are in
|
|
1094
|
+
// the list's output.
|
|
1090
1095
|
if (lowerer.hoistedFnDecls.has(stmt))
|
|
1091
1096
|
return null;
|
|
1092
1097
|
return lowerer.lowerNestedFunctionDecl(stmt);
|
|
@@ -1121,6 +1126,18 @@ export function lowerVarStatement(lowerer, stmt) {
|
|
|
1121
1126
|
const isConst = (list.flags & ts.NodeFlags.Const) !== 0;
|
|
1122
1127
|
const isLet = (list.flags & ts.NodeFlags.Let) !== 0 || (list.flags & ts.NodeFlags.BlockScoped) === 0;
|
|
1123
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
|
+
}
|
|
1124
1141
|
// CommonJS require declarations (JS files): at the module's top
|
|
1125
1142
|
// level the BINDINGS are alias plumbing (no storage;
|
|
1126
1143
|
// resolveValueSymbol routes the reads), but the require itself is
|
|
@@ -3302,13 +3319,10 @@ export function lowerVarDecl(lowerer, decl, isLet) {
|
|
|
3302
3319
|
(ts.canHaveModifiers(s) && ts.getModifiers(s)?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) === true))) {
|
|
3303
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)`);
|
|
3304
3321
|
}
|
|
3305
|
-
// `const
|
|
3306
|
-
//
|
|
3307
|
-
//
|
|
3308
|
-
|
|
3309
|
-
// never exists at runtime. collectGlobals skipped registering a
|
|
3310
|
-
// module global for it by the same test.
|
|
3311
|
-
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))
|
|
3312
3326
|
return null;
|
|
3313
3327
|
// `const inspect = require("util").inspect` — a named import in const
|
|
3314
3328
|
// clothing: builtinImportOf resolves uses through the module tables;
|
|
@@ -3340,7 +3354,16 @@ export function lowerVarDecl(lowerer, decl, isLet) {
|
|
|
3340
3354
|
return null;
|
|
3341
3355
|
// `const process = globalThis.process` — a stdlib-global snapshot:
|
|
3342
3356
|
// alias plumbing (see stdlibGlobalAliasDecl), no storage, no code.
|
|
3343
|
-
|
|
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))
|
|
3344
3367
|
return null;
|
|
3345
3368
|
// `const encoder = new TextEncoder()` and a statically-labelled
|
|
3346
3369
|
// TextDecoder twin: the codec has no general value representation, but calls
|
|
@@ -3371,6 +3394,13 @@ export function lowerVarDecl(lowerer, decl, isLet) {
|
|
|
3371
3394
|
// globals by the same test; block-scoped aliases register here).
|
|
3372
3395
|
if (bindingGenericFnAliasInfoOf(lowerer, decl))
|
|
3373
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;
|
|
3374
3404
|
// `const knownBy = (cmd) => ...` — an IMPLICIT-ANY function-value
|
|
3375
3405
|
// binding in npm-static JS (function-scope bindings register here, in
|
|
3376
3406
|
// source order before any use can lower; file-scope ones registered at
|
|
@@ -3564,6 +3594,8 @@ export function lowerVarDecl(lowerer, decl, isLet) {
|
|
|
3564
3594
|
// island members).
|
|
3565
3595
|
(lowerer.dynamic && init.type.kind === "dyn" && jsvalFlavoredType(lowerer.mapTypeOf(lowerer.typeOf(decl.name)) ?? DYN) ? DYN : null) ??
|
|
3566
3596
|
(bindingTainted ? null : lowerer.mapTypeOf(lowerer.typeOf(decl.name))) ??
|
|
3597
|
+
staticImportNamespaceType(lowerer, decl.initializer) ??
|
|
3598
|
+
(init.type.kind === "moduleNs" ? init.type : null) ??
|
|
3567
3599
|
(init.type.kind === "dyn" ? DYN : null);
|
|
3568
3600
|
if (lowerer.implicitParamTypes !== null &&
|
|
3569
3601
|
init.type.kind === "dyn" &&
|
|
@@ -4276,7 +4308,7 @@ function lowerCjsExportStatement(lowerer, cjs) {
|
|
|
4276
4308
|
if (discarded !== null)
|
|
4277
4309
|
lowerer.unsupported("SC1090", cjs.expr, discarded);
|
|
4278
4310
|
}
|
|
4279
|
-
const assignExport = (nameNode, value) => {
|
|
4311
|
+
const assignExport = (nameNode, value, root) => {
|
|
4280
4312
|
const symbol = lowerer.checker.getSymbolAtLocation(nameNode) ??
|
|
4281
4313
|
(ts.isIdentifier(nameNode) || ts.isPrivateIdentifier(nameNode)
|
|
4282
4314
|
? lowerer.cjsModuleExportSymbol(cjs.expr.getSourceFile(), nameNode.text)
|
|
@@ -4288,7 +4320,42 @@ function lowerCjsExportStatement(lowerer, cjs) {
|
|
|
4288
4320
|
lowerer.lowerExpr(value);
|
|
4289
4321
|
lowerer.badType(value, lowerer.typeOf(value));
|
|
4290
4322
|
}
|
|
4291
|
-
|
|
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
|
+
};
|
|
4292
4359
|
};
|
|
4293
4360
|
if (cjs.kind === "member") {
|
|
4294
4361
|
if (!ts.isIdentifier(cjs.name)) {
|
|
@@ -4350,7 +4417,15 @@ function lowerCjsExportStatement(lowerer, cjs) {
|
|
|
4350
4417
|
return { kind: "block", body: [], loc };
|
|
4351
4418
|
}
|
|
4352
4419
|
}
|
|
4353
|
-
|
|
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);
|
|
4354
4429
|
}
|
|
4355
4430
|
let tableObj = cjs.obj;
|
|
4356
4431
|
let resolvedTarget = false;
|
|
@@ -4494,6 +4569,21 @@ export function lowerExprStatement(lowerer, expr) {
|
|
|
4494
4569
|
const stmtNode = expr.parent;
|
|
4495
4570
|
while (ts.isParenthesizedExpression(expr))
|
|
4496
4571
|
expr = expr.expression;
|
|
4572
|
+
// A discarded conditional has no value to merge: represent its lazy
|
|
4573
|
+
// branch selection directly as statement control flow. In particular,
|
|
4574
|
+
// both arms may be void calls (`flag ? emitA() : emitB()`), for which a
|
|
4575
|
+
// value-shaped void ternary has no IR representation. Preserve the same
|
|
4576
|
+
// narrowing environments as a source if statement, and lower only a
|
|
4577
|
+
// statically selected arm when the condition folded without effects.
|
|
4578
|
+
if (ts.isConditionalExpression(expr)) {
|
|
4579
|
+
const cond = lowerer.lowerCondition(expr.condition);
|
|
4580
|
+
if (cond.kind === "boolLit") {
|
|
4581
|
+
return lowerExprStatement(lowerer, cond.value ? expr.whenTrue : expr.whenFalse);
|
|
4582
|
+
}
|
|
4583
|
+
const then = lowerer.narrowingAliases(aliasTypeofNarrows(lowerer, expr.condition, true), () => withRuntimeOptionalNarrowed(lowerer, runtimeOptionalTrueIds(lowerer, expr.condition), () => [lowerExprStatement(lowerer, expr.whenTrue)]));
|
|
4584
|
+
const else_ = lowerer.narrowingAliases(aliasTypeofNarrows(lowerer, expr.condition, false), () => [lowerExprStatement(lowerer, expr.whenFalse)]);
|
|
4585
|
+
return { kind: "if", cond, then, else_, loc: locOf(expr) };
|
|
4586
|
+
}
|
|
4497
4587
|
// Assignment statements over the no-storage binding families:
|
|
4498
4588
|
// - `f1 = f2` where the RHS roots at an ambient-undefined name:
|
|
4499
4589
|
// Node evaluates the RHS first and dies on the root's
|
|
@@ -4559,6 +4649,27 @@ export function lowerExprStatement(lowerer, expr) {
|
|
|
4559
4649
|
ts.isExpressionStatement(stmtNode) &&
|
|
4560
4650
|
ts.isSourceFile(stmtNode.parent) &&
|
|
4561
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
|
+
}
|
|
4562
4673
|
if (requireSpecOf(expr) !== null &&
|
|
4563
4674
|
ts.isCallExpression(expr) &&
|
|
4564
4675
|
ts.isIdentifier(expr.expression) &&
|
|
@@ -4855,6 +4966,15 @@ export function lowerExprStatement(lowerer, expr) {
|
|
|
4855
4966
|
}
|
|
4856
4967
|
}
|
|
4857
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
|
+
}
|
|
4858
4978
|
// `r._read = fn` / `w._write = fn` (and the other underscore
|
|
4859
4979
|
// methods) on a runtime-stream-rooted receiver: Node's
|
|
4860
4980
|
// own-property shadow of the prototype method — the runtime
|