@scriptc/compiler 0.0.35 → 0.1.1
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 +14 -11
- package/ambient/scriptc-overrides.d.ts +0 -7
- package/ambient/scriptc.d.ts +1 -1
- package/dist/backend/build-cache.d.ts +44 -0
- package/dist/backend/build-cache.js +241 -0
- package/dist/backend/build-cache.js.map +1 -0
- package/dist/backend/{emission/emit-async.d.ts → c/async.d.ts} +21 -30
- package/dist/backend/{emission/emit-async.js → c/async.js} +270 -286
- package/dist/backend/c/async.js.map +1 -0
- package/dist/backend/{emission/emitter.d.ts → c/c-emitter.d.ts} +6 -23
- package/dist/backend/{emission/emitter.js → c/c-emitter.js} +53 -107
- package/dist/backend/c/c-emitter.js.map +1 -0
- package/dist/backend/c/exprs.d.ts +8 -0
- package/dist/backend/c/exprs.js +7937 -0
- package/dist/backend/c/exprs.js.map +1 -0
- package/dist/backend/{emission/emit-island.d.ts → c/island.d.ts} +5 -5
- package/dist/backend/{emission/emit-island.js → c/island.js} +24 -22
- package/dist/backend/c/island.js.map +1 -0
- package/dist/backend/{emission → c}/may-throw.d.ts +1 -1
- package/dist/backend/{emission → c}/may-throw.js +4 -1
- package/dist/backend/c/may-throw.js.map +1 -0
- package/dist/backend/{emission/emit-shapes.d.ts → c/shapes.d.ts} +19 -19
- package/dist/backend/{emission/emit-shapes.js → c/shapes.js} +78 -87
- package/dist/backend/c/shapes.js.map +1 -0
- package/dist/backend/{emission/emit-stmts.d.ts → c/stmts.d.ts} +12 -12
- package/dist/backend/{emission/emit-stmts.js → c/stmts.js} +395 -343
- package/dist/backend/c/stmts.js.map +1 -0
- package/dist/backend/{emission/emit-types.d.ts → c/types.d.ts} +1 -1
- package/dist/backend/{emission/emit-types.js → c/types.js} +42 -286
- package/dist/backend/c/types.js.map +1 -0
- package/dist/backend/c/types.test.js +25 -0
- package/dist/backend/c/types.test.js.map +1 -0
- package/dist/backend/{emission/emit-walkers.d.ts → c/walkers.d.ts} +19 -41
- package/dist/backend/{emission/emit-walkers.js → c/walkers.js} +242 -304
- package/dist/backend/c/walkers.js.map +1 -0
- package/dist/backend/external-c.d.ts +33 -0
- package/dist/backend/external-c.js +51 -0
- package/dist/backend/external-c.js.map +1 -0
- package/dist/backend/ffi-callbacks.d.ts +1 -1
- package/dist/backend/ffi-callbacks.js +4 -3
- package/dist/backend/ffi-callbacks.js.map +1 -1
- package/dist/backend/{library-identity.d.ts → library-identity-markers.d.ts} +0 -4
- package/dist/backend/{library-identity.js → library-identity-markers.js} +10 -9
- package/dist/backend/library-identity-markers.js.map +1 -0
- package/dist/backend/link-plan.d.ts +37 -0
- package/dist/backend/link-plan.js +26 -0
- package/dist/backend/link-plan.js.map +1 -0
- package/dist/backend/linker.d.ts +22 -0
- package/dist/backend/linker.js +236 -0
- package/dist/backend/linker.js.map +1 -0
- package/dist/backend/llvm/blocks.d.ts +4 -0
- package/dist/backend/llvm/blocks.js +29 -0
- package/dist/backend/llvm/blocks.js.map +1 -1
- package/dist/backend/llvm/classes.d.ts +2 -19
- package/dist/backend/llvm/classes.js +20 -52
- package/dist/backend/llvm/classes.js.map +1 -1
- package/dist/backend/llvm/common.d.ts +4 -0
- package/dist/backend/llvm/common.js +27 -0
- package/dist/backend/llvm/common.js.map +1 -0
- package/dist/backend/llvm/dyn.d.ts +3 -8
- package/dist/backend/llvm/dyn.js +159 -224
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.d.ts +4 -1
- package/dist/backend/llvm/emitter.js +548 -9988
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/expr-async.d.ts +4 -0
- package/dist/backend/llvm/expr-async.js +726 -0
- package/dist/backend/llvm/expr-async.js.map +1 -0
- package/dist/backend/llvm/expr-bytes.d.ts +13 -0
- package/dist/backend/llvm/expr-bytes.js +456 -0
- package/dist/backend/llvm/expr-bytes.js.map +1 -0
- package/dist/backend/llvm/expr-callbacks.d.ts +22 -0
- package/dist/backend/llvm/expr-callbacks.js +520 -0
- package/dist/backend/llvm/expr-callbacks.js.map +1 -0
- package/dist/backend/llvm/expr-calls.d.ts +2 -0
- package/dist/backend/llvm/expr-calls.js +618 -0
- package/dist/backend/llvm/expr-calls.js.map +1 -0
- package/dist/backend/llvm/expr-containers.d.ts +25 -0
- package/dist/backend/llvm/expr-containers.js +637 -0
- package/dist/backend/llvm/expr-containers.js.map +1 -0
- package/dist/backend/llvm/expr-context.d.ts +255 -0
- package/dist/backend/llvm/expr-context.js +2 -0
- package/dist/backend/llvm/expr-context.js.map +1 -0
- package/dist/backend/llvm/expr-control.d.ts +2 -0
- package/dist/backend/llvm/expr-control.js +473 -0
- package/dist/backend/llvm/expr-control.js.map +1 -0
- package/dist/backend/llvm/expr-dispatch.d.ts +4 -0
- package/dist/backend/llvm/expr-dispatch.js +153 -0
- package/dist/backend/llvm/expr-dispatch.js.map +1 -0
- package/dist/backend/llvm/expr-dynamic.d.ts +2 -0
- package/dist/backend/llvm/expr-dynamic.js +810 -0
- package/dist/backend/llvm/expr-dynamic.js.map +1 -0
- package/dist/backend/llvm/expr-island.d.ts +15 -0
- package/dist/backend/llvm/expr-island.js +690 -0
- package/dist/backend/llvm/expr-island.js.map +1 -0
- package/dist/backend/llvm/expr-primitives.d.ts +6 -0
- package/dist/backend/llvm/expr-primitives.js +642 -0
- package/dist/backend/llvm/expr-primitives.js.map +1 -0
- package/dist/backend/llvm/expr-records.d.ts +9 -0
- package/dist/backend/llvm/expr-records.js +299 -0
- package/dist/backend/llvm/expr-records.js.map +1 -0
- package/dist/backend/llvm/expr-stream-bridges.d.ts +13 -0
- package/dist/backend/llvm/expr-stream-bridges.js +420 -0
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -0
- package/dist/backend/llvm/expr-stream-callbacks.d.ts +12 -0
- package/dist/backend/llvm/expr-stream-callbacks.js +360 -0
- package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -0
- package/dist/backend/llvm/lib-dispatch.d.ts +5 -0
- package/dist/backend/llvm/lib-dispatch.js +267 -0
- package/dist/backend/llvm/lib-dispatch.js.map +1 -0
- package/dist/backend/llvm/lib-filesystem.d.ts +6 -0
- package/dist/backend/llvm/lib-filesystem.js +594 -0
- package/dist/backend/llvm/lib-filesystem.js.map +1 -0
- package/dist/backend/llvm/lib-network.d.ts +2 -0
- package/dist/backend/llvm/lib-network.js +429 -0
- package/dist/backend/llvm/lib-network.js.map +1 -0
- package/dist/backend/llvm/lib-process.d.ts +5 -0
- package/dist/backend/llvm/lib-process.js +585 -0
- package/dist/backend/llvm/lib-process.js.map +1 -0
- package/dist/backend/llvm/lib-shared.d.ts +6 -0
- package/dist/backend/llvm/lib-shared.js +687 -0
- package/dist/backend/llvm/lib-shared.js.map +1 -0
- package/dist/backend/llvm/lib-stream.d.ts +2 -0
- package/dist/backend/llvm/lib-stream.js +470 -0
- package/dist/backend/llvm/lib-stream.js.map +1 -0
- package/dist/backend/llvm/shapes.d.ts +12 -2
- package/dist/backend/llvm/shapes.js +66 -307
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/backend/llvm/shapes.test.js +52 -0
- package/dist/backend/llvm/shapes.test.js.map +1 -0
- package/dist/backend/llvm/unsupported.d.ts +1 -1
- package/dist/backend/llvm/walkers.d.ts +2 -3
- package/dist/backend/llvm/walkers.js +195 -222
- package/dist/backend/llvm/walkers.js.map +1 -1
- package/dist/backend/native-codegen.d.ts +45 -0
- package/dist/backend/native-codegen.js +275 -0
- package/dist/backend/native-codegen.js.map +1 -0
- package/dist/backend/native-codegen.test.js +226 -0
- package/dist/backend/native-codegen.test.js.map +1 -0
- package/dist/backend/native-link-info.d.ts +96 -0
- package/dist/backend/native-link-info.js +243 -0
- package/dist/backend/native-link-info.js.map +1 -0
- package/dist/backend/native-link-info.test.d.ts +1 -0
- package/dist/backend/native-link-info.test.js +134 -0
- package/dist/backend/native-link-info.test.js.map +1 -0
- package/dist/backend/{cc.d.ts → native-toolchain.d.ts} +54 -34
- package/dist/backend/{cc.js → native-toolchain.js} +231 -810
- package/dist/backend/native-toolchain.js.map +1 -0
- package/dist/backend/native-toolchain.test.d.ts +1 -0
- package/dist/backend/{cc-cache.test.js → native-toolchain.test.js} +219 -7
- package/dist/backend/native-toolchain.test.js.map +1 -0
- package/dist/backend/object-localize.js +1 -1
- package/dist/backend/runtime-abi.d.ts +10 -0
- package/dist/backend/runtime-abi.js +11 -0
- package/dist/backend/runtime-abi.js.map +1 -0
- package/dist/backend/runtime-pack-targets.test.d.ts +1 -0
- package/dist/backend/runtime-pack-targets.test.js +54 -0
- package/dist/backend/runtime-pack-targets.test.js.map +1 -0
- package/dist/backend/runtime-pack.d.ts +112 -0
- package/dist/backend/runtime-pack.js +305 -0
- package/dist/backend/runtime-pack.js.map +1 -0
- package/dist/backend/runtime-pack.test.d.ts +1 -0
- package/dist/backend/runtime-pack.test.js +473 -0
- package/dist/backend/runtime-pack.test.js.map +1 -0
- package/dist/backend/targets.d.ts +76 -0
- package/dist/backend/targets.js +262 -0
- package/dist/backend/targets.js.map +1 -0
- package/dist/backend/targets.test.d.ts +1 -0
- package/dist/backend/targets.test.js +41 -0
- package/dist/backend/targets.test.js.map +1 -0
- package/dist/backend/vendor-archives.d.ts +41 -0
- package/dist/backend/vendor-archives.js +462 -0
- package/dist/backend/vendor-archives.js.map +1 -0
- package/dist/compat/fetch-profile.d.ts +0 -1
- package/dist/compat/fetch-profile.js +0 -1
- package/dist/compat/fetch-profile.js.map +1 -1
- package/dist/coverage/report.js +3 -3
- package/dist/coverage/report.js.map +1 -1
- package/dist/coverage/surface-manifest.js +35 -33
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/diagnostics/diagnostic.d.ts +11 -12
- package/dist/diagnostics/diagnostic.js +19 -17
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/diagnostics/render.d.ts +1 -1
- package/dist/diagnostics/render.js +1 -1
- package/dist/diagnostics/render.js.map +1 -1
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +9 -0
- package/dist/errors.js.map +1 -0
- package/dist/executable/{early-cache.d.ts → executable-cache.d.ts} +2 -2
- package/dist/executable/{early-cache.js → executable-cache.js} +36 -98
- package/dist/executable/executable-cache.js.map +1 -0
- package/dist/executable/executable-cache.test.d.ts +1 -0
- package/dist/executable/{early-cache.test.js → executable-cache.test.js} +3 -3
- package/dist/executable/executable-cache.test.js.map +1 -0
- package/dist/ffi/{profile.js → ffi-manifest.js} +1 -1
- package/dist/ffi/ffi-manifest.js.map +1 -0
- package/dist/frontend/builtin-modules.d.ts +21 -0
- package/dist/frontend/builtin-modules.js +82 -0
- package/dist/frontend/builtin-modules.js.map +1 -0
- package/dist/frontend/cjs-lexer.d.ts +7 -0
- package/dist/frontend/cjs-lexer.js +15 -17
- package/dist/frontend/cjs-lexer.js.map +1 -1
- package/dist/frontend/dts-paths.d.ts +26 -0
- package/dist/frontend/dts-paths.js +41 -0
- package/dist/frontend/dts-paths.js.map +1 -0
- package/dist/frontend/input-tracker.d.ts +0 -2
- package/dist/frontend/input-tracker.js +1 -4
- package/dist/frontend/input-tracker.js.map +1 -1
- package/dist/frontend/lib-contract.d.ts +1 -5
- package/dist/frontend/lib-contract.js +1 -1
- package/dist/frontend/lib-contract.js.map +1 -1
- package/dist/frontend/lib-exports.d.ts +1 -1
- package/dist/frontend/lowering/array-values.d.ts +8 -0
- package/dist/frontend/lowering/array-values.js +60 -0
- package/dist/frontend/lowering/array-values.js.map +1 -0
- package/dist/frontend/lowering/call-position.d.ts +4 -0
- package/dist/frontend/lowering/call-position.js +7 -0
- package/dist/frontend/lowering/call-position.js.map +1 -0
- package/dist/frontend/lowering/callback-arg.d.ts +20 -0
- package/dist/frontend/lowering/callback-arg.js +44 -0
- package/dist/frontend/lowering/callback-arg.js.map +1 -0
- package/dist/frontend/lowering/lib-boundary.d.ts +1 -1
- package/dist/frontend/lowering/lib-boundary.js +34 -34
- package/dist/frontend/lowering/lib-boundary.js.map +1 -1
- package/dist/frontend/lowering/lower-array-sort.d.ts +22 -0
- package/dist/frontend/lowering/lower-array-sort.js +619 -0
- package/dist/frontend/lowering/lower-array-sort.js.map +1 -0
- package/dist/frontend/lowering/lower-assert.d.ts +3 -3
- package/dist/frontend/lowering/lower-assert.js +214 -241
- package/dist/frontend/lowering/lower-assert.js.map +1 -1
- package/dist/frontend/lowering/lower-builtins.d.ts +74 -146
- package/dist/frontend/lowering/lower-builtins.js +1285 -1233
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.d.ts +59 -192
- package/dist/frontend/lowering/lower-calls.js +1644 -1506
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.d.ts +62 -125
- package/dist/frontend/lowering/lower-classes.js +832 -866
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-comptime.d.ts +5 -12
- package/dist/frontend/lowering/lower-comptime.js +32 -31
- package/dist/frontend/lowering/lower-comptime.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.d.ts +35 -135
- package/dist/frontend/lowering/lower-containers.js +1984 -2227
- package/dist/frontend/lowering/lower-containers.js.map +1 -1
- package/dist/frontend/lowering/lower-dgram.d.ts +3 -7
- package/dist/frontend/lowering/lower-dgram.js +97 -111
- package/dist/frontend/lowering/lower-dgram.js.map +1 -1
- package/dist/frontend/lowering/lower-enums.d.ts +4 -4
- package/dist/frontend/lowering/lower-enums.js +30 -30
- package/dist/frontend/lowering/lower-enums.js.map +1 -1
- package/dist/frontend/lowering/{lower-emitter.d.ts → lower-event-emitter.d.ts} +7 -18
- package/dist/frontend/lowering/{lower-emitter.js → lower-event-emitter.js} +172 -174
- package/dist/frontend/lowering/lower-event-emitter.js.map +1 -0
- package/dist/frontend/lowering/lower-expando.d.ts +5 -5
- package/dist/frontend/lowering/lower-expando.js +40 -40
- package/dist/frontend/lowering/lower-expando.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.d.ts +60 -264
- package/dist/frontend/lowering/lower-exprs.js +2361 -1765
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-generators.d.ts +6 -6
- package/dist/frontend/lowering/lower-generators.js +73 -72
- package/dist/frontend/lowering/lower-generators.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.d.ts +5 -17
- package/dist/frontend/lowering/lower-inspect.js +273 -261
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-island.d.ts +39 -49
- package/dist/frontend/lowering/lower-island.js +447 -513
- package/dist/frontend/lowering/lower-island.js.map +1 -1
- package/dist/frontend/lowering/lower-mixins.d.ts +7 -10
- package/dist/frontend/lowering/lower-mixins.js +85 -85
- package/dist/frontend/lowering/lower-mixins.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.d.ts +12 -18
- package/dist/frontend/lowering/lower-modules.js +284 -283
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-namespaces.d.ts +23 -49
- package/dist/frontend/lowering/lower-namespaces.js +123 -115
- package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
- package/dist/frontend/lowering/lower-server.d.ts +18 -25
- package/dist/frontend/lowering/lower-server.js +909 -899
- package/dist/frontend/lowering/lower-server.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.d.ts +30 -149
- package/dist/frontend/lowering/lower-stmts.js +1463 -1285
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lower-stream.d.ts +12 -12
- package/dist/frontend/lowering/lower-stream.js +300 -301
- package/dist/frontend/lowering/lower-stream.js.map +1 -1
- package/dist/frontend/lowering/lower-test.d.ts +5 -5
- package/dist/frontend/lowering/lower-test.js +82 -82
- package/dist/frontend/lowering/lower-test.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +134 -22
- package/dist/frontend/lowering/lowerer.js +1277 -126
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/pairs-snapshot.d.ts +11 -0
- package/dist/frontend/lowering/pairs-snapshot.js +85 -0
- package/dist/frontend/lowering/pairs-snapshot.js.map +1 -0
- package/dist/frontend/lowering/static-this.d.ts +6 -0
- package/dist/frontend/lowering/static-this.js +24 -0
- package/dist/frontend/lowering/static-this.js.map +1 -0
- package/dist/frontend/lowering/surfaces.d.ts +24 -35
- package/dist/frontend/lowering/surfaces.js +78 -66
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/npm-static-rewrite.js +6 -28
- package/dist/frontend/npm-static-rewrite.js.map +1 -1
- package/dist/frontend/npm-static.d.ts +0 -10
- package/dist/frontend/npm-static.js +4 -7
- package/dist/frontend/npm-static.js.map +1 -1
- package/dist/frontend/npm.d.ts +0 -24
- package/dist/frontend/npm.js +11 -85
- package/dist/frontend/npm.js.map +1 -1
- package/dist/frontend/program.d.ts +3 -1
- package/dist/frontend/program.js +9 -4
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/provenance-registry.d.ts +0 -2
- package/dist/frontend/provenance-registry.js +0 -10
- package/dist/frontend/provenance-registry.js.map +1 -1
- package/dist/frontend/provenance.js +4 -7
- package/dist/frontend/provenance.js.map +1 -1
- package/dist/frontend/resolve.d.ts +7 -2
- package/dist/frontend/resolve.js +12 -17
- package/dist/frontend/resolve.js.map +1 -1
- package/dist/frontend/resolve.test.d.ts +1 -0
- package/dist/frontend/resolve.test.js +29 -0
- package/dist/frontend/resolve.test.js.map +1 -0
- package/dist/frontend/ts7/adapter.d.ts +2 -2
- package/dist/frontend/ts7/adapter.js +1 -1
- package/dist/frontend/ts7/adapter.js.map +1 -1
- package/dist/frontend/ts7/checker.js +2 -36
- package/dist/frontend/ts7/checker.js.map +1 -1
- package/dist/frontend/ts7/enums.js +2 -1
- package/dist/frontend/ts7/enums.js.map +1 -1
- package/dist/frontend/ts7/{program.js → program-adapter.js} +7 -6
- package/dist/frontend/ts7/program-adapter.js.map +1 -0
- package/dist/frontend/ts7/world-check.d.ts +1 -3
- package/dist/frontend/ts7/world-check.js +3 -1
- package/dist/frontend/ts7/world-check.js.map +1 -1
- package/dist/frontend/tsc-codes.d.ts +8 -0
- package/dist/frontend/tsc-codes.js +109 -0
- package/dist/frontend/tsc-codes.js.map +1 -0
- package/dist/frontend/{types.d.ts → type-mapper.d.ts} +2 -25
- package/dist/frontend/{types.js → type-mapper.js} +12 -11
- package/dist/frontend/type-mapper.js.map +1 -0
- package/dist/frontend/workspace-registry.d.ts +26 -0
- package/dist/frontend/workspace-registry.js +71 -0
- package/dist/frontend/workspace-registry.js.map +1 -0
- package/dist/index.d.ts +113 -31
- package/dist/index.js +536 -128
- package/dist/index.js.map +1 -1
- package/dist/ir/analysis.d.ts +37 -0
- package/dist/ir/analysis.js +118 -0
- package/dist/ir/analysis.js.map +1 -0
- package/dist/ir/analysis.test.d.ts +1 -0
- package/dist/ir/analysis.test.js +21 -0
- package/dist/ir/analysis.test.js.map +1 -0
- package/dist/ir/build.d.ts +9 -0
- package/dist/ir/build.js +33 -0
- package/dist/ir/build.js.map +1 -0
- package/dist/ir/integer-loops.d.ts +1 -1
- package/dist/ir/{nodes.d.ts → ir.d.ts} +119 -37
- package/dist/ir/{nodes.js → ir.js} +170 -166
- package/dist/ir/ir.js.map +1 -0
- package/dist/ir/ir.test.d.ts +1 -0
- package/dist/ir/ir.test.js +17 -0
- package/dist/ir/ir.test.js.map +1 -0
- package/dist/ir/serialize.d.ts +2 -2
- package/dist/ir/serialize.js +3 -2
- package/dist/ir/serialize.js.map +1 -1
- package/dist/ir/validate.d.ts +1 -1
- package/dist/ir/validate.js +93 -41
- package/dist/ir/validate.js.map +1 -1
- package/dist/library/cache-primitives.d.ts +24 -0
- package/dist/library/cache-primitives.js +83 -0
- package/dist/library/cache-primitives.js.map +1 -0
- package/dist/library/cache-reset.test.d.ts +1 -0
- package/dist/library/cache-reset.test.js +47 -0
- package/dist/library/cache-reset.test.js.map +1 -0
- package/dist/library/{implementation-identity.js → compiler-self-identity.js} +1 -1
- package/dist/library/compiler-self-identity.js.map +1 -0
- package/dist/library/fence-eval.d.ts +3 -1
- package/dist/library/fence-eval.js +8 -2
- package/dist/library/fence-eval.js.map +1 -1
- package/dist/library/int-infer.d.ts +1 -36
- package/dist/library/int-infer.js +29 -18
- package/dist/library/int-infer.js.map +1 -1
- package/dist/library/int-infer.test.js +4 -4
- package/dist/library/{early-cache.d.ts → library-cache.d.ts} +1 -1
- package/dist/library/{early-cache.js → library-cache.js} +34 -89
- package/dist/library/library-cache.js.map +1 -0
- package/dist/library/library-cache.test.d.ts +1 -0
- package/dist/library/{early-cache.test.js → library-cache.test.js} +7 -7
- package/dist/library/library-cache.test.js.map +1 -0
- package/dist/library/{profile.d.ts → library-profile.d.ts} +4 -7
- package/dist/library/{profile.js → library-profile.js} +18 -11
- package/dist/library/library-profile.js.map +1 -0
- package/dist/library/semantic-source.js +2 -1
- package/dist/library/semantic-source.js.map +1 -1
- package/dist/library/sidecar.d.ts +5 -2
- package/dist/library/sidecar.js +11 -5
- package/dist/library/sidecar.js.map +1 -1
- package/dist/startup-cache.d.ts +11 -3
- package/dist/startup-cache.js +17 -2
- package/dist/startup-cache.js.map +1 -1
- package/package.json +19 -2
- package/surface-manifest.json +5 -5
- package/dist/backend/cc-cache.test.js.map +0 -1
- package/dist/backend/cc.js.map +0 -1
- package/dist/backend/emission/emit-async.js.map +0 -1
- package/dist/backend/emission/emit-exprs.d.ts +0 -13
- package/dist/backend/emission/emit-exprs.js +0 -7407
- package/dist/backend/emission/emit-exprs.js.map +0 -1
- package/dist/backend/emission/emit-island.js.map +0 -1
- package/dist/backend/emission/emit-shapes.js.map +0 -1
- package/dist/backend/emission/emit-stmts.js.map +0 -1
- package/dist/backend/emission/emit-types.js.map +0 -1
- package/dist/backend/emission/emit-walkers.js.map +0 -1
- package/dist/backend/emission/emitter.js.map +0 -1
- package/dist/backend/emission/may-throw.js.map +0 -1
- package/dist/backend/library-identity.js.map +0 -1
- package/dist/executable/early-cache.js.map +0 -1
- package/dist/executable/early-cache.test.js.map +0 -1
- package/dist/ffi/profile.js.map +0 -1
- package/dist/frontend/lowering/lower-emitter.js.map +0 -1
- package/dist/frontend/shared.d.ts +0 -82
- package/dist/frontend/shared.js +0 -308
- package/dist/frontend/shared.js.map +0 -1
- package/dist/frontend/ts7/program.js.map +0 -1
- package/dist/frontend/types.js.map +0 -1
- package/dist/ir/nodes.js.map +0 -1
- package/dist/library/early-cache.js.map +0 -1
- package/dist/library/early-cache.test.js.map +0 -1
- package/dist/library/implementation-identity.js.map +0 -1
- package/dist/library/profile.js.map +0 -1
- /package/dist/backend/{cc-cache.test.d.ts → c/types.test.d.ts} +0 -0
- /package/dist/{executable/early-cache.test.d.ts → backend/llvm/shapes.test.d.ts} +0 -0
- /package/dist/{library/early-cache.test.d.ts → backend/native-codegen.test.d.ts} +0 -0
- /package/dist/ffi/{profile.d.ts → ffi-manifest.d.ts} +0 -0
- /package/dist/frontend/ts7/{program.d.ts → program-adapter.d.ts} +0 -0
- /package/dist/library/{implementation-identity.d.ts → compiler-self-identity.d.ts} +0 -0
|
@@ -6,10 +6,11 @@ import * as ts from "../ts7/adapter.js";
|
|
|
6
6
|
import { dirname as dirnamePath, resolve as resolvePath } from "node:path";
|
|
7
7
|
import { NpmGraphBuilder, packageNameOfPath, probeNodeImportRefusal, probeNodeRequireRefusal } from "../npm.js";
|
|
8
8
|
import { isNpmStaticPackage } from "../npm-static.js";
|
|
9
|
-
import { isJsSourceFileName
|
|
9
|
+
import { isJsSourceFileName } from "../tsc-codes.js";
|
|
10
|
+
import { isRelativeSpecifier } from "../workspace-registry.js";
|
|
10
11
|
import { canonicalBuiltinModule, cjsExportAssignmentOf, cjsExportDiscardReason, isCjsJsFile, isJsSourceFile, isRequireStatement, locOf, makeCycleAdmission, orderedImportsOf, resolveImport, resolveNpmImport } from "../program.js";
|
|
11
12
|
import { invalidJsonModuleDiag, npmEmbedFailedDiag, requiresDynamicImportDiag } from "../../diagnostics/diagnostic.js";
|
|
12
|
-
import { BOOL, DYN, JSVAL, RUNTIME_ERROR_CLASSES, STRING, VOID, arrayOf, canConvertToDyn, isUnitType } from "../../ir/
|
|
13
|
+
import { BOOL, DYN, JSVAL, RUNTIME_ERROR_CLASSES, STRING, VOID, arrayOf, canConvertToDyn, isUnitType } from "../../ir/ir.js";
|
|
13
14
|
import { ENTRY_NAME, PoisonError, boundIdentifiersOf, dynFallbackType, dynUndefinedExpr, importCallHandleType, newFnCtx, uncheckedOverloadHandleCall } from "./lowerer.js";
|
|
14
15
|
import { builtinMemberRequireDecl, builtinNamespaceDestructureModuleOf, createRequireBindingDecl, createRequireNamespaceDecl, createRequireSpecOf, isPromisifyCall, textCodecBindingDecl } from "./lower-builtins.js";
|
|
15
16
|
import { bindingContextualGenericFnNodeOf, bindingGenericFnAliasInfoOf, bindingGenericFnInfoOf, bindingGenericFnNodeOf, deadUnmappableBinding, implicitLocalFnInfoOf, implicitLocalFnNodeOf, nullishGenericBindingUnitOf } from "./lower-calls.js";
|
|
@@ -18,7 +19,7 @@ import { streamClassAliasDecl } from "./lower-stream.js";
|
|
|
18
19
|
import { stdlibGlobalAliasDecl } from "./surfaces.js";
|
|
19
20
|
import { collectNamespaceStmt, nsPathPrefix, trapDeclRootOf } from "./lower-namespaces.js";
|
|
20
21
|
import { collectExpandoMembers } from "./lower-expando.js";
|
|
21
|
-
import { isUnitOnlyTsType, unitOnlyUnion } from "../
|
|
22
|
+
import { isUnitOnlyTsType, unitOnlyUnion } from "../type-mapper.js";
|
|
22
23
|
import { decoratorNodesOf, genericIfaceBindingKeepsClass, guaranteedDecorationThrow } from "./lower-classes.js";
|
|
23
24
|
import { isMixinFnBinding, mixinResultBindingClassOf } from "./lower-mixins.js";
|
|
24
25
|
/** Splits each file into function/class declarations and the top-level
|
|
@@ -26,8 +27,8 @@ import { isMixinFnBinding, mixinResultBindingClassOf } from "./lower-mixins.js";
|
|
|
26
27
|
* postorder, entry last), computed by preflight. Single-file programs
|
|
27
28
|
* (tests, coverage on broken files) may arrive with an empty order — fall
|
|
28
29
|
* back to the entry alone. */
|
|
29
|
-
export function splitFiles(
|
|
30
|
-
const files =
|
|
30
|
+
export function splitFiles(lowerer) {
|
|
31
|
+
const files = lowerer.moduleOrder.length > 0 ? lowerer.moduleOrder : [lowerer.entry];
|
|
31
32
|
return files.map((sf) => {
|
|
32
33
|
const fp = { sf, fnDecls: [], classDecls: [], topStmts: [] };
|
|
33
34
|
for (const stmt of sf.statements) {
|
|
@@ -40,7 +41,7 @@ export function splitFiles(L) {
|
|
|
40
41
|
// classes hoist under namespace-qualified names, statements join
|
|
41
42
|
// the init body in source order) — lower-namespaces.ts.
|
|
42
43
|
else if (ts.isModuleDeclaration(stmt))
|
|
43
|
-
collectNamespaceStmt(
|
|
44
|
+
collectNamespaceStmt(lowerer, stmt, fp);
|
|
44
45
|
else if (ts.isInterfaceDeclaration(stmt) ||
|
|
45
46
|
ts.isTypeAliasDeclaration(stmt) ||
|
|
46
47
|
ts.isImportDeclaration(stmt) ||
|
|
@@ -61,7 +62,7 @@ export function splitFiles(L) {
|
|
|
61
62
|
* that is not JSON and not CommonJS-flavored (a CJS namespace is built
|
|
62
63
|
* from module.exports through Node's lexer — a different surface with no
|
|
63
64
|
* static story here). Null for everything else. */
|
|
64
|
-
|
|
65
|
+
function dynamicImportProgramTargetOf(program, sf, spec) {
|
|
65
66
|
if (!isRelativeSpecifier(spec) && !spec.startsWith("/"))
|
|
66
67
|
return null;
|
|
67
68
|
const dep = resolveImport(program, sf, spec);
|
|
@@ -164,40 +165,40 @@ export function appendDynamicImportModules(program, order, onCycle) {
|
|
|
164
165
|
* cross-module references fall out for free. Runs in both passes —
|
|
165
166
|
* signatures are cheap and calls resolve against them; only BODY lowering
|
|
166
167
|
* is reachability-gated. */
|
|
167
|
-
export function collectProgram(
|
|
168
|
-
|
|
168
|
+
export function collectProgram(lowerer, parts) {
|
|
169
|
+
lowerer.collecting = true;
|
|
169
170
|
try {
|
|
170
171
|
for (const fp of parts)
|
|
171
172
|
for (const decl of fp.classDecls)
|
|
172
|
-
|
|
173
|
+
lowerer.collectClassShape(decl);
|
|
173
174
|
for (const fp of parts)
|
|
174
175
|
for (const decl of fp.fnDecls)
|
|
175
|
-
|
|
176
|
+
lowerer.collectSignature(decl);
|
|
176
177
|
}
|
|
177
178
|
finally {
|
|
178
|
-
|
|
179
|
+
lowerer.collecting = false;
|
|
179
180
|
}
|
|
180
181
|
// Globals are top-level (always reachable), so their collection reports
|
|
181
182
|
// eagerly — including deferred-class flushes their types trigger. The
|
|
182
183
|
// coverage remainder still needs the registrations but the emit pass
|
|
183
184
|
// already reported the diagnostics; discard the duplicates.
|
|
184
|
-
if (
|
|
185
|
-
|
|
185
|
+
if (lowerer.remainder) {
|
|
186
|
+
lowerer.diagSink = [];
|
|
186
187
|
try {
|
|
187
188
|
for (const fp of parts)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
lowerer.collectGlobals(fp.sf, fp.topStmts);
|
|
190
|
+
lowerer.collectNpmImports(parts);
|
|
191
|
+
lowerer.collectJsonImports(parts);
|
|
191
192
|
}
|
|
192
193
|
finally {
|
|
193
|
-
|
|
194
|
+
lowerer.diagSink = null;
|
|
194
195
|
}
|
|
195
196
|
}
|
|
196
197
|
else {
|
|
197
198
|
for (const fp of parts)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
lowerer.collectGlobals(fp.sf, fp.topStmts);
|
|
200
|
+
lowerer.collectNpmImports(parts);
|
|
201
|
+
lowerer.collectJsonImports(parts);
|
|
201
202
|
}
|
|
202
203
|
}
|
|
203
204
|
/** The npm-import chokepoint, run once per pass during collection (so
|
|
@@ -213,8 +214,8 @@ export function collectProgram(L, parts) {
|
|
|
213
214
|
* builds here too; its failures are ordinary diagnostics at the import
|
|
214
215
|
* site. Type-only imports are free either way: the .d.ts is a type
|
|
215
216
|
* surface, not code. */
|
|
216
|
-
export function collectNpmImports(
|
|
217
|
-
const builder =
|
|
217
|
+
export function collectNpmImports(lowerer, parts) {
|
|
218
|
+
const builder = lowerer.dynamic ? new NpmGraphBuilder() : null;
|
|
218
219
|
for (const fp of parts) {
|
|
219
220
|
for (const stmt of fp.sf.statements) {
|
|
220
221
|
// NAMED re-exports from npm packages (`export { isUrl } from
|
|
@@ -253,7 +254,7 @@ export function collectNpmImports(L, parts) {
|
|
|
253
254
|
// selects its package), the declaration mapping promises no npm or
|
|
254
255
|
// island runtime implementation; the preflight/import-use SC1010
|
|
255
256
|
// fences are the whole story.
|
|
256
|
-
if (
|
|
257
|
+
if (lowerer.externalTypes.has(spec))
|
|
257
258
|
continue;
|
|
258
259
|
const npm = resolveNpmImport(fp.sf.fileName, spec);
|
|
259
260
|
// --npm-static: an opted-in package that made it through preflight
|
|
@@ -264,7 +265,7 @@ export function collectNpmImports(L, parts) {
|
|
|
264
265
|
if (npm !== null &&
|
|
265
266
|
isNpmStaticPackage(npm.packageName) &&
|
|
266
267
|
isJsSourceFileName(npm.typesFile) &&
|
|
267
|
-
|
|
268
|
+
lowerer.program.getSourceFile(npm.typesFile) !== undefined) {
|
|
268
269
|
continue;
|
|
269
270
|
}
|
|
270
271
|
// A RELATIVE specifier resolving INTO node_modules (the e2e driver
|
|
@@ -293,7 +294,7 @@ export function collectNpmImports(L, parts) {
|
|
|
293
294
|
if (npm !== null && probeNodeImportRefusal(fp.sf.fileName, spec) !== null)
|
|
294
295
|
continue;
|
|
295
296
|
if (!builder) {
|
|
296
|
-
|
|
297
|
+
lowerer.pushDiag(requiresDynamicImportDiag(npm?.packageName ?? relPkg, locOf(stmt)));
|
|
297
298
|
continue;
|
|
298
299
|
}
|
|
299
300
|
const before = builder.errors.length;
|
|
@@ -301,13 +302,13 @@ export function collectNpmImports(L, parts) {
|
|
|
301
302
|
? (builder.addImport(fp.sf.fileName, spec), builder.entryOf(fp.sf.fileName, spec))
|
|
302
303
|
: builder.addFileImport(fp.sf.fileName, spec);
|
|
303
304
|
for (const err of builder.errors.slice(before)) {
|
|
304
|
-
|
|
305
|
+
lowerer.pushDiag(npmEmbedFailedDiag(err.message, locOf(stmt)));
|
|
305
306
|
}
|
|
306
307
|
if (entryKey === null)
|
|
307
308
|
continue; // resolution failed — reported above
|
|
308
309
|
const loc = locOf(stmt);
|
|
309
|
-
const byStmt =
|
|
310
|
-
|
|
310
|
+
const byStmt = lowerer.npmInitActions.get(fp.sf) ?? new Map();
|
|
311
|
+
lowerer.npmInitActions.set(fp.sf, byStmt);
|
|
311
312
|
const actions = byStmt.get(stmt) ?? [];
|
|
312
313
|
byStmt.set(stmt, actions);
|
|
313
314
|
const importExpr = (exportName) => ({
|
|
@@ -326,22 +327,22 @@ export function collectNpmImports(L, parts) {
|
|
|
326
327
|
loc,
|
|
327
328
|
});
|
|
328
329
|
const bind = (nameNode, exportName) => {
|
|
329
|
-
let symbol =
|
|
330
|
+
let symbol = lowerer.checker.getSymbolAtLocation(nameNode);
|
|
330
331
|
if (symbol && symbol.flags & ts.SymbolFlags.Alias) {
|
|
331
|
-
symbol =
|
|
332
|
+
symbol = lowerer.checker.getAliasedSymbol(symbol);
|
|
332
333
|
}
|
|
333
334
|
if (!symbol)
|
|
334
335
|
return;
|
|
335
|
-
let g =
|
|
336
|
+
let g = lowerer.globalsBySymbol.get(symbol);
|
|
336
337
|
if (!g) {
|
|
337
338
|
g = {
|
|
338
|
-
id: `%g.npm.${
|
|
339
|
+
id: `%g.npm.${lowerer.globalsList.length}`,
|
|
339
340
|
name: nameNode.text,
|
|
340
341
|
type: JSVAL,
|
|
341
342
|
mutable: false,
|
|
342
343
|
};
|
|
343
|
-
|
|
344
|
-
|
|
344
|
+
lowerer.globalsBySymbol.set(symbol, g);
|
|
345
|
+
lowerer.globalsList.push(g);
|
|
345
346
|
}
|
|
346
347
|
actions.push({ kind: "assign", localId: g.id, value: importExpr(exportName), loc });
|
|
347
348
|
};
|
|
@@ -376,17 +377,17 @@ export function collectNpmImports(L, parts) {
|
|
|
376
377
|
}
|
|
377
378
|
if (builder) {
|
|
378
379
|
for (const fp of parts)
|
|
379
|
-
collectDynamicImports(
|
|
380
|
+
collectDynamicImports(lowerer, builder, fp.sf);
|
|
380
381
|
for (const fp of parts)
|
|
381
|
-
collectCreateRequires(
|
|
382
|
+
collectCreateRequires(lowerer, builder, fp.sf);
|
|
382
383
|
const graph = builder.finish();
|
|
383
384
|
if (graph.modules.length > 0) {
|
|
384
|
-
|
|
385
|
+
lowerer.npmEmbedded = { modules: graph.modules, edges: graph.edges };
|
|
385
386
|
}
|
|
386
387
|
if (graph.builtins.length > 0)
|
|
387
|
-
|
|
388
|
+
lowerer.npmBuiltins = graph.builtins;
|
|
388
389
|
if (graph.lazyTraps.length > 0)
|
|
389
|
-
|
|
390
|
+
lowerer.npmLazyTraps = graph.lazyTraps;
|
|
390
391
|
}
|
|
391
392
|
}
|
|
392
393
|
/** The dynamic-import half of the npm chokepoint (--dynamic only): every
|
|
@@ -400,7 +401,7 @@ export function collectNpmImports(L, parts) {
|
|
|
400
401
|
* specifiers are skipped — the lowering owns that fence (the module
|
|
401
402
|
* graph is a build-time artifact; there is nothing to embed for a
|
|
402
403
|
* runtime-computed name). */
|
|
403
|
-
function collectDynamicImports(
|
|
404
|
+
function collectDynamicImports(lowerer, builder, sf) {
|
|
404
405
|
const visit = (node) => {
|
|
405
406
|
if (ts.isCallExpression(node) &&
|
|
406
407
|
node.expression.kind === ts.SyntaxKind.ImportKeyword &&
|
|
@@ -408,28 +409,28 @@ function collectDynamicImports(L, builder, sf) {
|
|
|
408
409
|
node.arguments[0] !== undefined &&
|
|
409
410
|
ts.isStringLiteralLike(node.arguments[0])) {
|
|
410
411
|
const spec = node.arguments[0].text;
|
|
411
|
-
if (
|
|
412
|
+
if (lowerer.externalTypes.has(spec)) {
|
|
412
413
|
ts.forEachChild(node, visit);
|
|
413
414
|
return;
|
|
414
415
|
}
|
|
415
416
|
const mapKey = `${sf.fileName}\u0000${spec}`;
|
|
416
|
-
if (!
|
|
417
|
+
if (!lowerer.dynImports.has(mapKey)) {
|
|
417
418
|
// The program's OWN modules first, by the checker's resolution
|
|
418
419
|
// (tsc already resolved "./helper.js" to helper.ts): a compiled
|
|
419
420
|
// module has no runtime namespace object — the per-site fence
|
|
420
421
|
// says so. Only non-declaration source files count; a sibling
|
|
421
422
|
// .d.mts typing shipped JS is the EMBED case, not this one.
|
|
422
|
-
const modSym =
|
|
423
|
-
const ownModule = modSym !== undefined &&
|
|
423
|
+
const modSym = lowerer.checker.getSymbolAtLocation(node.arguments[0]);
|
|
424
|
+
const ownModule = modSym !== undefined && lowerer.checker.declarationsOf(modSym).some((d) => ts.isSourceFile(d) && !d.isDeclarationFile);
|
|
424
425
|
const res = ownModule
|
|
425
426
|
? { kind: "program-module" }
|
|
426
427
|
: builder.addDynamicImport(sf.fileName, spec);
|
|
427
|
-
|
|
428
|
+
lowerer.dynImports.set(mapKey, res);
|
|
428
429
|
if (res.kind === "unsupported-builtin") {
|
|
429
|
-
|
|
430
|
+
lowerer.pushDiag(npmEmbedFailedDiag(`'${spec}' is a Node builtin the island does not provide a shim for`, locOf(node)));
|
|
430
431
|
}
|
|
431
432
|
else if (res.kind === "unresolved") {
|
|
432
|
-
|
|
433
|
+
lowerer.pushDiag(npmEmbedFailedDiag(res.message, locOf(node)));
|
|
433
434
|
}
|
|
434
435
|
}
|
|
435
436
|
}
|
|
@@ -446,10 +447,10 @@ function collectDynamicImports(L, builder, sf) {
|
|
|
446
447
|
* are the lowering's own arms — only resolvable installed packages
|
|
447
448
|
* register here; resolution failures are diagnostics at the call
|
|
448
449
|
* expression, exactly like static npm imports at their statements. */
|
|
449
|
-
function collectCreateRequires(
|
|
450
|
+
function collectCreateRequires(lowerer, builder, sf) {
|
|
450
451
|
const visit = (node) => {
|
|
451
452
|
if (ts.isCallExpression(node)) {
|
|
452
|
-
const cr = createRequireSpecOf(
|
|
453
|
+
const cr = createRequireSpecOf(lowerer, node);
|
|
453
454
|
const spec = cr?.spec ?? null;
|
|
454
455
|
if (cr !== null &&
|
|
455
456
|
spec !== null &&
|
|
@@ -462,13 +463,13 @@ function collectCreateRequires(L, builder, sf) {
|
|
|
462
463
|
? spec.split("/").slice(0, 2).join("/")
|
|
463
464
|
: spec.split("/")[0];
|
|
464
465
|
const mapKey = `${cr.baseFile.fileName}\u0000${spec}`;
|
|
465
|
-
if (!
|
|
466
|
+
if (!lowerer.createRequireImports.has(mapKey) && !isNpmStaticPackage(pkgName)) {
|
|
466
467
|
const before = builder.errors.length;
|
|
467
468
|
const entryKey = builder.addRequire(cr.baseFile.fileName, spec);
|
|
468
469
|
for (const err of builder.errors.slice(before)) {
|
|
469
|
-
|
|
470
|
+
lowerer.pushDiag(npmEmbedFailedDiag(err.message, locOf(node)));
|
|
470
471
|
}
|
|
471
|
-
|
|
472
|
+
lowerer.createRequireImports.set(mapKey, entryKey === null
|
|
472
473
|
? ""
|
|
473
474
|
: { entryKey, format: builder.moduleFormatOf(entryKey) ?? "cjs" });
|
|
474
475
|
}
|
|
@@ -490,7 +491,7 @@ function collectCreateRequires(L, builder, sf) {
|
|
|
490
491
|
* arrays, ...) report the standard unsupported-type diagnostic at the
|
|
491
492
|
* import site. Preflight already fenced named/namespace JSON imports
|
|
492
493
|
* and kept .json files out of the module order. */
|
|
493
|
-
export function collectJsonImports(
|
|
494
|
+
export function collectJsonImports(lowerer, parts) {
|
|
494
495
|
for (const fp of parts) {
|
|
495
496
|
for (const stmt of fp.sf.statements) {
|
|
496
497
|
if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
@@ -498,18 +499,18 @@ export function collectJsonImports(L, parts) {
|
|
|
498
499
|
const clause = stmt.importClause;
|
|
499
500
|
if (!clause?.name || clause.phaseModifier === ts.SyntaxKind.TypeKeyword)
|
|
500
501
|
continue;
|
|
501
|
-
const nameSym =
|
|
502
|
+
const nameSym = lowerer.checker.getSymbolAtLocation(clause.name);
|
|
502
503
|
if (!nameSym || !(nameSym.flags & ts.SymbolFlags.Alias))
|
|
503
504
|
continue;
|
|
504
|
-
const target =
|
|
505
|
-
const jsonSf =
|
|
505
|
+
const target = lowerer.checker.getAliasedSymbol(nameSym);
|
|
506
|
+
const jsonSf = lowerer.checker.declarationsOf(target)[0]?.getSourceFile();
|
|
506
507
|
if (!jsonSf || !jsonSf.fileName.endsWith(".json"))
|
|
507
508
|
continue;
|
|
508
509
|
try {
|
|
509
|
-
const tsType =
|
|
510
|
-
const mapped =
|
|
511
|
-
if (!mapped || !
|
|
512
|
-
|
|
510
|
+
const tsType = lowerer.typeOf(clause.name);
|
|
511
|
+
const mapped = lowerer.mapTypeOf(tsType);
|
|
512
|
+
if (!mapped || !lowerer.comptimeBakeable(mapped)) {
|
|
513
|
+
lowerer.badType(clause.name, tsType);
|
|
513
514
|
}
|
|
514
515
|
// tsgo tolerates JSON shapes strict JSON.parse rejects (a leading
|
|
515
516
|
// `//` comment — importAttributes11), so no SC0001 guarantees a
|
|
@@ -520,23 +521,23 @@ export function collectJsonImports(L, parts) {
|
|
|
520
521
|
parsed = JSON.parse(jsonSf.text);
|
|
521
522
|
}
|
|
522
523
|
catch (e) {
|
|
523
|
-
|
|
524
|
+
lowerer.pushDiag(invalidJsonModuleDiag(jsonSf.fileName, e instanceof Error ? e.message : String(e), locOf(stmt)));
|
|
524
525
|
throw new PoisonError();
|
|
525
526
|
}
|
|
526
|
-
const value =
|
|
527
|
-
let g =
|
|
527
|
+
const value = lowerer.comptimeValueToIr(parsed, mapped, "$", clause.name);
|
|
528
|
+
let g = lowerer.globalsBySymbol.get(target);
|
|
528
529
|
if (!g) {
|
|
529
530
|
g = {
|
|
530
|
-
id: `%g.json.${
|
|
531
|
+
id: `%g.json.${lowerer.globalsList.length}`,
|
|
531
532
|
name: clause.name.text,
|
|
532
533
|
type: mapped,
|
|
533
534
|
mutable: false,
|
|
534
535
|
};
|
|
535
|
-
|
|
536
|
-
|
|
536
|
+
lowerer.globalsBySymbol.set(target, g);
|
|
537
|
+
lowerer.globalsList.push(g);
|
|
537
538
|
}
|
|
538
|
-
const actions =
|
|
539
|
-
|
|
539
|
+
const actions = lowerer.jsonInitActions.get(fp.sf) ?? [];
|
|
540
|
+
lowerer.jsonInitActions.set(fp.sf, actions);
|
|
540
541
|
actions.push({ kind: "assign", localId: g.id, value, loc: locOf(stmt) });
|
|
541
542
|
}
|
|
542
543
|
catch (e) {
|
|
@@ -558,7 +559,7 @@ export function collectJsonImports(L, parts) {
|
|
|
558
559
|
* deferred: the reference flushes those diagnostics. Methods whose
|
|
559
560
|
* bodies were not lowered leave the def's method list, so vtable slots
|
|
560
561
|
* exist exactly for emitted overrides. */
|
|
561
|
-
export function moduleArtifacts(
|
|
562
|
+
export function moduleArtifacts(lowerer, functions) {
|
|
562
563
|
const classNames = new Set();
|
|
563
564
|
const shapeIds = new Set();
|
|
564
565
|
const unionIds = new Set();
|
|
@@ -592,7 +593,7 @@ export function moduleArtifacts(L, functions) {
|
|
|
592
593
|
}
|
|
593
594
|
};
|
|
594
595
|
visit(functions);
|
|
595
|
-
visit(
|
|
596
|
+
visit(lowerer.globalsList);
|
|
596
597
|
// The builtin error classes ride EVERY module: the runtime's own throws
|
|
597
598
|
// (JSON/dynCheck/regex failures) mint instances of them whether or not
|
|
598
599
|
// user code mentions Error, and the uncaught printer tells Error
|
|
@@ -612,26 +613,26 @@ export function moduleArtifacts(L, functions) {
|
|
|
612
613
|
// Declared fields AND the index-signature value type: an
|
|
613
614
|
// overflow-valued shape (`{ [key: string]: {script?: string} }`)
|
|
614
615
|
// references its value shape through indexValue alone.
|
|
615
|
-
const shape =
|
|
616
|
+
const shape = lowerer.shapes.get(pendingShapes.pop());
|
|
616
617
|
visit(shape?.fields);
|
|
617
618
|
if (shape?.indexValue)
|
|
618
619
|
visit(shape.indexValue);
|
|
619
620
|
}
|
|
620
621
|
while (pendingUnions.length > 0)
|
|
621
|
-
visit(
|
|
622
|
+
visit(lowerer.unions.get(pendingUnions.pop())?.arms);
|
|
622
623
|
while (pendingClasses.length > 0) {
|
|
623
624
|
const name = pendingClasses.pop();
|
|
624
|
-
const info =
|
|
625
|
+
const info = lowerer.classes.get(name);
|
|
625
626
|
if (!info) {
|
|
626
627
|
// Referenced by an emitted type but never registered: collection
|
|
627
628
|
// deferred its diagnostics — a reached reference makes them count.
|
|
628
|
-
|
|
629
|
+
lowerer.flushDeferredClass(name);
|
|
629
630
|
continue;
|
|
630
631
|
}
|
|
631
632
|
visit(info.def.fields);
|
|
632
633
|
if (info.base)
|
|
633
634
|
visit([{ className: info.base.def.name }]);
|
|
634
|
-
if (
|
|
635
|
+
if (lowerer.inHierarchy(info)) {
|
|
635
636
|
let root = info;
|
|
636
637
|
while (root.base)
|
|
637
638
|
root = root.base;
|
|
@@ -644,9 +645,9 @@ export function moduleArtifacts(L, functions) {
|
|
|
644
645
|
}
|
|
645
646
|
}
|
|
646
647
|
}
|
|
647
|
-
const reachable =
|
|
648
|
+
const reachable = lowerer.reachableForArtifacts ?? lowerer.reachable;
|
|
648
649
|
return {
|
|
649
|
-
classes: [...
|
|
650
|
+
classes: [...lowerer.classes.values()]
|
|
650
651
|
.map((c) => c.def)
|
|
651
652
|
.filter((def) => classNames.has(def.name))
|
|
652
653
|
.map((def) => {
|
|
@@ -670,8 +671,8 @@ export function moduleArtifacts(L, functions) {
|
|
|
670
671
|
...(abstractMethods.length > 0 ? { abstractMethods } : {}),
|
|
671
672
|
};
|
|
672
673
|
}),
|
|
673
|
-
records:
|
|
674
|
-
unions:
|
|
674
|
+
records: lowerer.shapes.shapes.filter((r) => shapeIds.has(r.id)),
|
|
675
|
+
unions: lowerer.unions.unions.filter((u) => unionIds.has(u.id)),
|
|
675
676
|
};
|
|
676
677
|
}
|
|
677
678
|
/** Registers every DIRECT top-level `const`/`let` of a file as a module
|
|
@@ -679,18 +680,18 @@ export function moduleArtifacts(L, functions) {
|
|
|
679
680
|
* reference them without capture). Block-scoped vars inside nested
|
|
680
681
|
* statements keep their different symbols and stay locals. */
|
|
681
682
|
/** JS collection failures defer to runtime fences: the registration's
|
|
682
|
-
* diagnostics move off the build (into
|
|
683
|
+
* diagnostics move off the build (into lowerer.runtimeFences) — the declaring
|
|
683
684
|
* statement re-fails during init lowering and compiles to the
|
|
684
685
|
* runtimeFence trap there, and every use site cascades to its own trap.
|
|
685
686
|
* TypeScript files keep eager collection reports. */
|
|
686
|
-
function deferJsCollectionDiags(
|
|
687
|
+
function deferJsCollectionDiags(lowerer, sf, diagsBefore) {
|
|
687
688
|
if (!isJsSourceFile(sf))
|
|
688
689
|
return;
|
|
689
|
-
const captured =
|
|
690
|
+
const captured = lowerer.diags.splice(diagsBefore);
|
|
690
691
|
const ice = captured.filter((d) => d.code === "SC9001");
|
|
691
692
|
if (ice.length > 0)
|
|
692
|
-
|
|
693
|
-
|
|
693
|
+
lowerer.diags.push(...ice);
|
|
694
|
+
lowerer.runtimeFences.push(...captured.filter((d) => d.code !== "SC9001"));
|
|
694
695
|
}
|
|
695
696
|
/** A scalar-literal expression a single-value `module.exports =` can carry
|
|
696
697
|
* without any declaration to alias to: string/number/boolean literals,
|
|
@@ -712,7 +713,7 @@ function cjsScalarLiteral(e) {
|
|
|
712
713
|
* an expando class member constructs a TYPED instance — corpus 2032), as
|
|
713
714
|
* does everything else (object/array literals have their own rules;
|
|
714
715
|
* typed-but-unmappable initializers keep the %init-local adoption). */
|
|
715
|
-
function jsDynHoldableInitializer(
|
|
716
|
+
function jsDynHoldableInitializer(lowerer, init) {
|
|
716
717
|
if (init === undefined)
|
|
717
718
|
return true;
|
|
718
719
|
let e = init;
|
|
@@ -723,7 +724,7 @@ function jsDynHoldableInitializer(L, init) {
|
|
|
723
724
|
if (ts.isIdentifier(e) && e.text === "undefined")
|
|
724
725
|
return true;
|
|
725
726
|
if ((ts.isCallExpression(e) || ts.isPropertyAccessExpression(e) || ts.isIdentifier(e)) &&
|
|
726
|
-
(
|
|
727
|
+
(lowerer.typeOf(e).flags & ts.TypeFlags.Any) !== 0) {
|
|
727
728
|
return true;
|
|
728
729
|
}
|
|
729
730
|
// A CALL whose inferred type has no static mapping and whose residue
|
|
@@ -735,22 +736,22 @@ function jsDynHoldableInitializer(L, init) {
|
|
|
735
736
|
// idiom. Non-dyn residues (pure single-signature function types, typed
|
|
736
737
|
// arrays) keep their static stories.
|
|
737
738
|
if (ts.isCallExpression(e)) {
|
|
738
|
-
const t =
|
|
739
|
-
if (
|
|
739
|
+
const t = lowerer.typeOf(e);
|
|
740
|
+
if (lowerer.mapTypeOf(t) === null && dynFallbackType(lowerer, e, t)?.kind === "dyn")
|
|
740
741
|
return true;
|
|
741
742
|
}
|
|
742
743
|
return false;
|
|
743
744
|
}
|
|
744
|
-
export function collectGlobals(
|
|
745
|
+
export function collectGlobals(lowerer, sf, topStmts) {
|
|
745
746
|
// Segment-tagged so mangled names can't collide across files (user
|
|
746
747
|
// identifiers cannot contain '.'): entry globals "e.<name>", others
|
|
747
748
|
// "m<i>.<name>".
|
|
748
|
-
const rawTag =
|
|
749
|
+
const rawTag = lowerer.fileTag.get(sf) ?? "";
|
|
749
750
|
const tag = rawTag === "" ? "e." : rawTag.replace(/^%/, "");
|
|
750
751
|
// Expando function members (`foo.bar = 12` anywhere in the file)
|
|
751
752
|
// register their module globals first — reads inside function bodies
|
|
752
753
|
// collected earlier in this pass must resolve them (lower-expando.ts).
|
|
753
|
-
collectExpandoMembers(
|
|
754
|
+
collectExpandoMembers(lowerer, sf);
|
|
754
755
|
for (const stmt of topStmts) {
|
|
755
756
|
// `export default <expr>`: the module's `default` binding is a const
|
|
756
757
|
// module global (registered under the checker's default-export
|
|
@@ -777,12 +778,12 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
777
778
|
// resolveValueSymbol's default-snapshot walk instead of chasing the
|
|
778
779
|
// alias to the live let.
|
|
779
780
|
if (ts.isExportAssignment(stmt) && !stmt.isExportEquals) {
|
|
780
|
-
const symbol = defaultExportSymbolOf(
|
|
781
|
+
const symbol = defaultExportSymbolOf(lowerer, sf);
|
|
781
782
|
if (!symbol)
|
|
782
783
|
continue;
|
|
783
784
|
if (symbol.flags & ts.SymbolFlags.Alias) {
|
|
784
|
-
const target =
|
|
785
|
-
const vd =
|
|
785
|
+
const target = lowerer.checker.getAliasedSymbol(symbol);
|
|
786
|
+
const vd = lowerer.checker.valueDeclarationOf(target);
|
|
786
787
|
const mutableVar = vd !== undefined &&
|
|
787
788
|
ts.isVariableDeclaration(vd) &&
|
|
788
789
|
!vd.getSourceFile().isDeclarationFile &&
|
|
@@ -807,31 +808,31 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
807
808
|
if (ts.isClassExpression(inner) && !isJsSourceFile(sf) &&
|
|
808
809
|
inner.typeParameters === undefined &&
|
|
809
810
|
(decoratorNodesOf(inner).length > 0 || inner.members.some((m) => decoratorNodesOf(m).length > 0)) &&
|
|
810
|
-
guaranteedDecorationThrow(
|
|
811
|
+
guaranteedDecorationThrow(lowerer, inner) !== null) {
|
|
811
812
|
continue;
|
|
812
813
|
}
|
|
813
814
|
}
|
|
814
815
|
try {
|
|
815
|
-
let tsType =
|
|
816
|
+
let tsType = lowerer.typeOf(stmt.expression);
|
|
816
817
|
// tsgo answers `any` at some export-assignment EXPRESSION
|
|
817
818
|
// positions (a bare literal default) — the SYMBOL's type is the
|
|
818
819
|
// declared truth and serves as the fallback.
|
|
819
820
|
if (tsType.flags & ts.TypeFlags.Any) {
|
|
820
|
-
const symType =
|
|
821
|
+
const symType = lowerer.checker.getTypeOfSymbol(symbol);
|
|
821
822
|
if (!(symType.flags & ts.TypeFlags.Any))
|
|
822
823
|
tsType = symType;
|
|
823
824
|
}
|
|
824
|
-
let type =
|
|
825
|
+
let type = lowerer.mapTypeOf(tsType) ?? dynFallbackType(lowerer, stmt.expression, tsType) ?? lowerer.badType(stmt.expression, tsType);
|
|
825
826
|
// `export default undefined` — the unit-only union, like any
|
|
826
827
|
// unit-only binding (`export default null` maps via mapType).
|
|
827
828
|
if (type.kind === "void" && isUnitOnlyTsType(tsType)) {
|
|
828
|
-
type = unitOnlyUnion(
|
|
829
|
+
type = unitOnlyUnion(lowerer.unions);
|
|
829
830
|
}
|
|
830
831
|
if (type.kind === "void")
|
|
831
|
-
|
|
832
|
+
lowerer.badType(stmt.expression, tsType);
|
|
832
833
|
const g = { id: `%g.${tag}default`, name: "default", type, mutable: false };
|
|
833
|
-
|
|
834
|
-
|
|
834
|
+
lowerer.globalsBySymbol.set(symbol, g);
|
|
835
|
+
lowerer.globalsList.push(g);
|
|
835
836
|
}
|
|
836
837
|
catch (e) {
|
|
837
838
|
if (!(e instanceof PoisonError))
|
|
@@ -854,22 +855,22 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
854
855
|
// importers never see. The statement lowering owns the diagnostic.
|
|
855
856
|
const cjs = cjsExportDiscardReason(stmt) === null ? cjsExportAssignmentOf(stmt) : null;
|
|
856
857
|
const registerExport = (nameNode, name, typeNode) => {
|
|
857
|
-
const diagsBefore =
|
|
858
|
+
const diagsBefore = lowerer.diags.length;
|
|
858
859
|
try {
|
|
859
860
|
// tsgo answers no symbol at the attachment site's NAME (no
|
|
860
861
|
// expando synthesis); the module symbol's exports table still
|
|
861
862
|
// names the member — the same identity use sites resolve.
|
|
862
|
-
const symbol =
|
|
863
|
-
if (!symbol ||
|
|
863
|
+
const symbol = lowerer.checker.getSymbolAtLocation(nameNode) ?? lowerer.cjsModuleExportSymbol(sf, name);
|
|
864
|
+
if (!symbol || lowerer.globalsBySymbol.has(symbol))
|
|
864
865
|
return;
|
|
865
866
|
// JS exports whose strict type has no mapping take the
|
|
866
867
|
// checked-dynamic fallback (implicit-any function exports —
|
|
867
868
|
// common/tls's `exports.check = function (certs) {...}` —
|
|
868
869
|
// keep func-ness with dyn pieces; everything else is dyn).
|
|
869
|
-
const strict =
|
|
870
|
-
const t =
|
|
870
|
+
const strict = lowerer.checker.getTypeOfSymbol(symbol);
|
|
871
|
+
const t = lowerer.mapTypeOf(strict) ?? dynFallbackType(lowerer, nameNode, strict);
|
|
871
872
|
if (!t || t.kind === "void")
|
|
872
|
-
|
|
873
|
+
lowerer.badType(typeNode, strict);
|
|
873
874
|
// `module.exports.Strings = Strings` naming a dyn-HOLDING
|
|
874
875
|
// const (the JS file-scope object-literal identity story): the
|
|
875
876
|
// export ALIASES the const's own dyn global — one storage, one
|
|
@@ -885,13 +886,13 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
885
886
|
while (ts.isParenthesizedExpression(rhs))
|
|
886
887
|
rhs = rhs.expression;
|
|
887
888
|
if (ts.isIdentifier(rhs)) {
|
|
888
|
-
const vSym =
|
|
889
|
-
const vG = vSym &&
|
|
889
|
+
const vSym = lowerer.checker.getSymbolAtLocation(rhs);
|
|
890
|
+
const vG = vSym && lowerer.globalsBySymbol.get(vSym);
|
|
890
891
|
if (vG?.type.kind === "dyn") {
|
|
891
892
|
if (!vG.mutable) {
|
|
892
|
-
|
|
893
|
-
for (const d of
|
|
894
|
-
|
|
893
|
+
lowerer.globalsBySymbol.set(symbol, vG);
|
|
894
|
+
for (const d of lowerer.checker.declarationsOf(symbol))
|
|
895
|
+
lowerer.globalsByDeclNode.set(d, vG);
|
|
895
896
|
return;
|
|
896
897
|
}
|
|
897
898
|
// A mutable (`let`) dyn source: separate DYN storage IS
|
|
@@ -900,28 +901,28 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
900
901
|
// export). The id must not collide with the let's own
|
|
901
902
|
// `%g.<tag><name>` global.
|
|
902
903
|
const g = { id: `%g.${tag}%export.${name}`, name, type: DYN, mutable: false };
|
|
903
|
-
|
|
904
|
-
for (const d of
|
|
905
|
-
|
|
906
|
-
|
|
904
|
+
lowerer.globalsBySymbol.set(symbol, g);
|
|
905
|
+
for (const d of lowerer.checker.declarationsOf(symbol))
|
|
906
|
+
lowerer.globalsByDeclNode.set(d, g);
|
|
907
|
+
lowerer.globalsList.push(g);
|
|
907
908
|
return;
|
|
908
909
|
}
|
|
909
910
|
}
|
|
910
911
|
}
|
|
911
912
|
const g = { id: `%g.${tag}${name}`, name, type: t, mutable: false };
|
|
912
|
-
|
|
913
|
+
lowerer.globalsBySymbol.set(symbol, g);
|
|
913
914
|
// Importer aliases resolve to a DISTINCT late-bound symbol with
|
|
914
915
|
// the same declaration — key the node too (globalOf's fallback).
|
|
915
|
-
for (const d of
|
|
916
|
-
|
|
917
|
-
|
|
916
|
+
for (const d of lowerer.checker.declarationsOf(symbol))
|
|
917
|
+
lowerer.globalsByDeclNode.set(d, g);
|
|
918
|
+
lowerer.globalsList.push(g);
|
|
918
919
|
}
|
|
919
920
|
catch (e) {
|
|
920
921
|
if (!(e instanceof PoisonError))
|
|
921
922
|
throw e;
|
|
922
923
|
// diagnostic recorded; the statement lowering poisons too —
|
|
923
924
|
// both defer to the statement's runtime fence in JS files.
|
|
924
|
-
deferJsCollectionDiags(
|
|
925
|
+
deferJsCollectionDiags(lowerer, sf, diagsBefore);
|
|
925
926
|
}
|
|
926
927
|
};
|
|
927
928
|
if (cjs?.kind === "member" && ts.isIdentifier(cjs.name)) {
|
|
@@ -930,7 +931,7 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
930
931
|
// builtin-derived classes); importers re-resolve to the class
|
|
931
932
|
// symbol (cjsMemberExportClassSymbol) and the class registry
|
|
932
933
|
// applies unchanged.
|
|
933
|
-
if (
|
|
934
|
+
if (lowerer.cjsMemberExportClassSymbol(cjs.expr) !== null)
|
|
934
935
|
continue;
|
|
935
936
|
registerExport(cjs.name, cjs.name.text, cjs.value);
|
|
936
937
|
continue;
|
|
@@ -958,20 +959,20 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
958
959
|
// fallback like every JS binding.
|
|
959
960
|
const fnValued = ts.isFunctionExpression(rhs) || ts.isArrowFunction(rhs);
|
|
960
961
|
if (cjsScalarLiteral(rhs) || fnValued) {
|
|
961
|
-
const diagsBefore =
|
|
962
|
+
const diagsBefore = lowerer.diags.length;
|
|
962
963
|
try {
|
|
963
|
-
const strict =
|
|
964
|
-
const t =
|
|
964
|
+
const strict = lowerer.typeOf(rhs);
|
|
965
|
+
const t = lowerer.mapTypeOf(strict) ?? (fnValued ? dynFallbackType(lowerer, rhs, strict) : null);
|
|
965
966
|
if (t && t.kind !== "void") {
|
|
966
967
|
const g = { id: `%g.${tag}exports`, name: "exports", type: t, mutable: false };
|
|
967
|
-
|
|
968
|
-
|
|
968
|
+
lowerer.globalsByDeclNode.set(cjs.expr, g);
|
|
969
|
+
lowerer.globalsList.push(g);
|
|
969
970
|
}
|
|
970
971
|
}
|
|
971
972
|
catch (e) {
|
|
972
973
|
if (!(e instanceof PoisonError))
|
|
973
974
|
throw e;
|
|
974
|
-
deferJsCollectionDiags(
|
|
975
|
+
deferJsCollectionDiags(lowerer, sf, diagsBefore);
|
|
975
976
|
}
|
|
976
977
|
}
|
|
977
978
|
continue;
|
|
@@ -1003,38 +1004,38 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1003
1004
|
if (ts.isImportEqualsDeclaration(stmt)) {
|
|
1004
1005
|
if (ts.isExternalModuleReference(stmt.moduleReference) || stmt.isTypeOnly)
|
|
1005
1006
|
continue;
|
|
1006
|
-
const aliasSym =
|
|
1007
|
-
if (!aliasSym || !(aliasSym.flags & ts.SymbolFlags.Alias) ||
|
|
1007
|
+
const aliasSym = lowerer.checker.getSymbolAtLocation(stmt.name);
|
|
1008
|
+
if (!aliasSym || !(aliasSym.flags & ts.SymbolFlags.Alias) || lowerer.globalsBySymbol.has(aliasSym))
|
|
1008
1009
|
continue;
|
|
1009
|
-
const target =
|
|
1010
|
-
const vd =
|
|
1010
|
+
const target = lowerer.checker.getAliasedSymbol(aliasSym);
|
|
1011
|
+
const vd = lowerer.checker.valueDeclarationOf(target);
|
|
1011
1012
|
const mutableVar = vd !== undefined &&
|
|
1012
1013
|
ts.isVariableDeclaration(vd) &&
|
|
1013
1014
|
!vd.getSourceFile().isDeclarationFile &&
|
|
1014
1015
|
(ts.getCombinedNodeFlags(vd) & ts.NodeFlags.Const) === 0;
|
|
1015
1016
|
if (!mutableVar)
|
|
1016
1017
|
continue;
|
|
1017
|
-
const diagsBefore =
|
|
1018
|
+
const diagsBefore = lowerer.diags.length;
|
|
1018
1019
|
try {
|
|
1019
|
-
let type =
|
|
1020
|
-
if (type.kind === "void" && isUnitOnlyTsType(
|
|
1021
|
-
type = unitOnlyUnion(
|
|
1020
|
+
let type = lowerer.irTypeOf(stmt.name);
|
|
1021
|
+
if (type.kind === "void" && isUnitOnlyTsType(lowerer.typeOf(stmt.name))) {
|
|
1022
|
+
type = unitOnlyUnion(lowerer.unions);
|
|
1022
1023
|
}
|
|
1023
1024
|
if (type.kind === "void")
|
|
1024
|
-
|
|
1025
|
+
lowerer.badType(stmt.name, lowerer.typeOf(stmt.name));
|
|
1025
1026
|
const g = {
|
|
1026
1027
|
id: `%g.${tag}${nsPathPrefix(stmt)}%alias.${stmt.name.text}%${stmt.getStart()}`,
|
|
1027
1028
|
name: stmt.name.text,
|
|
1028
1029
|
type,
|
|
1029
1030
|
mutable: false,
|
|
1030
1031
|
};
|
|
1031
|
-
|
|
1032
|
-
|
|
1032
|
+
lowerer.globalsBySymbol.set(aliasSym, g);
|
|
1033
|
+
lowerer.globalsList.push(g);
|
|
1033
1034
|
}
|
|
1034
1035
|
catch (e) {
|
|
1035
1036
|
if (!(e instanceof PoisonError))
|
|
1036
1037
|
throw e;
|
|
1037
|
-
deferJsCollectionDiags(
|
|
1038
|
+
deferJsCollectionDiags(lowerer, sf, diagsBefore);
|
|
1038
1039
|
}
|
|
1039
1040
|
continue;
|
|
1040
1041
|
}
|
|
@@ -1045,7 +1046,7 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1045
1046
|
// statements continue into the main registration below, which also
|
|
1046
1047
|
// owns the special forms — requires, aliases, promisify).
|
|
1047
1048
|
if (!ts.isVariableStatement(stmt)) {
|
|
1048
|
-
collectNestedVarGlobals(
|
|
1049
|
+
collectNestedVarGlobals(lowerer, sf, stmt, tag);
|
|
1049
1050
|
continue;
|
|
1050
1051
|
}
|
|
1051
1052
|
// CommonJS require declarations are alias plumbing (preflight owns
|
|
@@ -1059,7 +1060,7 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1059
1060
|
if (ts.isVariableStatement(stmt) &&
|
|
1060
1061
|
(stmt.declarationList.flags & ts.NodeFlags.Const) !== 0) {
|
|
1061
1062
|
for (const decl of stmt.declarationList.declarations) {
|
|
1062
|
-
stdlibGlobalAliasDecl(
|
|
1063
|
+
stdlibGlobalAliasDecl(lowerer, decl.name, decl.initializer);
|
|
1063
1064
|
}
|
|
1064
1065
|
}
|
|
1065
1066
|
continue;
|
|
@@ -1091,7 +1092,7 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1091
1092
|
// provenanceElidedConstDecl). Checked FIRST: the mixin/promisify
|
|
1092
1093
|
// probes below would otherwise claim the call-initializer shape
|
|
1093
1094
|
// and put its fences on the build.
|
|
1094
|
-
if (provenanceElidedConstDecl(
|
|
1095
|
+
if (provenanceElidedConstDecl(lowerer, decl))
|
|
1095
1096
|
continue;
|
|
1096
1097
|
// A stored built-in numeric value iterator has no first-class
|
|
1097
1098
|
// global representation. Its same-%init for-of uses are backed by
|
|
@@ -1101,7 +1102,7 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1101
1102
|
// Cross-function or exported uses still fence at reference sites.
|
|
1102
1103
|
if (isConst &&
|
|
1103
1104
|
ts.isIdentifier(decl.name) &&
|
|
1104
|
-
numericIteratorSourceOf(
|
|
1105
|
+
numericIteratorSourceOf(lowerer, decl.initializer) !== null) {
|
|
1105
1106
|
continue;
|
|
1106
1107
|
}
|
|
1107
1108
|
// The trap/nullish/dead classification probes below resolve
|
|
@@ -1113,7 +1114,7 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1113
1114
|
// registration, and the statement lowering re-fences at its own
|
|
1114
1115
|
// site (pushDiag dedupes), exactly the per-probe recovery the
|
|
1115
1116
|
// alias/generic-fn registrations below already use.
|
|
1116
|
-
const classifyDiagsBefore =
|
|
1117
|
+
const classifyDiagsBefore = lowerer.diags.length;
|
|
1117
1118
|
const classified = (() => {
|
|
1118
1119
|
try {
|
|
1119
1120
|
// A TRAP declaration at file scope — the initializer's chain roots
|
|
@@ -1125,11 +1126,11 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1125
1126
|
// lowers, so hoisted-function references resolve the trap), and
|
|
1126
1127
|
// the statement lowering emits the throw at its position.
|
|
1127
1128
|
// Written bindings keep ordinary storage (trapDeclRootOf).
|
|
1128
|
-
if (trapDeclRootOf(
|
|
1129
|
+
if (trapDeclRootOf(lowerer, decl) !== null) {
|
|
1129
1130
|
for (const nameNode of boundIdentifiersOf(decl.name)) {
|
|
1130
|
-
const sym =
|
|
1131
|
+
const sym = lowerer.checker.getSymbolAtLocation(nameNode);
|
|
1131
1132
|
if (sym)
|
|
1132
|
-
|
|
1133
|
+
lowerer.trapBindings.add(sym);
|
|
1133
1134
|
}
|
|
1134
1135
|
return true;
|
|
1135
1136
|
}
|
|
@@ -1138,14 +1139,14 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1138
1139
|
// value (lower-exprs/lower-calls claim them); the statement
|
|
1139
1140
|
// lowering emits nothing by the same test.
|
|
1140
1141
|
if (ts.isIdentifier(decl.name) &&
|
|
1141
|
-
nullishGenericBindingUnitOf(
|
|
1142
|
+
nullishGenericBindingUnitOf(lowerer, lowerer.checker.getSymbolAtLocation(decl.name) ?? null) !== null) {
|
|
1142
1143
|
return true;
|
|
1143
1144
|
}
|
|
1144
1145
|
// A DEAD unmappable binding at file scope (`var xs2: typeof
|
|
1145
1146
|
// Array;` — never read anywhere): no global, no statement, no
|
|
1146
1147
|
// type fence for a value the program never consumes.
|
|
1147
1148
|
if (ts.isIdentifier(decl.name) &&
|
|
1148
|
-
deadUnmappableBinding(
|
|
1149
|
+
deadUnmappableBinding(lowerer, lowerer.checker.getSymbolAtLocation(decl.name) ?? null, decl)) {
|
|
1149
1150
|
return true;
|
|
1150
1151
|
}
|
|
1151
1152
|
}
|
|
@@ -1157,7 +1158,7 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1157
1158
|
// collection failure; TS keeps the eager report (the
|
|
1158
1159
|
// statement lowering re-fences at its own site — pushDiag
|
|
1159
1160
|
// dedupes).
|
|
1160
|
-
deferJsCollectionDiags(
|
|
1161
|
+
deferJsCollectionDiags(lowerer, sf, classifyDiagsBefore);
|
|
1161
1162
|
}
|
|
1162
1163
|
return false;
|
|
1163
1164
|
})();
|
|
@@ -1172,10 +1173,10 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1172
1173
|
// by name; the statement lowering skips (or re-fences — pushDiag
|
|
1173
1174
|
// dedupes) by the same test.
|
|
1174
1175
|
{
|
|
1175
|
-
const gfnNode = bindingGenericFnNodeOf(decl) ?? bindingContextualGenericFnNodeOf(
|
|
1176
|
+
const gfnNode = bindingGenericFnNodeOf(decl) ?? bindingContextualGenericFnNodeOf(lowerer, decl);
|
|
1176
1177
|
if (gfnNode) {
|
|
1177
1178
|
try {
|
|
1178
|
-
bindingGenericFnInfoOf(
|
|
1179
|
+
bindingGenericFnInfoOf(lowerer, decl, gfnNode);
|
|
1179
1180
|
}
|
|
1180
1181
|
catch (e) {
|
|
1181
1182
|
if (!(e instanceof PoisonError))
|
|
@@ -1193,7 +1194,7 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1193
1194
|
{
|
|
1194
1195
|
let aliased = false;
|
|
1195
1196
|
try {
|
|
1196
|
-
aliased = bindingGenericFnAliasInfoOf(
|
|
1197
|
+
aliased = bindingGenericFnAliasInfoOf(lowerer, decl) !== null;
|
|
1197
1198
|
}
|
|
1198
1199
|
catch (e) {
|
|
1199
1200
|
if (!(e instanceof PoisonError))
|
|
@@ -1209,9 +1210,9 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1209
1210
|
// value references resolve through genericFnsBySymbol, and the
|
|
1210
1211
|
// statement lowering skips by the same test.
|
|
1211
1212
|
{
|
|
1212
|
-
const implicitNode = implicitLocalFnNodeOf(
|
|
1213
|
+
const implicitNode = implicitLocalFnNodeOf(lowerer, decl);
|
|
1213
1214
|
if (implicitNode) {
|
|
1214
|
-
implicitLocalFnInfoOf(
|
|
1215
|
+
implicitLocalFnInfoOf(lowerer, decl, implicitNode);
|
|
1215
1216
|
continue;
|
|
1216
1217
|
}
|
|
1217
1218
|
}
|
|
@@ -1220,7 +1221,7 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1220
1221
|
// branch above): no global exists — calls instantiate the class
|
|
1221
1222
|
// inside per site (lower-mixins.ts); the statement lowering skips
|
|
1222
1223
|
// by the same test.
|
|
1223
|
-
if (isMixinFnBinding(
|
|
1224
|
+
if (isMixinFnBinding(lowerer, decl))
|
|
1224
1225
|
continue;
|
|
1225
1226
|
// `const Thing1 = Tagged(Derived)` — a mixin RESULT binding: the
|
|
1226
1227
|
// binding provably holds that one call's class object forever
|
|
@@ -1236,9 +1237,9 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1236
1237
|
while (ts.isParenthesizedExpression(init))
|
|
1237
1238
|
init = init.expression;
|
|
1238
1239
|
if (ts.isCallExpression(init)) {
|
|
1239
|
-
const bindSym =
|
|
1240
|
+
const bindSym = lowerer.checker.getSymbolAtLocation(decl.name);
|
|
1240
1241
|
try {
|
|
1241
|
-
if (mixinResultBindingClassOf(
|
|
1242
|
+
if (mixinResultBindingClassOf(lowerer, bindSym))
|
|
1242
1243
|
continue;
|
|
1243
1244
|
}
|
|
1244
1245
|
catch (e) {
|
|
@@ -1254,9 +1255,9 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1254
1255
|
// statement lowering skips the declaration by the same check. A
|
|
1255
1256
|
// bad promisify target reports here (recorded once; the statement
|
|
1256
1257
|
// lowering poisons too, like every collectGlobals failure).
|
|
1257
|
-
if (ts.isIdentifier(decl.name) && decl.initializer && isPromisifyCall(
|
|
1258
|
+
if (ts.isIdentifier(decl.name) && decl.initializer && isPromisifyCall(lowerer, decl.initializer)) {
|
|
1258
1259
|
try {
|
|
1259
|
-
|
|
1260
|
+
lowerer.promisifiedExecFileDecl(decl.name, decl.initializer);
|
|
1260
1261
|
}
|
|
1261
1262
|
catch (e) {
|
|
1262
1263
|
if (!(e instanceof PoisonError))
|
|
@@ -1273,45 +1274,45 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1273
1274
|
// `const require = createRequire(import.meta.url)` at file scope:
|
|
1274
1275
|
// compile-time plumbing — no global storage; the statement
|
|
1275
1276
|
// lowering skips it by the same test.
|
|
1276
|
-
if (isConst && createRequireBindingDecl(
|
|
1277
|
+
if (isConst && createRequireBindingDecl(lowerer, decl.name, decl.initializer))
|
|
1277
1278
|
continue;
|
|
1278
1279
|
// `const fs = require("node:fs")` through that binding at file
|
|
1279
1280
|
// scope — a namespace import in const clothing, same story.
|
|
1280
|
-
if (isConst && createRequireNamespaceDecl(
|
|
1281
|
+
if (isConst && createRequireNamespaceDecl(lowerer, decl.name, decl.initializer))
|
|
1281
1282
|
continue;
|
|
1282
1283
|
// `const { createSign } = crypto` over a builtin NAMESPACE binding
|
|
1283
1284
|
// at file scope: alias plumbing like the destructured-require form
|
|
1284
1285
|
// — no storage (the statement lowering skips by the same test).
|
|
1285
|
-
if (builtinNamespaceDestructureModuleOf(
|
|
1286
|
+
if (builtinNamespaceDestructureModuleOf(lowerer, decl) !== null)
|
|
1286
1287
|
continue;
|
|
1287
1288
|
// `const { NGHTTP2_CANCEL } = http2.constants` at file scope: a
|
|
1288
1289
|
// destructure over the baked constants table — alias plumbing, no
|
|
1289
1290
|
// global storage (the statement lowering skips it by the same
|
|
1290
1291
|
// test).
|
|
1291
|
-
if (
|
|
1292
|
+
if (lowerer.builtinConstantsDestructureDecl(decl.name, decl.initializer))
|
|
1292
1293
|
continue;
|
|
1293
1294
|
// `const Writable = stream.Writable` at file scope: a stream
|
|
1294
1295
|
// class through the namespace binding — alias plumbing, no
|
|
1295
1296
|
// global storage (the statement lowering skips it by the same
|
|
1296
1297
|
// test).
|
|
1297
|
-
if (isConst && streamClassAliasDecl(
|
|
1298
|
+
if (isConst && streamClassAliasDecl(lowerer, decl.name, decl.initializer))
|
|
1298
1299
|
continue;
|
|
1299
1300
|
// `const process = globalThis.process` at file scope: a stdlib-
|
|
1300
1301
|
// global snapshot — alias plumbing, no global storage (see
|
|
1301
1302
|
// stdlibGlobalAliasDecl; the statement lowering skips it by the
|
|
1302
1303
|
// same test).
|
|
1303
|
-
if (isConst && stdlibGlobalAliasDecl(
|
|
1304
|
+
if (isConst && stdlibGlobalAliasDecl(lowerer, decl.name, decl.initializer))
|
|
1304
1305
|
continue;
|
|
1305
1306
|
// Stored default TextEncoder/TextDecoder instances are the same
|
|
1306
1307
|
// compile-time alias plumbing as their statement lowering: calls
|
|
1307
1308
|
// trace this const initializer, so no module global exists.
|
|
1308
|
-
if (isConst && textCodecBindingDecl(
|
|
1309
|
+
if (isConst && textCodecBindingDecl(lowerer, decl.name, decl.initializer))
|
|
1309
1310
|
continue;
|
|
1310
1311
|
// Destructuring declarations register EVERY bound identifier (the
|
|
1311
1312
|
// desugar in the init function assigns the pre-registered globals,
|
|
1312
1313
|
// exactly like plain declarations).
|
|
1313
1314
|
for (const nameNode of boundIdentifiersOf(decl.name)) {
|
|
1314
|
-
const diagsBefore =
|
|
1315
|
+
const diagsBefore = lowerer.diags.length;
|
|
1315
1316
|
try {
|
|
1316
1317
|
// A JS file-scope evolving ARRAY (`const mustCallChecks = [];`
|
|
1317
1318
|
// — test/common's exit-accounting ledger): the strict type
|
|
@@ -1322,14 +1323,14 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1322
1323
|
// storage instead of fencing per reference. Identifier
|
|
1323
1324
|
// declarations only: a destructured array literal binds its
|
|
1324
1325
|
// pieces, not the array.
|
|
1325
|
-
if (isJsSourceFile(sf) && !
|
|
1326
|
+
if (isJsSourceFile(sf) && !lowerer.mapTypeOf(lowerer.typeOf(nameNode)) &&
|
|
1326
1327
|
ts.isIdentifier(decl.name) && nameNode === decl.name &&
|
|
1327
1328
|
decl.initializer !== undefined && ts.isArrayLiteralExpression(decl.initializer)) {
|
|
1328
|
-
const symbol =
|
|
1329
|
+
const symbol = lowerer.checker.getSymbolAtLocation(nameNode);
|
|
1329
1330
|
if (symbol) {
|
|
1330
1331
|
const g = { id: `%g.${tag}${nameNode.text}`, name: nameNode.text, type: DYN, mutable: isLet };
|
|
1331
|
-
|
|
1332
|
-
|
|
1332
|
+
lowerer.globalsBySymbol.set(symbol, g);
|
|
1333
|
+
lowerer.globalsList.push(g);
|
|
1333
1334
|
}
|
|
1334
1335
|
continue;
|
|
1335
1336
|
}
|
|
@@ -1353,15 +1354,15 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1353
1354
|
decl.initializer.properties.every((p) => {
|
|
1354
1355
|
if (!ts.isPropertyAssignment(p) || ts.isComputedPropertyName(p.name))
|
|
1355
1356
|
return false;
|
|
1356
|
-
const mt =
|
|
1357
|
+
const mt = lowerer.mapTypeOf(lowerer.typeOf(p.initializer));
|
|
1357
1358
|
return mt === null || mt.kind === "dyn" ||
|
|
1358
|
-
canConvertToDyn(mt, (id) =>
|
|
1359
|
+
canConvertToDyn(mt, (id) => lowerer.shapes.get(id), (id) => lowerer.unions.get(id));
|
|
1359
1360
|
})) {
|
|
1360
|
-
const symbol =
|
|
1361
|
-
if (symbol && !
|
|
1361
|
+
const symbol = lowerer.checker.getSymbolAtLocation(nameNode);
|
|
1362
|
+
if (symbol && !lowerer.globalsBySymbol.has(symbol)) {
|
|
1362
1363
|
const g = { id: `%g.${tag}${nameNode.text}`, name: nameNode.text, type: DYN, mutable: isLet };
|
|
1363
|
-
|
|
1364
|
-
|
|
1364
|
+
lowerer.globalsBySymbol.set(symbol, g);
|
|
1365
|
+
lowerer.globalsList.push(g);
|
|
1365
1366
|
}
|
|
1366
1367
|
continue;
|
|
1367
1368
|
}
|
|
@@ -1378,21 +1379,21 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1378
1379
|
// decl keeps as an %init local) stay OUT: forcing those into
|
|
1379
1380
|
// the checked-dynamic tree would trade their working typed representation for
|
|
1380
1381
|
// fences.
|
|
1381
|
-
if (isJsSourceFile(sf) && !
|
|
1382
|
+
if (isJsSourceFile(sf) && !lowerer.mapTypeOf(lowerer.typeOf(nameNode)) &&
|
|
1382
1383
|
ts.isIdentifier(decl.name) && nameNode === decl.name &&
|
|
1383
|
-
jsDynHoldableInitializer(
|
|
1384
|
-
dynFallbackType(
|
|
1385
|
-
const symbol =
|
|
1386
|
-
if (symbol && !
|
|
1384
|
+
jsDynHoldableInitializer(lowerer, decl.initializer) &&
|
|
1385
|
+
dynFallbackType(lowerer, nameNode, lowerer.typeOf(nameNode))?.kind === "dyn") {
|
|
1386
|
+
const symbol = lowerer.checker.getSymbolAtLocation(nameNode);
|
|
1387
|
+
if (symbol && !lowerer.globalsBySymbol.has(symbol)) {
|
|
1387
1388
|
const g = { id: `%g.${tag}${nsPrefix}${nameNode.text}`, name: nameNode.text, type: DYN, mutable: isLet };
|
|
1388
|
-
|
|
1389
|
-
|
|
1389
|
+
lowerer.globalsBySymbol.set(symbol, g);
|
|
1390
|
+
lowerer.globalsList.push(g);
|
|
1390
1391
|
// Mutable dyn globals hold the dyn undefined from module
|
|
1391
1392
|
// entry (the main path's rule below): a closure called
|
|
1392
1393
|
// above the declaration reads undefined instead of
|
|
1393
1394
|
// faulting on NULL.
|
|
1394
1395
|
if (g.mutable)
|
|
1395
|
-
noteVarGlobalEntryInit(
|
|
1396
|
+
noteVarGlobalEntryInit(lowerer, sf, g);
|
|
1396
1397
|
}
|
|
1397
1398
|
continue;
|
|
1398
1399
|
}
|
|
@@ -1403,15 +1404,15 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1403
1404
|
// the binding holds the HANDLE — a jsval global, so exports
|
|
1404
1405
|
// and separately-declared functions reach the same engine
|
|
1405
1406
|
// object.
|
|
1406
|
-
if (
|
|
1407
|
+
if (lowerer.dynamic && isJsSourceFile(sf) && !lowerer.mapTypeOf(lowerer.typeOf(nameNode)) &&
|
|
1407
1408
|
ts.isIdentifier(decl.name) && nameNode === decl.name &&
|
|
1408
1409
|
decl.initializer !== undefined && ts.isObjectLiteralExpression(decl.initializer) &&
|
|
1409
1410
|
decl.initializer.properties.some((p) => ts.isGetAccessorDeclaration(p))) {
|
|
1410
|
-
const symbol =
|
|
1411
|
-
if (symbol && !
|
|
1411
|
+
const symbol = lowerer.checker.getSymbolAtLocation(nameNode);
|
|
1412
|
+
if (symbol && !lowerer.globalsBySymbol.has(symbol)) {
|
|
1412
1413
|
const g = { id: `%g.${tag}${nsPrefix}${nameNode.text}`, name: nameNode.text, type: JSVAL, mutable: isLet };
|
|
1413
|
-
|
|
1414
|
-
|
|
1414
|
+
lowerer.globalsBySymbol.set(symbol, g);
|
|
1415
|
+
lowerer.globalsList.push(g);
|
|
1415
1416
|
}
|
|
1416
1417
|
continue;
|
|
1417
1418
|
}
|
|
@@ -1422,20 +1423,20 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1422
1423
|
// and closures created in the init body capture it normally.
|
|
1423
1424
|
// References from separately-declared functions cascade to
|
|
1424
1425
|
// their own per-site runtime fences.
|
|
1425
|
-
if (isJsSourceFile(sf) && !
|
|
1426
|
+
if (isJsSourceFile(sf) && !lowerer.mapTypeOf(lowerer.typeOf(nameNode)))
|
|
1426
1427
|
continue;
|
|
1427
1428
|
// `var p1 = import("./m")` at file scope: the global holds the
|
|
1428
1429
|
// island promise/handle — the import expression's only
|
|
1429
1430
|
// production — whatever the checker's namespace type mapped to
|
|
1430
1431
|
// (lowerVarDecl's rule at module scope; the init body assigns
|
|
1431
1432
|
// it).
|
|
1432
|
-
const handleT =
|
|
1433
|
+
const handleT = lowerer.dynamic && ts.isIdentifier(decl.name) && nameNode === decl.name
|
|
1433
1434
|
? (importCallHandleType(decl.initializer) ??
|
|
1434
1435
|
// An unchecked-overload call result stores the handle,
|
|
1435
1436
|
// exactly the local rule (uncheckedOverloadHandleCall).
|
|
1436
|
-
(uncheckedOverloadHandleCall(
|
|
1437
|
+
(uncheckedOverloadHandleCall(lowerer, decl.initializer) ? JSVAL : null))
|
|
1437
1438
|
: null;
|
|
1438
|
-
let type = handleT ??
|
|
1439
|
+
let type = handleT ?? lowerer.irTypeOf(nameNode);
|
|
1439
1440
|
// An evolving-`any` array's DERIVED file-scope binding under
|
|
1440
1441
|
// --dynamic (`const kept = fns.filter(...)` where `fns`
|
|
1441
1442
|
// registered array<jsval> at its `any[]` declaration): the
|
|
@@ -1446,10 +1447,10 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1446
1447
|
// element array (lowerVarDecl's adoption, the file-scope
|
|
1447
1448
|
// face). Annotated declarations keep the validated-boundary
|
|
1448
1449
|
// fence.
|
|
1449
|
-
if (
|
|
1450
|
+
if (lowerer.dynamic && ts.isIdentifier(decl.name) && nameNode === decl.name &&
|
|
1450
1451
|
decl.type === undefined && decl.initializer !== undefined &&
|
|
1451
1452
|
type.kind === "array" && type.elem.kind !== "jsval" &&
|
|
1452
|
-
handleArrayPreservingCall(
|
|
1453
|
+
handleArrayPreservingCall(lowerer, decl.initializer)) {
|
|
1453
1454
|
type = arrayOf(JSVAL);
|
|
1454
1455
|
}
|
|
1455
1456
|
// `const r: Repo = new MemRepo()` over an all-generic-method
|
|
@@ -1458,8 +1459,8 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1458
1459
|
// copy would drop the class the generic-method calls
|
|
1459
1460
|
// monomorphize against) — see genericIfaceBindingKeepsClass.
|
|
1460
1461
|
if (type.kind === "record" && ts.isIdentifier(decl.name) && nameNode === decl.name &&
|
|
1461
|
-
genericIfaceBindingKeepsClass(
|
|
1462
|
-
const initT =
|
|
1462
|
+
genericIfaceBindingKeepsClass(lowerer, decl, type)) {
|
|
1463
|
+
const initT = lowerer.mapTypeOf(lowerer.typeOf(decl.initializer));
|
|
1463
1464
|
if (initT?.kind === "object")
|
|
1464
1465
|
type = initT;
|
|
1465
1466
|
}
|
|
@@ -1470,8 +1471,8 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1470
1471
|
// primitives exit eagerly to their static type, everything
|
|
1471
1472
|
// else stores the HANDLE (a func-typed slot could never take
|
|
1472
1473
|
// the engine value the desugar assigns).
|
|
1473
|
-
if (
|
|
1474
|
-
const srcT =
|
|
1474
|
+
if (lowerer.dynamic && !ts.isIdentifier(decl.name) && decl.initializer !== undefined) {
|
|
1475
|
+
const srcT = lowerer.mapTypeOf(lowerer.typeOf(decl.initializer));
|
|
1475
1476
|
const island = srcT !== null &&
|
|
1476
1477
|
(srcT.kind === "jsval" || srcT.kind === "f64" || srcT.kind === "bool" ||
|
|
1477
1478
|
srcT.kind === "string" || isUnitType(srcT));
|
|
@@ -1482,11 +1483,11 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1482
1483
|
// File-scope unit-only bindings (`var x: undefined`, `const
|
|
1483
1484
|
// y: void = undefined`) ride the unit-only union, exactly
|
|
1484
1485
|
// like function-scope locals (lowerVarDecl's rule).
|
|
1485
|
-
if (type.kind === "void" && isUnitOnlyTsType(
|
|
1486
|
-
type = unitOnlyUnion(
|
|
1486
|
+
if (type.kind === "void" && isUnitOnlyTsType(lowerer.typeOf(nameNode))) {
|
|
1487
|
+
type = unitOnlyUnion(lowerer.unions);
|
|
1487
1488
|
}
|
|
1488
1489
|
if (type.kind === "void")
|
|
1489
|
-
|
|
1490
|
+
lowerer.badType(nameNode, lowerer.typeOf(nameNode));
|
|
1490
1491
|
// A JS file-scope FUNCTION binding whose unannotated return
|
|
1491
1492
|
// infers a record (`const wrapped = function () { return
|
|
1492
1493
|
// expectedResult; }`): the closure VALUE lowers with a dyn
|
|
@@ -1508,15 +1509,15 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1508
1509
|
// type admits ANY later non-nullish assignment, so the static
|
|
1509
1510
|
// empty struct cannot hold the binding's future.
|
|
1510
1511
|
if (isLet && type.kind === "record" && isJsSourceFile(sf)) {
|
|
1511
|
-
const shape =
|
|
1512
|
+
const shape = lowerer.shapes.get(type.shapeId);
|
|
1512
1513
|
if (shape && shape.fields.length === 0 && !shape.indexValue && !shape.tuple)
|
|
1513
1514
|
type = DYN;
|
|
1514
1515
|
}
|
|
1515
|
-
const symbol =
|
|
1516
|
+
const symbol = lowerer.checker.getSymbolAtLocation(nameNode);
|
|
1516
1517
|
// Merged `var` redeclarations (`var y = 1; ...; var y = 2;` —
|
|
1517
1518
|
// one symbol) register exactly one global; later declarations
|
|
1518
1519
|
// are plain assignments.
|
|
1519
|
-
if (!symbol ||
|
|
1520
|
+
if (!symbol || lowerer.globalsBySymbol.has(symbol))
|
|
1520
1521
|
continue;
|
|
1521
1522
|
const g = {
|
|
1522
1523
|
id: `%g.${tag}${nsPrefix}${nameNode.text}`,
|
|
@@ -1524,15 +1525,15 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1524
1525
|
type,
|
|
1525
1526
|
mutable: isLet,
|
|
1526
1527
|
};
|
|
1527
|
-
|
|
1528
|
-
|
|
1528
|
+
lowerer.globalsBySymbol.set(symbol, g);
|
|
1529
|
+
lowerer.globalsList.push(g);
|
|
1529
1530
|
// Mutable checked-dynamic LET globals ride the same entry
|
|
1530
1531
|
// init: a closure called above the declaration statement
|
|
1531
1532
|
// reads the dyn undefined instead of faulting on NULL — the
|
|
1532
1533
|
// dyn face of let's documented pre-declaration window (Node
|
|
1533
1534
|
// throws the TDZ ReferenceError there).
|
|
1534
1535
|
if (isVarDeclared(decl) || (g.type.kind === "dyn" && g.mutable)) {
|
|
1535
|
-
noteVarGlobalEntryInit(
|
|
1536
|
+
noteVarGlobalEntryInit(lowerer, sf, g);
|
|
1536
1537
|
}
|
|
1537
1538
|
}
|
|
1538
1539
|
catch (e) {
|
|
@@ -1541,7 +1542,7 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1541
1542
|
// diagnostic already recorded; lowering the statement poisons
|
|
1542
1543
|
// too — and in a JS file BOTH defer to the statement's
|
|
1543
1544
|
// runtime fence (deferJsCollectionDiags).
|
|
1544
|
-
deferJsCollectionDiags(
|
|
1545
|
+
deferJsCollectionDiags(lowerer, sf, diagsBefore);
|
|
1545
1546
|
}
|
|
1546
1547
|
}
|
|
1547
1548
|
}
|
|
@@ -1554,7 +1555,7 @@ export function collectGlobals(L, sf, topStmts) {
|
|
|
1554
1555
|
* answers the receiver's own array type). Registration runs in source
|
|
1555
1556
|
* order, so the root's global — declared above, TDZ-guaranteed — is
|
|
1556
1557
|
* already in the table. */
|
|
1557
|
-
function handleArrayPreservingCall(
|
|
1558
|
+
function handleArrayPreservingCall(lowerer, e) {
|
|
1558
1559
|
const PRESERVING = new Set(["filter", "slice", "splice", "concat"]);
|
|
1559
1560
|
let cur = e;
|
|
1560
1561
|
for (;;) {
|
|
@@ -1569,8 +1570,8 @@ function handleArrayPreservingCall(L, e) {
|
|
|
1569
1570
|
}
|
|
1570
1571
|
if (!ts.isIdentifier(cur))
|
|
1571
1572
|
return false;
|
|
1572
|
-
const sym =
|
|
1573
|
-
const g = sym ?
|
|
1573
|
+
const sym = lowerer.checker.getSymbolAtLocation(cur);
|
|
1574
|
+
const g = sym ? lowerer.globalsBySymbol.get(sym) : undefined;
|
|
1574
1575
|
return g?.type.kind === "array" && g.type.elem.kind === "jsval";
|
|
1575
1576
|
}
|
|
1576
1577
|
/** Registers the entry-init note for a `var` module global: JS hoists
|
|
@@ -1582,7 +1583,7 @@ function handleArrayPreservingCall(L, e) {
|
|
|
1582
1583
|
* a value). Other types need nothing: tsc's flow analysis rejects their
|
|
1583
1584
|
* direct early reads, and closure reads share let's documented
|
|
1584
1585
|
* zero/NULL divergence window. */
|
|
1585
|
-
function noteVarGlobalEntryInit(
|
|
1586
|
+
function noteVarGlobalEntryInit(lowerer, sf, g) {
|
|
1586
1587
|
// 'any' globals need the entry init exactly like undefined-armed
|
|
1587
1588
|
// unions: tsc never guards `any` reads, so `var x: any;` is readable
|
|
1588
1589
|
// before any assignment and its slot must hold its world's undefined
|
|
@@ -1591,9 +1592,9 @@ function noteVarGlobalEntryInit(L, sf, g) {
|
|
|
1591
1592
|
// memory-unsafe, not a TypeError).
|
|
1592
1593
|
if (g.type.kind !== "union" && g.type.kind !== "jsval" && g.type.kind !== "dyn")
|
|
1593
1594
|
return;
|
|
1594
|
-
const inits =
|
|
1595
|
+
const inits = lowerer.varGlobalEntryInits.get(sf) ?? [];
|
|
1595
1596
|
inits.push(g);
|
|
1596
|
-
|
|
1597
|
+
lowerer.varGlobalEntryInits.set(sf, inits);
|
|
1597
1598
|
}
|
|
1598
1599
|
/** The nested half of module-scope `var` hoisting: a `var` inside a
|
|
1599
1600
|
* top-level BLOCK (an if arm, a loop body, a try) is module-scoped in
|
|
@@ -1605,7 +1606,7 @@ function noteVarGlobalEntryInit(L, sf, g) {
|
|
|
1605
1606
|
* scope). Registration mirrors the main path's identifier story:
|
|
1606
1607
|
* JS-unmappable types register nothing (per-site fences own the
|
|
1607
1608
|
* references), everything else gets a mutable global. */
|
|
1608
|
-
function collectNestedVarGlobals(
|
|
1609
|
+
function collectNestedVarGlobals(lowerer, sf, stmt, tag) {
|
|
1609
1610
|
const lists = [];
|
|
1610
1611
|
// Iterative walk (walkPreorder): this sweep sees every non-var top-level
|
|
1611
1612
|
// statement whole — the binderBinaryExpressionStress bare ~6500-term
|
|
@@ -1627,35 +1628,35 @@ function collectNestedVarGlobals(L, sf, stmt, tag) {
|
|
|
1627
1628
|
for (const list of lists) {
|
|
1628
1629
|
for (const decl of list.declarations) {
|
|
1629
1630
|
for (const nameNode of boundIdentifiersOf(decl.name)) {
|
|
1630
|
-
const diagsBefore =
|
|
1631
|
+
const diagsBefore = lowerer.diags.length;
|
|
1631
1632
|
try {
|
|
1632
|
-
if (isJsSourceFile(sf) && !
|
|
1633
|
+
if (isJsSourceFile(sf) && !lowerer.mapTypeOf(lowerer.typeOf(nameNode)))
|
|
1633
1634
|
continue;
|
|
1634
|
-
let type =
|
|
1635
|
+
let type = lowerer.irTypeOf(nameNode);
|
|
1635
1636
|
// Nested-var unit-only bindings take the unit-only union too
|
|
1636
1637
|
// (the top-level registration's rule).
|
|
1637
|
-
if (type.kind === "void" && isUnitOnlyTsType(
|
|
1638
|
-
type = unitOnlyUnion(
|
|
1638
|
+
if (type.kind === "void" && isUnitOnlyTsType(lowerer.typeOf(nameNode))) {
|
|
1639
|
+
type = unitOnlyUnion(lowerer.unions);
|
|
1639
1640
|
}
|
|
1640
1641
|
if (type.kind === "void")
|
|
1641
|
-
|
|
1642
|
+
lowerer.badType(nameNode, lowerer.typeOf(nameNode));
|
|
1642
1643
|
if (type.kind === "record" && isJsSourceFile(sf)) {
|
|
1643
|
-
const shape =
|
|
1644
|
+
const shape = lowerer.shapes.get(type.shapeId);
|
|
1644
1645
|
if (shape && shape.fields.length === 0 && !shape.indexValue && !shape.tuple)
|
|
1645
1646
|
type = DYN;
|
|
1646
1647
|
}
|
|
1647
|
-
const symbol =
|
|
1648
|
-
if (!symbol ||
|
|
1648
|
+
const symbol = lowerer.checker.getSymbolAtLocation(nameNode);
|
|
1649
|
+
if (!symbol || lowerer.globalsBySymbol.has(symbol))
|
|
1649
1650
|
continue;
|
|
1650
1651
|
const g = { id: `%g.${tag}${nameNode.text}`, name: nameNode.text, type, mutable: true };
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
noteVarGlobalEntryInit(
|
|
1652
|
+
lowerer.globalsBySymbol.set(symbol, g);
|
|
1653
|
+
lowerer.globalsList.push(g);
|
|
1654
|
+
noteVarGlobalEntryInit(lowerer, sf, g);
|
|
1654
1655
|
}
|
|
1655
1656
|
catch (e) {
|
|
1656
1657
|
if (!(e instanceof PoisonError))
|
|
1657
1658
|
throw e;
|
|
1658
|
-
deferJsCollectionDiags(
|
|
1659
|
+
deferJsCollectionDiags(lowerer, sf, diagsBefore);
|
|
1659
1660
|
}
|
|
1660
1661
|
}
|
|
1661
1662
|
}
|
|
@@ -1666,8 +1667,8 @@ function collectNestedVarGlobals(L, sf, stmt, tag) {
|
|
|
1666
1667
|
* the default's global by it makes every importer resolve to the same
|
|
1667
1668
|
* storage through the ordinary globalOf path. Null for modules without
|
|
1668
1669
|
* a default export (or non-module files). */
|
|
1669
|
-
export function defaultExportSymbolOf(
|
|
1670
|
-
const moduleSym =
|
|
1670
|
+
export function defaultExportSymbolOf(lowerer, sf) {
|
|
1671
|
+
const moduleSym = lowerer.checker.getSymbolAtLocation(sf);
|
|
1671
1672
|
return moduleSym?.getExports().get(ts.InternalSymbolName.Default) ?? null;
|
|
1672
1673
|
}
|
|
1673
1674
|
/** The declaration symbol of a top-level function/class declaration,
|
|
@@ -1677,14 +1678,14 @@ export function defaultExportSymbolOf(L, sf) {
|
|
|
1677
1678
|
* symbol (the binder declares it there), so collection, reachability,
|
|
1678
1679
|
* and body lowering all key that one identity — which is also what a
|
|
1679
1680
|
* default import's alias chain resolves to. */
|
|
1680
|
-
export function declSymbolOf(
|
|
1681
|
+
export function declSymbolOf(lowerer, decl) {
|
|
1681
1682
|
if (decl.name)
|
|
1682
|
-
return
|
|
1683
|
+
return lowerer.checker.getSymbolAtLocation(decl.name);
|
|
1683
1684
|
const isDefault = ts.canHaveModifiers(decl) &&
|
|
1684
1685
|
ts.getModifiers(decl)?.some((m) => m.kind === ts.SyntaxKind.DefaultKeyword) === true;
|
|
1685
1686
|
if (!isDefault)
|
|
1686
1687
|
return undefined;
|
|
1687
|
-
const sym = defaultExportSymbolOf(
|
|
1688
|
+
const sym = defaultExportSymbolOf(lowerer, decl.getSourceFile());
|
|
1688
1689
|
return sym ?? undefined;
|
|
1689
1690
|
}
|
|
1690
1691
|
/** `export default <expr>` in a module's init body: the first (and only)
|
|
@@ -1700,11 +1701,11 @@ export function declSymbolOf(L, decl) {
|
|
|
1700
1701
|
* registration (collection reported the blocker) re-lowers the
|
|
1701
1702
|
* expression so the expression's OWN diagnostic wins when it has one,
|
|
1702
1703
|
* then poisons. */
|
|
1703
|
-
export function lowerDefaultExport(
|
|
1704
|
-
const symbol = defaultExportSymbolOf(
|
|
1705
|
-
if (symbol && symbol.flags & ts.SymbolFlags.Alias && !
|
|
1704
|
+
export function lowerDefaultExport(lowerer, stmt) {
|
|
1705
|
+
const symbol = defaultExportSymbolOf(lowerer, stmt.getSourceFile());
|
|
1706
|
+
if (symbol && symbol.flags & ts.SymbolFlags.Alias && !lowerer.globalsBySymbol.has(symbol))
|
|
1706
1707
|
return null;
|
|
1707
|
-
const g = symbol ?
|
|
1708
|
+
const g = symbol ? lowerer.globalsBySymbol.get(symbol) : undefined;
|
|
1708
1709
|
if (!g) {
|
|
1709
1710
|
// A provably-throwing decorated class expression registered no
|
|
1710
1711
|
// storage (the registration pass skipped it): the statement IS the
|
|
@@ -1716,14 +1717,14 @@ export function lowerDefaultExport(L, stmt) {
|
|
|
1716
1717
|
if (ts.isClassExpression(inner) && !isJsSourceFile(stmt.getSourceFile()) &&
|
|
1717
1718
|
inner.typeParameters === undefined &&
|
|
1718
1719
|
(decoratorNodesOf(inner).length > 0 || inner.members.some((m) => decoratorNodesOf(m).length > 0)) &&
|
|
1719
|
-
guaranteedDecorationThrow(
|
|
1720
|
-
return { kind: "exprStmt", expr:
|
|
1720
|
+
guaranteedDecorationThrow(lowerer, inner) !== null) {
|
|
1721
|
+
return { kind: "exprStmt", expr: lowerer.lowerExpr(stmt.expression), loc: locOf(stmt) };
|
|
1721
1722
|
}
|
|
1722
1723
|
}
|
|
1723
|
-
|
|
1724
|
-
|
|
1724
|
+
lowerer.lowerExpr(stmt.expression);
|
|
1725
|
+
lowerer.badType(stmt.expression, lowerer.typeOf(stmt.expression));
|
|
1725
1726
|
}
|
|
1726
|
-
const value =
|
|
1727
|
+
const value = lowerer.lowerExprExpecting(stmt.expression, g.type);
|
|
1727
1728
|
return { kind: "assign", localId: g.id, value, loc: locOf(stmt) };
|
|
1728
1729
|
}
|
|
1729
1730
|
/** One file's top-level statements as its init function — RUN-ONCE like a
|
|
@@ -1740,16 +1741,16 @@ export function lowerDefaultExport(L, stmt) {
|
|
|
1740
1741
|
* inline in the body. JSON-import bindings (pure data) load next; then
|
|
1741
1742
|
* the body. Top-level var statements assign the pre-registered globals
|
|
1742
1743
|
* instead of declaring locals. */
|
|
1743
|
-
export function lowerFileInit(
|
|
1744
|
-
const isAsync =
|
|
1744
|
+
export function lowerFileInit(lowerer, sf, stmts, name) {
|
|
1745
|
+
const isAsync = lowerer.asyncInitFiles.has(sf);
|
|
1745
1746
|
const ctx = newFnCtx(false, null, null, VOID);
|
|
1746
1747
|
ctx.isAsync = isAsync;
|
|
1747
|
-
|
|
1748
|
+
lowerer.fnStack.push(ctx);
|
|
1748
1749
|
try {
|
|
1749
1750
|
const loc0 = { file: sf.fileName, start: 0, end: 0 };
|
|
1750
1751
|
const header = [];
|
|
1751
1752
|
const asyncDeps = [];
|
|
1752
|
-
const guardId =
|
|
1753
|
+
const guardId = lowerer.moduleGuardOf.get(sf);
|
|
1753
1754
|
if (guardId !== undefined) {
|
|
1754
1755
|
header.push({
|
|
1755
1756
|
kind: "if",
|
|
@@ -1768,8 +1769,8 @@ export function lowerFileInit(L, sf, stmts, name) {
|
|
|
1768
1769
|
loc: loc0,
|
|
1769
1770
|
});
|
|
1770
1771
|
}
|
|
1771
|
-
for (const { stmt, dep } of orderedImportsOf(
|
|
1772
|
-
const npm =
|
|
1772
|
+
for (const { stmt, dep } of orderedImportsOf(lowerer.program, sf)) {
|
|
1773
|
+
const npm = lowerer.npmInitActions.get(sf)?.get(stmt);
|
|
1773
1774
|
if (npm !== undefined && npm.length > 0) {
|
|
1774
1775
|
header.push(...npm);
|
|
1775
1776
|
}
|
|
@@ -1778,12 +1779,12 @@ export function lowerFileInit(L, sf, stmts, name) {
|
|
|
1778
1779
|
// to the importing module): Node answers it from the module
|
|
1779
1780
|
// cache mid-evaluation — no re-evaluation, nothing to call (and
|
|
1780
1781
|
// the ENTRY has no run-once guard, so a self-call would recurse).
|
|
1781
|
-
const depInit =
|
|
1782
|
+
const depInit = lowerer.initNameOf.get(dep);
|
|
1782
1783
|
if (depInit !== undefined) {
|
|
1783
1784
|
const loc = locOf(stmt);
|
|
1784
|
-
const depAsync =
|
|
1785
|
+
const depAsync = lowerer.asyncInitFiles.has(dep);
|
|
1785
1786
|
if (depAsync && !isAsync) {
|
|
1786
|
-
|
|
1787
|
+
lowerer.unsupported("SC1090", stmt, `loading '${dep.fileName}' from a CommonJS module ` +
|
|
1787
1788
|
"(the required ES-module graph uses top-level await; use import() instead)");
|
|
1788
1789
|
}
|
|
1789
1790
|
const call = {
|
|
@@ -1798,10 +1799,10 @@ export function lowerFileInit(L, sf, stmts, name) {
|
|
|
1798
1799
|
// any of them. ECMAScript's module evaluator continues into
|
|
1799
1800
|
// later sibling dependencies while an earlier one is
|
|
1800
1801
|
// suspended; the importer body waits for all of them.
|
|
1801
|
-
const p =
|
|
1802
|
+
const p = lowerer.declareHiddenLocal("%depInit", { kind: "promise", inner: VOID });
|
|
1802
1803
|
header.push({ kind: "varDecl", localId: p.id, init: call, loc });
|
|
1803
|
-
const sfCycle =
|
|
1804
|
-
const depCycle =
|
|
1804
|
+
const sfCycle = lowerer.asyncCycleRepresentativeOf.get(sf);
|
|
1805
|
+
const depCycle = lowerer.asyncCycleRepresentativeOf.get(dep);
|
|
1805
1806
|
const cycleInternal = sfCycle !== undefined && sfCycle === depCycle;
|
|
1806
1807
|
// An importer outside the requested member's SCC waits for
|
|
1807
1808
|
// the SCC's RUNTIME root, not merely that member's promise.
|
|
@@ -1812,7 +1813,7 @@ export function lowerFileInit(L, sf, stmts, name) {
|
|
|
1812
1813
|
// keep the member promise: their guard-hit completion is what
|
|
1813
1814
|
// breaks recursive evaluation without an await hop.
|
|
1814
1815
|
const completionId = !cycleInternal && depCycle !== undefined
|
|
1815
|
-
?
|
|
1816
|
+
? lowerer.asyncCyclePromiseOf.get(dep)
|
|
1816
1817
|
: p.id;
|
|
1817
1818
|
asyncDeps.push({
|
|
1818
1819
|
completionId,
|
|
@@ -1877,20 +1878,20 @@ export function lowerFileInit(L, sf, stmts, name) {
|
|
|
1877
1878
|
// a function called above the declaration reads `undefined`, exactly
|
|
1878
1879
|
// Node); checked-dynamic var globals hold the dyn undefined the same
|
|
1879
1880
|
// way. After the guard: a cache-hit revisit must not reset them.
|
|
1880
|
-
for (const g of
|
|
1881
|
-
const wrapped = g.type.kind === "dyn" ? dynUndefinedExpr(loc0) :
|
|
1881
|
+
for (const g of lowerer.varGlobalEntryInits.get(sf) ?? []) {
|
|
1882
|
+
const wrapped = g.type.kind === "dyn" ? dynUndefinedExpr(loc0) : lowerer.unassignedSlotInit(g.type, loc0);
|
|
1882
1883
|
if (wrapped) {
|
|
1883
1884
|
header.push({ kind: "assign", localId: g.id, value: wrapped, loc: loc0 });
|
|
1884
1885
|
}
|
|
1885
1886
|
}
|
|
1886
|
-
const prelude =
|
|
1887
|
+
const prelude = lowerer.jsonInitActions.get(sf) ?? [];
|
|
1887
1888
|
// Class STATIC readonly fields, static BLOCKS, and class DECORATORS
|
|
1888
1889
|
// run at their class statement's source position (splitFiles hoisted
|
|
1889
1890
|
// the declarations out of `stmts`, so the statements merge back in
|
|
1890
1891
|
// by position) — exactly when JS evaluates decorators, static
|
|
1891
1892
|
// initializers, and blocks, so code reading an earlier module
|
|
1892
1893
|
// binding sees its assigned value.
|
|
1893
|
-
const statics = [...
|
|
1894
|
+
const statics = [...lowerer.classes.values()]
|
|
1894
1895
|
.filter((c) =>
|
|
1895
1896
|
// Class DECLARATIONS only: expression classes run their static
|
|
1896
1897
|
// inits through pendingClassExprInits (below) at the statement
|
|
@@ -1906,7 +1907,7 @@ export function lowerFileInit(L, sf, stmts, name) {
|
|
|
1906
1907
|
// demand order (a nested mixin's base instantiates first, a
|
|
1907
1908
|
// heritage base before its derived class), so the stable sort keeps
|
|
1908
1909
|
// JS's evaluation order at equal positions.
|
|
1909
|
-
for (const c of
|
|
1910
|
+
for (const c of lowerer.classes.values()) {
|
|
1910
1911
|
const ms = c.mixinInstance?.statics;
|
|
1911
1912
|
if (ms && ms.sf === sf)
|
|
1912
1913
|
statics.push({ pos: ms.pos, info: c });
|
|
@@ -1921,17 +1922,17 @@ export function lowerFileInit(L, sf, stmts, name) {
|
|
|
1921
1922
|
// declarations never share a kept statement's start, so `<=`
|
|
1922
1923
|
// changes nothing for them.
|
|
1923
1924
|
while (at < statics.length && statics[at].pos <= stmt.getStart()) {
|
|
1924
|
-
body.push(...
|
|
1925
|
+
body.push(...lowerer.lowerStaticFieldInits(statics[at].info));
|
|
1925
1926
|
at++;
|
|
1926
1927
|
}
|
|
1927
|
-
const stmtIr =
|
|
1928
|
+
const stmtIr = lowerer.lowerStmts([stmt]);
|
|
1928
1929
|
// Class EXPRESSIONS inside this statement queued their static
|
|
1929
1930
|
// inits while it lowered: they land immediately before it — JS's
|
|
1930
1931
|
// order for the supported whole-initializer positions.
|
|
1931
|
-
body.push(...
|
|
1932
|
+
body.push(...lowerer.pendingClassExprInits.splice(0), ...stmtIr);
|
|
1932
1933
|
}
|
|
1933
1934
|
while (at < statics.length) {
|
|
1934
|
-
body.push(...
|
|
1935
|
+
body.push(...lowerer.lowerStaticFieldInits(statics[at].info));
|
|
1935
1936
|
at++;
|
|
1936
1937
|
}
|
|
1937
1938
|
const loc = { file: sf.fileName, start: 0, end: 0 };
|
|
@@ -1939,18 +1940,18 @@ export function lowerFileInit(L, sf, stmts, name) {
|
|
|
1939
1940
|
name,
|
|
1940
1941
|
params: [],
|
|
1941
1942
|
returnType: VOID,
|
|
1942
|
-
locals:
|
|
1943
|
+
locals: lowerer.ctx.locals,
|
|
1943
1944
|
body,
|
|
1944
1945
|
...(isAsync ? { async: true } : {}),
|
|
1945
|
-
...(isAsync ? { asyncCacheGlobal:
|
|
1946
|
-
...(
|
|
1947
|
-
? { asyncCycleCacheGlobal:
|
|
1946
|
+
...(isAsync ? { asyncCacheGlobal: lowerer.modulePromiseOf.get(sf) } : {}),
|
|
1947
|
+
...(lowerer.asyncCyclePromiseOf.has(sf)
|
|
1948
|
+
? { asyncCycleCacheGlobal: lowerer.asyncCyclePromiseOf.get(sf) }
|
|
1948
1949
|
: {}),
|
|
1949
1950
|
loc,
|
|
1950
1951
|
};
|
|
1951
1952
|
}
|
|
1952
1953
|
finally {
|
|
1953
|
-
|
|
1954
|
+
lowerer.fnStack.pop();
|
|
1954
1955
|
}
|
|
1955
1956
|
}
|
|
1956
1957
|
/** %main is just the entry's %init call: Node's whole module evaluation
|
|
@@ -1959,10 +1960,10 @@ export function lowerFileInit(L, sf, stmts, name) {
|
|
|
1959
1960
|
* nesting), CommonJS require statements call dependency inits inline in
|
|
1960
1961
|
* their bodies, and the run-once guards turn every revisit (diamonds,
|
|
1961
1962
|
* re-imports, re-requires) into a cache hit. */
|
|
1962
|
-
export function buildMain(
|
|
1963
|
-
const loc = { file:
|
|
1964
|
-
const entryInit =
|
|
1965
|
-
const isAsync =
|
|
1963
|
+
export function buildMain(lowerer) {
|
|
1964
|
+
const loc = { file: lowerer.entry.fileName, start: 0, end: 0 };
|
|
1965
|
+
const entryInit = lowerer.initNameOf.get(lowerer.entry);
|
|
1966
|
+
const isAsync = lowerer.asyncInitFiles.has(lowerer.entry);
|
|
1966
1967
|
const initCall = entryInit !== undefined
|
|
1967
1968
|
? {
|
|
1968
1969
|
kind: "call",
|
|
@@ -1990,15 +1991,15 @@ export function buildMain(L) {
|
|
|
1990
1991
|
// never runs. The init still lowers — the program must otherwise
|
|
1991
1992
|
// compile, exactly like Node parses every module before its
|
|
1992
1993
|
// fetch/instantiate phases refuse the graph.
|
|
1993
|
-
if (
|
|
1994
|
-
const crashLoc =
|
|
1994
|
+
if (lowerer.startupCrash !== null) {
|
|
1995
|
+
const crashLoc = lowerer.startupCrash.loc;
|
|
1995
1996
|
body.unshift({
|
|
1996
1997
|
kind: "throw",
|
|
1997
1998
|
value: {
|
|
1998
1999
|
kind: "libCall",
|
|
1999
2000
|
fn: "error.new",
|
|
2000
|
-
args: [{ kind: "strLit", value:
|
|
2001
|
-
type: { kind: "object", className:
|
|
2001
|
+
args: [{ kind: "strLit", value: lowerer.startupCrash.message, type: STRING, loc: crashLoc }],
|
|
2002
|
+
type: { kind: "object", className: lowerer.startupCrash.className },
|
|
2002
2003
|
loc: crashLoc,
|
|
2003
2004
|
},
|
|
2004
2005
|
loc: crashLoc,
|