@scriptc/compiler 0.3.6 → 0.4.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 +717 -55
- package/ambient/scriptc.d.ts +134 -0
- package/dist/backend/cycle-analysis.d.ts +1 -1
- package/dist/backend/cycle-analysis.js +1 -0
- package/dist/backend/cycle-analysis.js.map +1 -1
- package/dist/backend/cycle-analysis.test.js +13 -1
- package/dist/backend/cycle-analysis.test.js.map +1 -1
- package/dist/backend/cycle-mutability.js +16 -5
- package/dist/backend/cycle-mutability.js.map +1 -1
- package/dist/backend/executable-features.js +20 -0
- package/dist/backend/executable-features.js.map +1 -1
- package/dist/backend/immutability.test.js +1 -1
- package/dist/backend/library-pack.js +9 -0
- package/dist/backend/library-pack.js.map +1 -1
- package/dist/backend/link-plan-core.d.ts +2 -0
- package/dist/backend/link-plan-core.js +2 -0
- package/dist/backend/link-plan-core.js.map +1 -1
- package/dist/backend/link-plan.d.ts +1 -0
- package/dist/backend/link-plan.js +1 -0
- package/dist/backend/link-plan.js.map +1 -1
- package/dist/backend/llvm/alloc.d.ts +41 -4
- package/dist/backend/llvm/alloc.js +138 -7
- package/dist/backend/llvm/alloc.js.map +1 -1
- package/dist/backend/llvm/alloc.test.js +30 -1
- package/dist/backend/llvm/alloc.test.js.map +1 -1
- package/dist/backend/llvm/appended-array-literals.test.js +1 -1
- package/dist/backend/llvm/array-search.js +3 -1
- package/dist/backend/llvm/array-search.js.map +1 -1
- package/dist/backend/llvm/array-search.test.js +1 -1
- package/dist/backend/llvm/blocks.d.ts +8 -0
- package/dist/backend/llvm/blocks.js +43 -1
- package/dist/backend/llvm/blocks.js.map +1 -1
- package/dist/backend/llvm/blocks.test.js +22 -1
- package/dist/backend/llvm/blocks.test.js.map +1 -1
- package/dist/backend/llvm/byte-numbers.js +15 -5
- package/dist/backend/llvm/byte-numbers.js.map +1 -1
- package/dist/backend/llvm/bytes-alias.d.ts +14 -0
- package/dist/backend/llvm/bytes-alias.js +20 -0
- package/dist/backend/llvm/bytes-alias.js.map +1 -0
- package/dist/backend/llvm/bytes-loop-versions.d.ts +86 -0
- package/dist/backend/llvm/bytes-loop-versions.js +506 -0
- package/dist/backend/llvm/bytes-loop-versions.js.map +1 -0
- package/dist/backend/llvm/bytes-loop-versions.test.d.ts +1 -0
- package/dist/backend/llvm/bytes-loop-versions.test.js +244 -0
- package/dist/backend/llvm/bytes-loop-versions.test.js.map +1 -0
- package/dist/backend/llvm/call-lifetimes.js +50 -1
- package/dist/backend/llvm/call-lifetimes.js.map +1 -1
- package/dist/backend/llvm/call-lifetimes.test.js +34 -0
- package/dist/backend/llvm/call-lifetimes.test.js.map +1 -1
- package/dist/backend/llvm/checked-narrows.test.js +1 -1
- package/dist/backend/llvm/checked-value-lifetimes.js +4 -1
- package/dist/backend/llvm/checked-value-lifetimes.js.map +1 -1
- package/dist/backend/llvm/classes.d.ts +38 -1
- package/dist/backend/llvm/classes.js +185 -35
- package/dist/backend/llvm/classes.js.map +1 -1
- package/dist/backend/llvm/classes.test.js +79 -17
- package/dist/backend/llvm/classes.test.js.map +1 -1
- package/dist/backend/llvm/common.d.ts +21 -3
- package/dist/backend/llvm/common.js +51 -3
- package/dist/backend/llvm/common.js.map +1 -1
- package/dist/backend/llvm/constant-callbacks.d.ts +5 -1
- package/dist/backend/llvm/constant-callbacks.js +55 -12
- package/dist/backend/llvm/constant-callbacks.js.map +1 -1
- package/dist/backend/llvm/constant-callbacks.test.js +88 -1
- package/dist/backend/llvm/constant-callbacks.test.js.map +1 -1
- package/dist/backend/llvm/counted-loops.d.ts +4 -0
- package/dist/backend/llvm/counted-loops.js +37 -0
- package/dist/backend/llvm/counted-loops.js.map +1 -1
- package/dist/backend/llvm/dense-array-access.d.ts +15 -4
- package/dist/backend/llvm/dense-array-access.js +125 -44
- package/dist/backend/llvm/dense-array-access.js.map +1 -1
- package/dist/backend/llvm/dense-array-access.test.js +63 -3
- package/dist/backend/llvm/dense-array-access.test.js.map +1 -1
- package/dist/backend/llvm/dense-array-loops.d.ts +51 -0
- package/dist/backend/llvm/dense-array-loops.js +162 -0
- package/dist/backend/llvm/dense-array-loops.js.map +1 -0
- package/dist/backend/llvm/dense-array-loops.test.d.ts +1 -0
- package/dist/backend/llvm/dense-array-loops.test.js +128 -0
- package/dist/backend/llvm/dense-array-loops.test.js.map +1 -0
- package/dist/backend/llvm/dyn-handle-tags.test.d.ts +1 -0
- package/dist/backend/llvm/dyn-handle-tags.test.js +38 -0
- package/dist/backend/llvm/dyn-handle-tags.test.js.map +1 -0
- package/dist/backend/llvm/dyn.d.ts +37 -4
- package/dist/backend/llvm/dyn.js +354 -183
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emit-function.d.ts +64 -0
- package/dist/backend/llvm/emit-function.js +1193 -0
- package/dist/backend/llvm/emit-function.js.map +1 -0
- package/dist/backend/llvm/emit-module.d.ts +24 -0
- package/dist/backend/llvm/emit-module.js +1557 -0
- package/dist/backend/llvm/emit-module.js.map +1 -0
- package/dist/backend/llvm/emit-statements.d.ts +59 -0
- package/dist/backend/llvm/emit-statements.js +2041 -0
- package/dist/backend/llvm/emit-statements.js.map +1 -0
- package/dist/backend/llvm/emitter.d.ts +566 -291
- package/dist/backend/llvm/emitter.js +728 -4671
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/emitter.test.js +57 -3
- package/dist/backend/llvm/emitter.test.js.map +1 -1
- package/dist/backend/llvm/expr-async.js +73 -46
- package/dist/backend/llvm/expr-async.js.map +1 -1
- package/dist/backend/llvm/expr-async.test.js +1 -1
- package/dist/backend/llvm/expr-bytes.d.ts +2 -0
- package/dist/backend/llvm/expr-bytes.js +76 -29
- package/dist/backend/llvm/expr-bytes.js.map +1 -1
- package/dist/backend/llvm/expr-callbacks.d.ts +6 -2
- package/dist/backend/llvm/expr-callbacks.js +48 -11
- package/dist/backend/llvm/expr-callbacks.js.map +1 -1
- package/dist/backend/llvm/expr-calls.d.ts +1 -1
- package/dist/backend/llvm/expr-calls.js +87 -56
- package/dist/backend/llvm/expr-calls.js.map +1 -1
- package/dist/backend/llvm/expr-calls.test.js +1 -1
- package/dist/backend/llvm/expr-containers.js +45 -24
- package/dist/backend/llvm/expr-containers.js.map +1 -1
- package/dist/backend/llvm/expr-control.js +16 -16
- package/dist/backend/llvm/expr-control.js.map +1 -1
- package/dist/backend/llvm/expr-dynamic.d.ts +3 -0
- package/dist/backend/llvm/expr-dynamic.js +113 -66
- package/dist/backend/llvm/expr-dynamic.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.js +124 -28
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.test.js +57 -2
- package/dist/backend/llvm/expr-primitives.test.js.map +1 -1
- package/dist/backend/llvm/expr-records.d.ts +1 -1
- package/dist/backend/llvm/expr-records.js +32 -11
- package/dist/backend/llvm/expr-records.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.js +65 -27
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.test.js +2 -2
- package/dist/backend/llvm/expr-stream-callbacks.js +22 -1
- package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
- package/dist/backend/llvm/int32-abi.test.js +2 -2
- package/dist/backend/llvm/integer-clones.js +3 -3
- package/dist/backend/llvm/integer-clones.js.map +1 -1
- package/dist/backend/llvm/integer-clones.test.js +3 -3
- package/dist/backend/llvm/integer-remainder.d.ts +34 -13
- package/dist/backend/llvm/integer-remainder.js +156 -22
- package/dist/backend/llvm/integer-remainder.js.map +1 -1
- package/dist/backend/llvm/intern-tables.test.js +1 -1
- package/dist/backend/llvm/js-ic.d.ts +18 -0
- package/dist/backend/llvm/js-ic.js +712 -0
- package/dist/backend/llvm/js-ic.js.map +1 -0
- package/dist/backend/llvm/jsval-encoding.d.ts +21 -0
- package/dist/backend/llvm/jsval-encoding.js +20 -0
- package/dist/backend/llvm/jsval-encoding.js.map +1 -0
- package/dist/backend/llvm/jsval.d.ts +12 -0
- package/dist/backend/llvm/jsval.js +616 -0
- package/dist/backend/llvm/jsval.js.map +1 -0
- package/dist/backend/llvm/lazy-captures.d.ts +12 -2
- package/dist/backend/llvm/lazy-captures.js +39 -17
- package/dist/backend/llvm/lazy-captures.js.map +1 -1
- package/dist/backend/llvm/lib-abi.js +1 -1
- package/dist/backend/llvm/lib-abi.js.map +1 -1
- package/dist/backend/llvm/lib-connect.js +1 -1
- package/dist/backend/llvm/lib-connect.js.map +1 -1
- package/dist/backend/llvm/lib-datagram.js +14 -8
- package/dist/backend/llvm/lib-datagram.js.map +1 -1
- package/dist/backend/llvm/lib-dispatch.js +189 -23
- package/dist/backend/llvm/lib-dispatch.js.map +1 -1
- package/dist/backend/llvm/lib-filesystem.js +42 -13
- package/dist/backend/llvm/lib-filesystem.js.map +1 -1
- package/dist/backend/llvm/lib-http2.js +3 -3
- package/dist/backend/llvm/lib-http2.js.map +1 -1
- package/dist/backend/llvm/lib-lookup.js +2 -2
- package/dist/backend/llvm/lib-lookup.js.map +1 -1
- package/dist/backend/llvm/lib-network.js +56 -22
- package/dist/backend/llvm/lib-network.js.map +1 -1
- package/dist/backend/llvm/lib-process.js +94 -53
- package/dist/backend/llvm/lib-process.js.map +1 -1
- package/dist/backend/llvm/lib-shared.d.ts +12 -0
- package/dist/backend/llvm/lib-shared.js +209 -6
- package/dist/backend/llvm/lib-shared.js.map +1 -1
- package/dist/backend/llvm/lib-stream.js +46 -16
- package/dist/backend/llvm/lib-stream.js.map +1 -1
- package/dist/backend/llvm/lib-test.js +43 -7
- package/dist/backend/llvm/lib-test.js.map +1 -1
- package/dist/backend/llvm/lib-tls.js +4 -9
- package/dist/backend/llvm/lib-tls.js.map +1 -1
- package/dist/backend/llvm/local-array-reads.js +42 -33
- package/dist/backend/llvm/local-array-reads.js.map +1 -1
- package/dist/backend/llvm/local-array-reads.test.js +1 -1
- package/dist/backend/llvm/local-extents.d.ts +19 -0
- package/dist/backend/llvm/local-extents.js +169 -0
- package/dist/backend/llvm/local-extents.js.map +1 -0
- package/dist/backend/llvm/local-extents.test.d.ts +1 -0
- package/dist/backend/llvm/local-extents.test.js +92 -0
- package/dist/backend/llvm/local-extents.test.js.map +1 -0
- package/dist/backend/llvm/local-union-storage.js +7 -7
- package/dist/backend/llvm/local-union-storage.js.map +1 -1
- package/dist/backend/llvm/local-union-storage.test.js +2 -2
- package/dist/backend/llvm/map-entry-fusion.test.js +1 -1
- package/dist/backend/llvm/map-number-lookup.d.ts +20 -4
- package/dist/backend/llvm/map-number-lookup.js +45 -9
- package/dist/backend/llvm/map-number-lookup.js.map +1 -1
- package/dist/backend/llvm/map-number-lookup.test.js +2 -2
- package/dist/backend/llvm/map-read-lifetimes.test.js +2 -2
- package/dist/backend/llvm/narrow-guards.d.ts +38 -0
- package/dist/backend/llvm/narrow-guards.js +215 -0
- package/dist/backend/llvm/narrow-guards.js.map +1 -0
- package/dist/backend/llvm/nullable-unions.d.ts +64 -6
- package/dist/backend/llvm/nullable-unions.js +103 -6
- package/dist/backend/llvm/nullable-unions.js.map +1 -1
- package/dist/backend/llvm/nullable-unions.test.d.ts +1 -0
- package/dist/backend/llvm/nullable-unions.test.js +65 -0
- package/dist/backend/llvm/nullable-unions.test.js.map +1 -0
- package/dist/backend/llvm/publish.d.ts +7 -0
- package/dist/backend/llvm/publish.js +50 -19
- package/dist/backend/llvm/publish.js.map +1 -1
- package/dist/backend/llvm/publish.test.js +1 -1
- package/dist/backend/llvm/receivers.d.ts +31 -0
- package/dist/backend/llvm/receivers.js +395 -0
- package/dist/backend/llvm/receivers.js.map +1 -0
- package/dist/backend/llvm/record-results.d.ts +12 -1
- package/dist/backend/llvm/record-results.js +64 -4
- package/dist/backend/llvm/record-results.js.map +1 -1
- package/dist/backend/llvm/reference-effects.js +9 -0
- package/dist/backend/llvm/reference-effects.js.map +1 -1
- package/dist/backend/llvm/reference-writes.d.ts +4 -0
- package/dist/backend/llvm/reference-writes.js +142 -6
- package/dist/backend/llvm/reference-writes.js.map +1 -1
- package/dist/backend/llvm/reference-writes.test.d.ts +1 -0
- package/dist/backend/llvm/reference-writes.test.js +88 -0
- package/dist/backend/llvm/reference-writes.test.js.map +1 -0
- package/dist/backend/llvm/regex-matchers.d.ts +8 -0
- package/dist/backend/llvm/regex-matchers.js +33 -0
- package/dist/backend/llvm/regex-matchers.js.map +1 -1
- package/dist/backend/llvm/regex-matchers.test.js +23 -1
- package/dist/backend/llvm/regex-matchers.test.js.map +1 -1
- package/dist/backend/llvm/regions.d.ts +1 -1
- package/dist/backend/llvm/regions.js +10 -7
- package/dist/backend/llvm/regions.js.map +1 -1
- package/dist/backend/llvm/regions.test.js +8 -2
- package/dist/backend/llvm/regions.test.js.map +1 -1
- package/dist/backend/llvm/shapes.d.ts +74 -45
- package/dist/backend/llvm/shapes.js +289 -28
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/backend/llvm/shapes.test.js +37 -3
- package/dist/backend/llvm/shapes.test.js.map +1 -1
- package/dist/backend/llvm/speculative-integers.d.ts +20 -1
- package/dist/backend/llvm/speculative-integers.js +94 -6
- package/dist/backend/llvm/speculative-integers.js.map +1 -1
- package/dist/backend/llvm/speculative-integers.test.js +55 -1
- package/dist/backend/llvm/speculative-integers.test.js.map +1 -1
- package/dist/backend/llvm/split-loops.js +2 -2
- package/dist/backend/llvm/split-loops.js.map +1 -1
- package/dist/backend/llvm/stack-objects.d.ts +26 -6
- package/dist/backend/llvm/stack-objects.js +133 -10
- package/dist/backend/llvm/stack-objects.js.map +1 -1
- package/dist/backend/llvm/stack-objects.test.js +55 -1
- package/dist/backend/llvm/stack-objects.test.js.map +1 -1
- package/dist/backend/llvm/stack-unions.test.js +1 -1
- package/dist/backend/llvm/string-construction.test.js +1 -1
- package/dist/backend/llvm/string-lifetimes.test.js +15 -14
- package/dist/backend/llvm/string-lifetimes.test.js.map +1 -1
- package/dist/backend/llvm/string-reads.d.ts +1 -1
- package/dist/backend/llvm/string-reads.js +4 -4
- package/dist/backend/llvm/string-reads.js.map +1 -1
- package/dist/backend/llvm/string-slices.d.ts +25 -0
- package/dist/backend/llvm/string-slices.js +207 -1
- package/dist/backend/llvm/string-slices.js.map +1 -1
- package/dist/backend/llvm/string-slices.test.js +139 -2
- package/dist/backend/llvm/string-slices.test.js.map +1 -1
- package/dist/backend/llvm/switch-dispatch.test.js +2 -2
- package/dist/backend/llvm/thread-slots.d.ts +5 -0
- package/dist/backend/llvm/thread-slots.js +142 -0
- package/dist/backend/llvm/thread-slots.js.map +1 -0
- package/dist/backend/llvm/thread-slots.test.d.ts +1 -0
- package/dist/backend/llvm/thread-slots.test.js +111 -0
- package/dist/backend/llvm/thread-slots.test.js.map +1 -0
- package/dist/backend/llvm/union-repr.d.ts +7 -7
- package/dist/backend/llvm/union-repr.js +18 -2
- package/dist/backend/llvm/union-repr.js.map +1 -1
- package/dist/backend/llvm/union-retype.test.js +17 -3
- package/dist/backend/llvm/union-retype.test.js.map +1 -1
- package/dist/backend/llvm/walkers.d.ts +2 -2
- package/dist/backend/llvm/walkers.js +51 -26
- package/dist/backend/llvm/walkers.js.map +1 -1
- package/dist/backend/llvm/wasm-modules.d.ts +16 -0
- package/dist/backend/llvm/wasm-modules.js +66 -0
- package/dist/backend/llvm/wasm-modules.js.map +1 -0
- package/dist/backend/llvm/wrapping-sums.d.ts +7 -0
- package/dist/backend/llvm/wrapping-sums.js +11 -3
- package/dist/backend/llvm/wrapping-sums.js.map +1 -1
- package/dist/backend/mangle.d.ts +12 -0
- package/dist/backend/mangle.js +18 -0
- package/dist/backend/mangle.js.map +1 -1
- package/dist/backend/may-throw.d.ts +3 -0
- package/dist/backend/may-throw.js +4 -2
- package/dist/backend/may-throw.js.map +1 -1
- package/dist/backend/may-throw.test.js +1 -1
- package/dist/backend/native/contracts.d.ts +57 -0
- package/dist/backend/native/executable.js +211 -139
- package/dist/backend/native/executable.js.map +1 -1
- package/dist/backend/native/library.js +2 -0
- package/dist/backend/native/library.js.map +1 -1
- package/dist/backend/native/runtime-inputs.d.ts +1 -1
- package/dist/backend/native/runtime-inputs.js +1 -0
- package/dist/backend/native/runtime-inputs.js.map +1 -1
- package/dist/backend/native-codegen.d.ts +6 -0
- package/dist/backend/native-codegen.js +19 -0
- package/dist/backend/native-codegen.js.map +1 -1
- package/dist/backend/native-codegen.test.js +27 -0
- package/dist/backend/native-codegen.test.js.map +1 -1
- package/dist/backend/native-link-info-core.d.ts +48 -0
- package/dist/backend/native-link-info-core.js.map +1 -1
- package/dist/backend/native-profile.d.ts +32 -0
- package/dist/backend/native-profile.js +39 -0
- package/dist/backend/native-profile.js.map +1 -0
- package/dist/backend/native-profile.test.d.ts +1 -0
- package/dist/backend/native-profile.test.js +58 -0
- package/dist/backend/native-profile.test.js.map +1 -0
- package/dist/backend/native-tools.d.ts +14 -0
- package/dist/backend/native-tools.js +13 -0
- package/dist/backend/native-tools.js.map +1 -1
- package/dist/backend/publication.test.js +1 -1
- package/dist/backend/runtime-abi.d.ts +2 -2
- package/dist/backend/runtime-abi.js +2 -2
- package/dist/backend/runtime-pack-core.d.ts +13 -1
- package/dist/backend/runtime-pack-core.js +14 -1
- package/dist/backend/runtime-pack-core.js.map +1 -1
- package/dist/backend/runtime-pack-native.js +1 -1
- package/dist/backend/runtime-pack-native.js.map +1 -1
- package/dist/backend/runtime-pack-native.test.d.ts +1 -0
- package/dist/backend/runtime-pack-native.test.js +31 -0
- package/dist/backend/runtime-pack-native.test.js.map +1 -0
- package/dist/backend/runtime-pack-targets.test.js +9 -1
- package/dist/backend/runtime-pack-targets.test.js.map +1 -1
- package/dist/backend/runtime-pack.test.js +9 -1
- package/dist/backend/runtime-pack.test.js.map +1 -1
- package/dist/backend/stack-observations.d.ts +22 -0
- package/dist/backend/stack-observations.js +382 -0
- package/dist/backend/stack-observations.js.map +1 -0
- package/dist/backend/stack-observations.test.d.ts +1 -0
- package/dist/backend/stack-observations.test.js +233 -0
- package/dist/backend/stack-observations.test.js.map +1 -0
- package/dist/backend/target-diagnostics.js +15 -0
- package/dist/backend/target-diagnostics.js.map +1 -1
- package/dist/backend/target-diagnostics.test.js +1 -1
- package/dist/backend/warm-cache.js +8 -0
- package/dist/backend/warm-cache.js.map +1 -1
- package/dist/backend/young-nursery.d.ts +7 -0
- package/dist/backend/young-nursery.js +10 -0
- package/dist/backend/young-nursery.js.map +1 -0
- package/dist/cli/command.js +106 -4
- package/dist/cli/command.js.map +1 -1
- package/dist/cli/host.d.ts +3 -0
- package/dist/cli/output-options.d.ts +2 -0
- package/dist/cli/output-options.js +9 -0
- package/dist/cli/output-options.js.map +1 -1
- package/dist/cli/usage.d.ts +21 -1
- package/dist/cli/usage.js +43 -1
- package/dist/cli/usage.js.map +1 -1
- package/dist/compat/fetch-profile.js +10 -1
- package/dist/compat/fetch-profile.js.map +1 -1
- package/dist/compile-types.d.ts +22 -0
- package/dist/contracts/check.js +25 -8
- package/dist/contracts/check.js.map +1 -1
- package/dist/contracts/int32-elements.d.ts +115 -0
- package/dist/contracts/int32-elements.js +1179 -0
- package/dist/contracts/int32-elements.js.map +1 -0
- package/dist/coverage/report.d.ts +16 -0
- package/dist/coverage/report.js +182 -1
- package/dist/coverage/report.js.map +1 -1
- package/dist/coverage/surface-manifest.js +16 -3
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/coverage/verdict-cache.d.ts +2 -0
- package/dist/coverage/verdict-cache.js +12 -0
- package/dist/coverage/verdict-cache.js.map +1 -1
- package/dist/coverage/verdict-cache.test.js +2 -1
- package/dist/coverage/verdict-cache.test.js.map +1 -1
- package/dist/diagnostics/diagnostic.d.ts +10 -6
- package/dist/diagnostics/diagnostic.js +29 -21
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/diagnostics/envelope.d.ts +39 -2
- package/dist/diagnostics/envelope.js.map +1 -1
- package/dist/diagnostics/render.d.ts +7 -0
- package/dist/diagnostics/render.js +50 -13
- package/dist/diagnostics/render.js.map +1 -1
- package/dist/diagnostics/render.test.d.ts +1 -0
- package/dist/diagnostics/render.test.js +49 -0
- package/dist/diagnostics/render.test.js.map +1 -0
- package/dist/executable/executable-cache.d.ts +27 -0
- package/dist/executable/executable-cache.js +19 -1
- package/dist/executable/executable-cache.js.map +1 -1
- package/dist/executable/executable-cache.test.js +12 -1
- package/dist/executable/executable-cache.test.js.map +1 -1
- package/dist/executable/prepare.js +2 -1
- package/dist/executable/prepare.js.map +1 -1
- package/dist/frontend/analysis.js +6 -1
- package/dist/frontend/analysis.js.map +1 -1
- package/dist/frontend/arguments-usage.d.ts +8 -0
- package/dist/frontend/arguments-usage.js +98 -0
- package/dist/frontend/arguments-usage.js.map +1 -1
- package/dist/frontend/arguments-usage.test.d.ts +1 -0
- package/dist/frontend/arguments-usage.test.js +32 -0
- package/dist/frontend/arguments-usage.test.js.map +1 -0
- package/dist/frontend/builtin-modules.d.ts +16 -2
- package/dist/frontend/builtin-modules.js +40 -7
- package/dist/frontend/builtin-modules.js.map +1 -1
- package/dist/frontend/builtin-package-aliases.d.ts +24 -0
- package/dist/frontend/builtin-package-aliases.js +133 -0
- package/dist/frontend/builtin-package-aliases.js.map +1 -0
- package/dist/frontend/builtin-package-aliases.test.d.ts +1 -0
- package/dist/frontend/builtin-package-aliases.test.js +48 -0
- package/dist/frontend/builtin-package-aliases.test.js.map +1 -0
- package/dist/frontend/cjs-syntax.js +52 -51
- package/dist/frontend/cjs-syntax.js.map +1 -1
- package/dist/frontend/contract-types.d.ts +3 -0
- package/dist/frontend/contract-types.js +36 -7
- package/dist/frontend/contract-types.js.map +1 -1
- package/dist/frontend/dts-paths.d.ts +4 -0
- package/dist/frontend/dts-paths.js +9 -1
- package/dist/frontend/dts-paths.js.map +1 -1
- package/dist/frontend/experimental-import.d.ts +5 -1
- package/dist/frontend/experimental-import.js +26 -7
- package/dist/frontend/experimental-import.js.map +1 -1
- package/dist/frontend/fork-target.js +20 -22
- package/dist/frontend/fork-target.js.map +1 -1
- package/dist/frontend/fork-target.test.js +2 -1
- package/dist/frontend/fork-target.test.js.map +1 -1
- package/dist/frontend/function-completion.js +6 -6
- package/dist/frontend/function-completion.js.map +1 -1
- package/dist/frontend/helper-tokens.js +15 -3
- package/dist/frontend/helper-tokens.js.map +1 -1
- package/dist/frontend/helper-tokens.test.js +7 -1
- package/dist/frontend/helper-tokens.test.js.map +1 -1
- package/dist/frontend/inferred-js-diagnostics.js +14 -17
- package/dist/frontend/inferred-js-diagnostics.js.map +1 -1
- package/dist/frontend/input-tracker.d.ts +3 -0
- package/dist/frontend/input-tracker.js +32 -3
- package/dist/frontend/input-tracker.js.map +1 -1
- package/dist/frontend/lib-contract.js +36 -32
- package/dist/frontend/lib-contract.js.map +1 -1
- package/dist/frontend/lib-exports.js +3 -3
- package/dist/frontend/lib-exports.js.map +1 -1
- package/dist/frontend/lowering/array-values.d.ts +8 -3
- package/dist/frontend/lowering/array-values.js +60 -11
- package/dist/frontend/lowering/array-values.js.map +1 -1
- package/dist/frontend/lowering/assert-instances.js +4 -4
- package/dist/frontend/lowering/assert-instances.js.map +1 -1
- package/dist/frontend/lowering/assertion-identity.d.ts +12 -0
- package/dist/frontend/lowering/assertion-identity.js +70 -0
- package/dist/frontend/lowering/assertion-identity.js.map +1 -0
- package/dist/frontend/lowering/assertion-members.d.ts +28 -0
- package/dist/frontend/lowering/assertion-members.js +185 -0
- package/dist/frontend/lowering/assertion-members.js.map +1 -0
- package/dist/frontend/lowering/binding-analysis.js +27 -20
- package/dist/frontend/lowering/binding-analysis.js.map +1 -1
- package/dist/frontend/lowering/builtin-calls.js +63 -5
- package/dist/frontend/lowering/builtin-calls.js.map +1 -1
- package/dist/frontend/lowering/builtin-function-fences.d.ts +14 -0
- package/dist/frontend/lowering/builtin-function-fences.js +42 -0
- package/dist/frontend/lowering/builtin-function-fences.js.map +1 -0
- package/dist/frontend/lowering/builtins/arguments.js +1 -1
- package/dist/frontend/lowering/builtins/arguments.js.map +1 -1
- package/dist/frontend/lowering/builtins/async-context.js +53 -52
- package/dist/frontend/lowering/builtins/async-context.js.map +1 -1
- package/dist/frontend/lowering/builtins/atomics.js +6 -6
- package/dist/frontend/lowering/builtins/atomics.js.map +1 -1
- package/dist/frontend/lowering/builtins/blob.js +8 -6
- package/dist/frontend/lowering/builtins/blob.js.map +1 -1
- package/dist/frontend/lowering/builtins/builtin-class-dyn.d.ts +31 -0
- package/dist/frontend/lowering/builtins/builtin-class-dyn.js +205 -0
- package/dist/frontend/lowering/builtins/builtin-class-dyn.js.map +1 -0
- package/dist/frontend/lowering/builtins/callable-aliases.js +17 -5
- package/dist/frontend/lowering/builtins/callable-aliases.js.map +1 -1
- package/dist/frontend/lowering/builtins/child-process-async.js +7 -7
- package/dist/frontend/lowering/builtins/child-process-async.js.map +1 -1
- package/dist/frontend/lowering/builtins/child-process-methods.d.ts +6 -4
- package/dist/frontend/lowering/builtins/child-process-methods.js +310 -57
- package/dist/frontend/lowering/builtins/child-process-methods.js.map +1 -1
- package/dist/frontend/lowering/builtins/child-process-sync.js +16 -10
- package/dist/frontend/lowering/builtins/child-process-sync.js.map +1 -1
- package/dist/frontend/lowering/builtins/child-process.d.ts +6 -4
- package/dist/frontend/lowering/builtins/child-process.js +85 -61
- package/dist/frontend/lowering/builtins/child-process.js.map +1 -1
- package/dist/frontend/lowering/builtins/class-values.d.ts +60 -0
- package/dist/frontend/lowering/builtins/class-values.js +226 -0
- package/dist/frontend/lowering/builtins/class-values.js.map +1 -0
- package/dist/frontend/lowering/builtins/compression.d.ts +9 -0
- package/dist/frontend/lowering/builtins/compression.js +107 -44
- package/dist/frontend/lowering/builtins/compression.js.map +1 -1
- package/dist/frontend/lowering/builtins/constants.d.ts +9 -1
- package/dist/frontend/lowering/builtins/constants.js +28 -7
- package/dist/frontend/lowering/builtins/constants.js.map +1 -1
- package/dist/frontend/lowering/builtins/crypto.d.ts +22 -0
- package/dist/frontend/lowering/builtins/crypto.js +215 -38
- package/dist/frontend/lowering/builtins/crypto.js.map +1 -1
- package/dist/frontend/lowering/builtins/dates.d.ts +7 -1
- package/dist/frontend/lowering/builtins/dates.js +92 -16
- package/dist/frontend/lowering/builtins/dates.js.map +1 -1
- package/dist/frontend/lowering/builtins/disposable-stack.d.ts +18 -0
- package/dist/frontend/lowering/builtins/disposable-stack.js +137 -0
- package/dist/frontend/lowering/builtins/disposable-stack.js.map +1 -0
- package/dist/frontend/lowering/builtins/ecdh.d.ts +10 -0
- package/dist/frontend/lowering/builtins/ecdh.js +208 -0
- package/dist/frontend/lowering/builtins/ecdh.js.map +1 -0
- package/dist/frontend/lowering/builtins/environment.js +3 -3
- package/dist/frontend/lowering/builtins/environment.js.map +1 -1
- package/dist/frontend/lowering/builtins/errors.d.ts +14 -10
- package/dist/frontend/lowering/builtins/errors.js +169 -3
- package/dist/frontend/lowering/builtins/errors.js.map +1 -1
- package/dist/frontend/lowering/builtins/filesystem-calls.js +128 -116
- package/dist/frontend/lowering/builtins/filesystem-calls.js.map +1 -1
- package/dist/frontend/lowering/builtins/filesystem.js +77 -77
- package/dist/frontend/lowering/builtins/filesystem.js.map +1 -1
- package/dist/frontend/lowering/builtins/fs-glob.js +3 -3
- package/dist/frontend/lowering/builtins/fs-glob.js.map +1 -1
- package/dist/frontend/lowering/builtins/fs-streams.js +10 -11
- package/dist/frontend/lowering/builtins/fs-streams.js.map +1 -1
- package/dist/frontend/lowering/builtins/ipc.js +45 -8
- package/dist/frontend/lowering/builtins/ipc.js.map +1 -1
- package/dist/frontend/lowering/builtins/json.js +284 -24
- package/dist/frontend/lowering/builtins/json.js.map +1 -1
- package/dist/frontend/lowering/builtins/key-object.js +4 -4
- package/dist/frontend/lowering/builtins/key-object.js.map +1 -1
- package/dist/frontend/lowering/builtins/module-bindings.d.ts +8 -0
- package/dist/frontend/lowering/builtins/module-bindings.js +71 -22
- package/dist/frontend/lowering/builtins/module-bindings.js.map +1 -1
- package/dist/frontend/lowering/builtins/module-calls.js +55 -44
- package/dist/frontend/lowering/builtins/module-calls.js.map +1 -1
- package/dist/frontend/lowering/builtins/module-resolution.d.ts +4 -3
- package/dist/frontend/lowering/builtins/module-resolution.js +24 -23
- package/dist/frontend/lowering/builtins/module-resolution.js.map +1 -1
- package/dist/frontend/lowering/builtins/navigator.d.ts +13 -0
- package/dist/frontend/lowering/builtins/navigator.js +40 -0
- package/dist/frontend/lowering/builtins/navigator.js.map +1 -0
- package/dist/frontend/lowering/builtins/net-address.d.ts +19 -0
- package/dist/frontend/lowering/builtins/net-address.js +156 -0
- package/dist/frontend/lowering/builtins/net-address.js.map +1 -0
- package/dist/frontend/lowering/builtins/numbers.js +25 -9
- package/dist/frontend/lowering/builtins/numbers.js.map +1 -1
- package/dist/frontend/lowering/builtins/operating-system.d.ts +4 -0
- package/dist/frontend/lowering/builtins/operating-system.js +25 -12
- package/dist/frontend/lowering/builtins/operating-system.js.map +1 -1
- package/dist/frontend/lowering/builtins/performance.d.ts +12 -0
- package/dist/frontend/lowering/builtins/performance.js +259 -8
- package/dist/frontend/lowering/builtins/performance.js.map +1 -1
- package/dist/frontend/lowering/builtins/process.d.ts +41 -1
- package/dist/frontend/lowering/builtins/process.js +505 -99
- package/dist/frontend/lowering/builtins/process.js.map +1 -1
- package/dist/frontend/lowering/builtins/promises.d.ts +5 -1
- package/dist/frontend/lowering/builtins/promises.js +326 -43
- package/dist/frontend/lowering/builtins/promises.js.map +1 -1
- package/dist/frontend/lowering/builtins/promisify-callback.d.ts +40 -0
- package/dist/frontend/lowering/builtins/promisify-callback.js +338 -0
- package/dist/frontend/lowering/builtins/promisify-callback.js.map +1 -0
- package/dist/frontend/lowering/builtins/properties.js +37 -1
- package/dist/frontend/lowering/builtins/properties.js.map +1 -1
- package/dist/frontend/lowering/builtins/querystring.js +14 -14
- package/dist/frontend/lowering/builtins/querystring.js.map +1 -1
- package/dist/frontend/lowering/builtins/readline.d.ts +12 -2
- package/dist/frontend/lowering/builtins/readline.js +136 -39
- package/dist/frontend/lowering/builtins/readline.js.map +1 -1
- package/dist/frontend/lowering/builtins/receiver-types.js +3 -5
- package/dist/frontend/lowering/builtins/receiver-types.js.map +1 -1
- package/dist/frontend/lowering/builtins/reflection.js +42 -14
- package/dist/frontend/lowering/builtins/reflection.js.map +1 -1
- package/dist/frontend/lowering/builtins/runtime-constructor.d.ts +26 -0
- package/dist/frontend/lowering/builtins/runtime-constructor.js +165 -0
- package/dist/frontend/lowering/builtins/runtime-constructor.js.map +1 -0
- package/dist/frontend/lowering/builtins/strings.js +101 -12
- package/dist/frontend/lowering/builtins/strings.js.map +1 -1
- package/dist/frontend/lowering/builtins/text-codecs.js +41 -38
- package/dist/frontend/lowering/builtins/text-codecs.js.map +1 -1
- package/dist/frontend/lowering/builtins/timers.js +79 -30
- package/dist/frontend/lowering/builtins/timers.js.map +1 -1
- package/dist/frontend/lowering/builtins/typed-array-members.d.ts +7 -0
- package/dist/frontend/lowering/builtins/typed-array-members.js +160 -0
- package/dist/frontend/lowering/builtins/typed-array-members.js.map +1 -0
- package/dist/frontend/lowering/builtins/url.d.ts +3 -0
- package/dist/frontend/lowering/builtins/url.js +120 -17
- package/dist/frontend/lowering/builtins/url.js.map +1 -1
- package/dist/frontend/lowering/builtins/util-types.js +20 -4
- package/dist/frontend/lowering/builtins/util-types.js.map +1 -1
- package/dist/frontend/lowering/builtins/v8.d.ts +11 -0
- package/dist/frontend/lowering/builtins/v8.js +105 -0
- package/dist/frontend/lowering/builtins/v8.js.map +1 -0
- package/dist/frontend/lowering/builtins/webassembly.d.ts +33 -0
- package/dist/frontend/lowering/builtins/webassembly.js +388 -0
- package/dist/frontend/lowering/builtins/webassembly.js.map +1 -0
- package/dist/frontend/lowering/builtins/webcrypto.d.ts +20 -0
- package/dist/frontend/lowering/builtins/webcrypto.js +112 -0
- package/dist/frontend/lowering/builtins/webcrypto.js.map +1 -0
- package/dist/frontend/lowering/builtins/workers.d.ts +12 -0
- package/dist/frontend/lowering/builtins/workers.js +193 -8
- package/dist/frontend/lowering/builtins/workers.js.map +1 -1
- package/dist/frontend/lowering/call-arguments.js +69 -14
- package/dist/frontend/lowering/call-arguments.js.map +1 -1
- package/dist/frontend/lowering/call-signatures.d.ts +23 -1
- package/dist/frontend/lowering/call-signatures.js +379 -55
- package/dist/frontend/lowering/call-signatures.js.map +1 -1
- package/dist/frontend/lowering/checked-promise-all.d.ts +3 -0
- package/dist/frontend/lowering/checked-promise-all.js +1 -1
- package/dist/frontend/lowering/checked-promise-all.js.map +1 -1
- package/dist/frontend/lowering/cjs-exports-object.d.ts +53 -0
- package/dist/frontend/lowering/cjs-exports-object.js +561 -0
- package/dist/frontend/lowering/cjs-exports-object.js.map +1 -0
- package/dist/frontend/lowering/cjs-inline-require.d.ts +86 -0
- package/dist/frontend/lowering/cjs-inline-require.js +314 -0
- package/dist/frontend/lowering/cjs-inline-require.js.map +1 -0
- package/dist/frontend/lowering/cjs-tsc-interop.d.ts +28 -0
- package/dist/frontend/lowering/cjs-tsc-interop.js +208 -0
- package/dist/frontend/lowering/cjs-tsc-interop.js.map +1 -0
- package/dist/frontend/lowering/class-attributes.d.ts +19 -0
- package/dist/frontend/lowering/class-attributes.js +378 -0
- package/dist/frontend/lowering/class-attributes.js.map +1 -0
- package/dist/frontend/lowering/class-callbacks.d.ts +3 -1
- package/dist/frontend/lowering/class-callbacks.js +21 -10
- package/dist/frontend/lowering/class-callbacks.js.map +1 -1
- package/dist/frontend/lowering/class-construction.js +49 -4
- package/dist/frontend/lowering/class-construction.js.map +1 -1
- package/dist/frontend/lowering/class-descriptors.d.ts +2 -0
- package/dist/frontend/lowering/class-descriptors.js +8 -8
- package/dist/frontend/lowering/class-descriptors.js.map +1 -1
- package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +64 -0
- package/dist/frontend/lowering/class-dynamic-dispatch.js +1124 -90
- package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
- package/dist/frontend/lowering/class-instance-constructor.js +1 -1
- package/dist/frontend/lowering/class-instance-constructor.js.map +1 -1
- package/dist/frontend/lowering/class-iterables.d.ts +11 -0
- package/dist/frontend/lowering/class-iterables.js +31 -0
- package/dist/frontend/lowering/class-iterables.js.map +1 -0
- package/dist/frontend/lowering/class-method-mutations.js +73 -35
- package/dist/frontend/lowering/class-method-mutations.js.map +1 -1
- package/dist/frontend/lowering/class-method-values.js +56 -10
- package/dist/frontend/lowering/class-method-values.js.map +1 -1
- package/dist/frontend/lowering/class-protocol-dispatch.js +24 -22
- package/dist/frontend/lowering/class-protocol-dispatch.js.map +1 -1
- package/dist/frontend/lowering/class-protocols.d.ts +10 -0
- package/dist/frontend/lowering/class-protocols.js +76 -45
- package/dist/frontend/lowering/class-protocols.js.map +1 -1
- package/dist/frontend/lowering/class-prototypes.d.ts +6 -0
- package/dist/frontend/lowering/class-prototypes.js +86 -19
- package/dist/frontend/lowering/class-prototypes.js.map +1 -1
- package/dist/frontend/lowering/class-runtime-statics.js +1 -1
- package/dist/frontend/lowering/class-runtime-statics.js.map +1 -1
- package/dist/frontend/lowering/class-static-data.js +2 -2
- package/dist/frontend/lowering/class-static-data.js.map +1 -1
- package/dist/frontend/lowering/class-to-primitive.d.ts +25 -0
- package/dist/frontend/lowering/class-to-primitive.js +264 -0
- package/dist/frontend/lowering/class-to-primitive.js.map +1 -0
- package/dist/frontend/lowering/class-unions.d.ts +25 -0
- package/dist/frontend/lowering/class-unions.js +102 -1
- package/dist/frontend/lowering/class-unions.js.map +1 -1
- package/dist/frontend/lowering/code-generation.d.ts +14 -0
- package/dist/frontend/lowering/code-generation.js +127 -0
- package/dist/frontend/lowering/code-generation.js.map +1 -0
- package/dist/frontend/lowering/coercions/fresh-spread.d.ts +13 -0
- package/dist/frontend/lowering/coercions/fresh-spread.js +95 -0
- package/dist/frontend/lowering/coercions/fresh-spread.js.map +1 -0
- package/dist/frontend/lowering/coercions/function-adapters.d.ts +16 -2
- package/dist/frontend/lowering/coercions/function-adapters.js +239 -68
- package/dist/frontend/lowering/coercions/function-adapters.js.map +1 -1
- package/dist/frontend/lowering/coercions/structural-plans.js +25 -3
- package/dist/frontend/lowering/coercions/structural-plans.js.map +1 -1
- package/dist/frontend/lowering/coercions/structural.js +35 -3
- package/dist/frontend/lowering/coercions/structural.js.map +1 -1
- package/dist/frontend/lowering/coercions/unions.d.ts +15 -0
- package/dist/frontend/lowering/coercions/unions.js +57 -1
- package/dist/frontend/lowering/coercions/unions.js.map +1 -1
- package/dist/frontend/lowering/collection-ingestion.js +2 -2
- package/dist/frontend/lowering/collection-ingestion.js.map +1 -1
- package/dist/frontend/lowering/collection-narrowing.js +2 -4
- package/dist/frontend/lowering/collection-narrowing.js.map +1 -1
- package/dist/frontend/lowering/construction-escapes.js +8 -8
- package/dist/frontend/lowering/construction-escapes.js.map +1 -1
- package/dist/frontend/lowering/construction-escapes.test.js +4 -4
- package/dist/frontend/lowering/construction-escapes.test.js.map +1 -1
- package/dist/frontend/lowering/constructor-returns.d.ts +61 -0
- package/dist/frontend/lowering/constructor-returns.js +477 -0
- package/dist/frontend/lowering/constructor-returns.js.map +1 -0
- package/dist/frontend/lowering/containers/array-callback-call.js +1 -1
- package/dist/frontend/lowering/containers/array-callback-call.js.map +1 -1
- package/dist/frontend/lowering/containers/array-callbacks.d.ts +17 -0
- package/dist/frontend/lowering/containers/array-callbacks.js +287 -118
- package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
- package/dist/frontend/lowering/containers/array-concat.js +1 -1
- package/dist/frontend/lowering/containers/array-concat.js.map +1 -1
- package/dist/frontend/lowering/containers/array-construction.d.ts +0 -1
- package/dist/frontend/lowering/containers/array-construction.js +58 -13
- package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
- package/dist/frontend/lowering/containers/array-from-async.d.ts +6 -5
- package/dist/frontend/lowering/containers/array-from-async.js +159 -14
- package/dist/frontend/lowering/containers/array-from-async.js.map +1 -1
- package/dist/frontend/lowering/containers/array-methods.js +94 -77
- package/dist/frontend/lowering/containers/array-methods.js.map +1 -1
- package/dist/frontend/lowering/containers/array-pipelines.js +1 -0
- package/dist/frontend/lowering/containers/array-pipelines.js.map +1 -1
- package/dist/frontend/lowering/containers/bytes.d.ts +9 -0
- package/dist/frontend/lowering/containers/bytes.js +649 -113
- package/dist/frontend/lowering/containers/bytes.js.map +1 -1
- package/dist/frontend/lowering/containers/callback-arguments.d.ts +9 -1
- package/dist/frontend/lowering/containers/callback-arguments.js +55 -5
- package/dist/frontend/lowering/containers/callback-arguments.js.map +1 -1
- package/dist/frontend/lowering/containers/collection-grouping.d.ts +7 -8
- package/dist/frontend/lowering/containers/collection-grouping.js +217 -26
- package/dist/frontend/lowering/containers/collection-grouping.js.map +1 -1
- package/dist/frontend/lowering/containers/collection-methods.js +126 -28
- package/dist/frontend/lowering/containers/collection-methods.js.map +1 -1
- package/dist/frontend/lowering/containers/dynamic-receivers.js +1 -1
- package/dist/frontend/lowering/containers/dynamic-receivers.js.map +1 -1
- package/dist/frontend/lowering/containers/exec-result-uses.js +2 -2
- package/dist/frontend/lowering/containers/exec-result-uses.js.map +1 -1
- package/dist/frontend/lowering/containers/for-of.d.ts +6 -0
- package/dist/frontend/lowering/containers/for-of.js +19 -19
- package/dist/frontend/lowering/containers/for-of.js.map +1 -1
- package/dist/frontend/lowering/containers/indexed-objects.js +142 -57
- package/dist/frontend/lowering/containers/indexed-objects.js.map +1 -1
- package/dist/frontend/lowering/containers/iterator-helpers.d.ts +53 -4
- package/dist/frontend/lowering/containers/iterator-helpers.js +1581 -462
- package/dist/frontend/lowering/containers/iterator-helpers.js.map +1 -1
- package/dist/frontend/lowering/containers/match-row-uses.d.ts +17 -0
- package/dist/frontend/lowering/containers/match-row-uses.js +264 -0
- package/dist/frontend/lowering/containers/match-row-uses.js.map +1 -0
- package/dist/frontend/lowering/containers/string-and-regexp.d.ts +14 -0
- package/dist/frontend/lowering/containers/string-and-regexp.js +455 -30
- package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
- package/dist/frontend/lowering/containers/string-replacement.js +1 -1
- package/dist/frontend/lowering/containers/string-replacement.js.map +1 -1
- package/dist/frontend/lowering/cycle-initialization.d.ts +30 -10
- package/dist/frontend/lowering/cycle-initialization.js +191 -35
- package/dist/frontend/lowering/cycle-initialization.js.map +1 -1
- package/dist/frontend/lowering/deferred-module-initializers.js +47 -43
- package/dist/frontend/lowering/deferred-module-initializers.js.map +1 -1
- package/dist/frontend/lowering/devirtualize.d.ts +1 -1
- package/dist/frontend/lowering/devirtualize.js +27 -7
- package/dist/frontend/lowering/devirtualize.js.map +1 -1
- package/dist/frontend/lowering/divergences.d.ts +0 -5
- package/dist/frontend/lowering/divergences.js +62 -125
- package/dist/frontend/lowering/divergences.js.map +1 -1
- package/dist/frontend/lowering/dyn-streams.d.ts +25 -0
- package/dist/frontend/lowering/dyn-streams.js +257 -0
- package/dist/frontend/lowering/dyn-streams.js.map +1 -0
- package/dist/frontend/lowering/error-methods.js +4 -1
- package/dist/frontend/lowering/error-methods.js.map +1 -1
- package/dist/frontend/lowering/error-name-order.d.ts +19 -0
- package/dist/frontend/lowering/error-name-order.js +93 -0
- package/dist/frontend/lowering/error-name-order.js.map +1 -0
- package/dist/frontend/lowering/expressions/array-literals.d.ts +21 -0
- package/dist/frontend/lowering/expressions/array-literals.js +723 -0
- package/dist/frontend/lowering/expressions/array-literals.js.map +1 -0
- package/dist/frontend/lowering/expressions/binary.d.ts +35 -0
- package/dist/frontend/lowering/expressions/binary.js +2557 -0
- package/dist/frontend/lowering/expressions/binary.js.map +1 -0
- package/dist/frontend/lowering/expressions/element-access.d.ts +31 -0
- package/dist/frontend/lowering/expressions/element-access.js +1804 -0
- package/dist/frontend/lowering/expressions/element-access.js.map +1 -0
- package/dist/frontend/lowering/expressions/evaluation-safety.js +4 -3
- package/dist/frontend/lowering/expressions/evaluation-safety.js.map +1 -1
- package/dist/frontend/lowering/expressions/hosted-narrowing.d.ts +38 -0
- package/dist/frontend/lowering/expressions/hosted-narrowing.js +160 -0
- package/dist/frontend/lowering/expressions/hosted-narrowing.js.map +1 -0
- package/dist/frontend/lowering/expressions/identifiers.d.ts +4 -0
- package/dist/frontend/lowering/expressions/identifiers.js +830 -0
- package/dist/frontend/lowering/expressions/identifiers.js.map +1 -0
- package/dist/frontend/lowering/expressions/keyed-field-targets.d.ts +52 -0
- package/dist/frontend/lowering/expressions/keyed-field-targets.js +307 -0
- package/dist/frontend/lowering/expressions/keyed-field-targets.js.map +1 -0
- package/dist/frontend/lowering/expressions/narrowing.d.ts +37 -0
- package/dist/frontend/lowering/expressions/narrowing.js +1337 -0
- package/dist/frontend/lowering/expressions/narrowing.js.map +1 -0
- package/dist/frontend/lowering/expressions/native-proxy.js +4 -4
- package/dist/frontend/lowering/expressions/native-proxy.js.map +1 -1
- package/dist/frontend/lowering/expressions/nullish-assignment.js +45 -0
- package/dist/frontend/lowering/expressions/nullish-assignment.js.map +1 -1
- package/dist/frontend/lowering/expressions/object-literals.d.ts +10 -0
- package/dist/frontend/lowering/expressions/object-literals.js +301 -86
- package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
- package/dist/frontend/lowering/expressions/optional-chains.d.ts +3 -2
- package/dist/frontend/lowering/expressions/optional-chains.js +103 -17
- package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
- package/dist/frontend/lowering/expressions/property-access.d.ts +115 -0
- package/dist/frontend/lowering/expressions/property-access.js +3787 -0
- package/dist/frontend/lowering/expressions/property-access.js.map +1 -0
- package/dist/frontend/lowering/expressions/relational.d.ts +28 -0
- package/dist/frontend/lowering/expressions/relational.js +1724 -0
- package/dist/frontend/lowering/expressions/relational.js.map +1 -0
- package/dist/frontend/lowering/expressions/typeof.d.ts +22 -0
- package/dist/frontend/lowering/expressions/typeof.js +551 -0
- package/dist/frontend/lowering/expressions/typeof.js.map +1 -0
- package/dist/frontend/lowering/expressions/union-fields.js +1 -1
- package/dist/frontend/lowering/expressions/union-fields.js.map +1 -1
- package/dist/frontend/lowering/expressions/updates.d.ts +21 -0
- package/dist/frontend/lowering/expressions/updates.js +780 -0
- package/dist/frontend/lowering/expressions/updates.js.map +1 -0
- package/dist/frontend/lowering/function-context.d.ts +10 -0
- package/dist/frontend/lowering/function-context.js +11 -1
- package/dist/frontend/lowering/function-context.js.map +1 -1
- package/dist/frontend/lowering/function-returns.js +52 -28
- package/dist/frontend/lowering/function-returns.js.map +1 -1
- package/dist/frontend/lowering/general-streams.d.ts +25 -0
- package/dist/frontend/lowering/general-streams.js +108 -0
- package/dist/frontend/lowering/general-streams.js.map +1 -0
- package/dist/frontend/lowering/generator-delegation.d.ts +8 -0
- package/dist/frontend/lowering/generator-delegation.js +191 -1
- package/dist/frontend/lowering/generator-delegation.js.map +1 -1
- package/dist/frontend/lowering/generator-dynamic-dispatch.d.ts +7 -0
- package/dist/frontend/lowering/generator-dynamic-dispatch.js +172 -69
- package/dist/frontend/lowering/generator-dynamic-dispatch.js.map +1 -1
- package/dist/frontend/lowering/generic-functions.d.ts +43 -0
- package/dist/frontend/lowering/generic-functions.js +593 -118
- package/dist/frontend/lowering/generic-functions.js.map +1 -1
- package/dist/frontend/lowering/handle-properties.d.ts +24 -0
- package/dist/frontend/lowering/handle-properties.js +281 -0
- package/dist/frontend/lowering/handle-properties.js.map +1 -0
- package/dist/frontend/lowering/import-meta.js +2 -2
- package/dist/frontend/lowering/import-meta.js.map +1 -1
- package/dist/frontend/lowering/intern-tables.js +10 -9
- package/dist/frontend/lowering/intern-tables.js.map +1 -1
- package/dist/frontend/lowering/iterable-spelling.d.ts +7 -0
- package/dist/frontend/lowering/iterable-spelling.js +38 -0
- package/dist/frontend/lowering/iterable-spelling.js.map +1 -0
- package/dist/frontend/lowering/iterator-adapters.d.ts +19 -0
- package/dist/frontend/lowering/iterator-adapters.js +331 -3
- package/dist/frontend/lowering/iterator-adapters.js.map +1 -1
- package/dist/frontend/lowering/js-class-fields.d.ts +28 -0
- package/dist/frontend/lowering/js-class-fields.js +170 -0
- package/dist/frontend/lowering/js-class-fields.js.map +1 -0
- package/dist/frontend/lowering/js-dynamic-objects.d.ts +15 -0
- package/dist/frontend/lowering/js-dynamic-objects.js +299 -0
- package/dist/frontend/lowering/js-dynamic-objects.js.map +1 -0
- package/dist/frontend/lowering/js-dynamic-objects.test.d.ts +1 -0
- package/dist/frontend/lowering/js-dynamic-objects.test.js +35 -0
- package/dist/frontend/lowering/js-dynamic-objects.test.js.map +1 -0
- package/dist/frontend/lowering/json-require.d.ts +22 -0
- package/dist/frontend/lowering/json-require.js +131 -0
- package/dist/frontend/lowering/json-require.js.map +1 -0
- package/dist/frontend/lowering/key-order-witness.d.ts +44 -0
- package/dist/frontend/lowering/key-order-witness.js +641 -0
- package/dist/frontend/lowering/key-order-witness.js.map +1 -0
- package/dist/frontend/lowering/key-order-witness.test.d.ts +1 -0
- package/dist/frontend/lowering/key-order-witness.test.js +239 -0
- package/dist/frontend/lowering/key-order-witness.test.js.map +1 -0
- package/dist/frontend/lowering/lifetime-regions.js +7 -7
- package/dist/frontend/lowering/lifetime-regions.js.map +1 -1
- package/dist/frontend/lowering/lower-array-sort.d.ts +33 -15
- package/dist/frontend/lowering/lower-array-sort.js +117 -21
- package/dist/frontend/lowering/lower-array-sort.js.map +1 -1
- package/dist/frontend/lowering/lower-array-sort.test.js +93 -14
- package/dist/frontend/lowering/lower-array-sort.test.js.map +1 -1
- package/dist/frontend/lowering/lower-assert.js +61 -60
- package/dist/frontend/lowering/lower-assert.js.map +1 -1
- package/dist/frontend/lowering/lower-async-iteration.d.ts +10 -1
- package/dist/frontend/lowering/lower-async-iteration.js +34 -6
- package/dist/frontend/lowering/lower-async-iteration.js.map +1 -1
- package/dist/frontend/lowering/lower-builtin-values.d.ts +5 -0
- package/dist/frontend/lowering/lower-builtin-values.js +33 -3
- package/dist/frontend/lowering/lower-builtin-values.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +1404 -448
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.d.ts +54 -3
- package/dist/frontend/lowering/lower-classes.js +1529 -472
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-comptime.d.ts +4 -2
- package/dist/frontend/lowering/lower-comptime.js +111 -13
- package/dist/frontend/lowering/lower-comptime.js.map +1 -1
- package/dist/frontend/lowering/lower-console.js +13 -11
- package/dist/frontend/lowering/lower-console.js.map +1 -1
- package/dist/frontend/lowering/lower-dgram.d.ts +10 -0
- package/dist/frontend/lowering/lower-dgram.js +241 -21
- package/dist/frontend/lowering/lower-dgram.js.map +1 -1
- package/dist/frontend/lowering/lower-enums.js +113 -14
- package/dist/frontend/lowering/lower-enums.js.map +1 -1
- package/dist/frontend/lowering/lower-event-emitter.d.ts +16 -7
- package/dist/frontend/lowering/lower-event-emitter.js +258 -70
- package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
- package/dist/frontend/lowering/lower-event-target.js +2 -2
- package/dist/frontend/lowering/lower-event-target.js.map +1 -1
- package/dist/frontend/lowering/lower-expando.js +17 -13
- package/dist/frontend/lowering/lower-expando.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.d.ts +188 -186
- package/dist/frontend/lowering/lower-exprs.js +1509 -12486
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-functions.js +72 -22
- package/dist/frontend/lowering/lower-functions.js.map +1 -1
- package/dist/frontend/lowering/lower-generators.d.ts +6 -0
- package/dist/frontend/lowering/lower-generators.js +39 -20
- package/dist/frontend/lowering/lower-generators.js.map +1 -1
- package/dist/frontend/lowering/lower-global-value.js +5 -1
- package/dist/frontend/lowering/lower-global-value.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.js +900 -107
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-mixins.js +23 -20
- package/dist/frontend/lowering/lower-mixins.js.map +1 -1
- package/dist/frontend/lowering/lower-mock.d.ts +8 -1
- package/dist/frontend/lowering/lower-mock.js +185 -18
- package/dist/frontend/lowering/lower-mock.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.d.ts +11 -3
- package/dist/frontend/lowering/lower-modules.js +445 -94
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-namespaces.d.ts +6 -0
- package/dist/frontend/lowering/lower-namespaces.js +65 -33
- package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
- package/dist/frontend/lowering/lower-node-module.d.ts +16 -0
- package/dist/frontend/lowering/lower-node-module.js +147 -14
- package/dist/frontend/lowering/lower-node-module.js.map +1 -1
- package/dist/frontend/lowering/lower-server.d.ts +6 -6
- package/dist/frontend/lowering/lower-server.js +514 -101
- package/dist/frontend/lowering/lower-server.js.map +1 -1
- package/dist/frontend/lowering/lower-stdlib.d.ts +4 -0
- package/dist/frontend/lowering/lower-stdlib.js +179 -118
- package/dist/frontend/lowering/lower-stdlib.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.d.ts +30 -7
- package/dist/frontend/lowering/lower-stmts.js +1950 -433
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lower-stream.d.ts +3 -0
- package/dist/frontend/lowering/lower-stream.js +398 -56
- package/dist/frontend/lowering/lower-stream.js.map +1 -1
- package/dist/frontend/lowering/lower-test.d.ts +3 -0
- package/dist/frontend/lowering/lower-test.js +437 -62
- package/dist/frontend/lowering/lower-test.js.map +1 -1
- package/dist/frontend/lowering/lower-timers.js +96 -32
- package/dist/frontend/lowering/lower-timers.js.map +1 -1
- package/dist/frontend/lowering/lower-url.js +1 -1
- package/dist/frontend/lowering/lower-url.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +424 -27
- package/dist/frontend/lowering/lowerer.js +2062 -310
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/lowerer.test.js +10 -4
- package/dist/frontend/lowering/lowerer.test.js.map +1 -1
- package/dist/frontend/lowering/maybe-promise.d.ts +46 -0
- package/dist/frontend/lowering/maybe-promise.js +249 -0
- package/dist/frontend/lowering/maybe-promise.js.map +1 -0
- package/dist/frontend/lowering/module-member-this.d.ts +3 -0
- package/dist/frontend/lowering/module-member-this.js +262 -0
- package/dist/frontend/lowering/module-member-this.js.map +1 -0
- package/dist/frontend/lowering/module-namespace-elements.js +1 -1
- package/dist/frontend/lowering/module-namespace-elements.js.map +1 -1
- package/dist/frontend/lowering/nan-coded-reads.d.ts +3 -0
- package/dist/frontend/lowering/nan-coded-reads.js +45 -32
- package/dist/frontend/lowering/nan-coded-reads.js.map +1 -1
- package/dist/frontend/lowering/narrowing-stability.d.ts +18 -3
- package/dist/frontend/lowering/narrowing-stability.js +104 -32
- package/dist/frontend/lowering/narrowing-stability.js.map +1 -1
- package/dist/frontend/lowering/native-ffi.js +11 -11
- package/dist/frontend/lowering/native-ffi.js.map +1 -1
- package/dist/frontend/lowering/object-factory-new.js +6 -8
- package/dist/frontend/lowering/object-factory-new.js.map +1 -1
- package/dist/frontend/lowering/private-brands.d.ts +46 -0
- package/dist/frontend/lowering/private-brands.js +265 -0
- package/dist/frontend/lowering/private-brands.js.map +1 -0
- package/dist/frontend/lowering/promise-executor-adapter.d.ts +11 -0
- package/dist/frontend/lowering/promise-executor-adapter.js +87 -0
- package/dist/frontend/lowering/promise-executor-adapter.js.map +1 -0
- package/dist/frontend/lowering/rebindable-functions.d.ts +8 -0
- package/dist/frontend/lowering/rebindable-functions.js +54 -0
- package/dist/frontend/lowering/rebindable-functions.js.map +1 -0
- package/dist/frontend/lowering/require-initialization.d.ts +32 -0
- package/dist/frontend/lowering/require-initialization.js +246 -0
- package/dist/frontend/lowering/require-initialization.js.map +1 -0
- package/dist/frontend/lowering/runtime-optional-bounds.js +7 -7
- package/dist/frontend/lowering/runtime-optional-bounds.js.map +1 -1
- package/dist/frontend/lowering/runtime-optional-elements.js +12 -12
- package/dist/frontend/lowering/runtime-optional-elements.js.map +1 -1
- package/dist/frontend/lowering/runtime-optional-guards.js +10 -10
- package/dist/frontend/lowering/runtime-optional-guards.js.map +1 -1
- package/dist/frontend/lowering/runtime-optional-guards.test.js +1 -1
- package/dist/frontend/lowering/runtime-optional-guards.test.js.map +1 -1
- package/dist/frontend/lowering/runtime-optional-ownership.js +10 -9
- package/dist/frontend/lowering/runtime-optional-ownership.js.map +1 -1
- package/dist/frontend/lowering/runtime-optional-provenance.js +2 -2
- package/dist/frontend/lowering/runtime-optional-provenance.js.map +1 -1
- package/dist/frontend/lowering/runtime-optional-records.d.ts +35 -0
- package/dist/frontend/lowering/runtime-optional-records.js +205 -32
- package/dist/frontend/lowering/runtime-optional-records.js.map +1 -1
- package/dist/frontend/lowering/runtime-optional-records.test.js +19 -1
- package/dist/frontend/lowering/runtime-optional-records.test.js.map +1 -1
- package/dist/frontend/lowering/sanitize-class-types.test.js +2 -2
- package/dist/frontend/lowering/split-consumers.js +4 -4
- package/dist/frontend/lowering/split-consumers.js.map +1 -1
- package/dist/frontend/lowering/static-function-names.d.ts +28 -0
- package/dist/frontend/lowering/static-function-names.js +212 -0
- package/dist/frontend/lowering/static-function-names.js.map +1 -0
- package/dist/frontend/lowering/static-this.js +6 -6
- package/dist/frontend/lowering/static-this.js.map +1 -1
- package/dist/frontend/lowering/static-typeof.d.ts +26 -0
- package/dist/frontend/lowering/static-typeof.js +133 -0
- package/dist/frontend/lowering/static-typeof.js.map +1 -0
- package/dist/frontend/lowering/strict-mode.d.ts +5 -0
- package/dist/frontend/lowering/strict-mode.js +31 -0
- package/dist/frontend/lowering/strict-mode.js.map +1 -0
- package/dist/frontend/lowering/string-index-bounds.js +13 -12
- package/dist/frontend/lowering/string-index-bounds.js.map +1 -1
- package/dist/frontend/lowering/string-index.d.ts +12 -0
- package/dist/frontend/lowering/string-index.js +72 -1
- package/dist/frontend/lowering/string-index.js.map +1 -1
- package/dist/frontend/lowering/surfaces.d.ts +12 -3
- package/dist/frontend/lowering/surfaces.js +282 -45
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/lowering/symbol-fields.d.ts +7 -0
- package/dist/frontend/lowering/symbol-fields.js +204 -36
- package/dist/frontend/lowering/symbol-fields.js.map +1 -1
- package/dist/frontend/lowering/symbol-methods.d.ts +2 -1
- package/dist/frontend/lowering/symbol-methods.js +24 -6
- package/dist/frontend/lowering/symbol-methods.js.map +1 -1
- package/dist/frontend/lowering/thenables.d.ts +16 -0
- package/dist/frontend/lowering/thenables.js +124 -0
- package/dist/frontend/lowering/thenables.js.map +1 -0
- package/dist/frontend/lowering/thread-slots.d.ts +13 -0
- package/dist/frontend/lowering/thread-slots.js +208 -0
- package/dist/frontend/lowering/thread-slots.js.map +1 -0
- package/dist/frontend/lowering/typed-arguments.d.ts +74 -0
- package/dist/frontend/lowering/typed-arguments.js +472 -0
- package/dist/frontend/lowering/typed-arguments.js.map +1 -0
- package/dist/frontend/lowering/union-retag.d.ts +8 -0
- package/dist/frontend/lowering/union-retag.js +27 -0
- package/dist/frontend/lowering/union-retag.js.map +1 -1
- package/dist/frontend/lowering/union-retag.test.js +24 -1
- package/dist/frontend/lowering/union-retag.test.js.map +1 -1
- package/dist/frontend/lowering/var-hoisting.js +6 -6
- package/dist/frontend/lowering/var-hoisting.js.map +1 -1
- package/dist/frontend/lowering/width-lift.d.ts +4 -0
- package/dist/frontend/mock-shapes.js +13 -6
- package/dist/frontend/mock-shapes.js.map +1 -1
- package/dist/frontend/module-source-candidates.js +1 -1
- package/dist/frontend/module-source-candidates.js.map +1 -1
- package/dist/frontend/module-source-candidates.test.js +2 -1
- package/dist/frontend/module-source-candidates.test.js.map +1 -1
- package/dist/frontend/module-syntax.js +8 -8
- package/dist/frontend/module-syntax.js.map +1 -1
- package/dist/frontend/npm-static-builtin-aliases.d.ts +8 -0
- package/dist/frontend/npm-static-builtin-aliases.js +65 -0
- package/dist/frontend/npm-static-builtin-aliases.js.map +1 -0
- package/dist/frontend/npm-static-bundled-chunks.d.ts +58 -0
- package/dist/frontend/npm-static-bundled-chunks.js +981 -0
- package/dist/frontend/npm-static-bundled-chunks.js.map +1 -0
- package/dist/frontend/npm-static-bundled-chunks.test.d.ts +1 -0
- package/dist/frontend/npm-static-bundled-chunks.test.js +399 -0
- package/dist/frontend/npm-static-bundled-chunks.test.js.map +1 -0
- package/dist/frontend/npm-static-bundled-cjs.js +24 -23
- package/dist/frontend/npm-static-bundled-cjs.js.map +1 -1
- package/dist/frontend/npm-static-bundled-esm.d.ts +9 -0
- package/dist/frontend/npm-static-bundled-esm.js +988 -0
- package/dist/frontend/npm-static-bundled-esm.js.map +1 -0
- package/dist/frontend/npm-static-bundled-esm.test.d.ts +1 -0
- package/dist/frontend/npm-static-bundled-esm.test.js +336 -0
- package/dist/frontend/npm-static-bundled-esm.test.js.map +1 -0
- package/dist/frontend/npm-static-cjs-exports-alias.d.ts +2 -0
- package/dist/frontend/npm-static-cjs-exports-alias.js +186 -0
- package/dist/frontend/npm-static-cjs-exports-alias.js.map +1 -0
- package/dist/frontend/npm-static-cjs-exports-alias.test.d.ts +1 -0
- package/dist/frontend/npm-static-cjs-exports-alias.test.js +73 -0
- package/dist/frontend/npm-static-cjs-exports-alias.test.js.map +1 -0
- package/dist/frontend/npm-static-cjs-exports-var.d.ts +2 -0
- package/dist/frontend/npm-static-cjs-exports-var.js +236 -0
- package/dist/frontend/npm-static-cjs-exports-var.js.map +1 -0
- package/dist/frontend/npm-static-declaration-syntax.js +102 -101
- package/dist/frontend/npm-static-declaration-syntax.js.map +1 -1
- package/dist/frontend/npm-static-enum-iife.d.ts +6 -0
- package/dist/frontend/npm-static-enum-iife.js +280 -0
- package/dist/frontend/npm-static-enum-iife.js.map +1 -0
- package/dist/frontend/npm-static-enum-iife.test.d.ts +1 -0
- package/dist/frontend/npm-static-enum-iife.test.js +116 -0
- package/dist/frontend/npm-static-enum-iife.test.js.map +1 -0
- package/dist/frontend/npm-static-prune.js +36 -24
- package/dist/frontend/npm-static-prune.js.map +1 -1
- package/dist/frontend/npm-static-rewrite-host.d.ts +4 -1
- package/dist/frontend/npm-static-rewrite-host.js +14 -3
- package/dist/frontend/npm-static-rewrite-host.js.map +1 -1
- package/dist/frontend/npm-static-rewrite-syntax.d.ts +19 -0
- package/dist/frontend/npm-static-rewrite-syntax.js +274 -101
- package/dist/frontend/npm-static-rewrite-syntax.js.map +1 -1
- package/dist/frontend/npm-static-subtyping.js +7 -9
- package/dist/frontend/npm-static-subtyping.js.map +1 -1
- package/dist/frontend/npm-static.d.ts +25 -1
- package/dist/frontend/npm-static.js +212 -16
- package/dist/frontend/npm-static.js.map +1 -1
- package/dist/frontend/npm-static.test.js +22 -1
- package/dist/frontend/npm-static.test.js.map +1 -1
- package/dist/frontend/npm.js +13 -0
- package/dist/frontend/npm.js.map +1 -1
- package/dist/frontend/package-shims.d.ts +47 -0
- package/dist/frontend/package-shims.js +300 -0
- package/dist/frontend/package-shims.js.map +1 -0
- package/dist/frontend/pipeline.js +230 -26
- package/dist/frontend/pipeline.js.map +1 -1
- package/dist/frontend/pipeline.test.js +22 -1
- package/dist/frontend/pipeline.test.js.map +1 -1
- package/dist/frontend/program-analysis.d.ts +6 -1
- package/dist/frontend/program-analysis.js +7 -0
- package/dist/frontend/program-analysis.js.map +1 -1
- package/dist/frontend/program.d.ts +100 -2
- package/dist/frontend/program.js +1627 -262
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/program.test.js +76 -6
- package/dist/frontend/program.test.js.map +1 -1
- package/dist/frontend/resolve.js +49 -2
- package/dist/frontend/resolve.js.map +1 -1
- package/dist/frontend/resolve.test.js +49 -0
- package/dist/frontend/resolve.test.js.map +1 -1
- package/dist/frontend/services.d.ts +26 -1
- package/dist/frontend/services.js +59 -3
- package/dist/frontend/services.js.map +1 -1
- package/dist/frontend/services.test.js +2 -1
- package/dist/frontend/services.test.js.map +1 -1
- package/dist/frontend/threads-import.js +1 -1
- package/dist/frontend/threads-import.js.map +1 -1
- package/dist/frontend/tier-analysis.d.ts +71 -0
- package/dist/frontend/tier-analysis.js +522 -0
- package/dist/frontend/tier-analysis.js.map +1 -0
- package/dist/frontend/ts7/api-conformance.d.ts +234 -0
- package/dist/frontend/ts7/api-conformance.js +7 -0
- package/dist/frontend/ts7/api-conformance.js.map +1 -0
- package/dist/frontend/ts7/ast-guards.generated.js +2 -1
- package/dist/frontend/ts7/ast-guards.generated.js.map +1 -1
- package/dist/frontend/ts7/ast-node.d.ts +47 -25
- package/dist/frontend/ts7/ast-node.js +64 -18
- package/dist/frontend/ts7/ast-node.js.map +1 -1
- package/dist/frontend/ts7/ast-node.test.js +36 -12
- package/dist/frontend/ts7/ast-node.test.js.map +1 -1
- package/dist/frontend/ts7/ast-types.d.ts +10 -3
- package/dist/frontend/ts7/ast-types.generated.d.ts +39 -39
- package/dist/frontend/ts7/ast.d.ts +1 -0
- package/dist/frontend/ts7/ast.js +3 -2
- package/dist/frontend/ts7/ast.js.map +1 -1
- package/dist/frontend/ts7/checker-backend.d.ts +23 -0
- package/dist/frontend/ts7/checker-backend.js +88 -0
- package/dist/frontend/ts7/checker-backend.js.map +1 -0
- package/dist/frontend/ts7/checker-backend.test.d.ts +1 -0
- package/dist/frontend/ts7/checker-backend.test.js +63 -0
- package/dist/frontend/ts7/checker-backend.test.js.map +1 -0
- package/dist/frontend/ts7/checker-cache.d.ts +0 -3
- package/dist/frontend/ts7/checker-cache.js +0 -6
- package/dist/frontend/ts7/checker-cache.js.map +1 -1
- package/dist/frontend/ts7/checker.d.ts +18 -11
- package/dist/frontend/ts7/checker.js +42 -55
- package/dist/frontend/ts7/checker.js.map +1 -1
- package/dist/frontend/ts7/checker.test.js +10 -7
- package/dist/frontend/ts7/checker.test.js.map +1 -1
- package/dist/frontend/ts7/diagnostic.d.ts +19 -0
- package/dist/frontend/ts7/diagnostic.js +22 -0
- package/dist/frontend/ts7/diagnostic.js.map +1 -0
- package/dist/frontend/ts7/node-functions.d.ts +8 -0
- package/dist/frontend/ts7/node-functions.js +18 -0
- package/dist/frontend/ts7/node-functions.js.map +1 -0
- package/dist/frontend/ts7/program-host.d.ts +10 -5
- package/dist/frontend/ts7/program-host.js +19 -0
- package/dist/frontend/ts7/program-host.js.map +1 -1
- package/dist/frontend/ts7/rpc-api.d.ts +5 -1
- package/dist/frontend/ts7/rpc-api.js +8 -1
- package/dist/frontend/ts7/rpc-api.js.map +1 -1
- package/dist/frontend/ts7/semantic-checker.d.ts +13 -6
- package/dist/frontend/ts7/semantic-checker.js +26 -8
- package/dist/frontend/ts7/semantic-checker.js.map +1 -1
- package/dist/frontend/ts7/semantic-checker.test.js +12 -9
- package/dist/frontend/ts7/semantic-checker.test.js.map +1 -1
- package/dist/frontend/ts7/semantic-model.d.ts +57 -24
- package/dist/frontend/ts7/semantic-model.js +114 -16
- package/dist/frontend/ts7/semantic-model.js.map +1 -1
- package/dist/frontend/ts7/semantic-model.test.js +4 -4
- package/dist/frontend/ts7/semantic-model.test.js.map +1 -1
- package/dist/frontend/ts7/semantic-types.d.ts +7 -3
- package/dist/frontend/ts7/semantic-types.js +1 -1
- package/dist/frontend/ts7/semantic-types.js.map +1 -1
- package/dist/frontend/ts7/session.d.ts +30 -15
- package/dist/frontend/ts7/session.js +8 -5
- package/dist/frontend/ts7/session.js.map +1 -1
- package/dist/frontend/ts7/session.test.js +9 -5
- package/dist/frontend/ts7/session.test.js.map +1 -1
- package/dist/frontend/ts7/source-parser.d.ts +6 -2
- package/dist/frontend/ts7/source-parser.js +24 -3
- package/dist/frontend/ts7/source-parser.js.map +1 -1
- package/dist/frontend/ts7/source-parser.test.js +38 -17
- package/dist/frontend/ts7/source-parser.test.js.map +1 -1
- package/dist/frontend/type-mapper.d.ts +122 -2
- package/dist/frontend/type-mapper.js +2735 -723
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/frontend/type-only-imports.d.ts +28 -0
- package/dist/frontend/type-only-imports.js +122 -0
- package/dist/frontend/type-only-imports.js.map +1 -0
- package/dist/frontend/worker-target.js +8 -8
- package/dist/frontend/worker-target.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +87 -8
- package/dist/index.js.map +1 -1
- package/dist/ir/analysis.js +4 -2
- package/dist/ir/analysis.js.map +1 -1
- package/dist/ir/api.d.ts +1 -1
- package/dist/ir/api.js +1 -1
- package/dist/ir/api.js.map +1 -1
- package/dist/ir/array-length-stability.d.ts +31 -0
- package/dist/ir/array-length-stability.js +249 -0
- package/dist/ir/array-length-stability.js.map +1 -0
- package/dist/ir/array-length-stability.test.d.ts +1 -0
- package/dist/ir/array-length-stability.test.js +134 -0
- package/dist/ir/array-length-stability.test.js.map +1 -0
- package/dist/ir/build.d.ts +2 -2
- package/dist/ir/build.js +1 -1
- package/dist/ir/build.js.map +1 -1
- package/dist/ir/builtin-effects.js +116 -0
- package/dist/ir/builtin-effects.js.map +1 -1
- package/dist/ir/builtin-signatures.d.ts +1 -1
- package/dist/ir/builtin-signatures.js +540 -29
- package/dist/ir/builtin-signatures.js.map +1 -1
- package/dist/ir/byte-numbers.js +3 -0
- package/dist/ir/byte-numbers.js.map +1 -1
- package/dist/ir/callback-specialization.d.ts +37 -0
- package/dist/ir/callback-specialization.js +459 -0
- package/dist/ir/callback-specialization.js.map +1 -0
- package/dist/ir/callback-specialization.test.d.ts +1 -0
- package/dist/ir/callback-specialization.test.js +208 -0
- package/dist/ir/callback-specialization.test.js.map +1 -0
- package/dist/ir/capture-values.d.ts +0 -1
- package/dist/ir/capture-values.js +51 -40
- package/dist/ir/capture-values.js.map +1 -1
- package/dist/ir/constant-globals.test.js +1 -1
- package/dist/ir/constant-tables.test.js +1 -1
- package/dist/ir/field-values.test.js +1 -1
- package/dist/ir/final-fields.test.js +1 -1
- package/dist/ir/function-references.test.js +9 -1
- package/dist/ir/function-references.test.js.map +1 -1
- package/dist/ir/init-only-globals.test.js +1 -1
- package/dist/ir/initializer-bindings.test.js +1 -1
- package/dist/ir/int32-slots.d.ts +14 -0
- package/dist/ir/int32-slots.js +97 -14
- package/dist/ir/int32-slots.js.map +1 -1
- package/dist/ir/int32-slots.test.js +1 -1
- package/dist/ir/integer-loop-facts.d.ts +7 -0
- package/dist/ir/integer-loop-facts.js +103 -17
- package/dist/ir/integer-loop-facts.js.map +1 -1
- package/dist/ir/integer-loops.d.ts +1 -1
- package/dist/ir/integer-loops.js +39 -9
- package/dist/ir/integer-loops.js.map +1 -1
- package/dist/ir/integer-loops.test.js +104 -0
- package/dist/ir/integer-loops.test.js.map +1 -1
- package/dist/ir/integer-ranges.d.ts +13 -1
- package/dist/ir/integer-ranges.js +125 -26
- package/dist/ir/integer-ranges.js.map +1 -1
- package/dist/ir/integer-ranges.test.js +273 -2
- package/dist/ir/integer-ranges.test.js.map +1 -1
- package/dist/ir/intrinsic-signatures.js +6 -0
- package/dist/ir/intrinsic-signatures.js.map +1 -1
- package/dist/ir/ir.d.ts +221 -58
- package/dist/ir/ir.js +127 -12
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/ir.test.js +10 -0
- package/dist/ir/ir.test.js.map +1 -1
- package/dist/ir/js-ic.d.ts +52 -0
- package/dist/ir/js-ic.js +199 -0
- package/dist/ir/js-ic.js.map +1 -0
- package/dist/ir/js-ic.test.d.ts +1 -0
- package/dist/ir/js-ic.test.js +148 -0
- package/dist/ir/js-ic.test.js.map +1 -0
- package/dist/ir/jsval.d.ts +8 -0
- package/dist/ir/jsval.js +399 -0
- package/dist/ir/jsval.js.map +1 -0
- package/dist/ir/jsval.test.d.ts +1 -0
- package/dist/ir/jsval.test.js +239 -0
- package/dist/ir/jsval.test.js.map +1 -0
- package/dist/ir/runtime-features.d.ts +183 -33
- package/dist/ir/runtime-features.js +795 -422
- package/dist/ir/runtime-features.js.map +1 -1
- package/dist/ir/scalar-records.test.js +1 -1
- package/dist/ir/self-captures.d.ts +33 -0
- package/dist/ir/self-captures.js +245 -0
- package/dist/ir/self-captures.js.map +1 -0
- package/dist/ir/self-captures.test.d.ts +1 -0
- package/dist/ir/self-captures.test.js +135 -0
- package/dist/ir/self-captures.test.js.map +1 -0
- package/dist/ir/serialize.d.ts +1 -1
- package/dist/ir/serialize.js +7 -4
- package/dist/ir/serialize.js.map +1 -1
- package/dist/ir/tiers.d.ts +26 -0
- package/dist/ir/tiers.js +101 -0
- package/dist/ir/tiers.js.map +1 -0
- package/dist/ir/tiers.test.d.ts +1 -0
- package/dist/ir/tiers.test.js +140 -0
- package/dist/ir/tiers.test.js.map +1 -0
- package/dist/ir/traverse.js +201 -150
- package/dist/ir/traverse.js.map +1 -1
- package/dist/ir/traverse.test.js +33 -30
- package/dist/ir/traverse.test.js.map +1 -1
- package/dist/ir/unshare.js +65 -3
- package/dist/ir/unshare.js.map +1 -1
- package/dist/ir/unshare.test.js +1 -1
- package/dist/ir/validate.js +196 -76
- package/dist/ir/validate.js.map +1 -1
- package/dist/ir/validate.test.js +41 -11
- package/dist/ir/validate.test.js.map +1 -1
- package/dist/library/fence-eval.test.js +1 -1
- package/dist/library/int-infer.test.js +4 -4
- package/dist/library/ir-policy.js +14 -0
- package/dist/library/ir-policy.js.map +1 -1
- package/dist/library/library-cache.d.ts +1 -0
- package/dist/library/library-cache.js.map +1 -1
- package/dist/library/library-cache.test.js +5 -5
- package/dist/library/library-profile.d.ts +4 -4
- package/dist/library/library-profile.js +35 -7
- package/dist/library/library-profile.js.map +1 -1
- package/dist/library/prepare.js +13 -1
- package/dist/library/prepare.js.map +1 -1
- package/dist/native/cli.js +22 -0
- package/dist/native/cli.js.map +1 -1
- package/dist/native/compiler.js +35 -6
- package/dist/native/compiler.js.map +1 -1
- package/dist/native/compiler.test.js +2 -2
- package/dist/native/executable-cache.js +3 -0
- package/dist/native/executable-cache.js.map +1 -1
- package/dist/native/prepare.js +10 -0
- package/dist/native/prepare.js.map +1 -1
- package/dist/native/sanitizer.test.js +19 -0
- package/dist/native/sanitizer.test.js.map +1 -1
- package/dist/native/toolchain.d.ts +2 -0
- package/dist/native/toolchain.js +10 -1
- package/dist/native/toolchain.js.map +1 -1
- package/dist/native/toolchain.test.js +39 -1
- package/dist/native/toolchain.test.js.map +1 -1
- package/dist/startup-cache.d.ts +1 -0
- package/dist/startup-cache.js +1 -0
- package/dist/startup-cache.js.map +1 -1
- package/dist/wasm/base64.d.ts +5 -0
- package/dist/wasm/base64.js +62 -0
- package/dist/wasm/base64.js.map +1 -0
- package/dist/wasm/binary.d.ts +36 -0
- package/dist/wasm/binary.js +1976 -0
- package/dist/wasm/binary.js.map +1 -0
- package/dist/wasm/binary.test.d.ts +1 -0
- package/dist/wasm/binary.test.js +190 -0
- package/dist/wasm/binary.test.js.map +1 -0
- package/dist/wasm/discover.d.ts +38 -0
- package/dist/wasm/discover.js +377 -0
- package/dist/wasm/discover.js.map +1 -0
- package/dist/wasm/discover.test.d.ts +1 -0
- package/dist/wasm/discover.test.js +24 -0
- package/dist/wasm/discover.test.js.map +1 -0
- package/dist/wasm/module.d.ts +151 -0
- package/dist/wasm/module.js +575 -0
- package/dist/wasm/module.js.map +1 -0
- package/dist/wasm/translate.d.ts +48 -0
- package/dist/wasm/translate.js +2129 -0
- package/dist/wasm/translate.js.map +1 -0
- package/dist/wasm/translate.test.d.ts +1 -0
- package/dist/wasm/translate.test.js +207 -0
- package/dist/wasm/translate.test.js.map +1 -0
- package/package.json +22 -20
- package/shims/fs-extra/core/api.ts +1192 -0
- package/shims/fs-extra/index.ts +9 -0
- package/shims/undici/core/agent.ts +163 -0
- package/shims/undici/core/api.ts +93 -0
- package/shims/undici/core/client.ts +1304 -0
- package/shims/undici/core/connector.ts +157 -0
- package/shims/undici/core/diagnostics-types.ts +68 -0
- package/shims/undici/core/diagnostics.ts +16 -0
- package/shims/undici/core/dispatcher.ts +574 -0
- package/shims/undici/core/errors-v5.ts +22 -0
- package/shims/undici/core/errors-v7.ts +25 -0
- package/shims/undici/core/errors.ts +255 -0
- package/shims/undici/core/fetch.ts +635 -0
- package/shims/undici/core/pool.ts +280 -0
- package/shims/undici/core/readable.ts +268 -0
- package/shims/undici/core/request.ts +313 -0
- package/shims/undici/core/timers.ts +80 -0
- package/shims/undici/core/types.ts +167 -0
- package/shims/undici/core/util.ts +67 -0
- package/shims/undici/v5.ts +119 -0
- package/shims/undici/v7.ts +119 -0
- package/surface-manifest.json +304 -22
package/dist/frontend/program.js
CHANGED
|
@@ -44,19 +44,21 @@ import * as ts from "./ts7/adapter.js";
|
|
|
44
44
|
import { commonJsModuleSyntaxDiag, invalidPackageConfigDiag, strictNullChecksFloorDiag, tscPassthroughDiag, unsupportedDiag, } from "../diagnostics/diagnostic.js";
|
|
45
45
|
import { isNodeModulesPath, nearestInvalidPackageJsonPath, nearestPackageType, nearestPkgJsonPath, packageImportTarget, projectDtsRuntimeSibling, resolveBareModule, resolveProjectModule, resolveTypeDirective, setProjectPathMappings, setProjectRealm, } from "./resolve.js";
|
|
46
46
|
import { probeNodeImportRefusal, probeNodeRequireRefusal } from "./npm.js";
|
|
47
|
-
import { isNpmStaticPackage, npmStaticActive, npmStaticFsShadow, npmStaticPackageOfPath, reportNpmStaticOffender, setNpmStaticDeclarationOverloads, setNpmStaticPackages, } from "./npm-static.js";
|
|
47
|
+
import { isNpmStaticPackage, npmStaticActive, npmStaticFsShadow, programBuiltinAliasSource, clearProgramBuiltinAliasCache, npmStaticLexerVisibleNames, npmStaticLiveExportTable, npmStaticPackageOfPath, reportNpmStaticOffender, setNpmStaticDeclarationOverloads, setNpmStaticPackages, } from "./npm-static.js";
|
|
48
48
|
import { isPrunedNpmReexport, planNpmStaticReexports } from "./npm-static-prune.js";
|
|
49
49
|
import { isNpmStaticSubclassArgument } from "./npm-static-subtyping.js";
|
|
50
50
|
import { npmStaticDeclarationReexports, npmStaticRuntimeClassTargets, parseNpmStaticDeclarationOverloads, parseNpmStaticDeclarationProperties, } from "./npm-static-declaration-syntax.js";
|
|
51
|
+
import { configurePackageShims, isPackageShimFile, isPackageShimName, isShimmedImport, } from "./package-shims.js";
|
|
51
52
|
import { provenanceEntryFor, provenancePaths } from "./provenance-registry.js";
|
|
52
53
|
import { cjsLexedExportsOfFile, cjsVisibleNames } from "./cjs-syntax.js";
|
|
53
54
|
import { ambientDtsPath, fallbackDtsPath, isNodeTypesPath, overridesDtsPath, tsgoPath, } from "./dts-paths.js";
|
|
54
|
-
import { builtinDefaultImportModule, canonicalBuiltinModule, SUPPORTED_NODE_MODULES, unsupportedModuleFeatureOf, } from "./builtin-modules.js";
|
|
55
|
+
import { builtinDefaultImportModule, canonicalBuiltinModule, npmBuiltinAliasOf, SUPPORTED_NODE_MODULES, unsupportedModuleFeatureOf, TEMPORAL_GLOBAL, } from "./builtin-modules.js";
|
|
55
56
|
import { clearWorkspacePackages, isRelativeSpecifier, isWorkspacePackageName, npmPackageNameOf, registerWorkspacePackage, workspacePackageOfPath, } from "./workspace-registry.js";
|
|
56
57
|
import { ADOPTED_OPTIONS, isJsSourceFileName, JS_ANY_OPERATOR_CODES, JS_RELAXED_TSC_CODES, } from "./tsc-codes.js";
|
|
57
58
|
import { trackedFileExists, trackedReadFile, trackedRealpath } from "./input-tracker.js";
|
|
58
59
|
import { forkTargetPaths } from "./fork-target.js";
|
|
59
60
|
import { workerTargetPaths } from "./worker-target.js";
|
|
61
|
+
import { erasedTypeOnlyImport, typeOnlyNamedImport, typeOnlyReachedFiles, } from "./type-only-imports.js";
|
|
60
62
|
import { moduleSourceCandidates } from "./module-source-candidates.js";
|
|
61
63
|
import { inferredJsDiagnosticSuppressed } from "./inferred-js-diagnostics.js";
|
|
62
64
|
const BASE_OPTIONS = {
|
|
@@ -74,11 +76,16 @@ const FORCED_OPTIONS = {
|
|
|
74
76
|
// classification is intentionally independent below; this option is only
|
|
75
77
|
// the binder's scope decision.
|
|
76
78
|
moduleDetection: ts.ModuleDetectionKind.Force,
|
|
77
|
-
// Explicit resource management
|
|
78
|
-
// slices in TS 7 even though Node 24 ships them. Include
|
|
79
|
-
// libs without widening the rest of the standard-library
|
|
80
|
-
// ES2025.
|
|
81
|
-
lib: [
|
|
79
|
+
// Explicit resource management, Array.fromAsync and Error.isError are
|
|
80
|
+
// ESNext library slices in TS 7 even though Node 24 ships them. Include
|
|
81
|
+
// those focused libs without widening the rest of the standard-library
|
|
82
|
+
// target past ES2025.
|
|
83
|
+
lib: [
|
|
84
|
+
"lib.es2025.d.ts",
|
|
85
|
+
"lib.esnext.disposable.d.ts",
|
|
86
|
+
"lib.esnext.array.d.ts",
|
|
87
|
+
"lib.esnext.error.d.ts",
|
|
88
|
+
],
|
|
82
89
|
types: [],
|
|
83
90
|
allowImportingTsExtensions: true,
|
|
84
91
|
allowJs: true,
|
|
@@ -221,6 +228,7 @@ function adoptProjectConfig7(host, entryPath) {
|
|
|
221
228
|
diags,
|
|
222
229
|
...(projectLib === undefined ? {} : { projectLib }),
|
|
223
230
|
forcedStrictNullChecks,
|
|
231
|
+
checkJs: parsed.options["checkJs"] === true,
|
|
224
232
|
};
|
|
225
233
|
}
|
|
226
234
|
/** The target project's @types/node, resolved with the OWN resolver's
|
|
@@ -409,12 +417,12 @@ function createRequireProgramRoots7(program) {
|
|
|
409
417
|
const calls = [];
|
|
410
418
|
for (const node of moduleSourceCandidates(program, sf).calls) {
|
|
411
419
|
if (node.questionDotToken !== undefined ||
|
|
412
|
-
node.arguments.length !== 1 ||
|
|
413
|
-
!ts.isStringLiteralLike(node.arguments[0]) ||
|
|
420
|
+
node.arguments.nodes.length !== 1 ||
|
|
421
|
+
!ts.isStringLiteralLike(node.arguments.nodes[0]) ||
|
|
414
422
|
!ts.isIdentifier(node.expression)) {
|
|
415
423
|
continue;
|
|
416
424
|
}
|
|
417
|
-
calls.push({ callee: node.expression, spec: node.arguments[0].text });
|
|
425
|
+
calls.push({ callee: node.expression, spec: node.arguments.nodes[0].text });
|
|
418
426
|
}
|
|
419
427
|
// Root discovery only needs the callee's binding. A first-miss lookup
|
|
420
428
|
// otherwise fetches symbols and types for every identifier in the file,
|
|
@@ -462,9 +470,10 @@ export function entryPackageFilePredicate(entryPath) {
|
|
|
462
470
|
};
|
|
463
471
|
}
|
|
464
472
|
/** maxNodeModuleJsDepth can omit relative imports within an admitted
|
|
465
|
-
* package
|
|
466
|
-
*
|
|
467
|
-
|
|
473
|
+
* package, and opted-in packages deep in the dependency graph. Discover
|
|
474
|
+
* their runtime sources to a fixpoint so the checker and module resolver
|
|
475
|
+
* see the same graph regardless of import traversal order or depth. */
|
|
476
|
+
function entryPackageProgramRoots7(program, entryPath, rootNpmStaticEdges) {
|
|
468
477
|
const belongsToEntry = entryPackageFilePredicate(entryPath);
|
|
469
478
|
const roots = new Set();
|
|
470
479
|
for (const sf of program.getImplementationSourceFiles()) {
|
|
@@ -480,11 +489,80 @@ function entryPackageProgramRoots7(program, entryPath) {
|
|
|
480
489
|
isJsSourceFileName(target) &&
|
|
481
490
|
program.getSourceFile(target) === undefined)
|
|
482
491
|
roots.add(target);
|
|
492
|
+
// An opted-in package's bare edge counts against the same depth
|
|
493
|
+
// budget: tsgo charges every node_modules JS hop, so express's
|
|
494
|
+
// body-parser → qs → side-channel → get-intrinsic chain runs out of
|
|
495
|
+
// depth before its leaves load. Root the runtime file this edge
|
|
496
|
+
// lowers to (preflight's own resolution and miss rule) so the leaf
|
|
497
|
+
// joins like a shallow one; complete programs add nothing. Only
|
|
498
|
+
// the shadowed lowering world does this (the authored world checks
|
|
499
|
+
// user code against declarations), and only from package files: a
|
|
500
|
+
// program file's own edges are never deeper than one hop.
|
|
501
|
+
// (resolveBareModule directly: resolveNpmImport7's workspace
|
|
502
|
+
// registration stays with preflight's own walk.)
|
|
503
|
+
if (target === null &&
|
|
504
|
+
rootNpmStaticEdges &&
|
|
505
|
+
npmStaticPackageOfPath(sf.fileName) !== null &&
|
|
506
|
+
!isRelativeSpecifier(specifier.text)) {
|
|
507
|
+
const spec = specifier.text;
|
|
508
|
+
if (spec.startsWith("#") || canonicalBuiltinModule(spec) !== null)
|
|
509
|
+
continue;
|
|
510
|
+
const npm = resolveBareModule(sf.fileName, spec, undefined, moduleSpecifierKind7(specifier));
|
|
511
|
+
if (npm !== null &&
|
|
512
|
+
isNpmStaticPackage(npm.packageName) &&
|
|
513
|
+
(isNodeModulesPath(npm.typesFile) || npm.workspaceDir !== undefined) &&
|
|
514
|
+
isJsSourceFileName(npm.typesFile) &&
|
|
515
|
+
npmStaticProgramFile(program, npm.typesFile) === null)
|
|
516
|
+
roots.add(tsgoPath(resolve(npm.typesFile)));
|
|
517
|
+
}
|
|
483
518
|
}
|
|
484
519
|
}
|
|
485
520
|
return [...roots].sort();
|
|
486
521
|
}
|
|
487
|
-
|
|
522
|
+
/** TS 7's ESNext temporal declarations: a lib slice scriptc adds only for
|
|
523
|
+
* programs whose sources name the global (programNamesTemporal7). */
|
|
524
|
+
const TEMPORAL_LIB = "lib.esnext.temporal.d.ts";
|
|
525
|
+
/** True when a program source (user code or compiled npm JavaScript)
|
|
526
|
+
* contains the temporal global's name as a whole word. A cheap syntactic
|
|
527
|
+
* scan of the implementation files root discovery already materialized; a
|
|
528
|
+
* mention in a comment or string also counts, which only adds the lib
|
|
529
|
+
* slice. */
|
|
530
|
+
function programNamesTemporal7(program) {
|
|
531
|
+
for (const sf of program.getImplementationSourceFiles()) {
|
|
532
|
+
const text = sf.text;
|
|
533
|
+
for (let at = text.indexOf(TEMPORAL_GLOBAL); at >= 0; at = text.indexOf(TEMPORAL_GLOBAL, at + 8)) {
|
|
534
|
+
if (!isIdentifierCharAt(text, at - 1) && !isIdentifierCharAt(text, at + 8))
|
|
535
|
+
return true;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
function isIdentifierCharAt(text, index) {
|
|
541
|
+
if (index < 0 || index >= text.length)
|
|
542
|
+
return false;
|
|
543
|
+
const c = text.charCodeAt(index);
|
|
544
|
+
return ((c >= 48 && c <= 57) ||
|
|
545
|
+
(c >= 65 && c <= 90) ||
|
|
546
|
+
(c >= 97 && c <= 122) ||
|
|
547
|
+
c === 36 ||
|
|
548
|
+
c === 95 ||
|
|
549
|
+
c > 127);
|
|
550
|
+
}
|
|
551
|
+
/** "require" for a CommonJS edge (`require("x")`, `import x = require("x")`),
|
|
552
|
+
* "import" for every ESM form — the resolution kind preflight uses. */
|
|
553
|
+
function moduleSpecifierKind7(specifier) {
|
|
554
|
+
const parent = specifier.parent;
|
|
555
|
+
if (ts.isExternalModuleReference(parent))
|
|
556
|
+
return "require";
|
|
557
|
+
return ts.isCallExpression(parent) &&
|
|
558
|
+
ts.isIdentifier(parent.expression) &&
|
|
559
|
+
parent.expression.text === "require"
|
|
560
|
+
? "require"
|
|
561
|
+
: "import";
|
|
562
|
+
}
|
|
563
|
+
function loadProgram7(host, entryPath, externalTypes = new Map(),
|
|
564
|
+
/** The --npm-static lowering world: root opted-in packages' deep edges. */
|
|
565
|
+
rootNpmStaticEdges = false) {
|
|
488
566
|
const config = adoptProjectConfig7(host, entryPath);
|
|
489
567
|
const configuredPaths = config.options["paths"];
|
|
490
568
|
setProjectPathMappings(configuredPaths !== undefined && typeof configuredPaths === "object" && configuredPaths !== null
|
|
@@ -530,7 +608,7 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
530
608
|
try {
|
|
531
609
|
for (let pass = 0; pass < 32; pass++) {
|
|
532
610
|
const candidates = [
|
|
533
|
-
...entryPackageProgramRoots7(program, entryPath),
|
|
611
|
+
...entryPackageProgramRoots7(program, entryPath, rootNpmStaticEdges),
|
|
534
612
|
...createRequireProgramRoots7(program),
|
|
535
613
|
...forkTargetPaths(program, program.getImplementationSourceFiles()),
|
|
536
614
|
...workerTargetPaths(program, program.getImplementationSourceFiles()),
|
|
@@ -544,6 +622,20 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
544
622
|
if (pass === 31)
|
|
545
623
|
throw new Error("static program-root discovery did not converge");
|
|
546
624
|
}
|
|
625
|
+
// Node 24 ships no temporal global, but TS 7 types it in an ESNext
|
|
626
|
+
// lib slice. Programs that name it (feature probes such as smol-toml's
|
|
627
|
+
// typeof check) get that slice so they type-check, and lower to Node's
|
|
628
|
+
// answers (typeof "undefined", ReferenceError on use). Every other
|
|
629
|
+
// program keeps the identical lib set: the slice would add globals to
|
|
630
|
+
// the checker's world for everyone.
|
|
631
|
+
if (programNamesTemporal7(program)) {
|
|
632
|
+
program.dispose();
|
|
633
|
+
options = {
|
|
634
|
+
...options,
|
|
635
|
+
lib: [...(options.lib ?? []), TEMPORAL_LIB],
|
|
636
|
+
};
|
|
637
|
+
program = host.createProgram([...programRoots, overridesDtsPath()], options);
|
|
638
|
+
}
|
|
547
639
|
const entry = program.getSourceFile(entryPath);
|
|
548
640
|
if (!entry)
|
|
549
641
|
throw new Error(`could not load ${entryPath}`);
|
|
@@ -558,6 +650,7 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
558
650
|
nodeFallback: nodeTypes === null,
|
|
559
651
|
projectLib: config.projectLib ?? null,
|
|
560
652
|
forcedStrictNullChecks: config.forcedStrictNullChecks ?? false,
|
|
653
|
+
projectCheckJs: config.checkJs ?? false,
|
|
561
654
|
},
|
|
562
655
|
externalTypes,
|
|
563
656
|
externalTypeSpecifiersByFile,
|
|
@@ -594,7 +687,11 @@ export function loadProgram(entryPath, services, opts) {
|
|
|
594
687
|
}
|
|
595
688
|
externalTypes.set(specifier, declarationPath);
|
|
596
689
|
}
|
|
597
|
-
|
|
690
|
+
// Packages scriptc implements itself or the project marks never loaded
|
|
691
|
+
// (package-shims.ts) never compile their published JavaScript, even when
|
|
692
|
+
// named.
|
|
693
|
+
configurePackageShims(entryPath);
|
|
694
|
+
const npmStaticPackages = [...new Set(opts?.npmStatic ?? [])].filter((name) => !isPackageShimName(name));
|
|
598
695
|
// Resolve authored declaration entries before enabling the JS-only
|
|
599
696
|
// package resolver. Safe overload metadata binds through the runtime
|
|
600
697
|
// entry to one exact implementation file; it never contributes values
|
|
@@ -706,13 +803,14 @@ export function loadProgram(entryPath, services, opts) {
|
|
|
706
803
|
// the checker, so its resolution lands on the JS Node actually loads;
|
|
707
804
|
// resolve.ts answers the same sibling for scriptc's own edges).
|
|
708
805
|
const npmShadow = npmStaticFsShadow(services);
|
|
806
|
+
clearProgramBuiltinAliasCache();
|
|
709
807
|
const fsShadow = {
|
|
710
|
-
readFile: (path) => npmShadow?.readFile(path),
|
|
808
|
+
readFile: (path) => npmShadow?.readFile(path) ?? programBuiltinAliasSource(services, path),
|
|
711
809
|
hideFile: (path) => (npmShadow?.hideFile(path) ?? false) || projectDtsRuntimeSibling(path) !== null,
|
|
712
810
|
};
|
|
713
811
|
const host = services.createProgramHost({ cwd: dirname(entryPath), fsShadow });
|
|
714
812
|
try {
|
|
715
|
-
const load = loadProgram7(host, entryPath, externalTypes);
|
|
813
|
+
const load = loadProgram7(host, entryPath, externalTypes, npmStaticPackages.length > 0);
|
|
716
814
|
let authoredHost = null;
|
|
717
815
|
let authoredLoad = null;
|
|
718
816
|
return {
|
|
@@ -757,9 +855,11 @@ export function loadProgram(entryPath, services, opts) {
|
|
|
757
855
|
* preflight diagnostics. Preserve the caller's complete load shape when
|
|
758
856
|
* mutating it, including its owned services and disposal callback. */
|
|
759
857
|
export function checkPreflight(load) {
|
|
760
|
-
const { diags, moduleOrder, startupCrash } = preflight7(load);
|
|
858
|
+
const { diags, moduleOrder, startupCrash, inlineRequireCycleCalls, moduleEdges } = preflight7(load);
|
|
761
859
|
load.moduleOrder = moduleOrder;
|
|
762
860
|
load.startupCrash = startupCrash;
|
|
861
|
+
load.inlineRequireCycleCalls = inlineRequireCycleCalls;
|
|
862
|
+
load.moduleEdges = moduleEdges;
|
|
763
863
|
return diags;
|
|
764
864
|
}
|
|
765
865
|
/* Finding 5: tsgo's strict CommonJS modeling fires checker codes on JS
|
|
@@ -779,6 +879,13 @@ export function checkPreflight(load) {
|
|
|
779
879
|
// retains only their call signature after a factory return. Heritage
|
|
780
880
|
// lowering separately verifies the actual constructor implementation.
|
|
781
881
|
const TS7_JS_RELAXED_EXTRA = new Set([2309, 2323, 2507]);
|
|
882
|
+
/** Relaxed JavaScript codes that checked JavaScript files keep: values of
|
|
883
|
+
* another type in a typed slot (2322 and its elaborations 2740/2741/2559,
|
|
884
|
+
* 2345, 2769), call arity (2554-2556) and incompatible subclass members
|
|
885
|
+
* (2415). */
|
|
886
|
+
const CHECKED_JS_ENFORCED_CODES = new Set([
|
|
887
|
+
2322, 2345, 2415, 2554, 2555, 2556, 2559, 2740, 2741, 2769,
|
|
888
|
+
]);
|
|
782
889
|
function suppressedJsStrictness7(d) {
|
|
783
890
|
const file = d.fileName;
|
|
784
891
|
if (!file || !isJsSourceFileName(file))
|
|
@@ -812,9 +919,9 @@ function requireSpecOf7(node) {
|
|
|
812
919
|
return null;
|
|
813
920
|
if (!ts.isIdentifier(value.expression) || value.expression.text !== "require")
|
|
814
921
|
return null;
|
|
815
|
-
if (value.arguments.length !== 1)
|
|
922
|
+
if (value.arguments.nodes.length !== 1)
|
|
816
923
|
return null;
|
|
817
|
-
const arg = value.arguments[0];
|
|
924
|
+
const arg = value.arguments.nodes[0];
|
|
818
925
|
return ts.isStringLiteral(arg) ? arg.text : null;
|
|
819
926
|
}
|
|
820
927
|
/** True for statements that are CommonJS require IMPORTS at a module's top
|
|
@@ -827,7 +934,7 @@ function isRequireStatement7(stmt) {
|
|
|
827
934
|
return requireSpecOf7(stmt.expression) !== null;
|
|
828
935
|
if (!ts.isVariableStatement(stmt))
|
|
829
936
|
return false;
|
|
830
|
-
const decls = stmt.declarationList.declarations;
|
|
937
|
+
const decls = stmt.declarationList.declarations.nodes;
|
|
831
938
|
return (decls.length > 0 &&
|
|
832
939
|
decls.every((d) => d.initializer !== undefined && requireSpecOf7(d.initializer) !== null));
|
|
833
940
|
}
|
|
@@ -841,7 +948,7 @@ function requiresOf7(stmt) {
|
|
|
841
948
|
if (!ts.isVariableStatement(stmt))
|
|
842
949
|
return [];
|
|
843
950
|
const out = [];
|
|
844
|
-
for (const decl of stmt.declarationList.declarations) {
|
|
951
|
+
for (const decl of stmt.declarationList.declarations.nodes) {
|
|
845
952
|
const spec = decl.initializer !== undefined ? requireSpecOf7(decl.initializer) : null;
|
|
846
953
|
if (spec !== null)
|
|
847
954
|
out.push({ spec, node: decl, decl });
|
|
@@ -861,9 +968,9 @@ export function isEsModuleStamp(expr) {
|
|
|
861
968
|
callee.name.text !== "defineProperty") {
|
|
862
969
|
return false;
|
|
863
970
|
}
|
|
864
|
-
if (expr.arguments.length !== 3)
|
|
971
|
+
if (expr.arguments.nodes.length !== 3)
|
|
865
972
|
return false;
|
|
866
|
-
const [recv, nameArg, desc] = expr.arguments;
|
|
973
|
+
const [recv, nameArg, desc] = expr.arguments.nodes;
|
|
867
974
|
const isExports = (ts.isIdentifier(recv) && recv.text === "exports") ||
|
|
868
975
|
(ts.isPropertyAccessExpression(recv) &&
|
|
869
976
|
ts.isIdentifier(recv.expression) &&
|
|
@@ -874,9 +981,9 @@ export function isEsModuleStamp(expr) {
|
|
|
874
981
|
return false;
|
|
875
982
|
if (!ts.isStringLiteral(nameArg) || nameArg.text !== "__esModule")
|
|
876
983
|
return false;
|
|
877
|
-
if (!ts.isObjectLiteralExpression(desc) || desc.properties.length !== 1)
|
|
984
|
+
if (!ts.isObjectLiteralExpression(desc) || desc.properties.nodes.length !== 1)
|
|
878
985
|
return false;
|
|
879
|
-
const p = desc.properties[0];
|
|
986
|
+
const p = desc.properties.nodes[0];
|
|
880
987
|
return (ts.isPropertyAssignment(p) &&
|
|
881
988
|
ts.isIdentifier(p.name) &&
|
|
882
989
|
p.name.text === "value" &&
|
|
@@ -890,13 +997,13 @@ function pureCjsExport7(program, stmt) {
|
|
|
890
997
|
const cjs = cjsExportAssignmentOf(stmt);
|
|
891
998
|
if (cjs === null)
|
|
892
999
|
return false;
|
|
893
|
-
const sf =
|
|
1000
|
+
const sf = ts.getSourceFileOfNode(stmt);
|
|
894
1001
|
const plainMember = (left) => {
|
|
895
1002
|
if (!ts.isPropertyAccessExpression(left) || left.questionDotToken)
|
|
896
1003
|
return false;
|
|
897
1004
|
// A replacement export can have setters or non-writable function
|
|
898
1005
|
// properties. Only the wrapper's original object gets this exception.
|
|
899
|
-
if (sf.statements.some((s) => cjsExportAssignmentOf(s)?.kind === "table"))
|
|
1006
|
+
if (sf.statements.nodes.some((s) => cjsExportAssignmentOf(s)?.kind === "table"))
|
|
900
1007
|
return false;
|
|
901
1008
|
if (left.name.text === "__proto__" || left.name.text === "__esModule")
|
|
902
1009
|
return false;
|
|
@@ -938,17 +1045,13 @@ function pureCjsExport7(program, stmt) {
|
|
|
938
1045
|
const checker = program.getTypeChecker();
|
|
939
1046
|
const symbol = checker.getSymbolAtLocation(value);
|
|
940
1047
|
return (symbol !== undefined &&
|
|
941
|
-
|
|
942
|
-
.declarationsOf(symbol)
|
|
943
|
-
.some((decl) => ts.isFunctionDeclaration(decl) && decl.parent === stmt.parent));
|
|
1048
|
+
symbol.declarations.some((decl) => ts.isFunctionDeclaration(decl) && decl.parent === stmt.parent));
|
|
944
1049
|
}
|
|
945
1050
|
function sourceBinding7(program, ident) {
|
|
946
1051
|
const checker = program.getTypeChecker();
|
|
947
1052
|
const symbol = checker.getSymbolAtLocation(ident);
|
|
948
1053
|
return (symbol !== undefined &&
|
|
949
|
-
|
|
950
|
-
.declarationsOf(symbol)
|
|
951
|
-
.some((decl) => !decl.getSourceFile().isDeclarationFile && !ts.isSourceFile(decl)));
|
|
1054
|
+
symbol.declarations.some((decl) => !ts.getSourceFileOfNode(decl).isDeclarationFile && !ts.isSourceFile(decl)));
|
|
952
1055
|
}
|
|
953
1056
|
function purePrefixDecl7(decl) {
|
|
954
1057
|
const init = decl.initializer;
|
|
@@ -972,11 +1075,11 @@ function purePrefixStmt7(program, s) {
|
|
|
972
1075
|
return true; // directive
|
|
973
1076
|
if (isRequireStatement7(s))
|
|
974
1077
|
return true;
|
|
975
|
-
if (isCjsJsFile7(
|
|
1078
|
+
if (isCjsJsFile7(ts.getSourceFileOfNode(s), program)) {
|
|
976
1079
|
if (ts.isExpressionStatement(s) && isEsModuleStamp(s.expression)) {
|
|
977
1080
|
const call = s.expression;
|
|
978
1081
|
const object = call.expression.expression;
|
|
979
|
-
let receiver = call.arguments[0];
|
|
1082
|
+
let receiver = call.arguments.nodes[0];
|
|
980
1083
|
if (ts.isPropertyAccessExpression(receiver))
|
|
981
1084
|
receiver = receiver.expression;
|
|
982
1085
|
if (!sourceBinding7(program, object) &&
|
|
@@ -988,7 +1091,7 @@ function purePrefixStmt7(program, s) {
|
|
|
988
1091
|
return true;
|
|
989
1092
|
}
|
|
990
1093
|
if (ts.isVariableStatement(s)) {
|
|
991
|
-
return s.declarationList.declarations.every(purePrefixDecl7);
|
|
1094
|
+
return s.declarationList.declarations.nodes.every(purePrefixDecl7);
|
|
992
1095
|
}
|
|
993
1096
|
return false;
|
|
994
1097
|
}
|
|
@@ -1012,7 +1115,7 @@ export function bindingEarlyUse7(program, sf, k, decl, precedingDecls) {
|
|
|
1012
1115
|
if (ts.isIdentifier(decl.name))
|
|
1013
1116
|
bound.push(decl.name);
|
|
1014
1117
|
else if (ts.isObjectBindingPattern(decl.name)) {
|
|
1015
|
-
for (const el of decl.name.elements)
|
|
1118
|
+
for (const el of decl.name.elements.nodes)
|
|
1016
1119
|
if (el.name !== undefined && ts.isIdentifier(el.name))
|
|
1017
1120
|
bound.push(el.name);
|
|
1018
1121
|
}
|
|
@@ -1024,7 +1127,7 @@ export function bindingEarlyUse7(program, sf, k, decl, precedingDecls) {
|
|
|
1024
1127
|
}
|
|
1025
1128
|
if (bindings.size === 0)
|
|
1026
1129
|
return null;
|
|
1027
|
-
const stmts = sf.statements;
|
|
1130
|
+
const stmts = sf.statements.nodes;
|
|
1028
1131
|
const hoisted = new Map();
|
|
1029
1132
|
for (const s of stmts) {
|
|
1030
1133
|
if ((ts.isFunctionDeclaration(s) || ts.isClassDeclaration(s)) && s.name) {
|
|
@@ -1083,6 +1186,542 @@ export function bindingEarlyUse7(program, sf, k, decl, precedingDecls) {
|
|
|
1083
1186
|
}
|
|
1084
1187
|
return hit;
|
|
1085
1188
|
}
|
|
1189
|
+
/** The first reference to a top-level require declaration's bindings that
|
|
1190
|
+
* code running before the require completes can reach, or null when no
|
|
1191
|
+
* earlier code can run or reach one. Memoized per program: preflight
|
|
1192
|
+
* decides the fence and the lowering places the initialization checks
|
|
1193
|
+
* from the same answer. */
|
|
1194
|
+
function requireEarlyReference7(program, decl) {
|
|
1195
|
+
const memo = program.analysis.requireEarlyReferences;
|
|
1196
|
+
const cached = memo.get(decl);
|
|
1197
|
+
if (cached !== undefined)
|
|
1198
|
+
return cached;
|
|
1199
|
+
let found = null;
|
|
1200
|
+
const stmt = decl.parent?.parent;
|
|
1201
|
+
const sf = ts.getSourceFileOfNode(decl);
|
|
1202
|
+
if (stmt !== undefined && ts.isVariableStatement(stmt) && ts.isSourceFile(stmt.parent)) {
|
|
1203
|
+
const stmts = sf.statements.nodes;
|
|
1204
|
+
const k = stmts.indexOf(stmt);
|
|
1205
|
+
const declarations = stmt.declarationList.declarations.nodes;
|
|
1206
|
+
// Earlier declarators run too: `const x = read(), dep = require('./dep')`.
|
|
1207
|
+
const precedingDecls = declarations.slice(0, declarations.indexOf(decl));
|
|
1208
|
+
let firstRunnable = program.analysis.requireFirstRunnable.get(sf);
|
|
1209
|
+
if (firstRunnable === undefined) {
|
|
1210
|
+
firstRunnable = stmts.findIndex((s) => !purePrefixStmt7(program, s));
|
|
1211
|
+
program.analysis.requireFirstRunnable.set(sf, firstRunnable);
|
|
1212
|
+
}
|
|
1213
|
+
const prefixCanRun = (firstRunnable >= 0 && firstRunnable < k) || precedingDecls.some((d) => !purePrefixDecl7(d));
|
|
1214
|
+
if (prefixCanRun)
|
|
1215
|
+
found = requireBindingEarlyUse7(program, sf, k, decl, precedingDecls);
|
|
1216
|
+
}
|
|
1217
|
+
memo.set(decl, found);
|
|
1218
|
+
return found;
|
|
1219
|
+
}
|
|
1220
|
+
/** The CommonJS twin of bindingEarlyUse7 for a top-level require binding:
|
|
1221
|
+
* the first reference to one of `decl`'s bindings that code running before
|
|
1222
|
+
* the require completes can reach, or null. It follows Node's evaluation
|
|
1223
|
+
* order instead of the conservative "every earlier statement" scan:
|
|
1224
|
+
* - hoisted functions and classes, and the function and class values a
|
|
1225
|
+
* var stored before the require, run only when reachable code names
|
|
1226
|
+
* them; a class statement runs only its heritage, computed keys,
|
|
1227
|
+
* decorators and static initializers;
|
|
1228
|
+
* - callbacks handed to timers, microtasks and promise reactions run after
|
|
1229
|
+
* the module body, hence after the require;
|
|
1230
|
+
* - publishing a value (`module.exports = f`, `exports.n = f`,
|
|
1231
|
+
* `Object.defineProperty(exports, "n", { get })`, `F.prototype.m = f`)
|
|
1232
|
+
* runs nothing. The published value becomes reachable only when
|
|
1233
|
+
* reachable code reads it back: an `exports.n` read reaches the values
|
|
1234
|
+
* published as `n`, any other read of the export object reaches all of
|
|
1235
|
+
* them, and naming `F` reaches what was stored on `F`. No other module
|
|
1236
|
+
* can read this module's exports before its body completes: require
|
|
1237
|
+
* cycles keep their SC1016 fence and a compiled module graph has no
|
|
1238
|
+
* reflective exports object.
|
|
1239
|
+
* Every other function-like met in reachable code counts as reachable
|
|
1240
|
+
* because it may be handed to a callee. */
|
|
1241
|
+
export function requireBindingEarlyUse7(program, sf, k, decl, precedingDecls,
|
|
1242
|
+
/** A reference of the binding whose early evaluation is known exact. */
|
|
1243
|
+
exactEarlyRead) {
|
|
1244
|
+
const checker = program.getTypeChecker();
|
|
1245
|
+
const bindings = new Set();
|
|
1246
|
+
for (const id of boundNames7(decl.name)) {
|
|
1247
|
+
const sym = checker.getSymbolAtLocation(id);
|
|
1248
|
+
if (sym)
|
|
1249
|
+
bindings.add(sym);
|
|
1250
|
+
}
|
|
1251
|
+
if (bindings.size === 0)
|
|
1252
|
+
return null;
|
|
1253
|
+
const stmts = sf.statements.nodes;
|
|
1254
|
+
const cjs = isCjsJsFile7(sf, program);
|
|
1255
|
+
const symbolOf = (id) => {
|
|
1256
|
+
const parent = id.parent;
|
|
1257
|
+
if (parent !== undefined && ts.isShorthandPropertyAssignment(parent) && parent.name === id) {
|
|
1258
|
+
return checker.getShorthandAssignmentValueSymbol(parent);
|
|
1259
|
+
}
|
|
1260
|
+
return checker.getSymbolAtLocation(id);
|
|
1261
|
+
};
|
|
1262
|
+
// Stored callables and the scans that skip them.
|
|
1263
|
+
const units = new Map();
|
|
1264
|
+
const stored = new Set();
|
|
1265
|
+
const addUnit = (name, node) => {
|
|
1266
|
+
const sym = checker.getSymbolAtLocation(name);
|
|
1267
|
+
if (sym === undefined)
|
|
1268
|
+
return;
|
|
1269
|
+
stored.add(node);
|
|
1270
|
+
const list = units.get(sym);
|
|
1271
|
+
if (list)
|
|
1272
|
+
list.push(node);
|
|
1273
|
+
else
|
|
1274
|
+
units.set(sym, [node]);
|
|
1275
|
+
};
|
|
1276
|
+
const storedCallables = (e, out) => {
|
|
1277
|
+
while (ts.isParenthesizedExpression(e))
|
|
1278
|
+
e = e.expression;
|
|
1279
|
+
if (ts.isArrowFunction(e) || ts.isFunctionExpression(e) || ts.isClassExpression(e)) {
|
|
1280
|
+
out.push(e);
|
|
1281
|
+
}
|
|
1282
|
+
else if (ts.isObjectLiteralExpression(e)) {
|
|
1283
|
+
for (const p of e.properties.nodes) {
|
|
1284
|
+
if ((ts.isMethodDeclaration(p) ||
|
|
1285
|
+
ts.isGetAccessorDeclaration(p) ||
|
|
1286
|
+
ts.isSetAccessorDeclaration(p)) &&
|
|
1287
|
+
!ts.isComputedPropertyName(p.name)) {
|
|
1288
|
+
out.push(p);
|
|
1289
|
+
}
|
|
1290
|
+
else if (ts.isPropertyAssignment(p) && !ts.isComputedPropertyName(p.name)) {
|
|
1291
|
+
storedCallables(p.initializer, out);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
};
|
|
1296
|
+
stmts.forEach((s, i) => {
|
|
1297
|
+
if ((ts.isFunctionDeclaration(s) || ts.isClassDeclaration(s)) && s.name !== undefined) {
|
|
1298
|
+
addUnit(s.name, s);
|
|
1299
|
+
}
|
|
1300
|
+
else if (i < k && ts.isVariableStatement(s)) {
|
|
1301
|
+
for (const d of s.declarationList.declarations.nodes) {
|
|
1302
|
+
if (!ts.isIdentifier(d.name) || d.initializer === undefined)
|
|
1303
|
+
continue;
|
|
1304
|
+
const out = [];
|
|
1305
|
+
storedCallables(d.initializer, out);
|
|
1306
|
+
for (const node of out)
|
|
1307
|
+
addUnit(d.name, node);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
// Callbacks that only run as later jobs never run before the require:
|
|
1312
|
+
// the timers, microtasks and promise reactions. (Event listeners can run
|
|
1313
|
+
// synchronously from an emit, so they keep the conservative rule.)
|
|
1314
|
+
const laterJob = (callee) => {
|
|
1315
|
+
while (ts.isParenthesizedExpression(callee))
|
|
1316
|
+
callee = callee.expression;
|
|
1317
|
+
const name = ts.isIdentifier(callee)
|
|
1318
|
+
? callee.text
|
|
1319
|
+
: ts.isPropertyAccessExpression(callee)
|
|
1320
|
+
? callee.name.text
|
|
1321
|
+
: null;
|
|
1322
|
+
return (name !== null &&
|
|
1323
|
+
(LATER_JOB_BUILTINS7.has(name) || name === "nextTick") &&
|
|
1324
|
+
laterJobCallee7(checker, callee));
|
|
1325
|
+
};
|
|
1326
|
+
if (!hasTopLevelAwait7(sf)) {
|
|
1327
|
+
const callbacks = (e) => {
|
|
1328
|
+
while (ts.isParenthesizedExpression(e))
|
|
1329
|
+
e = e.expression;
|
|
1330
|
+
if (ts.isArrowFunction(e) || ts.isFunctionExpression(e))
|
|
1331
|
+
stored.add(e);
|
|
1332
|
+
};
|
|
1333
|
+
for (const s of stmts.slice(0, k)) {
|
|
1334
|
+
ts.walkPreorder(s, (node) => {
|
|
1335
|
+
if ((ts.isCallExpression(node) || ts.isNewExpression(node)) && laterJob(node.expression)) {
|
|
1336
|
+
for (const arg of node.arguments?.nodes ?? [])
|
|
1337
|
+
callbacks(arg);
|
|
1338
|
+
}
|
|
1339
|
+
return undefined;
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
const isWrapperName = (e, name) => ts.isIdentifier(e) && e.text === name && !sourceBinding7(program, e);
|
|
1344
|
+
/** `this` at the module's top level: the original export object. */
|
|
1345
|
+
const isModuleThis = (e) => {
|
|
1346
|
+
if (e.kind !== ts.SyntaxKind.ThisKeyword)
|
|
1347
|
+
return false;
|
|
1348
|
+
for (let p = e.parent; p !== undefined && !ts.isSourceFile(p); p = p.parent) {
|
|
1349
|
+
if (ts.isFunctionLike(p) && !ts.isArrowFunction(p))
|
|
1350
|
+
return false;
|
|
1351
|
+
if (ts.isClassExpression(p) || ts.isClassDeclaration(p))
|
|
1352
|
+
return false;
|
|
1353
|
+
}
|
|
1354
|
+
return true;
|
|
1355
|
+
};
|
|
1356
|
+
const isExportObject = (e) => isWrapperName(e, "exports") ||
|
|
1357
|
+
isModuleThis(e) ||
|
|
1358
|
+
(isModuleExportsAccess(e) && isWrapperName(e.expression, "module"));
|
|
1359
|
+
const replacesExports = stmts.some((st) => cjsExportAssignmentOf(st)?.kind === "table");
|
|
1360
|
+
// Published values: by export name ("*" for a whole replacement), and by
|
|
1361
|
+
// the stored callable whose properties hold them.
|
|
1362
|
+
const exportLinks = new Map();
|
|
1363
|
+
const ownerLinks = new Map();
|
|
1364
|
+
const reachedKeys = new Set();
|
|
1365
|
+
const writtenKeys = new Set();
|
|
1366
|
+
const reachedUnits = new Set();
|
|
1367
|
+
const work = [];
|
|
1368
|
+
let hit = null;
|
|
1369
|
+
const reachUnit = (node) => {
|
|
1370
|
+
if (reachedUnits.has(node))
|
|
1371
|
+
return;
|
|
1372
|
+
reachedUnits.add(node);
|
|
1373
|
+
work.push(node);
|
|
1374
|
+
};
|
|
1375
|
+
const reachSymbol = (sym) => {
|
|
1376
|
+
for (const node of units.get(sym) ?? [])
|
|
1377
|
+
reachUnit(node);
|
|
1378
|
+
for (const node of ownerLinks.get(sym) ?? [])
|
|
1379
|
+
reachUnit(node);
|
|
1380
|
+
};
|
|
1381
|
+
let allReached = false;
|
|
1382
|
+
const reachKey = (key) => {
|
|
1383
|
+
if (key === null) {
|
|
1384
|
+
allReached = true;
|
|
1385
|
+
for (const list of exportLinks.values())
|
|
1386
|
+
for (const node of list)
|
|
1387
|
+
reachUnit(node);
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
reachedKeys.add(key);
|
|
1391
|
+
for (const name of [key, "*"])
|
|
1392
|
+
for (const node of exportLinks.get(name) ?? [])
|
|
1393
|
+
reachUnit(node);
|
|
1394
|
+
};
|
|
1395
|
+
const keyReached = (key) => allReached || reachedKeys.has(key) || (key === "*" && reachedKeys.size > 0);
|
|
1396
|
+
/** A read of the export object: which published names it can observe. */
|
|
1397
|
+
const exportRead = (node) => {
|
|
1398
|
+
let use = node;
|
|
1399
|
+
while (ts.isParenthesizedExpression(use.parent))
|
|
1400
|
+
use = use.parent;
|
|
1401
|
+
const parent = use.parent;
|
|
1402
|
+
// A truthiness test reads no member (tsc's `this && this.__helper`).
|
|
1403
|
+
if (ts.isBinaryExpression(parent) &&
|
|
1404
|
+
parent.left === use &&
|
|
1405
|
+
parent.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {
|
|
1406
|
+
return;
|
|
1407
|
+
}
|
|
1408
|
+
if (ts.isTypeOfExpression(parent))
|
|
1409
|
+
return;
|
|
1410
|
+
if (ts.isPropertyAccessExpression(parent) && parent.expression === use) {
|
|
1411
|
+
let target = parent;
|
|
1412
|
+
while (ts.isParenthesizedExpression(target.parent))
|
|
1413
|
+
target = target.parent;
|
|
1414
|
+
const assignment = target.parent;
|
|
1415
|
+
if (ts.isBinaryExpression(assignment) &&
|
|
1416
|
+
assignment.left === target &&
|
|
1417
|
+
assignment.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
1418
|
+
// A plain write reads no member. It can still run a setter: one
|
|
1419
|
+
// published for that name (now or later), or a static one of a
|
|
1420
|
+
// replacing class.
|
|
1421
|
+
writtenKeys.add(parent.name.text);
|
|
1422
|
+
for (const node of exportLinks.get(parent.name.text) ?? [])
|
|
1423
|
+
reachUnit(node);
|
|
1424
|
+
for (const node of exportLinks.get("*") ?? []) {
|
|
1425
|
+
if (ts.isClassDeclaration(node) || ts.isClassExpression(node))
|
|
1426
|
+
reachUnit(node);
|
|
1427
|
+
}
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
reachKey(parent.name.text);
|
|
1431
|
+
return;
|
|
1432
|
+
}
|
|
1433
|
+
if (ts.isElementAccessExpression(parent) &&
|
|
1434
|
+
parent.expression === use &&
|
|
1435
|
+
ts.isStringLiteralLike(parent.argumentExpression)) {
|
|
1436
|
+
reachKey(parent.argumentExpression.text);
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1439
|
+
reachKey(null);
|
|
1440
|
+
};
|
|
1441
|
+
const scan = (root) => {
|
|
1442
|
+
ts.walkPreorder(root, (n) => {
|
|
1443
|
+
if (hit !== null)
|
|
1444
|
+
return "stop";
|
|
1445
|
+
if (n !== root && stored.has(n)) {
|
|
1446
|
+
if (ts.isClassExpression(n) || ts.isClassDeclaration(n)) {
|
|
1447
|
+
for (const part of classSyncParts7(n))
|
|
1448
|
+
scan(part);
|
|
1449
|
+
}
|
|
1450
|
+
return "skip";
|
|
1451
|
+
}
|
|
1452
|
+
// A self-require answers this module's partially built exports.
|
|
1453
|
+
if (cjs && ts.isCallExpression(n)) {
|
|
1454
|
+
const spec = requireSpecOf7(n);
|
|
1455
|
+
if (spec !== null && resolveImport7(program, sf, spec, "require") === sf)
|
|
1456
|
+
reachKey(null);
|
|
1457
|
+
}
|
|
1458
|
+
if (cjs && n.kind === ts.SyntaxKind.ThisKeyword && isModuleThis(n)) {
|
|
1459
|
+
exportRead(n);
|
|
1460
|
+
return undefined;
|
|
1461
|
+
}
|
|
1462
|
+
if (!ts.isIdentifier(n))
|
|
1463
|
+
return undefined;
|
|
1464
|
+
if (inTypePosition7(n))
|
|
1465
|
+
return undefined;
|
|
1466
|
+
const named = n.parent;
|
|
1467
|
+
if ((ts.isPropertyAccessExpression(named) ||
|
|
1468
|
+
ts.isPropertyAssignment(named) ||
|
|
1469
|
+
ts.isMethodDeclaration(named) ||
|
|
1470
|
+
ts.isGetAccessorDeclaration(named) ||
|
|
1471
|
+
ts.isSetAccessorDeclaration(named) ||
|
|
1472
|
+
ts.isPropertyDeclaration(named)) &&
|
|
1473
|
+
named.name === n) {
|
|
1474
|
+
return undefined;
|
|
1475
|
+
}
|
|
1476
|
+
// A declaration's own name reads nothing.
|
|
1477
|
+
if (named !== undefined && declaredName7(named) === n)
|
|
1478
|
+
return undefined;
|
|
1479
|
+
if (cjs && isWrapperName(n, "exports")) {
|
|
1480
|
+
exportRead(n);
|
|
1481
|
+
return undefined;
|
|
1482
|
+
}
|
|
1483
|
+
if (cjs && isWrapperName(n, "module")) {
|
|
1484
|
+
const parent = n.parent;
|
|
1485
|
+
if (ts.isPropertyAccessExpression(parent) && parent.expression === n) {
|
|
1486
|
+
if (parent.name.text === "exports")
|
|
1487
|
+
exportRead(parent);
|
|
1488
|
+
return "skip";
|
|
1489
|
+
}
|
|
1490
|
+
reachKey(null);
|
|
1491
|
+
return undefined;
|
|
1492
|
+
}
|
|
1493
|
+
const sym = symbolOf(n);
|
|
1494
|
+
if (sym === undefined)
|
|
1495
|
+
return undefined;
|
|
1496
|
+
if (bindings.has(sym)) {
|
|
1497
|
+
if (exactEarlyRead?.(n) === true)
|
|
1498
|
+
return undefined;
|
|
1499
|
+
hit = n;
|
|
1500
|
+
return "stop";
|
|
1501
|
+
}
|
|
1502
|
+
reachSymbol(sym);
|
|
1503
|
+
return undefined;
|
|
1504
|
+
});
|
|
1505
|
+
};
|
|
1506
|
+
/** Links a published value: evaluating it reads identifiers, but the
|
|
1507
|
+
* callables it names run only once they are read back. */
|
|
1508
|
+
const publish = (value, link) => {
|
|
1509
|
+
while (ts.isParenthesizedExpression(value))
|
|
1510
|
+
value = value.expression;
|
|
1511
|
+
if (ts.isIdentifier(value)) {
|
|
1512
|
+
const sym = symbolOf(value);
|
|
1513
|
+
if (sym !== undefined && bindings.has(sym)) {
|
|
1514
|
+
hit = value;
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
if (sym !== undefined) {
|
|
1518
|
+
// What was stored on the value stays reachable through it.
|
|
1519
|
+
for (const node of [...(units.get(sym) ?? []), ...(ownerLinks.get(sym) ?? [])])
|
|
1520
|
+
link(node);
|
|
1521
|
+
}
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
if (ts.isFunctionExpression(value) || ts.isArrowFunction(value)) {
|
|
1525
|
+
link(value);
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
if (ts.isClassExpression(value)) {
|
|
1529
|
+
for (const part of classSyncParts7(value))
|
|
1530
|
+
scan(part);
|
|
1531
|
+
link(value);
|
|
1532
|
+
return;
|
|
1533
|
+
}
|
|
1534
|
+
if (ts.isObjectLiteralExpression(value)) {
|
|
1535
|
+
for (const p of value.properties.nodes) {
|
|
1536
|
+
if (ts.isShorthandPropertyAssignment(p)) {
|
|
1537
|
+
const sym = checker.getShorthandAssignmentValueSymbol(p);
|
|
1538
|
+
if (sym !== undefined && bindings.has(sym))
|
|
1539
|
+
hit = p.name;
|
|
1540
|
+
else if (sym !== undefined) {
|
|
1541
|
+
for (const node of [...(units.get(sym) ?? []), ...(ownerLinks.get(sym) ?? [])]) {
|
|
1542
|
+
link(node);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
else if (ts.isPropertyAssignment(p) && !ts.isComputedPropertyName(p.name)) {
|
|
1547
|
+
publish(p.initializer, link);
|
|
1548
|
+
}
|
|
1549
|
+
else if ((ts.isMethodDeclaration(p) ||
|
|
1550
|
+
ts.isGetAccessorDeclaration(p) ||
|
|
1551
|
+
ts.isSetAccessorDeclaration(p)) &&
|
|
1552
|
+
!ts.isComputedPropertyName(p.name)) {
|
|
1553
|
+
link(p);
|
|
1554
|
+
}
|
|
1555
|
+
else
|
|
1556
|
+
scan(p);
|
|
1557
|
+
}
|
|
1558
|
+
return;
|
|
1559
|
+
}
|
|
1560
|
+
if (ts.isStringLiteralLike(value) ||
|
|
1561
|
+
ts.isNumericLiteral(value) ||
|
|
1562
|
+
value.kind === ts.SyntaxKind.TrueKeyword ||
|
|
1563
|
+
value.kind === ts.SyntaxKind.FalseKeyword ||
|
|
1564
|
+
value.kind === ts.SyntaxKind.NullKeyword ||
|
|
1565
|
+
(ts.isVoidExpression(value) && ts.isNumericLiteral(value.expression))) {
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
scan(value);
|
|
1569
|
+
// Whatever an arbitrary expression evaluates to is opaque: treat it as
|
|
1570
|
+
// reachable through the target too (scan already reached its parts).
|
|
1571
|
+
};
|
|
1572
|
+
const targetOf = (left) => {
|
|
1573
|
+
if (isModuleExportsAccess(left) && isWrapperName(left.expression, "module")) {
|
|
1574
|
+
return { kind: "key", key: "*" };
|
|
1575
|
+
}
|
|
1576
|
+
const names = [];
|
|
1577
|
+
let e = left;
|
|
1578
|
+
for (;;) {
|
|
1579
|
+
if (ts.isPropertyAccessExpression(e) && !e.questionDotToken) {
|
|
1580
|
+
if (isExportObject(e))
|
|
1581
|
+
break;
|
|
1582
|
+
names.unshift(e.name.text);
|
|
1583
|
+
e = e.expression;
|
|
1584
|
+
}
|
|
1585
|
+
else if (ts.isElementAccessExpression(e) &&
|
|
1586
|
+
!e.questionDotToken &&
|
|
1587
|
+
ts.isStringLiteralLike(e.argumentExpression)) {
|
|
1588
|
+
names.unshift(e.argumentExpression.text);
|
|
1589
|
+
e = e.expression;
|
|
1590
|
+
}
|
|
1591
|
+
else
|
|
1592
|
+
break;
|
|
1593
|
+
}
|
|
1594
|
+
if (names.length === 0)
|
|
1595
|
+
return null;
|
|
1596
|
+
if (isExportObject(e)) {
|
|
1597
|
+
// __proto__ and the interop marker are not plain data slots, and a
|
|
1598
|
+
// member of a replaced export may be a read-only function property:
|
|
1599
|
+
// those writes keep the conservative scan.
|
|
1600
|
+
if (names[0] === "__proto__" || names[0] === "__esModule" || replacesExports)
|
|
1601
|
+
return null;
|
|
1602
|
+
return { kind: "key", key: names[0] };
|
|
1603
|
+
}
|
|
1604
|
+
if (ts.isIdentifier(e)) {
|
|
1605
|
+
const sym = symbolOf(e);
|
|
1606
|
+
if (sym !== undefined && units.has(sym) && !bindings.has(sym))
|
|
1607
|
+
return { kind: "owner", owner: sym };
|
|
1608
|
+
}
|
|
1609
|
+
return null;
|
|
1610
|
+
};
|
|
1611
|
+
const linkTo = (target, node) => {
|
|
1612
|
+
if (target.kind === "key") {
|
|
1613
|
+
const replacingClass = target.key === "*" &&
|
|
1614
|
+
writtenKeys.size > 0 &&
|
|
1615
|
+
(ts.isClassDeclaration(node) || ts.isClassExpression(node));
|
|
1616
|
+
if (keyReached(target.key) || writtenKeys.has(target.key) || replacingClass) {
|
|
1617
|
+
reachUnit(node);
|
|
1618
|
+
}
|
|
1619
|
+
const list = exportLinks.get(target.key);
|
|
1620
|
+
if (list)
|
|
1621
|
+
list.push(node);
|
|
1622
|
+
else
|
|
1623
|
+
exportLinks.set(target.key, [node]);
|
|
1624
|
+
}
|
|
1625
|
+
else {
|
|
1626
|
+
if ((units.get(target.owner) ?? []).some((u) => reachedUnits.has(u)))
|
|
1627
|
+
reachUnit(node);
|
|
1628
|
+
if ((units.get(target.owner) ?? []).includes(node))
|
|
1629
|
+
return;
|
|
1630
|
+
const list = ownerLinks.get(target.owner);
|
|
1631
|
+
if (list === undefined)
|
|
1632
|
+
ownerLinks.set(target.owner, [node]);
|
|
1633
|
+
else if (!list.includes(node))
|
|
1634
|
+
list.push(node);
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
/** A top-level publication statement, handled in place; false for any
|
|
1638
|
+
* other statement. */
|
|
1639
|
+
const publication = (s) => {
|
|
1640
|
+
if (!cjs || !ts.isExpressionStatement(s))
|
|
1641
|
+
return false;
|
|
1642
|
+
const e = s.expression;
|
|
1643
|
+
if (ts.isBinaryExpression(e) && e.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
1644
|
+
const targets = [];
|
|
1645
|
+
let value = e;
|
|
1646
|
+
while (ts.isBinaryExpression(value) &&
|
|
1647
|
+
value.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
1648
|
+
const target = targetOf(value.left);
|
|
1649
|
+
if (target === null)
|
|
1650
|
+
return false;
|
|
1651
|
+
targets.push(target);
|
|
1652
|
+
value = value.right;
|
|
1653
|
+
}
|
|
1654
|
+
publish(value, (node) => {
|
|
1655
|
+
for (const t of targets)
|
|
1656
|
+
linkTo(t, node);
|
|
1657
|
+
});
|
|
1658
|
+
return true;
|
|
1659
|
+
}
|
|
1660
|
+
// Object.defineProperty(exports, "name", { get() {...}, value: f, ... })
|
|
1661
|
+
if (ts.isCallExpression(e) &&
|
|
1662
|
+
ts.isPropertyAccessExpression(e.expression) &&
|
|
1663
|
+
isWrapperName(e.expression.expression, "Object") &&
|
|
1664
|
+
e.expression.name.text === "defineProperty" &&
|
|
1665
|
+
e.arguments.nodes.length === 3) {
|
|
1666
|
+
const [recv, key, desc] = e.arguments.nodes;
|
|
1667
|
+
if (!isExportObject(recv) || !ts.isStringLiteralLike(key))
|
|
1668
|
+
return false;
|
|
1669
|
+
if (!ts.isObjectLiteralExpression(desc))
|
|
1670
|
+
return false;
|
|
1671
|
+
const keyTarget = { kind: "key", key: key.text };
|
|
1672
|
+
const link = (node) => linkTo(keyTarget, node);
|
|
1673
|
+
for (const p of desc.properties.nodes) {
|
|
1674
|
+
if ((ts.isMethodDeclaration(p) || ts.isPropertyAssignment(p)) &&
|
|
1675
|
+
ts.isIdentifier(p.name) &&
|
|
1676
|
+
(p.name.text === "get" || p.name.text === "set")) {
|
|
1677
|
+
if (ts.isMethodDeclaration(p))
|
|
1678
|
+
link(p);
|
|
1679
|
+
else
|
|
1680
|
+
publish(p.initializer, link);
|
|
1681
|
+
}
|
|
1682
|
+
else if (ts.isPropertyAssignment(p) &&
|
|
1683
|
+
ts.isIdentifier(p.name) &&
|
|
1684
|
+
p.name.text === "value") {
|
|
1685
|
+
publish(p.initializer, link);
|
|
1686
|
+
}
|
|
1687
|
+
else
|
|
1688
|
+
scan(p);
|
|
1689
|
+
}
|
|
1690
|
+
return true;
|
|
1691
|
+
}
|
|
1692
|
+
return false;
|
|
1693
|
+
};
|
|
1694
|
+
const drain = () => {
|
|
1695
|
+
while (hit === null && work.length > 0) {
|
|
1696
|
+
const unit = work.pop();
|
|
1697
|
+
checker.prefetchSymbolRoots([unit]);
|
|
1698
|
+
scan(unit);
|
|
1699
|
+
}
|
|
1700
|
+
};
|
|
1701
|
+
const roots = stmts.slice(0, k);
|
|
1702
|
+
checker.prefetchSymbolRoots([...roots, ...precedingDecls]);
|
|
1703
|
+
for (const s of roots) {
|
|
1704
|
+
if (hit !== null)
|
|
1705
|
+
break;
|
|
1706
|
+
if (ts.isFunctionDeclaration(s))
|
|
1707
|
+
continue;
|
|
1708
|
+
if (ts.isClassDeclaration(s)) {
|
|
1709
|
+
for (const part of classSyncParts7(s))
|
|
1710
|
+
scan(part);
|
|
1711
|
+
}
|
|
1712
|
+
else if (!publication(s)) {
|
|
1713
|
+
scan(s);
|
|
1714
|
+
}
|
|
1715
|
+
drain();
|
|
1716
|
+
}
|
|
1717
|
+
for (const d of precedingDecls) {
|
|
1718
|
+
if (hit !== null)
|
|
1719
|
+
break;
|
|
1720
|
+
scan(d);
|
|
1721
|
+
drain();
|
|
1722
|
+
}
|
|
1723
|
+
return hit;
|
|
1724
|
+
}
|
|
1086
1725
|
/** Bare `require("...")` EXPRESSION STATEMENTS anywhere below the top
|
|
1087
1726
|
* level of a file — inside top-level ifs/blocks/loops and inside function
|
|
1088
1727
|
* bodies (the lazy-require idiom). No bindings, pure side-effect loads. */
|
|
@@ -1101,6 +1740,35 @@ function nestedBareRequiresOf7(sf) {
|
|
|
1101
1740
|
});
|
|
1102
1741
|
return out;
|
|
1103
1742
|
}
|
|
1743
|
+
/** INLINE `require("...")` calls in expression position anywhere in a file
|
|
1744
|
+
* (`require("./x").f`, `require("debug")("ns")`, `module.exports =
|
|
1745
|
+
* require("./y")`, `{ v: require("./v") }`): each evaluates its module at
|
|
1746
|
+
* that position, exactly like a bare require statement. Top-level require
|
|
1747
|
+
* statements and bare require statements are collected by their own
|
|
1748
|
+
* scans; a require that initializes a nested declaration keeps its
|
|
1749
|
+
* lowering fence and is not an edge. */
|
|
1750
|
+
function inlineRequiresOf7(sf) {
|
|
1751
|
+
const out = [];
|
|
1752
|
+
ts.walkPreorder(sf, (n) => {
|
|
1753
|
+
if (!ts.isCallExpression(n) || requireSpecOf7(n) === null)
|
|
1754
|
+
return;
|
|
1755
|
+
let outer = n;
|
|
1756
|
+
while (outer.parent !== undefined &&
|
|
1757
|
+
(ts.isParenthesizedExpression(outer.parent) ||
|
|
1758
|
+
ts.isAsExpression(outer.parent) ||
|
|
1759
|
+
ts.isTypeAssertion(outer.parent) ||
|
|
1760
|
+
ts.isNonNullExpression(outer.parent))) {
|
|
1761
|
+
outer = outer.parent;
|
|
1762
|
+
}
|
|
1763
|
+
const parent = outer.parent;
|
|
1764
|
+
if (parent !== undefined && ts.isExpressionStatement(parent))
|
|
1765
|
+
return;
|
|
1766
|
+
if (parent !== undefined && ts.isVariableDeclaration(parent) && parent.initializer === outer)
|
|
1767
|
+
return;
|
|
1768
|
+
out.push(n);
|
|
1769
|
+
});
|
|
1770
|
+
return out;
|
|
1771
|
+
}
|
|
1104
1772
|
function stripRequireCasts7(expr) {
|
|
1105
1773
|
let cur = expr;
|
|
1106
1774
|
while (ts.isParenthesizedExpression(cur) ||
|
|
@@ -1117,7 +1785,7 @@ function stripRequireCasts7(expr) {
|
|
|
1117
1785
|
function isCreateRequireImport7(program, ident) {
|
|
1118
1786
|
const checker = program.getTypeChecker();
|
|
1119
1787
|
const symbol = checker.getSymbolAtLocation(ident);
|
|
1120
|
-
const decl = symbol ?
|
|
1788
|
+
const decl = symbol ? symbol.declarations[0] : undefined;
|
|
1121
1789
|
if (decl === undefined || !ts.isImportSpecifier(decl))
|
|
1122
1790
|
return false;
|
|
1123
1791
|
const importDecl = decl.parent?.parent?.parent;
|
|
@@ -1129,11 +1797,12 @@ function isCreateRequireImport7(program, ident) {
|
|
|
1129
1797
|
}
|
|
1130
1798
|
if (symbol !== undefined && (symbol.flags & ts.SymbolFlags.Alias) !== 0) {
|
|
1131
1799
|
const target = checker.getAliasedSymbol(symbol);
|
|
1132
|
-
const targetDecl =
|
|
1133
|
-
if (targetDecl !== undefined &&
|
|
1800
|
+
const targetDecl = target.declarations[0];
|
|
1801
|
+
if (targetDecl !== undefined && ts.getSourceFileOfNode(targetDecl).isDeclarationFile) {
|
|
1134
1802
|
for (let p = targetDecl.parent; p !== undefined && !ts.isSourceFile(p); p = p.parent) {
|
|
1135
1803
|
if (ts.isModuleDeclaration(p) && ts.isStringLiteral(p.name)) {
|
|
1136
|
-
return (canonicalBuiltinModule(p.name.text) === "module" &&
|
|
1804
|
+
return (canonicalBuiltinModule(p.name.text) === "module" &&
|
|
1805
|
+
ts.symbolName(target) === "createRequire");
|
|
1137
1806
|
}
|
|
1138
1807
|
}
|
|
1139
1808
|
}
|
|
@@ -1147,9 +1816,7 @@ export function isCreateRequireBinding7(program, callee) {
|
|
|
1147
1816
|
const checker = program.getTypeChecker();
|
|
1148
1817
|
const symbol = checker.getSymbolAtLocation(callee);
|
|
1149
1818
|
const decl = symbol
|
|
1150
|
-
?
|
|
1151
|
-
.declarationsOf(symbol)
|
|
1152
|
-
.find((d) => ts.isVariableDeclaration(d))
|
|
1819
|
+
? symbol.declarations.find((d) => ts.isVariableDeclaration(d))
|
|
1153
1820
|
: undefined;
|
|
1154
1821
|
if (decl === undefined ||
|
|
1155
1822
|
decl.initializer === undefined ||
|
|
@@ -1182,13 +1849,14 @@ function staticCreateRequireUse7(expr) {
|
|
|
1182
1849
|
return (ts.isCallExpression(call) &&
|
|
1183
1850
|
call.expression === use &&
|
|
1184
1851
|
!call.questionDotToken &&
|
|
1185
|
-
call.arguments.length === 1 &&
|
|
1186
|
-
ts.isStringLiteralLike(call.arguments[0]));
|
|
1852
|
+
call.arguments.nodes.length === 1 &&
|
|
1853
|
+
ts.isStringLiteralLike(call.arguments.nodes[0]));
|
|
1187
1854
|
}
|
|
1188
1855
|
function stableCreateRequireBindingReason7(program, decl) {
|
|
1189
1856
|
const cache = program.analysis.createRequireReasons;
|
|
1190
|
-
|
|
1191
|
-
|
|
1857
|
+
const cached = cache.get(decl);
|
|
1858
|
+
if (cached !== undefined)
|
|
1859
|
+
return cached;
|
|
1192
1860
|
const check = () => {
|
|
1193
1861
|
const stmt = decl.parent?.parent;
|
|
1194
1862
|
if (!ts.isIdentifier(decl.name) ||
|
|
@@ -1198,11 +1866,11 @@ function stableCreateRequireBindingReason7(program, decl) {
|
|
|
1198
1866
|
}
|
|
1199
1867
|
const checker = program.getTypeChecker();
|
|
1200
1868
|
const symbol = checker.getSymbolAtLocation(decl.name);
|
|
1201
|
-
if (!symbol ||
|
|
1869
|
+
if (!symbol || symbol.declarations.length !== 1)
|
|
1202
1870
|
return "its createRequire binding is redeclared";
|
|
1203
1871
|
if ((ts.getCombinedModifierFlags(decl) & ts.ModifierFlags.Export) !== 0)
|
|
1204
1872
|
return "its createRequire result escapes through an exported binding";
|
|
1205
|
-
const sf =
|
|
1873
|
+
const sf = ts.getSourceFileOfNode(decl);
|
|
1206
1874
|
const refs = identifierOccurrences7(sf, decl.name.text);
|
|
1207
1875
|
checker.prefetchSymbolNodesExact(refs);
|
|
1208
1876
|
for (const ref of refs) {
|
|
@@ -1217,8 +1885,8 @@ function stableCreateRequireBindingReason7(program, decl) {
|
|
|
1217
1885
|
return "its createRequire binding is reassigned, escapes, or uses a computed specifier";
|
|
1218
1886
|
}
|
|
1219
1887
|
}
|
|
1220
|
-
const preceding = stmt.declarationList.declarations.slice(0, stmt.declarationList.declarations.indexOf(decl));
|
|
1221
|
-
if (bindingEarlyUse7(program, sf, sf.statements.indexOf(stmt), decl, preceding) !== null) {
|
|
1888
|
+
const preceding = stmt.declarationList.declarations.nodes.slice(0, stmt.declarationList.declarations.nodes.indexOf(decl));
|
|
1889
|
+
if (bindingEarlyUse7(program, sf, sf.statements.nodes.indexOf(stmt), decl, preceding) !== null) {
|
|
1222
1890
|
return "its createRequire binding can be used before initialization";
|
|
1223
1891
|
}
|
|
1224
1892
|
return null;
|
|
@@ -1233,10 +1901,10 @@ function isCreateRequireBaseCall7(program, expr) {
|
|
|
1233
1901
|
init.questionDotToken !== undefined ||
|
|
1234
1902
|
!ts.isIdentifier(init.expression) ||
|
|
1235
1903
|
!isCreateRequireImport7(program, init.expression) ||
|
|
1236
|
-
init.arguments.length !== 1) {
|
|
1904
|
+
init.arguments.nodes.length !== 1) {
|
|
1237
1905
|
return false;
|
|
1238
1906
|
}
|
|
1239
|
-
const base = stripRequireCasts7(init.arguments[0]);
|
|
1907
|
+
const base = stripRequireCasts7(init.arguments.nodes[0]);
|
|
1240
1908
|
if (ts.isIdentifier(base) && base.text === "__filename")
|
|
1241
1909
|
return !sourceBinding7(program, base);
|
|
1242
1910
|
return (ts.isPropertyAccessExpression(base) &&
|
|
@@ -1259,8 +1927,8 @@ function npmStaticModuleImportReason7(program, stmt) {
|
|
|
1259
1927
|
if (!bindings || !ts.isNamedImports(bindings))
|
|
1260
1928
|
return null;
|
|
1261
1929
|
const checker = program.getTypeChecker();
|
|
1262
|
-
const sf =
|
|
1263
|
-
for (const specifier of bindings.elements) {
|
|
1930
|
+
const sf = ts.getSourceFileOfNode(stmt);
|
|
1931
|
+
for (const specifier of bindings.elements.nodes) {
|
|
1264
1932
|
if ((specifier.propertyName?.text ?? specifier.name.text) !== "createRequire")
|
|
1265
1933
|
continue;
|
|
1266
1934
|
const imported = checker.getSymbolAtLocation(specifier.name);
|
|
@@ -1335,8 +2003,8 @@ function requireCallBindingKind7(program, node) {
|
|
|
1335
2003
|
const symbol = checker.getSymbolAtLocation(call.expression);
|
|
1336
2004
|
if (symbol === undefined)
|
|
1337
2005
|
return "ambient";
|
|
1338
|
-
const decls =
|
|
1339
|
-
if (decls.every((d) =>
|
|
2006
|
+
const decls = symbol.declarations;
|
|
2007
|
+
if (decls.every((d) => ts.getSourceFileOfNode(d).isDeclarationFile))
|
|
1340
2008
|
return "ambient";
|
|
1341
2009
|
return isCreateRequireBinding7(program, call.expression) ? "createRequire" : "source";
|
|
1342
2010
|
}
|
|
@@ -1349,7 +2017,7 @@ const CJS_WRAPPER_NAMES = new Set(["require", "module", "exports", "__dirname",
|
|
|
1349
2017
|
function bindingDeclaresCjsWrapper7(name) {
|
|
1350
2018
|
if (ts.isIdentifier(name))
|
|
1351
2019
|
return CJS_WRAPPER_NAMES.has(name.text) ? name : null;
|
|
1352
|
-
for (const el of name.elements) {
|
|
2020
|
+
for (const el of name.elements.nodes) {
|
|
1353
2021
|
if (el.name === undefined)
|
|
1354
2022
|
continue;
|
|
1355
2023
|
const hit = bindingDeclaresCjsWrapper7(el.name);
|
|
@@ -1372,10 +2040,10 @@ function insideFunctionLike7(node) {
|
|
|
1372
2040
|
* import/export forms, import.meta, top-level await/for-await, or a top-level
|
|
1373
2041
|
* lexical declaration that would redeclare a CommonJS wrapper binding. */
|
|
1374
2042
|
function nodeEsmSyntaxMarker7(sf) {
|
|
1375
|
-
for (const stmt of sf.statements) {
|
|
2043
|
+
for (const stmt of sf.statements.nodes) {
|
|
1376
2044
|
if (ts.isImportDeclaration(stmt) && !erasedTypeOnlyImport(stmt))
|
|
1377
2045
|
return stmt;
|
|
1378
|
-
if (ts.isExportDeclaration(stmt) && !stmt.isTypeOnly
|
|
2046
|
+
if (ts.isExportDeclaration(stmt) && !stmt.isTypeOnly) {
|
|
1379
2047
|
return stmt;
|
|
1380
2048
|
}
|
|
1381
2049
|
if (ts.isExportAssignment(stmt))
|
|
@@ -1386,7 +2054,7 @@ function nodeEsmSyntaxMarker7(sf) {
|
|
|
1386
2054
|
}
|
|
1387
2055
|
if (ts.isVariableStatement(stmt) &&
|
|
1388
2056
|
(stmt.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) !== 0) {
|
|
1389
|
-
for (const decl of stmt.declarationList.declarations) {
|
|
2057
|
+
for (const decl of stmt.declarationList.declarations.nodes) {
|
|
1390
2058
|
const hit = bindingDeclaresCjsWrapper7(decl.name);
|
|
1391
2059
|
if (hit !== null)
|
|
1392
2060
|
return hit;
|
|
@@ -1479,15 +2147,15 @@ function selfImportTdzFences7(program, sf, clause, diags) {
|
|
|
1479
2147
|
// The aliased declaration's TDZ horizon: the position after which reads
|
|
1480
2148
|
// are initialized. Hoisted functions have none.
|
|
1481
2149
|
const tdzEndOf = (aliased) => {
|
|
1482
|
-
const d =
|
|
1483
|
-
if (d === undefined ||
|
|
2150
|
+
const d = aliased.valueDeclaration ?? aliased.declarations[0];
|
|
2151
|
+
if (d === undefined || ts.getSourceFileOfNode(d) !== sf)
|
|
1484
2152
|
return null;
|
|
1485
2153
|
if (ts.isFunctionDeclaration(d))
|
|
1486
2154
|
return null;
|
|
1487
|
-
return d.
|
|
2155
|
+
return d.end;
|
|
1488
2156
|
};
|
|
1489
2157
|
const fence = (ref, name) => {
|
|
1490
|
-
diags.push(unsupportedDiag("SC1030", { file: sf.fileName, start:
|
|
2158
|
+
diags.push(unsupportedDiag("SC1030", { file: sf.fileName, start: ts.tokenStartOfNode(ref), end: ref.end }, `the self-import binding '${name}' read above its declaration (the import aliases this module's OWN binding — Node initializes it when the declaration executes, so this read throws ReferenceError; move the read below the declaration)`));
|
|
1491
2159
|
};
|
|
1492
2160
|
const checkNamed = (bindingName) => {
|
|
1493
2161
|
const sym = checker.getSymbolAtLocation(bindingName);
|
|
@@ -1501,7 +2169,7 @@ function selfImportTdzFences7(program, sf, clause, diags) {
|
|
|
1501
2169
|
if (ts.isIdentifier(node) &&
|
|
1502
2170
|
node !== bindingName &&
|
|
1503
2171
|
node.text === bindingName.text &&
|
|
1504
|
-
|
|
2172
|
+
ts.tokenStartOfNode(node) < end &&
|
|
1505
2173
|
!insideFunction(node) &&
|
|
1506
2174
|
checker.getSymbolAtLocation(node) === sym) {
|
|
1507
2175
|
fence(node, bindingName.text);
|
|
@@ -1513,7 +2181,7 @@ function selfImportTdzFences7(program, sf, clause, diags) {
|
|
|
1513
2181
|
if (clause.name !== undefined)
|
|
1514
2182
|
checkNamed(clause.name);
|
|
1515
2183
|
if (clause.namedBindings !== undefined && ts.isNamedImports(clause.namedBindings)) {
|
|
1516
|
-
for (const el of clause.namedBindings.elements) {
|
|
2184
|
+
for (const el of clause.namedBindings.elements.nodes) {
|
|
1517
2185
|
if (!el.isTypeOnly)
|
|
1518
2186
|
checkNamed(el.name);
|
|
1519
2187
|
}
|
|
@@ -1534,7 +2202,7 @@ function selfImportTdzFences7(program, sf, clause, diags) {
|
|
|
1534
2202
|
const memberSym = checker.getSymbolAtLocation(node.name);
|
|
1535
2203
|
if (memberSym !== undefined) {
|
|
1536
2204
|
const end = tdzEndOf(memberSym);
|
|
1537
|
-
if (end !== null &&
|
|
2205
|
+
if (end !== null && ts.tokenStartOfNode(node) < end)
|
|
1538
2206
|
fence(node.expression, `${nsName.text}.${node.name.text}`);
|
|
1539
2207
|
}
|
|
1540
2208
|
}
|
|
@@ -1632,7 +2300,7 @@ function inTypePosition7(node) {
|
|
|
1632
2300
|
* coercion of a user object) disqualifies the module's cycles. */
|
|
1633
2301
|
function nonInertTopLevel7(program, sf) {
|
|
1634
2302
|
const nonInert = topLevelInertness7(program);
|
|
1635
|
-
for (const stmt of sf.statements) {
|
|
2303
|
+
for (const stmt of sf.statements.nodes) {
|
|
1636
2304
|
const offence = nonInert(stmt);
|
|
1637
2305
|
if (offence !== null)
|
|
1638
2306
|
return offence;
|
|
@@ -1677,10 +2345,10 @@ function topLevelInertness7(program) {
|
|
|
1677
2345
|
return false;
|
|
1678
2346
|
if (sym.flags & ts.SymbolFlags.Alias)
|
|
1679
2347
|
sym = checker.getAliasedSymbol(sym);
|
|
1680
|
-
const decls =
|
|
1681
|
-
return decls.length > 0 && decls.every((d) =>
|
|
2348
|
+
const decls = sym.declarations;
|
|
2349
|
+
return decls.length > 0 && decls.every((d) => ts.getSourceFileOfNode(d).isDeclarationFile);
|
|
1682
2350
|
};
|
|
1683
|
-
const hasDecorator = (n) => (n.modifiers ?? []).some((m) => m.kind === ts.SyntaxKind.Decorator);
|
|
2351
|
+
const hasDecorator = (n) => (n.modifiers?.nodes ?? []).some((m) => m.kind === ts.SyntaxKind.Decorator);
|
|
1684
2352
|
/** No function-like node anywhere in the subtree — arguments to builtin
|
|
1685
2353
|
* calls must not smuggle a callback the builtin could invoke. */
|
|
1686
2354
|
const containsFunctionLike = (n) => {
|
|
@@ -1697,14 +2365,14 @@ function topLevelInertness7(program) {
|
|
|
1697
2365
|
const inertClass = (c) => {
|
|
1698
2366
|
if (hasDecorator(c))
|
|
1699
2367
|
return c;
|
|
1700
|
-
for (const h of c.heritageClauses ?? []) {
|
|
2368
|
+
for (const h of c.heritageClauses?.nodes ?? []) {
|
|
1701
2369
|
if (h.token !== ts.SyntaxKind.ExtendsKeyword)
|
|
1702
2370
|
continue;
|
|
1703
|
-
for (const t of h.types)
|
|
2371
|
+
for (const t of h.types.nodes)
|
|
1704
2372
|
if (!inert(t.expression))
|
|
1705
2373
|
return t.expression;
|
|
1706
2374
|
}
|
|
1707
|
-
for (const m of c.members) {
|
|
2375
|
+
for (const m of c.members.nodes) {
|
|
1708
2376
|
if (ts.isClassStaticBlockDeclaration(m))
|
|
1709
2377
|
return m;
|
|
1710
2378
|
if (hasDecorator(m))
|
|
@@ -1761,7 +2429,7 @@ function topLevelInertness7(program) {
|
|
|
1761
2429
|
return dtsRooted(e) && inert(e.argumentExpression) && primitiveTyped(e.argumentExpression);
|
|
1762
2430
|
}
|
|
1763
2431
|
if (ts.isTemplateExpression(e)) {
|
|
1764
|
-
return e.templateSpans.every((s) => inert(s.expression) && primitiveTyped(s.expression));
|
|
2432
|
+
return e.templateSpans.nodes.every((s) => inert(s.expression) && primitiveTyped(s.expression));
|
|
1765
2433
|
}
|
|
1766
2434
|
if (ts.isVoidExpression(e) || ts.isTypeOfExpression(e))
|
|
1767
2435
|
return inert(e.expression);
|
|
@@ -1785,9 +2453,9 @@ function topLevelInertness7(program) {
|
|
|
1785
2453
|
if (ts.isConditionalExpression(e))
|
|
1786
2454
|
return inert(e.condition) && inert(e.whenTrue) && inert(e.whenFalse);
|
|
1787
2455
|
if (ts.isArrayLiteralExpression(e))
|
|
1788
|
-
return e.elements.every((el) => !ts.isSpreadElement(el) && inert(el));
|
|
2456
|
+
return e.elements.nodes.every((el) => !ts.isSpreadElement(el) && inert(el));
|
|
1789
2457
|
if (ts.isObjectLiteralExpression(e)) {
|
|
1790
|
-
return e.properties.every((p) => {
|
|
2458
|
+
return e.properties.nodes.every((p) => {
|
|
1791
2459
|
if (ts.isShorthandPropertyAssignment(p))
|
|
1792
2460
|
return true;
|
|
1793
2461
|
if (!ts.isPropertyAssignment(p) || ts.isComputedPropertyName(p.name))
|
|
@@ -1798,7 +2466,7 @@ function topLevelInertness7(program) {
|
|
|
1798
2466
|
if (ts.isCallExpression(e) || ts.isNewExpression(e)) {
|
|
1799
2467
|
if (!dtsRooted(e.expression) || !ts.isIdentifier(chainRoot7(e.expression)))
|
|
1800
2468
|
return false;
|
|
1801
|
-
const args = e.arguments ?? [];
|
|
2469
|
+
const args = e.arguments?.nodes ?? [];
|
|
1802
2470
|
// A CALLABLE argument is admissible when it is itself dts-rooted:
|
|
1803
2471
|
// a builtin-owned function value (the `promisify(fs.readFile)`
|
|
1804
2472
|
// at every cycle member's top level) is runtime-implemented — even
|
|
@@ -1825,12 +2493,12 @@ function topLevelInertness7(program) {
|
|
|
1825
2493
|
return null;
|
|
1826
2494
|
}
|
|
1827
2495
|
if (ts.isEnumDeclaration(stmt)) {
|
|
1828
|
-
return stmt.members.find((m) => m.initializer !== undefined && !inert(m.initializer)) ?? null;
|
|
2496
|
+
return (stmt.members.nodes.find((m) => m.initializer !== undefined && !inert(m.initializer)) ?? null);
|
|
1829
2497
|
}
|
|
1830
2498
|
if (ts.isClassDeclaration(stmt))
|
|
1831
2499
|
return inertClass(stmt);
|
|
1832
2500
|
if (ts.isVariableStatement(stmt)) {
|
|
1833
|
-
for (const d of stmt.declarationList.declarations) {
|
|
2501
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
1834
2502
|
if (!ts.isIdentifier(d.name))
|
|
1835
2503
|
return d.name; // patterns can invoke getters/iterators
|
|
1836
2504
|
if (d.initializer !== undefined && !inert(d.initializer))
|
|
@@ -1883,7 +2551,7 @@ function backEdgeUseOffence7(program, stmt, occurrences) {
|
|
|
1883
2551
|
if (ts.isNamespaceImport(clause.namedBindings))
|
|
1884
2552
|
bindingNames.push(clause.namedBindings.name);
|
|
1885
2553
|
else
|
|
1886
|
-
for (const el of clause.namedBindings.elements)
|
|
2554
|
+
for (const el of clause.namedBindings.elements.nodes)
|
|
1887
2555
|
if (!el.isTypeOnly)
|
|
1888
2556
|
bindingNames.push(el.name);
|
|
1889
2557
|
}
|
|
@@ -1948,8 +2616,8 @@ export function makeCycleAdmission(program, edgesOf) {
|
|
|
1948
2616
|
}
|
|
1949
2617
|
};
|
|
1950
2618
|
const lineOf = (node) => {
|
|
1951
|
-
const nsf =
|
|
1952
|
-
return `${nsf.fileName}:${ts.getLineAndCharacterOfPosition(nsf,
|
|
2619
|
+
const nsf = ts.getSourceFileOfNode(node);
|
|
2620
|
+
return `${nsf.fileName}:${ts.getLineAndCharacterOfPosition(nsf, ts.tokenStartOfNode(node)).line + 1}`;
|
|
1953
2621
|
};
|
|
1954
2622
|
// Cluster verdict memo (keyed by the component array identity): true
|
|
1955
2623
|
// when every member is an ES module passing the inert-top-level bar.
|
|
@@ -1980,13 +2648,26 @@ export function makeCycleAdmission(program, edgesOf) {
|
|
|
1980
2648
|
bindingUses.set(sf, uses);
|
|
1981
2649
|
return uses;
|
|
1982
2650
|
};
|
|
2651
|
+
// The CommonJS cluster verdict, same keying (cjsCycleRefusal7).
|
|
2652
|
+
const cjsVerdict = new Map();
|
|
1983
2653
|
return (importer, e) => {
|
|
1984
|
-
if (e.stmt === undefined)
|
|
1985
|
-
|
|
2654
|
+
if (e.stmt === undefined) {
|
|
2655
|
+
if (!index.has(importer))
|
|
2656
|
+
strongconnect(importer);
|
|
2657
|
+
const comp = sccOf.get(e.dep);
|
|
2658
|
+
if (comp === undefined || comp.length < 2 || !comp.includes(importer)) {
|
|
2659
|
+
return "the cycle closes through a require() edge";
|
|
2660
|
+
}
|
|
2661
|
+
if (!cjsVerdict.has(comp))
|
|
2662
|
+
cjsVerdict.set(comp, cjsCycleRefusal7(program, comp, lineOf));
|
|
2663
|
+
const reason = cjsVerdict.get(comp) ?? null;
|
|
2664
|
+
return reason === null ? null : `the cycle closes through a require() edge: ${reason}`;
|
|
2665
|
+
}
|
|
1986
2666
|
// Cheap per-edge admission: nothing readable binds through the edge.
|
|
1987
2667
|
if (ts.isImportDeclaration(e.stmt)) {
|
|
1988
2668
|
const clause = e.stmt.importClause;
|
|
1989
2669
|
if (clause === undefined ||
|
|
2670
|
+
typeOnlyNamedImport(e.stmt) ||
|
|
1990
2671
|
(clause.name === undefined &&
|
|
1991
2672
|
(clause.namedBindings === undefined ||
|
|
1992
2673
|
(ts.isNamespaceImport(clause.namedBindings) &&
|
|
@@ -2022,6 +2703,364 @@ export function makeCycleAdmission(program, edgesOf) {
|
|
|
2022
2703
|
return exactVerdict.get(comp) ?? null;
|
|
2023
2704
|
};
|
|
2024
2705
|
}
|
|
2706
|
+
/** The reason a strongly-connected cluster of CommonJS modules cannot be
|
|
2707
|
+
* initialized exactly through its require() cycle, or null when it can.
|
|
2708
|
+
* Node answers a require of a module that is still evaluating with that
|
|
2709
|
+
* module's exports object as it stands, while the compiled bindings alias
|
|
2710
|
+
* the exporter's final declarations. The two agree when:
|
|
2711
|
+
* - every member settles its exports before anything can enter the
|
|
2712
|
+
* cycle: all of its export statements come before its first top-level
|
|
2713
|
+
* statement that can run another module's code (a require, or anything
|
|
2714
|
+
* but literals, plain reads, function and class values, and
|
|
2715
|
+
* standard-library globals called with literal arguments), and every
|
|
2716
|
+
* other use of its export object is a plain member read; and
|
|
2717
|
+
* - no member's top-level code can reach its binding of another member,
|
|
2718
|
+
* so no member runs another member's code while the cluster is still
|
|
2719
|
+
* initializing. Each module then initializes exactly as it would
|
|
2720
|
+
* outside the cycle, and its own require bindings keep the acyclic
|
|
2721
|
+
* analysis (requireEarlyReference).
|
|
2722
|
+
* Other cycles keep the SC1016 fence. */
|
|
2723
|
+
function cjsCycleRefusal7(program, comp, lineOf) {
|
|
2724
|
+
const members = new Set(comp);
|
|
2725
|
+
const builtinRoot = (e) => {
|
|
2726
|
+
while (ts.isPropertyAccessExpression(e))
|
|
2727
|
+
e = e.expression;
|
|
2728
|
+
return ts.isIdentifier(e) && !sourceBinding7(program, e);
|
|
2729
|
+
};
|
|
2730
|
+
const literal = (e) => ts.isStringLiteralLike(e) ||
|
|
2731
|
+
ts.isNumericLiteral(e) ||
|
|
2732
|
+
ts.isRegularExpressionLiteral(e) ||
|
|
2733
|
+
e.kind === ts.SyntaxKind.TrueKeyword ||
|
|
2734
|
+
e.kind === ts.SyntaxKind.FalseKeyword ||
|
|
2735
|
+
e.kind === ts.SyntaxKind.NullKeyword;
|
|
2736
|
+
/** An expression whose evaluation runs no user code and requires
|
|
2737
|
+
* nothing: literals, plain reads, function and class values, literal
|
|
2738
|
+
* containers of those, and standard-library globals called with
|
|
2739
|
+
* literal arguments. */
|
|
2740
|
+
const inertExpr = (e) => {
|
|
2741
|
+
while (ts.isParenthesizedExpression(e))
|
|
2742
|
+
e = e.expression;
|
|
2743
|
+
if (literal(e) || ts.isIdentifier(e))
|
|
2744
|
+
return true;
|
|
2745
|
+
if (ts.isFunctionExpression(e) || ts.isArrowFunction(e))
|
|
2746
|
+
return true;
|
|
2747
|
+
if (ts.isClassExpression(e))
|
|
2748
|
+
return classSyncParts7(e).every(inertPart);
|
|
2749
|
+
if (ts.isObjectLiteralExpression(e)) {
|
|
2750
|
+
return e.properties.nodes.every((p) => ts.isShorthandPropertyAssignment(p)
|
|
2751
|
+
? true
|
|
2752
|
+
: ts.isPropertyAssignment(p)
|
|
2753
|
+
? !ts.isComputedPropertyName(p.name) && inertExpr(p.initializer)
|
|
2754
|
+
: (ts.isMethodDeclaration(p) ||
|
|
2755
|
+
ts.isGetAccessorDeclaration(p) ||
|
|
2756
|
+
ts.isSetAccessorDeclaration(p)) &&
|
|
2757
|
+
!ts.isComputedPropertyName(p.name));
|
|
2758
|
+
}
|
|
2759
|
+
if (ts.isArrayLiteralExpression(e)) {
|
|
2760
|
+
return e.elements.nodes.every((el) => !ts.isSpreadElement(el) && inertExpr(el));
|
|
2761
|
+
}
|
|
2762
|
+
if (ts.isPropertyAccessExpression(e))
|
|
2763
|
+
return builtinRoot(e);
|
|
2764
|
+
if (ts.isVoidExpression(e))
|
|
2765
|
+
return literal(e.expression);
|
|
2766
|
+
if (ts.isCallExpression(e) || ts.isNewExpression(e)) {
|
|
2767
|
+
return (requireSpecOf7(e) === null &&
|
|
2768
|
+
builtinRoot(e.expression) &&
|
|
2769
|
+
(e.arguments?.nodes ?? []).every(literal));
|
|
2770
|
+
}
|
|
2771
|
+
return false;
|
|
2772
|
+
};
|
|
2773
|
+
const inertPart = (part) => {
|
|
2774
|
+
if (ts.isHeritageClause(part))
|
|
2775
|
+
return part.types.nodes.every((t) => inertExpr(t.expression));
|
|
2776
|
+
if (ts.isComputedPropertyName(part))
|
|
2777
|
+
return inertExpr(part.expression);
|
|
2778
|
+
return ts.isExpression(part) && inertExpr(part);
|
|
2779
|
+
};
|
|
2780
|
+
const exportObject = (e) => (ts.isIdentifier(e) && e.text === "exports" && !sourceBinding7(program, e)) ||
|
|
2781
|
+
(isModuleExportsAccess(e) &&
|
|
2782
|
+
ts.isIdentifier(e.expression) &&
|
|
2783
|
+
!sourceBinding7(program, e.expression));
|
|
2784
|
+
/** A top-level statement that only publishes inert values. */
|
|
2785
|
+
const exportStatement = (stmt) => {
|
|
2786
|
+
if (!ts.isExpressionStatement(stmt))
|
|
2787
|
+
return false;
|
|
2788
|
+
if (isEsModuleStamp(stmt.expression))
|
|
2789
|
+
return true;
|
|
2790
|
+
const cjs = cjsExportAssignmentOf(stmt);
|
|
2791
|
+
if (cjs !== null) {
|
|
2792
|
+
let value = cjs.expr;
|
|
2793
|
+
while (ts.isBinaryExpression(value) &&
|
|
2794
|
+
value.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
2795
|
+
const left = value.left;
|
|
2796
|
+
if (!isModuleExportsAccess(left) &&
|
|
2797
|
+
!(ts.isPropertyAccessExpression(left) && exportObject(left.expression)))
|
|
2798
|
+
return false;
|
|
2799
|
+
value = value.right;
|
|
2800
|
+
}
|
|
2801
|
+
return inertExpr(value);
|
|
2802
|
+
}
|
|
2803
|
+
const call = stmt.expression;
|
|
2804
|
+
return (ts.isCallExpression(call) &&
|
|
2805
|
+
ts.isPropertyAccessExpression(call.expression) &&
|
|
2806
|
+
ts.isIdentifier(call.expression.expression) &&
|
|
2807
|
+
call.expression.expression.text === "Object" &&
|
|
2808
|
+
!sourceBinding7(program, call.expression.expression) &&
|
|
2809
|
+
call.expression.name.text === "defineProperty" &&
|
|
2810
|
+
call.arguments.nodes.length === 3 &&
|
|
2811
|
+
exportObject(call.arguments.nodes[0]) &&
|
|
2812
|
+
ts.isStringLiteralLike(call.arguments.nodes[1]) &&
|
|
2813
|
+
inertExpr(call.arguments.nodes[2]));
|
|
2814
|
+
};
|
|
2815
|
+
for (const m of comp) {
|
|
2816
|
+
if (!isCjsJsFile7(m, program)) {
|
|
2817
|
+
return `${m.fileName} is not a CommonJS module — require cycles are admitted between CommonJS modules only`;
|
|
2818
|
+
}
|
|
2819
|
+
const stmts = m.statements.nodes;
|
|
2820
|
+
// The first statement that can run another module's code.
|
|
2821
|
+
let firstEntry = stmts.length;
|
|
2822
|
+
for (let i = 0; i < stmts.length; i++) {
|
|
2823
|
+
const st = stmts[i];
|
|
2824
|
+
const inert = ts.isFunctionDeclaration(st) ||
|
|
2825
|
+
ts.isEmptyStatement(st) ||
|
|
2826
|
+
(ts.isExpressionStatement(st) && ts.isStringLiteral(st.expression)) ||
|
|
2827
|
+
(ts.isClassDeclaration(st) && classSyncParts7(st).every(inertPart)) ||
|
|
2828
|
+
(ts.isVariableStatement(st) &&
|
|
2829
|
+
st.declarationList.declarations.nodes.every((d) => ts.isIdentifier(d.name) && (d.initializer === undefined || inertExpr(d.initializer)))) ||
|
|
2830
|
+
exportStatement(st);
|
|
2831
|
+
if (!inert) {
|
|
2832
|
+
firstEntry = i;
|
|
2833
|
+
break;
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
// Every other use of the export object must be a plain member read:
|
|
2837
|
+
// anything else can change what a module of the cycle observes.
|
|
2838
|
+
let stray = null;
|
|
2839
|
+
const settled = new Set(stmts.slice(0, firstEntry).filter(exportStatement));
|
|
2840
|
+
// A bundler export table the rewrite certified (npmStaticLiveExportTable)
|
|
2841
|
+
// stands for the live getter object the original installed before its
|
|
2842
|
+
// first require: the tail table settles as if it ran there.
|
|
2843
|
+
const tail = stmts[stmts.length - 1];
|
|
2844
|
+
if (tail !== undefined &&
|
|
2845
|
+
npmStaticLiveExportTable(m.fileName) &&
|
|
2846
|
+
cjsExportAssignmentOf(tail)?.kind === "table")
|
|
2847
|
+
settled.add(tail);
|
|
2848
|
+
ts.walkPreorder(m, (n) => {
|
|
2849
|
+
if (stray !== null)
|
|
2850
|
+
return "stop";
|
|
2851
|
+
if (ts.isStatement(n) && settled.has(n))
|
|
2852
|
+
return "skip";
|
|
2853
|
+
let use = null;
|
|
2854
|
+
if (n.kind === ts.SyntaxKind.ThisKeyword) {
|
|
2855
|
+
let moduleThis = true;
|
|
2856
|
+
for (let p = n.parent; p !== undefined && !ts.isSourceFile(p); p = p.parent) {
|
|
2857
|
+
if ((ts.isFunctionLike(p) && !ts.isArrowFunction(p)) ||
|
|
2858
|
+
ts.isClassDeclaration(p) ||
|
|
2859
|
+
ts.isClassExpression(p)) {
|
|
2860
|
+
moduleThis = false;
|
|
2861
|
+
break;
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
if (moduleThis)
|
|
2865
|
+
use = n;
|
|
2866
|
+
}
|
|
2867
|
+
else if (ts.isIdentifier(n) &&
|
|
2868
|
+
(n.text === "exports" || n.text === "module") &&
|
|
2869
|
+
!(ts.isPropertyAccessExpression(n.parent) && n.parent.name === n) &&
|
|
2870
|
+
!sourceBinding7(program, n)) {
|
|
2871
|
+
if (n.text === "exports")
|
|
2872
|
+
use = n;
|
|
2873
|
+
else if (!ts.isPropertyAccessExpression(n.parent) || n.parent.expression !== n)
|
|
2874
|
+
stray = n;
|
|
2875
|
+
else if (n.parent.name.text === "exports")
|
|
2876
|
+
use = n.parent;
|
|
2877
|
+
}
|
|
2878
|
+
if (use === null)
|
|
2879
|
+
return undefined;
|
|
2880
|
+
const parent = use.parent;
|
|
2881
|
+
const read = ts.isPropertyAccessExpression(parent) &&
|
|
2882
|
+
parent.expression === use &&
|
|
2883
|
+
!(ts.isBinaryExpression(parent.parent) &&
|
|
2884
|
+
parent.parent.left === parent &&
|
|
2885
|
+
parent.parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&
|
|
2886
|
+
parent.parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment) &&
|
|
2887
|
+
!(ts.isCallExpression(parent.parent) && parent.parent.expression === parent) &&
|
|
2888
|
+
!ts.isDeleteExpression(parent.parent);
|
|
2889
|
+
if (!read)
|
|
2890
|
+
stray = use;
|
|
2891
|
+
return undefined;
|
|
2892
|
+
});
|
|
2893
|
+
if (stray !== null) {
|
|
2894
|
+
return `${m.fileName} uses its exports at ${lineOf(stray)} outside the export statements that precede its first require, so a module of the cycle can observe them before they settle`;
|
|
2895
|
+
}
|
|
2896
|
+
// Bindings of other members must stay unreachable from top-level code.
|
|
2897
|
+
for (const st of stmts) {
|
|
2898
|
+
for (const req of requiresOf7(st)) {
|
|
2899
|
+
if (req.decl === null)
|
|
2900
|
+
continue;
|
|
2901
|
+
const dep = resolveImport7(program, m, req.spec, "require");
|
|
2902
|
+
if (dep === null || !members.has(dep))
|
|
2903
|
+
continue;
|
|
2904
|
+
const reached = requireBindingEarlyUse7(program, m, stmts.length, req.decl, [], (id) => functionExportRead7(id, dep));
|
|
2905
|
+
if (reached !== null) {
|
|
2906
|
+
return `the top-level code of ${m.fileName} can use its binding '${reached.text}' of a module of the cycle (${lineOf(reached)}) while the cycle initializes`;
|
|
2907
|
+
}
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
return null;
|
|
2912
|
+
}
|
|
2913
|
+
/** True when `use` initializes a top-level const whose every other
|
|
2914
|
+
* reference is a value of an export statement (`module.exports = { … }`
|
|
2915
|
+
* or `exports.n = …`). */
|
|
2916
|
+
function publishedAlias7(use, decl) {
|
|
2917
|
+
if (decl === undefined ||
|
|
2918
|
+
!ts.isVariableDeclaration(decl) ||
|
|
2919
|
+
decl.initializer !== use ||
|
|
2920
|
+
!ts.isIdentifier(decl.name))
|
|
2921
|
+
return false;
|
|
2922
|
+
const list = decl.parent;
|
|
2923
|
+
const stmt = list?.parent;
|
|
2924
|
+
const sf = stmt?.parent;
|
|
2925
|
+
if (list === undefined ||
|
|
2926
|
+
(list.flags & ts.NodeFlags.Const) === 0 ||
|
|
2927
|
+
stmt === undefined ||
|
|
2928
|
+
!ts.isVariableStatement(stmt) ||
|
|
2929
|
+
sf === undefined ||
|
|
2930
|
+
!ts.isSourceFile(sf))
|
|
2931
|
+
return false;
|
|
2932
|
+
const alias = decl.name;
|
|
2933
|
+
const published = new Set();
|
|
2934
|
+
for (const st of sf.statements.nodes) {
|
|
2935
|
+
const cjs = cjsExportAssignmentOf(st);
|
|
2936
|
+
if (cjs === null)
|
|
2937
|
+
continue;
|
|
2938
|
+
if (cjs.kind === "member")
|
|
2939
|
+
published.add(cjs.value);
|
|
2940
|
+
else if (cjs.obj !== null) {
|
|
2941
|
+
for (const p of cjs.obj.properties.nodes) {
|
|
2942
|
+
if (ts.isPropertyAssignment(p) && !ts.isComputedPropertyName(p.name))
|
|
2943
|
+
published.add(p.initializer);
|
|
2944
|
+
else if (ts.isShorthandPropertyAssignment(p))
|
|
2945
|
+
published.add(p.name);
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2949
|
+
let kept = false;
|
|
2950
|
+
ts.walkPreorder(sf, (n) => {
|
|
2951
|
+
if (kept)
|
|
2952
|
+
return "stop";
|
|
2953
|
+
if (!ts.isIdentifier(n) || n === alias || n.text !== alias.text)
|
|
2954
|
+
return undefined;
|
|
2955
|
+
const p = n.parent;
|
|
2956
|
+
if (p !== undefined &&
|
|
2957
|
+
((ts.isPropertyAccessExpression(p) && p.name === n) ||
|
|
2958
|
+
(ts.isPropertyAssignment(p) && p.name === n)))
|
|
2959
|
+
return undefined;
|
|
2960
|
+
if (!published.has(n))
|
|
2961
|
+
kept = true;
|
|
2962
|
+
return undefined;
|
|
2963
|
+
});
|
|
2964
|
+
return !kept;
|
|
2965
|
+
}
|
|
2966
|
+
/** True for a plain read `binding.name` (not a call, not a write, not a
|
|
2967
|
+
* value that is stored or passed on) of the cycle member `dep` whose
|
|
2968
|
+
* export `name` is a top-level function declaration nothing reassigns.
|
|
2969
|
+
* Every member settles its exports before entering the cycle, so Node
|
|
2970
|
+
* reads that same function whenever the read runs, and the compiled read
|
|
2971
|
+
* resolves to the declaration itself. */
|
|
2972
|
+
function functionExportRead7(id, dep) {
|
|
2973
|
+
const access = id.parent;
|
|
2974
|
+
if (!ts.isPropertyAccessExpression(access) || access.expression !== id)
|
|
2975
|
+
return false;
|
|
2976
|
+
// The value the read yields: through parentheses and the right operand
|
|
2977
|
+
// of a comma, so `(0, binding.name)(...)` is the call it spells.
|
|
2978
|
+
let use = access;
|
|
2979
|
+
for (;;) {
|
|
2980
|
+
const p = use.parent;
|
|
2981
|
+
if (ts.isParenthesizedExpression(p))
|
|
2982
|
+
use = p;
|
|
2983
|
+
else if (ts.isBinaryExpression(p) &&
|
|
2984
|
+
p.operatorToken.kind === ts.SyntaxKind.CommaToken &&
|
|
2985
|
+
p.right === use)
|
|
2986
|
+
use = p;
|
|
2987
|
+
else
|
|
2988
|
+
break;
|
|
2989
|
+
}
|
|
2990
|
+
const parent = use.parent;
|
|
2991
|
+
// Only a use that neither runs the function nor keeps it is a read: a
|
|
2992
|
+
// stored alias (`const f = binding.name`, `{ f: binding.name }`) or an
|
|
2993
|
+
// argument can be called while the cycle initializes. A top-level const
|
|
2994
|
+
// that only publishes it (`module.exports = { name: f }`, the static
|
|
2995
|
+
// rewrite's re-export spelling) runs nothing: a module that reads the
|
|
2996
|
+
// export back checks that read itself.
|
|
2997
|
+
const observes = publishedAlias7(use, parent) ||
|
|
2998
|
+
ts.isExpressionStatement(parent) ||
|
|
2999
|
+
ts.isTypeOfExpression(parent) ||
|
|
3000
|
+
ts.isVoidExpression(parent) ||
|
|
3001
|
+
(ts.isPrefixUnaryExpression(parent) && parent.operator === ts.SyntaxKind.ExclamationToken) ||
|
|
3002
|
+
(ts.isBinaryExpression(parent) &&
|
|
3003
|
+
(parent.operatorToken.kind === ts.SyntaxKind.EqualsEqualsEqualsToken ||
|
|
3004
|
+
parent.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsEqualsToken ||
|
|
3005
|
+
parent.operatorToken.kind === ts.SyntaxKind.EqualsEqualsToken ||
|
|
3006
|
+
parent.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsToken)) ||
|
|
3007
|
+
((ts.isIfStatement(parent) || ts.isWhileStatement(parent) || ts.isDoStatement(parent)) &&
|
|
3008
|
+
parent.expression === use) ||
|
|
3009
|
+
(ts.isConditionalExpression(parent) && parent.condition === use);
|
|
3010
|
+
if (!observes)
|
|
3011
|
+
return false;
|
|
3012
|
+
const name = access.name.text;
|
|
3013
|
+
// The exported value's identifier: a table entry or a member export.
|
|
3014
|
+
const values = [];
|
|
3015
|
+
for (const stmt of dep.statements.nodes) {
|
|
3016
|
+
if (!ts.isExpressionStatement(stmt) || !ts.isBinaryExpression(stmt.expression))
|
|
3017
|
+
continue;
|
|
3018
|
+
const e = stmt.expression;
|
|
3019
|
+
if (e.operatorToken.kind !== ts.SyntaxKind.EqualsToken)
|
|
3020
|
+
continue;
|
|
3021
|
+
if (isModuleExportsAccess(e.left)) {
|
|
3022
|
+
if (!ts.isObjectLiteralExpression(e.right))
|
|
3023
|
+
return false;
|
|
3024
|
+
for (const p of e.right.properties.nodes) {
|
|
3025
|
+
if (ts.isSpreadAssignment(p))
|
|
3026
|
+
return false;
|
|
3027
|
+
if (ts.isShorthandPropertyAssignment(p) && p.name.text === name)
|
|
3028
|
+
values.push(p.name);
|
|
3029
|
+
else if (ts.isPropertyAssignment(p) &&
|
|
3030
|
+
(ts.isIdentifier(p.name) || ts.isStringLiteral(p.name)) &&
|
|
3031
|
+
p.name.text === name)
|
|
3032
|
+
values.push(p.initializer);
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
else if (ts.isPropertyAccessExpression(e.left) &&
|
|
3036
|
+
e.left.name.text === name &&
|
|
3037
|
+
((ts.isIdentifier(e.left.expression) && e.left.expression.text === "exports") ||
|
|
3038
|
+
isModuleExportsAccess(e.left.expression))) {
|
|
3039
|
+
values.push(e.right);
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
const value = values.length === 1 ? values[0] : null;
|
|
3043
|
+
if (value === null || !ts.isIdentifier(value))
|
|
3044
|
+
return false;
|
|
3045
|
+
const fnName = value.text;
|
|
3046
|
+
if (!dep.statements.nodes.some((st) => ts.isFunctionDeclaration(st) && st.name?.text === fnName && st.body !== undefined))
|
|
3047
|
+
return false;
|
|
3048
|
+
let rebound = false;
|
|
3049
|
+
ts.walkPreorder(dep, (n) => {
|
|
3050
|
+
if (rebound)
|
|
3051
|
+
return "stop";
|
|
3052
|
+
if ((ts.isBinaryExpression(n) &&
|
|
3053
|
+
ts.isIdentifier(n.left) &&
|
|
3054
|
+
n.left.text === fnName &&
|
|
3055
|
+
n.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&
|
|
3056
|
+
n.operatorToken.kind <= ts.SyntaxKind.LastAssignment) ||
|
|
3057
|
+
(ts.isVariableDeclaration(n) && ts.isIdentifier(n.name) && n.name.text === fnName) ||
|
|
3058
|
+
(ts.isFunctionDeclaration(n) && n.name?.text === fnName && !ts.isSourceFile(n.parent)))
|
|
3059
|
+
rebound = true;
|
|
3060
|
+
return undefined;
|
|
3061
|
+
});
|
|
3062
|
+
return !rebound;
|
|
3063
|
+
}
|
|
2025
3064
|
/* ── exact cyclic initialization ─────────────────────────────────────────
|
|
2026
3065
|
* Cycles that fail the declaration-only rule still evaluate exactly like
|
|
2027
3066
|
* Node when their shape is representable: the guarded %init calls already
|
|
@@ -2065,7 +3104,7 @@ function exactCycleRefusal7(program, comp, lineOf) {
|
|
|
2065
3104
|
const spec = stmt.moduleSpecifier;
|
|
2066
3105
|
if (spec === undefined || !ts.isStringLiteral(spec))
|
|
2067
3106
|
return null;
|
|
2068
|
-
const sf =
|
|
3107
|
+
const sf = ts.getSourceFileOfNode(stmt);
|
|
2069
3108
|
return resolveImport7(program, sf, spec.text) ?? npmStaticDepSf7(program, sf, spec.text);
|
|
2070
3109
|
};
|
|
2071
3110
|
for (const m of comp) {
|
|
@@ -2075,7 +3114,7 @@ function exactCycleRefusal7(program, comp, lineOf) {
|
|
|
2075
3114
|
if (hasTopLevelAwait7(m)) {
|
|
2076
3115
|
return `${m.fileName} uses top-level await inside the cycle`;
|
|
2077
3116
|
}
|
|
2078
|
-
for (const stmt of m.statements) {
|
|
3117
|
+
for (const stmt of m.statements.nodes) {
|
|
2079
3118
|
if (ts.isExportAssignment(stmt) && !stmt.isExportEquals) {
|
|
2080
3119
|
return `the default export expression at ${lineOf(stmt)} has no initialization state inside the cycle`;
|
|
2081
3120
|
}
|
|
@@ -2223,7 +3262,7 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2223
3262
|
const names = new Set();
|
|
2224
3263
|
let dirty = !known;
|
|
2225
3264
|
evaluation.forEach((m, rank) => {
|
|
2226
|
-
for (const stmt of m.statements) {
|
|
3265
|
+
for (const stmt of m.statements.nodes) {
|
|
2227
3266
|
const offence = nonInert(stmt);
|
|
2228
3267
|
const exposed = dirty || offence !== null;
|
|
2229
3268
|
const declared = [];
|
|
@@ -2232,7 +3271,7 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2232
3271
|
ts.ModifierFlags.Ambient) ===
|
|
2233
3272
|
0) {
|
|
2234
3273
|
const lexical = (stmt.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) !== 0;
|
|
2235
|
-
for (const d of stmt.declarationList.declarations) {
|
|
3274
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
2236
3275
|
for (const name of boundNames7(d.name)) {
|
|
2237
3276
|
declared.push({ name, kind: lexical ? "lexical" : "var" });
|
|
2238
3277
|
}
|
|
@@ -2252,10 +3291,11 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2252
3291
|
module: m,
|
|
2253
3292
|
exposed,
|
|
2254
3293
|
rank,
|
|
2255
|
-
start:
|
|
2256
|
-
end: stmt.
|
|
3294
|
+
start: ts.tokenStartOfNode(stmt),
|
|
3295
|
+
end: stmt.end,
|
|
2257
3296
|
reference: null,
|
|
2258
3297
|
folded: null,
|
|
3298
|
+
localNames: new Map(),
|
|
2259
3299
|
});
|
|
2260
3300
|
names.add(name.text);
|
|
2261
3301
|
}
|
|
@@ -2266,14 +3306,36 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2266
3306
|
if (candidates.size === 0)
|
|
2267
3307
|
continue;
|
|
2268
3308
|
const rankOf = new Map(evaluation.map((m, i) => [m, i]));
|
|
2269
|
-
// References: every identifier spelled like a candidate
|
|
2270
|
-
//
|
|
3309
|
+
// References: every identifier spelled like a candidate or like a
|
|
3310
|
+
// local name the file imports one under (`import { x as y }`, a
|
|
3311
|
+
// default import), resolved through import aliases to the
|
|
3312
|
+
// declaration's symbol.
|
|
2271
3313
|
for (const sf of order) {
|
|
3314
|
+
const local = new Set();
|
|
3315
|
+
for (const stmt of sf.statements.nodes) {
|
|
3316
|
+
if (!ts.isImportDeclaration(stmt) || stmt.importClause === undefined)
|
|
3317
|
+
continue;
|
|
3318
|
+
const clause = stmt.importClause;
|
|
3319
|
+
const bound = clause.name !== undefined ? [clause.name] : [];
|
|
3320
|
+
if (clause.namedBindings !== undefined && ts.isNamedImports(clause.namedBindings))
|
|
3321
|
+
for (const element of clause.namedBindings.elements.nodes)
|
|
3322
|
+
bound.push(element.name);
|
|
3323
|
+
for (const name of bound) {
|
|
3324
|
+
if (names.has(name.text))
|
|
3325
|
+
continue;
|
|
3326
|
+
const imported = checker.getSymbolAtLocation(name);
|
|
3327
|
+
const candidate = imported === undefined ? undefined : candidates.get(checker.getAliasedSymbol(imported));
|
|
3328
|
+
if (candidate === undefined)
|
|
3329
|
+
continue;
|
|
3330
|
+
local.add(name.text);
|
|
3331
|
+
candidate.localNames.set(sf.fileName, name.text);
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
2272
3334
|
const refs = [];
|
|
2273
3335
|
ts.walkPreorder(sf, (node) => {
|
|
2274
3336
|
if (ts.isImportDeclaration(node))
|
|
2275
3337
|
return "skip";
|
|
2276
|
-
if (ts.isIdentifier(node) && names.has(node.text))
|
|
3338
|
+
if (ts.isIdentifier(node) && (names.has(node.text) || local.has(node.text)))
|
|
2277
3339
|
refs.push(node);
|
|
2278
3340
|
return undefined;
|
|
2279
3341
|
});
|
|
@@ -2305,14 +3367,14 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2305
3367
|
// A class body names its own inner binding, initialized throughout.
|
|
2306
3368
|
if (c.kind === "class" &&
|
|
2307
3369
|
sf === c.module &&
|
|
2308
|
-
|
|
2309
|
-
ref.
|
|
3370
|
+
ts.tokenStartOfNode(ref) >= c.start &&
|
|
3371
|
+
ref.end <= c.end)
|
|
2310
3372
|
continue;
|
|
2311
3373
|
let early;
|
|
2312
3374
|
if (inDeferredPosition7(ref))
|
|
2313
3375
|
early = c.exposed;
|
|
2314
3376
|
else if (sf === c.module)
|
|
2315
|
-
early =
|
|
3377
|
+
early = ts.tokenStartOfNode(ref) < c.start;
|
|
2316
3378
|
else if (!memberSet.has(sf) || !rankOf.has(sf))
|
|
2317
3379
|
early = false;
|
|
2318
3380
|
else
|
|
@@ -2336,6 +3398,7 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2336
3398
|
reference: c.reference,
|
|
2337
3399
|
...(c.folded !== null ? { folded: c.folded } : {}),
|
|
2338
3400
|
settled,
|
|
3401
|
+
...(c.localNames.size > 0 ? { localNames: c.localNames } : {}),
|
|
2339
3402
|
});
|
|
2340
3403
|
}
|
|
2341
3404
|
}
|
|
@@ -2406,7 +3469,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2406
3469
|
immediate.set(e, classSyncParts7(e));
|
|
2407
3470
|
}
|
|
2408
3471
|
else if (ts.isObjectLiteralExpression(e)) {
|
|
2409
|
-
for (const p of e.properties) {
|
|
3472
|
+
for (const p of e.properties.nodes) {
|
|
2410
3473
|
if (ts.isMethodDeclaration(p) ||
|
|
2411
3474
|
ts.isGetAccessorDeclaration(p) ||
|
|
2412
3475
|
ts.isSetAccessorDeclaration(p)) {
|
|
@@ -2424,14 +3487,14 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2424
3487
|
}
|
|
2425
3488
|
}
|
|
2426
3489
|
else if (ts.isArrayLiteralExpression(e)) {
|
|
2427
|
-
for (const el of e.elements)
|
|
3490
|
+
for (const el of e.elements.nodes)
|
|
2428
3491
|
if (!ts.isSpreadElement(el))
|
|
2429
3492
|
storedIn(el, units);
|
|
2430
3493
|
}
|
|
2431
3494
|
else if (ts.isCallExpression(e)) {
|
|
2432
3495
|
// `const f = wrap(callback)` where wrap only returns closures over
|
|
2433
3496
|
// the callback: it runs when the stored result is called.
|
|
2434
|
-
e.arguments.forEach((arg, index) => {
|
|
3497
|
+
e.arguments.nodes.forEach((arg, index) => {
|
|
2435
3498
|
let fn = arg;
|
|
2436
3499
|
while (ts.isParenthesizedExpression(fn))
|
|
2437
3500
|
fn = fn.expression;
|
|
@@ -2441,7 +3504,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2441
3504
|
});
|
|
2442
3505
|
}
|
|
2443
3506
|
};
|
|
2444
|
-
sf.statements.forEach((stmt, index) => {
|
|
3507
|
+
sf.statements.nodes.forEach((stmt, index) => {
|
|
2445
3508
|
if (ambient(stmt))
|
|
2446
3509
|
return;
|
|
2447
3510
|
if (ts.isFunctionDeclaration(stmt) && stmt.name !== undefined && stmt.body !== undefined) {
|
|
@@ -2449,12 +3512,12 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2449
3512
|
}
|
|
2450
3513
|
else if (ts.isClassDeclaration(stmt) && stmt.name !== undefined) {
|
|
2451
3514
|
store(stmt.name, [stmt]);
|
|
2452
|
-
candidates.push({ name: stmt.name, index, start:
|
|
3515
|
+
candidates.push({ name: stmt.name, index, start: ts.tokenStartOfNode(stmt), cls: stmt });
|
|
2453
3516
|
candidateNames.add(stmt.name.text);
|
|
2454
3517
|
}
|
|
2455
3518
|
else if (ts.isVariableStatement(stmt)) {
|
|
2456
3519
|
const lexical = (stmt.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) !== 0;
|
|
2457
|
-
for (const d of stmt.declarationList.declarations) {
|
|
3520
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
2458
3521
|
if (ts.isIdentifier(d.name) && d.initializer !== undefined) {
|
|
2459
3522
|
const units = [];
|
|
2460
3523
|
storedIn(d.initializer, units);
|
|
@@ -2463,7 +3526,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2463
3526
|
if (!lexical)
|
|
2464
3527
|
continue;
|
|
2465
3528
|
for (const name of boundNames7(d.name)) {
|
|
2466
|
-
candidates.push({ name, index, start:
|
|
3529
|
+
candidates.push({ name, index, start: ts.tokenStartOfNode(stmt) });
|
|
2467
3530
|
candidateNames.add(name.text);
|
|
2468
3531
|
}
|
|
2469
3532
|
}
|
|
@@ -2506,7 +3569,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2506
3569
|
if (ts.isArrowFunction(e) || ts.isFunctionExpression(e))
|
|
2507
3570
|
stored.add(e);
|
|
2508
3571
|
else if (ts.isObjectLiteralExpression(e)) {
|
|
2509
|
-
for (const p of e.properties) {
|
|
3572
|
+
for (const p of e.properties.nodes) {
|
|
2510
3573
|
if (ts.isMethodDeclaration(p))
|
|
2511
3574
|
stored.add(p);
|
|
2512
3575
|
else if (ts.isPropertyAssignment(p))
|
|
@@ -2517,7 +3580,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2517
3580
|
ts.walkPreorder(sf, (node) => {
|
|
2518
3581
|
if ((ts.isCallExpression(node) || ts.isNewExpression(node)) &&
|
|
2519
3582
|
laterJobCallee7(checker, node.expression)) {
|
|
2520
|
-
for (const arg of node.arguments ?? [])
|
|
3583
|
+
for (const arg of node.arguments?.nodes ?? [])
|
|
2521
3584
|
callbacks(arg);
|
|
2522
3585
|
}
|
|
2523
3586
|
return undefined;
|
|
@@ -2569,8 +3632,8 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2569
3632
|
if (c !== undefined &&
|
|
2570
3633
|
node !== c.name &&
|
|
2571
3634
|
!reachedRefs.has(symbol) &&
|
|
2572
|
-
!(c.cls !== undefined &&
|
|
2573
|
-
if (inDeferredPosition7(node) ||
|
|
3635
|
+
!(c.cls !== undefined && ts.tokenStartOfNode(node) >= c.cls.pos && node.end <= c.cls.end)) {
|
|
3636
|
+
if (inDeferredPosition7(node) || ts.tokenStartOfNode(node) < c.start)
|
|
2574
3637
|
reachedRefs.set(symbol, node);
|
|
2575
3638
|
}
|
|
2576
3639
|
for (const unit of unitsBySymbol.get(symbol) ?? []) {
|
|
@@ -2591,8 +3654,8 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2591
3654
|
let next = 0;
|
|
2592
3655
|
const report = (declaration) => {
|
|
2593
3656
|
while (next < candidates.length &&
|
|
2594
|
-
candidates[next].name
|
|
2595
|
-
candidates[next].name.
|
|
3657
|
+
ts.tokenStartOfNode(candidates[next].name) >= ts.tokenStartOfNode(declaration) &&
|
|
3658
|
+
candidates[next].name.end <= declaration.end) {
|
|
2596
3659
|
const c = candidates[next++];
|
|
2597
3660
|
const symbol = checker.getSymbolAtLocation(c.name);
|
|
2598
3661
|
const reference = symbol === undefined ? undefined : reachedRefs.get(symbol);
|
|
@@ -2608,7 +3671,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2608
3671
|
});
|
|
2609
3672
|
}
|
|
2610
3673
|
};
|
|
2611
|
-
for (const stmt of sf.statements) {
|
|
3674
|
+
for (const stmt of sf.statements.nodes) {
|
|
2612
3675
|
if (ts.isClassDeclaration(stmt)) {
|
|
2613
3676
|
// The binding initializes once the class definition, static
|
|
2614
3677
|
// initializers included, has run.
|
|
@@ -2620,7 +3683,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2620
3683
|
else if (ts.isVariableStatement(stmt)) {
|
|
2621
3684
|
// Declarators run in order: a later declarator's initializer cannot
|
|
2622
3685
|
// observe an earlier binding before it was initialized.
|
|
2623
|
-
for (const d of stmt.declarationList.declarations) {
|
|
3686
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
2624
3687
|
visit(d);
|
|
2625
3688
|
drain();
|
|
2626
3689
|
report(d);
|
|
@@ -2650,11 +3713,11 @@ function returnsOnlyClosuresOver7(checker, callee, index) {
|
|
|
2650
3713
|
if (symbol !== undefined && symbol.flags & ts.SymbolFlags.Alias) {
|
|
2651
3714
|
symbol = checker.getAliasedSymbol(symbol);
|
|
2652
3715
|
}
|
|
2653
|
-
const decls = symbol === undefined ? [] :
|
|
3716
|
+
const decls = symbol === undefined ? [] : symbol.declarations;
|
|
2654
3717
|
if (decls.length !== 1)
|
|
2655
3718
|
return false;
|
|
2656
3719
|
const decl = decls[0];
|
|
2657
|
-
if (
|
|
3720
|
+
if (ts.getSourceFileOfNode(decl).isDeclarationFile)
|
|
2658
3721
|
return false;
|
|
2659
3722
|
let fn;
|
|
2660
3723
|
if (ts.isFunctionDeclaration(decl))
|
|
@@ -2670,12 +3733,12 @@ function returnsOnlyClosuresOver7(checker, callee, index) {
|
|
|
2670
3733
|
return false;
|
|
2671
3734
|
const like = fn;
|
|
2672
3735
|
const body = like.body;
|
|
2673
|
-
const param = like.parameters[index];
|
|
3736
|
+
const param = like.parameters.nodes[index];
|
|
2674
3737
|
if (body === undefined || !ts.isBlock(body) || param === undefined)
|
|
2675
3738
|
return false;
|
|
2676
3739
|
if (!ts.isIdentifier(param.name) || param.dotDotDotToken !== undefined)
|
|
2677
3740
|
return false;
|
|
2678
|
-
if (like.parameters.slice(0, index).some((p) => p.dotDotDotToken !== undefined))
|
|
3741
|
+
if (like.parameters.nodes.slice(0, index).some((p) => p.dotDotDotToken !== undefined))
|
|
2679
3742
|
return false;
|
|
2680
3743
|
const paramName = param.name.text;
|
|
2681
3744
|
let deferred = true;
|
|
@@ -2723,9 +3786,9 @@ function returnsOnlyClosuresOver7(checker, callee, index) {
|
|
|
2723
3786
|
* initializers and static blocks. Methods and instance fields wait for a
|
|
2724
3787
|
* call or a construction. */
|
|
2725
3788
|
function classSyncParts7(c) {
|
|
2726
|
-
const decorators = (n) => (n.modifiers ?? []).filter((m) => m.kind === ts.SyntaxKind.Decorator);
|
|
2727
|
-
const parts = [...decorators(c), ...(c.heritageClauses ?? [])];
|
|
2728
|
-
for (const m of c.members) {
|
|
3789
|
+
const decorators = (n) => (n.modifiers?.nodes ?? []).filter((m) => m.kind === ts.SyntaxKind.Decorator);
|
|
3790
|
+
const parts = [...decorators(c), ...(c.heritageClauses?.nodes ?? [])];
|
|
3791
|
+
for (const m of c.members.nodes) {
|
|
2729
3792
|
parts.push(...decorators(m));
|
|
2730
3793
|
const memberName = m.name;
|
|
2731
3794
|
if (memberName !== undefined && ts.isComputedPropertyName(memberName))
|
|
@@ -2784,15 +3847,15 @@ function laterJobCallee7(checker, callee) {
|
|
|
2784
3847
|
}
|
|
2785
3848
|
if (symbol === undefined)
|
|
2786
3849
|
return false;
|
|
2787
|
-
const decls =
|
|
2788
|
-
if (decls.length === 0 || !decls.every((d) =>
|
|
3850
|
+
const decls = symbol.declarations;
|
|
3851
|
+
if (decls.length === 0 || !decls.every((d) => ts.getSourceFileOfNode(d).isDeclarationFile))
|
|
2789
3852
|
return false;
|
|
2790
3853
|
if (LATER_JOB_BUILTINS7.has(name.text))
|
|
2791
3854
|
return true;
|
|
2792
3855
|
// The JavaScript standard library's callbacks mostly run synchronously;
|
|
2793
3856
|
// package declarations describe user code.
|
|
2794
3857
|
return decls.every((d) => {
|
|
2795
|
-
const file =
|
|
3858
|
+
const file = ts.getSourceFileOfNode(d).fileName;
|
|
2796
3859
|
return isNodeTypesPath(file) || file === fallbackDtsPath();
|
|
2797
3860
|
});
|
|
2798
3861
|
}
|
|
@@ -2855,7 +3918,7 @@ function boundNames7(name) {
|
|
|
2855
3918
|
if (ts.isIdentifier(name))
|
|
2856
3919
|
return [name];
|
|
2857
3920
|
const out = [];
|
|
2858
|
-
for (const el of name.elements) {
|
|
3921
|
+
for (const el of name.elements.nodes) {
|
|
2859
3922
|
if (ts.isOmittedExpression(el) || el.name === undefined)
|
|
2860
3923
|
continue;
|
|
2861
3924
|
out.push(...boundNames7(el.name));
|
|
@@ -2870,7 +3933,7 @@ function typeOnlyNamespace7(decl) {
|
|
|
2870
3933
|
body = body.body;
|
|
2871
3934
|
if (body === undefined || !ts.isModuleBlock(body))
|
|
2872
3935
|
return true;
|
|
2873
|
-
return body.statements.every((s) => ts.isInterfaceDeclaration(s) ||
|
|
3936
|
+
return body.statements.nodes.every((s) => ts.isInterfaceDeclaration(s) ||
|
|
2874
3937
|
ts.isTypeAliasDeclaration(s) ||
|
|
2875
3938
|
(ts.isModuleDeclaration(s) && typeOnlyNamespace7(s)));
|
|
2876
3939
|
}
|
|
@@ -2891,10 +3954,22 @@ function resolveNpmImport7(fromFileName, specifier, resolutionKind = "import") {
|
|
|
2891
3954
|
if (isRelativeSpecifier(specifier) || specifier.startsWith("node:")) {
|
|
2892
3955
|
return null;
|
|
2893
3956
|
}
|
|
3957
|
+
// Node resolves a bare core-module name (`string_decoder`, `events`,
|
|
3958
|
+
// `fs/promises`) to the builtin before it looks in node_modules, so an
|
|
3959
|
+
// installed npm package of the same name never answers it. Prefix-only
|
|
3960
|
+
// builtins (`node:test`) are listed with their prefix, so a bare `test`
|
|
3961
|
+
// still names the package.
|
|
3962
|
+
if (nodeBuiltinNames.has(specifier))
|
|
3963
|
+
return null;
|
|
2894
3964
|
// --provenance-sources: a registered specifier is NOT an npm import —
|
|
2895
3965
|
// its attested source compiles as program modules (resolveProjectModule
|
|
2896
3966
|
if (provenanceEntryFor(specifier) !== null)
|
|
2897
3967
|
return null;
|
|
3968
|
+
// Shimmed and never-loaded packages (package-shims.ts) are not npm
|
|
3969
|
+
// imports either: the shim compiles as a program module, and an unloaded
|
|
3970
|
+
// package's require() is Node's MODULE_NOT_FOUND.
|
|
3971
|
+
if (isShimmedImport(fromFileName, specifier))
|
|
3972
|
+
return null;
|
|
2898
3973
|
const resolved = resolveBareModule(fromFileName, specifier, undefined, resolutionKind);
|
|
2899
3974
|
if (!resolved)
|
|
2900
3975
|
return null;
|
|
@@ -2917,18 +3992,12 @@ function resolveNpmImport7(fromFileName, specifier, resolutionKind = "import") {
|
|
|
2917
3992
|
};
|
|
2918
3993
|
}
|
|
2919
3994
|
function locOf7(node) {
|
|
2920
|
-
const sf =
|
|
2921
|
-
return { file: sf.fileName, start:
|
|
3995
|
+
const sf = ts.getSourceFileOfNode(node);
|
|
3996
|
+
return { file: sf.fileName, start: ts.tokenStartOfNode(node), end: node.end };
|
|
2922
3997
|
}
|
|
2923
|
-
/** The
|
|
2924
|
-
*
|
|
2925
|
-
|
|
2926
|
-
* program — a path-identity mismatch between the two resolvers). */
|
|
2927
|
-
function npmStaticProgramDep(program, packageName, resolvedFile) {
|
|
2928
|
-
if (!isJsSourceFileName(resolvedFile)) {
|
|
2929
|
-
reportNpmStaticOffender(packageName, `its import resolves to '${resolvedFile}', not to runtime JavaScript`);
|
|
2930
|
-
return null;
|
|
2931
|
-
}
|
|
3998
|
+
/** The program file holding an opted-in package's resolved runtime JS:
|
|
3999
|
+
* the file itself, or its same-stem TypeScript twin. */
|
|
4000
|
+
function npmStaticProgramFile(program, resolvedFile) {
|
|
2932
4001
|
let dep = program.getSourceFile(resolvedFile) ?? null;
|
|
2933
4002
|
if (dep === null) {
|
|
2934
4003
|
// A workspace-linked package shipping its .ts SOURCE beside the
|
|
@@ -2942,6 +4011,18 @@ function npmStaticProgramDep(program, packageName, resolvedFile) {
|
|
|
2942
4011
|
break;
|
|
2943
4012
|
}
|
|
2944
4013
|
}
|
|
4014
|
+
return dep;
|
|
4015
|
+
}
|
|
4016
|
+
/** The PROGRAM source file an opted-in --npm-static package's resolved
|
|
4017
|
+
* entry maps to, or null with the package marked an offender (resolution
|
|
4018
|
+
* still answering declarations, or the file missing from the type-checked
|
|
4019
|
+
* program — a path-identity mismatch between the two resolvers). */
|
|
4020
|
+
function npmStaticProgramDep(program, packageName, resolvedFile) {
|
|
4021
|
+
if (!isJsSourceFileName(resolvedFile)) {
|
|
4022
|
+
reportNpmStaticOffender(packageName, `its import resolves to '${resolvedFile}', not to runtime JavaScript`);
|
|
4023
|
+
return null;
|
|
4024
|
+
}
|
|
4025
|
+
const dep = npmStaticProgramFile(program, resolvedFile);
|
|
2945
4026
|
if (dep === null) {
|
|
2946
4027
|
reportNpmStaticOffender(packageName, `its entry '${resolvedFile}' did not join the type-checked program`);
|
|
2947
4028
|
return null;
|
|
@@ -3064,7 +4145,7 @@ function preflight7(load) {
|
|
|
3064
4145
|
names = new Set();
|
|
3065
4146
|
builtinNamespaceNames.set(d.fileName, names);
|
|
3066
4147
|
const sf = p.getSourceFile(d.fileName);
|
|
3067
|
-
for (const stmt of sf?.statements ?? []) {
|
|
4148
|
+
for (const stmt of sf?.statements?.nodes ?? []) {
|
|
3068
4149
|
if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
3069
4150
|
continue;
|
|
3070
4151
|
if (canonicalBuiltinModule(stmt.moduleSpecifier.text) === null)
|
|
@@ -3116,6 +4197,29 @@ function preflight7(load) {
|
|
|
3116
4197
|
return true;
|
|
3117
4198
|
return d.code === 2300 && commentDup.has(`${d.fileName}:${sf.text.slice(d.pos, d.end)}`);
|
|
3118
4199
|
};
|
|
4200
|
+
/* `typeof window` / `typeof self` in a JavaScript file: the operand of
|
|
4201
|
+
* typeof may name a global nothing declares (Node answers "undefined"
|
|
4202
|
+
* and never throws), the feature-detection idiom every isomorphic
|
|
4203
|
+
* package uses, and the guarded uses of that name (`typeof window < "u"
|
|
4204
|
+
* ? window : …`) are code Node never runs. A name the file feature-tests
|
|
4205
|
+
* this way is therefore not a type error in JavaScript; a reached use
|
|
4206
|
+
* still meets the lowering's located refusal. TypeScript files keep the
|
|
4207
|
+
* error and its hint. */
|
|
4208
|
+
const typeofTestedNameSuppressed = (p, d) => {
|
|
4209
|
+
if (d.code !== 2304 && d.code !== 2552 && d.code !== 2584)
|
|
4210
|
+
return false;
|
|
4211
|
+
if (d.fileName === undefined || !isJsSourceFileName(d.fileName))
|
|
4212
|
+
return false;
|
|
4213
|
+
if (d.pos === undefined || d.end === undefined)
|
|
4214
|
+
return false;
|
|
4215
|
+
const sf = p.getSourceFile(d.fileName);
|
|
4216
|
+
if (!sf)
|
|
4217
|
+
return false;
|
|
4218
|
+
const name = sf.text.slice(d.pos, d.end);
|
|
4219
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(name))
|
|
4220
|
+
return false;
|
|
4221
|
+
return new RegExp(`\\btypeof\\s*\\(?\\s*${name.replace(/\$/g, "\\$")}(?![\\w$])`).test(sf.text);
|
|
4222
|
+
};
|
|
3119
4223
|
const workspaceImplicitAnySuppressed = (p, d) => {
|
|
3120
4224
|
if (d.code !== 7016 || d.fileName === undefined || d.pos === undefined || d.end === undefined)
|
|
3121
4225
|
return false;
|
|
@@ -3128,6 +4232,17 @@ function preflight7(load) {
|
|
|
3128
4232
|
: spec.split("/")[0];
|
|
3129
4233
|
return isWorkspacePackageName(prefix);
|
|
3130
4234
|
};
|
|
4235
|
+
// A JavaScript file that TypeScript checks keeps the type errors that
|
|
4236
|
+
// protect its JSDoc types: a value of another type reaching a typed slot,
|
|
4237
|
+
// a call with the wrong arity, and a subclass member that does not
|
|
4238
|
+
// match its base.
|
|
4239
|
+
const projectCheckJs = load.typeWorld?.projectCheckJs ?? false;
|
|
4240
|
+
const enforcedInCheckedJs = (p, d) => {
|
|
4241
|
+
if (!CHECKED_JS_ENFORCED_CODES.has(d.code) || d.fileName === undefined)
|
|
4242
|
+
return false;
|
|
4243
|
+
const sf = p.getSourceFile(d.fileName);
|
|
4244
|
+
return sf !== undefined && isCheckedJsSourceFile(sf, projectCheckJs);
|
|
4245
|
+
};
|
|
3131
4246
|
const errorsOf = (p) => {
|
|
3132
4247
|
const all = ts.getPreEmitDiagnostics(p);
|
|
3133
4248
|
// First pass: every comment-side 2300's (file, name) — the partners
|
|
@@ -3143,13 +4258,15 @@ function preflight7(load) {
|
|
|
3143
4258
|
commentDup.add(`${d.fileName}:${sf.text.slice(d.pos, d.end)}`);
|
|
3144
4259
|
}
|
|
3145
4260
|
return all.filter((d) => d.category === ts.DiagnosticCategory.Error &&
|
|
3146
|
-
!suppressedJsStrictness7(d) &&
|
|
4261
|
+
(!suppressedJsStrictness7(d) || enforcedInCheckedJs(p, d)) &&
|
|
3147
4262
|
!npmStaticFileSuppressed(d) &&
|
|
3148
4263
|
!nodeModulesJsSuppressed(d) &&
|
|
4264
|
+
(d.fileName === undefined || !isPackageShimFile(d.fileName)) &&
|
|
3149
4265
|
!namespaceCalleeSuppressed(p, d) &&
|
|
3150
4266
|
!inferredJsDiagnosticSuppressed(p, d) &&
|
|
3151
4267
|
!isNpmStaticSubclassArgument(p, d) &&
|
|
3152
4268
|
!workspaceImplicitAnySuppressed(p, d) &&
|
|
4269
|
+
!typeofTestedNameSuppressed(p, d) &&
|
|
3153
4270
|
!jsdocTypeSuppressed(p, d, commentDup));
|
|
3154
4271
|
};
|
|
3155
4272
|
// The tsc gate, with a second chance: the LOWERING world's checker
|
|
@@ -3185,14 +4302,23 @@ function preflight7(load) {
|
|
|
3185
4302
|
entryPackageFile(sf.fileName) ||
|
|
3186
4303
|
npmStaticPackageOfPath(sf.fileName) !== null) &&
|
|
3187
4304
|
!unselectedPackageJsFile(sf.fileName));
|
|
4305
|
+
// Files reached only through `import type` / `export type … from` are
|
|
4306
|
+
// checker input, never program modules: Node does not load them, so
|
|
4307
|
+
// their imports and syntax must not fence the program.
|
|
4308
|
+
const resolveRuntimeEdge = (sf, spec, resolutionKind) => resolveImport7(program, sf, spec, resolutionKind) ??
|
|
4309
|
+
npmStaticDepSf7(program, sf, spec, resolutionKind);
|
|
4310
|
+
const typeOnlyFiles = typeOnlyReachedFiles(program, entry, programFiles, () => [
|
|
4311
|
+
...forkTargetPaths(program, program.getImplementationSourceFiles()),
|
|
4312
|
+
...workerTargetPaths(program, program.getImplementationSourceFiles()),
|
|
4313
|
+
], resolveRuntimeEdge);
|
|
4314
|
+
const runtimeFiles = typeOnlyFiles.size === 0 ? programFiles : programFiles.filter((sf) => !typeOnlyFiles.has(sf));
|
|
3188
4315
|
const userFiles = npmStaticActive()
|
|
3189
|
-
? planNpmStaticReexports(program, entry,
|
|
4316
|
+
? planNpmStaticReexports(program, entry, runtimeFiles, [
|
|
3190
4317
|
...createRequireProgramRoots7(program),
|
|
3191
4318
|
...forkTargetPaths(program, program.getImplementationSourceFiles()),
|
|
3192
4319
|
...workerTargetPaths(program, program.getImplementationSourceFiles()),
|
|
3193
|
-
],
|
|
3194
|
-
|
|
3195
|
-
: programFiles;
|
|
4320
|
+
], resolveRuntimeEdge)
|
|
4321
|
+
: runtimeFiles;
|
|
3196
4322
|
program.getTypeChecker().prefetchSourceFileStructures(userFiles);
|
|
3197
4323
|
// Unselected node_modules JS is not native program source even when
|
|
3198
4324
|
// maxNodeModuleJsDepth pulled it into the checker (nodeModulesJsSuppressed).
|
|
@@ -3229,7 +4355,7 @@ function preflight7(load) {
|
|
|
3229
4355
|
if (ambientModuleDecls === null) {
|
|
3230
4356
|
ambientModuleDecls = { names: new Set(), patterns: [] };
|
|
3231
4357
|
for (const f of program.getSourceFiles()) {
|
|
3232
|
-
for (const s of f.statements) {
|
|
4358
|
+
for (const s of f.statements.nodes) {
|
|
3233
4359
|
if (!ts.isModuleDeclaration(s) || !ts.isStringLiteral(s.name))
|
|
3234
4360
|
continue;
|
|
3235
4361
|
const name = s.name.text;
|
|
@@ -3270,7 +4396,7 @@ function preflight7(load) {
|
|
|
3270
4396
|
edges.set(sf, deps);
|
|
3271
4397
|
refusals.set(sf, []);
|
|
3272
4398
|
depPositions.set(sf, []);
|
|
3273
|
-
for (const stmt of sf.statements) {
|
|
4399
|
+
for (const stmt of sf.statements.nodes) {
|
|
3274
4400
|
if (ts.isImportEqualsDeclaration(stmt)) {
|
|
3275
4401
|
// The ENTITY form (`import a = A`, `import x = N.y`) is namespace
|
|
3276
4402
|
// alias plumbing — the lowerer resolves references through it and
|
|
@@ -3300,7 +4426,7 @@ function preflight7(load) {
|
|
|
3300
4426
|
continue;
|
|
3301
4427
|
}
|
|
3302
4428
|
if (ts.isExportDeclaration(stmt)) {
|
|
3303
|
-
if (stmt.isTypeOnly ||
|
|
4429
|
+
if (stmt.isTypeOnly || isPrunedNpmReexport(program, stmt))
|
|
3304
4430
|
continue;
|
|
3305
4431
|
if (!stmt.moduleSpecifier)
|
|
3306
4432
|
continue;
|
|
@@ -3353,7 +4479,7 @@ function preflight7(load) {
|
|
|
3353
4479
|
}
|
|
3354
4480
|
if (reDep && !reDep.fileName.endsWith(".json")) {
|
|
3355
4481
|
deps.push({ dep: reDep, stmt });
|
|
3356
|
-
depPositions.get(sf).push({ dep: reDep, pos:
|
|
4482
|
+
depPositions.get(sf).push({ dep: reDep, pos: ts.tokenStartOfNode(stmt) });
|
|
3357
4483
|
}
|
|
3358
4484
|
continue;
|
|
3359
4485
|
}
|
|
@@ -3400,7 +4526,7 @@ function preflight7(load) {
|
|
|
3400
4526
|
refusals.get(sf).push({
|
|
3401
4527
|
crash: { message, className, loc: locOf7(stmt) },
|
|
3402
4528
|
fallback: unsupportedDiag("SC1010", locOf7(stmt), fallbackFeature),
|
|
3403
|
-
pos:
|
|
4529
|
+
pos: ts.tokenStartOfNode(stmt),
|
|
3404
4530
|
});
|
|
3405
4531
|
};
|
|
3406
4532
|
// Project modules win before npm fallback: this is the source graph
|
|
@@ -3566,21 +4692,39 @@ function preflight7(load) {
|
|
|
3566
4692
|
}
|
|
3567
4693
|
if (dep && !isJson) {
|
|
3568
4694
|
deps.push({ dep, stmt });
|
|
3569
|
-
depPositions.get(sf).push({ dep, pos:
|
|
4695
|
+
depPositions.get(sf).push({ dep, pos: ts.tokenStartOfNode(stmt) });
|
|
3570
4696
|
}
|
|
3571
4697
|
}
|
|
3572
4698
|
{
|
|
3573
4699
|
const jsRequireFile = isJsSourceFileName(sf.fileName);
|
|
3574
|
-
const stmts = sf.statements;
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
4700
|
+
const stmts = sf.statements.nodes;
|
|
4701
|
+
// A binding that code running before the require can reach. Node
|
|
4702
|
+
// initializes it AT the require: a const/let read earlier throws
|
|
4703
|
+
// ReferenceError, which the lowering reproduces with an
|
|
4704
|
+
// initialization check at every reference that can run early
|
|
4705
|
+
// (require-initialization.ts). A var reads undefined there, which
|
|
4706
|
+
// module aliases cannot represent; createRequire bindings have no
|
|
4707
|
+
// checked form either.
|
|
4708
|
+
const earlyRequireFence = (req, bindingKind, loc) => {
|
|
4709
|
+
const early = req.decl !== null ? requireEarlyReference7(program, req.decl) : null;
|
|
4710
|
+
if (early === null ||
|
|
4711
|
+
(bindingKind !== "createRequire" &&
|
|
4712
|
+
((req.decl.parent?.flags ?? 0) & (ts.NodeFlags.Const | ts.NodeFlags.Let)) !== 0)) {
|
|
4713
|
+
return false;
|
|
4714
|
+
}
|
|
4715
|
+
diags.push(unsupportedDiag("SC1013", loc, bindingKind === "createRequire"
|
|
4716
|
+
? `createRequire() binding '${early.text}' below code that can reach it (Node throws ReferenceError on any earlier access, which is not modeled — move the require above the code that can run first)`
|
|
4717
|
+
: `var require() binding '${early.text}' below code that can reach it (Node reads undefined before the require runs, which is not modeled — declare it with const or let, or move the require above the code that can run first)`));
|
|
4718
|
+
return true;
|
|
4719
|
+
};
|
|
3580
4720
|
for (let k = 0; k < stmts.length; k++) {
|
|
3581
4721
|
const stmt = stmts[k];
|
|
3582
4722
|
for (const req of requiresOf7(stmt)) {
|
|
3583
|
-
const loc = {
|
|
4723
|
+
const loc = {
|
|
4724
|
+
file: sf.fileName,
|
|
4725
|
+
start: ts.tokenStartOfNode(req.node),
|
|
4726
|
+
end: req.node.end,
|
|
4727
|
+
};
|
|
3584
4728
|
const bindingKind = requireCallBindingKind7(program, req.node);
|
|
3585
4729
|
// TypeScript source files join this scan only through the
|
|
3586
4730
|
// canonical createRequire bridge. Their ordinary require-shaped
|
|
@@ -3597,20 +4741,72 @@ function preflight7(load) {
|
|
|
3597
4741
|
if (load.externalTypes.has(req.spec)) {
|
|
3598
4742
|
continue;
|
|
3599
4743
|
}
|
|
4744
|
+
// A JSON document: the require answers its cached parsed object
|
|
4745
|
+
// (json-require.ts), an ordinary value the binding stores, so
|
|
4746
|
+
// every destructuring form lowers as usual. No module edge.
|
|
4747
|
+
const jsonDep = resolveImport7(program, sf, req.spec, "require");
|
|
4748
|
+
if (jsonDep !== null && jsonDep.fileName.endsWith(".json")) {
|
|
4749
|
+
if (bindingKind === "createRequire")
|
|
4750
|
+
continue;
|
|
4751
|
+
if (ts.isVariableStatement(stmt) && requiresOf7(stmt).length > 1) {
|
|
4752
|
+
const others = requiresOf7(stmt).some((r) => {
|
|
4753
|
+
const d = resolveImport7(program, sf, r.spec, "require");
|
|
4754
|
+
return d === null || !d.fileName.endsWith(".json");
|
|
4755
|
+
});
|
|
4756
|
+
if (others) {
|
|
4757
|
+
diags.push(unsupportedDiag("SC1012", loc, "require() of a JSON module declared together with other require() bindings"));
|
|
4758
|
+
continue;
|
|
4759
|
+
}
|
|
4760
|
+
}
|
|
4761
|
+
earlyRequireFence(req, bindingKind, loc);
|
|
4762
|
+
continue;
|
|
4763
|
+
}
|
|
3600
4764
|
if (req.decl && ts.isArrayBindingPattern(req.decl.name)) {
|
|
3601
4765
|
diags.push(unsupportedDiag("SC1012", loc, "array-destructuring require() bindings"));
|
|
3602
4766
|
continue;
|
|
3603
4767
|
}
|
|
3604
4768
|
if (req.decl && ts.isObjectBindingPattern(req.decl.name)) {
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
4769
|
+
// A nested pattern of a builtin binds members of the sub-module
|
|
4770
|
+
// its key names (`const { types: { isPromise } } =
|
|
4771
|
+
// require("util")` — util.types IS util/types).
|
|
4772
|
+
const builtin = canonicalBuiltinModule(req.spec);
|
|
4773
|
+
const plainElements = (pattern, module) => pattern.elements.nodes.every((e) => {
|
|
4774
|
+
if (e.initializer !== undefined || e.dotDotDotToken !== undefined)
|
|
4775
|
+
return false;
|
|
4776
|
+
if (e.name !== undefined && ts.isIdentifier(e.name))
|
|
4777
|
+
return true;
|
|
4778
|
+
// A nested pattern under a named export of a program module
|
|
4779
|
+
// destructures that export's VALUE at the require
|
|
4780
|
+
// (`const { codes: { ERR_X } } = require("./errors")`): the
|
|
4781
|
+
// inner bindings are ordinary destructured storage.
|
|
4782
|
+
if (module === null &&
|
|
4783
|
+
builtin === null &&
|
|
4784
|
+
bindingKind !== "createRequire" &&
|
|
4785
|
+
pattern === req.decl.name &&
|
|
4786
|
+
e.name !== undefined &&
|
|
4787
|
+
ts.isObjectBindingPattern(e.name) &&
|
|
4788
|
+
e.propertyName !== undefined &&
|
|
4789
|
+
ts.isIdentifier(e.propertyName))
|
|
4790
|
+
return true;
|
|
4791
|
+
if (module === null || e.name === undefined || !ts.isObjectBindingPattern(e.name))
|
|
4792
|
+
return false;
|
|
4793
|
+
const key = e.propertyName;
|
|
4794
|
+
if (key === undefined || !ts.isIdentifier(key))
|
|
4795
|
+
return false;
|
|
4796
|
+
const sub = canonicalBuiltinModule(`${module}/${key.text}`);
|
|
4797
|
+
return sub !== null && plainElements(e.name, sub);
|
|
4798
|
+
});
|
|
4799
|
+
if (!plainElements(req.decl.name, builtin)) {
|
|
4800
|
+
diags.push(unsupportedDiag("SC1012", loc, builtin !== null
|
|
4801
|
+
? "require() destructuring with defaults, rest, or nested patterns other than builtin sub-modules"
|
|
4802
|
+
: "require() destructuring with defaults, rest, or nested patterns of program modules (JSON documents and builtin sub-modules destructure fully)"));
|
|
3611
4803
|
continue;
|
|
3612
4804
|
}
|
|
3613
4805
|
}
|
|
4806
|
+
// An npm package served as a builtin (graceful-fs as fs) is never
|
|
4807
|
+
// a program-module edge, even when --npm-static names it.
|
|
4808
|
+
if (npmBuiltinAliasOf(req.spec) !== null)
|
|
4809
|
+
continue;
|
|
3614
4810
|
const isRelative = isRelativeSpecifier(req.spec);
|
|
3615
4811
|
let dep = resolveImport7(program, sf, req.spec, "require");
|
|
3616
4812
|
if (dep === null && !isRelative) {
|
|
@@ -3649,27 +4845,8 @@ function preflight7(load) {
|
|
|
3649
4845
|
continue;
|
|
3650
4846
|
}
|
|
3651
4847
|
}
|
|
3652
|
-
if (
|
|
3653
|
-
if (bindingKind === "createRequire")
|
|
3654
|
-
continue;
|
|
3655
|
-
diags.push(unsupportedDiag("SC1012", loc, "require() of JSON modules"));
|
|
4848
|
+
if (earlyRequireFence(req, bindingKind, loc))
|
|
3656
4849
|
continue;
|
|
3657
|
-
}
|
|
3658
|
-
// Earlier declarators run too: `const x = read(), dep =
|
|
3659
|
-
// require('./dep')` must not lose the guard merely because both
|
|
3660
|
-
// initializers share one VariableStatement.
|
|
3661
|
-
const precedingDecls = req.decl && ts.isVariableStatement(stmt)
|
|
3662
|
-
? stmt.declarationList.declarations.slice(0, stmt.declarationList.declarations.indexOf(req.decl))
|
|
3663
|
-
: [];
|
|
3664
|
-
const prefixCanRun = (firstRunnable >= 0 && firstRunnable < k) ||
|
|
3665
|
-
precedingDecls.some((decl) => !purePrefixDecl7(decl));
|
|
3666
|
-
const tdzName = prefixCanRun && req.decl
|
|
3667
|
-
? bindingEarlyUse7(program, sf, k, req.decl, precedingDecls)
|
|
3668
|
-
: null;
|
|
3669
|
-
if (tdzName !== null) {
|
|
3670
|
-
diags.push(unsupportedDiag("SC1013", loc, `require() below code that can reach its binding '${tdzName}' (Node initializes the binding AT the require and throws ReferenceError on any earlier access, which is not modeled — move the require above the code that can run first)`));
|
|
3671
|
-
continue;
|
|
3672
|
-
}
|
|
3673
4850
|
if (dep)
|
|
3674
4851
|
deps.push({ dep });
|
|
3675
4852
|
}
|
|
@@ -3680,7 +4857,7 @@ function preflight7(load) {
|
|
|
3680
4857
|
.prefetchSymbolNodesExact(nestedBareRequires.flatMap((call) => ts.isIdentifier(call.expression) ? [call.expression] : []));
|
|
3681
4858
|
for (const call of nestedBareRequires) {
|
|
3682
4859
|
const spec = requireSpecOf7(call);
|
|
3683
|
-
const loc = { file: sf.fileName, start:
|
|
4860
|
+
const loc = { file: sf.fileName, start: ts.tokenStartOfNode(call), end: call.end };
|
|
3684
4861
|
const bindingKind = requireCallBindingKind7(program, call);
|
|
3685
4862
|
if (!jsRequireFile && bindingKind !== "createRequire")
|
|
3686
4863
|
continue;
|
|
@@ -3693,14 +4870,14 @@ function preflight7(load) {
|
|
|
3693
4870
|
if (load.externalTypes.has(spec)) {
|
|
3694
4871
|
continue;
|
|
3695
4872
|
}
|
|
4873
|
+
if (npmBuiltinAliasOf(spec) !== null)
|
|
4874
|
+
continue;
|
|
3696
4875
|
const projectDep = resolveImport7(program, sf, spec, "require");
|
|
3697
4876
|
if (projectDep !== null) {
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
diags.push(unsupportedDiag("SC1012", loc, "require() of JSON modules"));
|
|
4877
|
+
// A bare require of a JSON document only parses it: nothing to
|
|
4878
|
+
// evaluate (json-require.ts creates the cached object).
|
|
4879
|
+
if (projectDep.fileName.endsWith(".json"))
|
|
3702
4880
|
continue;
|
|
3703
|
-
}
|
|
3704
4881
|
deps.push({ dep: projectDep });
|
|
3705
4882
|
continue;
|
|
3706
4883
|
}
|
|
@@ -3728,6 +4905,36 @@ function preflight7(load) {
|
|
|
3728
4905
|
continue;
|
|
3729
4906
|
}
|
|
3730
4907
|
}
|
|
4908
|
+
// Inline requires of program modules are module edges like the bare
|
|
4909
|
+
// statements above (cjs-inline-require.ts lowers each to the module's
|
|
4910
|
+
// %init at its position). Only the CommonJS global in a CommonJS file
|
|
4911
|
+
// counts, and targets outside the compiled graph add nothing here:
|
|
4912
|
+
// their use sites keep their existing lowering fences.
|
|
4913
|
+
if (jsRequireFile && !isNodeEsmFile7(sf, program)) {
|
|
4914
|
+
for (const call of inlineRequiresOf7(sf)) {
|
|
4915
|
+
if (requireCallBindingKind7(program, call) !== "ambient")
|
|
4916
|
+
continue;
|
|
4917
|
+
const spec = requireSpecOf7(call);
|
|
4918
|
+
if (load.externalTypes.has(spec) || canonicalBuiltinModule(spec) !== null)
|
|
4919
|
+
continue;
|
|
4920
|
+
const lazy = inDeferredPosition7(call);
|
|
4921
|
+
const edgeTo = (dep) => lazy ? { dep, lazy: true, call } : { dep, call };
|
|
4922
|
+
const projectDep = resolveImport7(program, sf, spec, "require");
|
|
4923
|
+
if (projectDep !== null) {
|
|
4924
|
+
if (!projectDep.fileName.endsWith(".json"))
|
|
4925
|
+
deps.push(edgeTo(projectDep));
|
|
4926
|
+
continue;
|
|
4927
|
+
}
|
|
4928
|
+
if (isRelativeSpecifier(spec) || spec.startsWith("#"))
|
|
4929
|
+
continue;
|
|
4930
|
+
const npmReq = resolveNpmImport7(sf.fileName, spec, "require");
|
|
4931
|
+
if (npmReq !== null && isNpmStaticPackage(npmReq.packageName)) {
|
|
4932
|
+
const nDep = npmStaticProgramDep(program, npmReq.packageName, npmReq.typesFile);
|
|
4933
|
+
if (nDep !== null)
|
|
4934
|
+
deps.push(edgeTo(nDep));
|
|
4935
|
+
}
|
|
4936
|
+
}
|
|
4937
|
+
}
|
|
3731
4938
|
}
|
|
3732
4939
|
}
|
|
3733
4940
|
// Node's evaluation order: depth-first postorder from the entry, each
|
|
@@ -3753,8 +4960,12 @@ function preflight7(load) {
|
|
|
3753
4960
|
// reads are all let/const bindings with module storage — the
|
|
3754
4961
|
// lowering checks each one (cycleEarlyBindings) and throws Node's
|
|
3755
4962
|
// ReferenceError on a read before the declaration ran.
|
|
3756
|
-
const cycleAdmissionReason = makeCycleAdmission(program, (sf) =>
|
|
4963
|
+
const cycleAdmissionReason = makeCycleAdmission(program, (sf) => {
|
|
4964
|
+
const all = edges.get(sf) ?? [];
|
|
4965
|
+
return all.some((e) => e.call !== undefined) ? all.filter((e) => e.call === undefined) : all;
|
|
4966
|
+
});
|
|
3757
4967
|
const order = [];
|
|
4968
|
+
const inlineRequireCycleCalls = new Set();
|
|
3758
4969
|
const state = new Map();
|
|
3759
4970
|
const stack = [];
|
|
3760
4971
|
const visit = (sf) => {
|
|
@@ -3763,10 +4974,16 @@ function preflight7(load) {
|
|
|
3763
4974
|
for (const e of edges.get(sf) ?? []) {
|
|
3764
4975
|
if (e.dep === sf)
|
|
3765
4976
|
continue; // self-import: a Node cache hit, not a cycle
|
|
4977
|
+
if (e.lazy === true)
|
|
4978
|
+
continue; // visited after this module completes
|
|
3766
4979
|
const s = state.get(e.dep);
|
|
3767
4980
|
if (s === "done")
|
|
3768
4981
|
continue;
|
|
3769
4982
|
if (s === "visiting") {
|
|
4983
|
+
if (e.call !== undefined) {
|
|
4984
|
+
inlineRequireCycleCalls.add(e.call);
|
|
4985
|
+
continue;
|
|
4986
|
+
}
|
|
3770
4987
|
// A back-edge: Node answers it from the cache (the module is
|
|
3771
4988
|
// already evaluating) — admitted by the cheap per-edge rule, the
|
|
3772
4989
|
// declaration-only init window rule, or the exact initialization
|
|
@@ -3784,6 +5001,12 @@ function preflight7(load) {
|
|
|
3784
5001
|
stack.pop();
|
|
3785
5002
|
state.set(sf, "done");
|
|
3786
5003
|
order.push(sf);
|
|
5004
|
+
// Lazy inline requires run after this module's top level: their
|
|
5005
|
+
// modules join the order afterwards (cache hits when already loaded).
|
|
5006
|
+
for (const e of edges.get(sf) ?? []) {
|
|
5007
|
+
if (e.lazy === true && state.get(e.dep) === undefined)
|
|
5008
|
+
visit(e.dep);
|
|
5009
|
+
}
|
|
3787
5010
|
};
|
|
3788
5011
|
visit(entry);
|
|
3789
5012
|
// The startup crash Node's RESOLUTION phase reports: modules resolve
|
|
@@ -3833,7 +5056,13 @@ function preflight7(load) {
|
|
|
3833
5056
|
const linkCrash = resolveCrash !== null
|
|
3834
5057
|
? null
|
|
3835
5058
|
: earlierLinkCrash(order, cjsNamedImportLinkCheck(program, entry, order, diags), esmNamedImportLinkCheck(program, entry, order, diags));
|
|
3836
|
-
return {
|
|
5059
|
+
return {
|
|
5060
|
+
diags,
|
|
5061
|
+
moduleOrder: order,
|
|
5062
|
+
startupCrash: resolveCrash ?? linkCrash,
|
|
5063
|
+
inlineRequireCycleCalls,
|
|
5064
|
+
moduleEdges: edges,
|
|
5065
|
+
};
|
|
3837
5066
|
}
|
|
3838
5067
|
/** Walks the entry's ESM instantiate graph exactly as V8 does — children
|
|
3839
5068
|
* in request order, each module's own imports checked AFTER its children
|
|
@@ -3867,12 +5096,19 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3867
5096
|
npmStaticDepSf7(program, from, spec, "require");
|
|
3868
5097
|
return dep !== null && isCjsJsFile7(dep, program) ? dep : null;
|
|
3869
5098
|
};
|
|
5099
|
+
// A bundler rewrite spells some lexer-visible names as accessors.
|
|
5100
|
+
const lexWithAccessorNames = (sf) => {
|
|
5101
|
+
const lexed = cjsLexedExportsOfFile(sf);
|
|
5102
|
+
for (const name of npmStaticLexerVisibleNames(sf.fileName))
|
|
5103
|
+
lexed.exports.add(name);
|
|
5104
|
+
return lexed;
|
|
5105
|
+
};
|
|
3870
5106
|
const visible = (dep, name) =>
|
|
3871
5107
|
// `default` is the module.exports binding itself — always provided.
|
|
3872
5108
|
// The program already owns native source ASTs; reuse them without
|
|
3873
5109
|
// starting another syntax session or reparsing their source text.
|
|
3874
5110
|
name === "default" ||
|
|
3875
|
-
cjsVisibleNames(dep,
|
|
5111
|
+
cjsVisibleNames(dep, lexWithAccessorNames, resolveCjsDep, lexMemo).has(name);
|
|
3876
5112
|
/** The statement's resolved LOCAL CommonJS dependency, when it is an
|
|
3877
5113
|
* import/re-export from one. */
|
|
3878
5114
|
const cjsDepOf = (sf, spec) => {
|
|
@@ -3884,7 +5120,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3884
5120
|
* then `export { x } from` elements in source order. */
|
|
3885
5121
|
const firstInvisibleOf = (sf) => {
|
|
3886
5122
|
const entries = [];
|
|
3887
|
-
for (const stmt of sf.statements) {
|
|
5123
|
+
for (const stmt of sf.statements.nodes) {
|
|
3888
5124
|
if (!ts.isImportDeclaration(stmt) ||
|
|
3889
5125
|
stmt.moduleSpecifier === undefined ||
|
|
3890
5126
|
!ts.isStringLiteral(stmt.moduleSpecifier))
|
|
@@ -3898,7 +5134,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3898
5134
|
const dep = cjsDepOf(sf, spec);
|
|
3899
5135
|
if (dep === null)
|
|
3900
5136
|
continue;
|
|
3901
|
-
for (const e of clause.namedBindings.elements) {
|
|
5137
|
+
for (const e of clause.namedBindings.elements.nodes) {
|
|
3902
5138
|
if (e.isTypeOnly)
|
|
3903
5139
|
continue;
|
|
3904
5140
|
const nameNode = e.propertyName ?? e.name;
|
|
@@ -3910,7 +5146,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3910
5146
|
if (!visible(e.dep, e.exportName))
|
|
3911
5147
|
return { exportName: e.exportName, spec: e.spec, nameNode: e.nameNode, sf };
|
|
3912
5148
|
}
|
|
3913
|
-
for (const stmt of sf.statements) {
|
|
5149
|
+
for (const stmt of sf.statements.nodes) {
|
|
3914
5150
|
if (!ts.isExportDeclaration(stmt) || stmt.isTypeOnly)
|
|
3915
5151
|
continue;
|
|
3916
5152
|
if (stmt.moduleSpecifier === undefined || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
@@ -3921,7 +5157,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3921
5157
|
const dep = cjsDepOf(sf, spec);
|
|
3922
5158
|
if (dep === null)
|
|
3923
5159
|
continue;
|
|
3924
|
-
for (const e of stmt.exportClause.elements) {
|
|
5160
|
+
for (const e of stmt.exportClause.elements.nodes) {
|
|
3925
5161
|
if (e.isTypeOnly)
|
|
3926
5162
|
continue;
|
|
3927
5163
|
const nameNode = e.propertyName ?? e.name;
|
|
@@ -3940,7 +5176,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3940
5176
|
if (visited.has(sf))
|
|
3941
5177
|
return null;
|
|
3942
5178
|
visited.add(sf);
|
|
3943
|
-
for (const stmt of sf.statements) {
|
|
5179
|
+
for (const stmt of sf.statements.nodes) {
|
|
3944
5180
|
if (!ts.isImportDeclaration(stmt) && !(ts.isExportDeclaration(stmt) && !stmt.isTypeOnly))
|
|
3945
5181
|
continue;
|
|
3946
5182
|
if (ts.isExportDeclaration(stmt) && isPrunedNpmReexport(program, stmt))
|
|
@@ -3981,7 +5217,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3981
5217
|
// it is CommonJS (module_job.js consults the ROOT job's moduleRequests/
|
|
3982
5218
|
// commonJsDeps — a deep module's failure keeps the generic wording).
|
|
3983
5219
|
let flavored = false;
|
|
3984
|
-
for (const stmt of entry.statements) {
|
|
5220
|
+
for (const stmt of entry.statements.nodes) {
|
|
3985
5221
|
if (!ts.isImportDeclaration(stmt) && !(ts.isExportDeclaration(stmt) && !stmt.isTypeOnly))
|
|
3986
5222
|
continue;
|
|
3987
5223
|
if (ts.isImportDeclaration(stmt) &&
|
|
@@ -4008,7 +5244,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
4008
5244
|
// swaps ` as ` for `: ` — reproduced exactly, quirks included
|
|
4009
5245
|
// (multi-line import statements simply lose the hint).
|
|
4010
5246
|
const text = bad.sf.text;
|
|
4011
|
-
const pos =
|
|
5247
|
+
const pos = ts.tokenStartOfNode(bad.nameNode);
|
|
4012
5248
|
const lineStart = text.lastIndexOf("\n", pos - 1) + 1;
|
|
4013
5249
|
const lineEnd = text.indexOf("\n", pos);
|
|
4014
5250
|
let line = text.slice(lineStart, lineEnd < 0 ? text.length : lineEnd);
|
|
@@ -4066,9 +5302,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4066
5302
|
// type-only, but the native ESM linker sees the runtime placeholder.
|
|
4067
5303
|
if (name === "default" &&
|
|
4068
5304
|
hasNodeTsDefaultInterfacePlaceholder7(dep) &&
|
|
4069
|
-
|
|
4070
|
-
.declarationsOf(resolved)
|
|
4071
|
-
.some((declaration) => ts.isInterfaceDeclaration(declaration) &&
|
|
5305
|
+
resolved.declarations.some((declaration) => ts.isInterfaceDeclaration(declaration) &&
|
|
4072
5306
|
ts
|
|
4073
5307
|
.getModifiers(declaration)
|
|
4074
5308
|
?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) === true &&
|
|
@@ -4087,7 +5321,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4087
5321
|
if (name === "default")
|
|
4088
5322
|
return undefined;
|
|
4089
5323
|
let starExport;
|
|
4090
|
-
for (const stmt of dep.statements) {
|
|
5324
|
+
for (const stmt of dep.statements.nodes) {
|
|
4091
5325
|
if (!ts.isExportDeclaration(stmt) || stmt.isTypeOnly || stmt.exportClause !== undefined)
|
|
4092
5326
|
continue;
|
|
4093
5327
|
if (stmt.moduleSpecifier === undefined || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
@@ -4106,7 +5340,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4106
5340
|
};
|
|
4107
5341
|
const firstMissingOf = (sf) => {
|
|
4108
5342
|
const imports = [];
|
|
4109
|
-
for (const stmt of sf.statements) {
|
|
5343
|
+
for (const stmt of sf.statements.nodes) {
|
|
4110
5344
|
if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
4111
5345
|
continue;
|
|
4112
5346
|
const clause = stmt.importClause;
|
|
@@ -4127,7 +5361,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4127
5361
|
}
|
|
4128
5362
|
if (clause.namedBindings === undefined || !ts.isNamedImports(clause.namedBindings))
|
|
4129
5363
|
continue;
|
|
4130
|
-
for (const element of clause.namedBindings.elements) {
|
|
5364
|
+
for (const element of clause.namedBindings.elements.nodes) {
|
|
4131
5365
|
if (element.isTypeOnly)
|
|
4132
5366
|
continue;
|
|
4133
5367
|
const nameNode = element.propertyName ?? element.name;
|
|
@@ -4154,7 +5388,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4154
5388
|
};
|
|
4155
5389
|
}
|
|
4156
5390
|
}
|
|
4157
|
-
for (const stmt of sf.statements) {
|
|
5391
|
+
for (const stmt of sf.statements.nodes) {
|
|
4158
5392
|
if (!ts.isExportDeclaration(stmt) || stmt.isTypeOnly)
|
|
4159
5393
|
continue;
|
|
4160
5394
|
const moduleSpecifier = stmt.moduleSpecifier;
|
|
@@ -4167,7 +5401,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4167
5401
|
const dep = resolveEdge(sf, spec);
|
|
4168
5402
|
if (dep === null || dep.fileName.endsWith(".json") || !isNodeEsmFile7(dep, program))
|
|
4169
5403
|
continue;
|
|
4170
|
-
for (const element of exportClause.elements) {
|
|
5404
|
+
for (const element of exportClause.elements.nodes) {
|
|
4171
5405
|
if (element.isTypeOnly)
|
|
4172
5406
|
continue;
|
|
4173
5407
|
const nameNode = element.propertyName ?? element.name;
|
|
@@ -4186,7 +5420,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4186
5420
|
if (visited.has(sf))
|
|
4187
5421
|
return null;
|
|
4188
5422
|
visited.add(sf);
|
|
4189
|
-
for (const stmt of sf.statements) {
|
|
5423
|
+
for (const stmt of sf.statements.nodes) {
|
|
4190
5424
|
if (!ts.isImportDeclaration(stmt) && !(ts.isExportDeclaration(stmt) && !stmt.isTypeOnly))
|
|
4191
5425
|
continue;
|
|
4192
5426
|
if (ts.isExportDeclaration(stmt) && isPrunedNpmReexport(program, stmt))
|
|
@@ -4268,17 +5502,17 @@ function earlierLinkCrash(moduleOrder, first, second) {
|
|
|
4268
5502
|
return first.loc.start < second.loc.start ? first : second;
|
|
4269
5503
|
const rank = (crash) => {
|
|
4270
5504
|
const entries = [];
|
|
4271
|
-
for (const stmt of sf.statements) {
|
|
5505
|
+
for (const stmt of sf.statements.nodes) {
|
|
4272
5506
|
if (ts.isImportDeclaration(stmt) && ts.isStringLiteral(stmt.moduleSpecifier)) {
|
|
4273
5507
|
const clause = stmt.importClause;
|
|
4274
5508
|
if (clause?.phaseModifier === ts.SyntaxKind.TypeKeyword)
|
|
4275
5509
|
continue;
|
|
4276
5510
|
if (clause?.namedBindings && ts.isNamedImports(clause.namedBindings)) {
|
|
4277
|
-
for (const element of clause.namedBindings.elements) {
|
|
5511
|
+
for (const element of clause.namedBindings.elements.nodes) {
|
|
4278
5512
|
if (!element.isTypeOnly) {
|
|
4279
5513
|
entries.push({
|
|
4280
5514
|
local: element.name.text,
|
|
4281
|
-
start: (element.propertyName ?? element.name)
|
|
5515
|
+
start: ts.tokenStartOfNode(element.propertyName ?? element.name),
|
|
4282
5516
|
kind: 0,
|
|
4283
5517
|
});
|
|
4284
5518
|
}
|
|
@@ -4291,16 +5525,16 @@ function earlierLinkCrash(moduleOrder, first, second) {
|
|
|
4291
5525
|
if (direct >= 0)
|
|
4292
5526
|
return [0, direct];
|
|
4293
5527
|
let reexport = 0;
|
|
4294
|
-
for (const stmt of sf.statements) {
|
|
5528
|
+
for (const stmt of sf.statements.nodes) {
|
|
4295
5529
|
const exportClause = ts.isExportDeclaration(stmt) ? stmt.exportClause : undefined;
|
|
4296
5530
|
if (!ts.isExportDeclaration(stmt) ||
|
|
4297
5531
|
stmt.isTypeOnly ||
|
|
4298
5532
|
exportClause === undefined ||
|
|
4299
5533
|
!ts.isNamedExports(exportClause))
|
|
4300
5534
|
continue;
|
|
4301
|
-
for (const element of exportClause.elements) {
|
|
5535
|
+
for (const element of exportClause.elements.nodes) {
|
|
4302
5536
|
if (!element.isTypeOnly &&
|
|
4303
|
-
(element.propertyName ?? element.name)
|
|
5537
|
+
ts.tokenStartOfNode(element.propertyName ?? element.name) === crash.loc.start) {
|
|
4304
5538
|
return [1, reexport];
|
|
4305
5539
|
}
|
|
4306
5540
|
if (!element.isTypeOnly)
|
|
@@ -4328,54 +5562,38 @@ const nodeBuiltinNames = new Set(builtinModules);
|
|
|
4328
5562
|
* established (the phase-2 port kept every spelling); the world-neutral
|
|
4329
5563
|
* helpers re-export from their focused modules. */
|
|
4330
5564
|
export { ambientDtsPath, fallbackDtsPath, isNodeTypesPath, overridesDtsPath } from "./dts-paths.js";
|
|
4331
|
-
export { builtinDefaultImportModule, canonicalBuiltinModule, SUPPORTED_BUILTIN_MODULES, } from "./builtin-modules.js";
|
|
5565
|
+
export { builtinDefaultImportModule, canonicalBuiltinModule, npmBuiltinAliasOf, SUPPORTED_BUILTIN_MODULES, } from "./builtin-modules.js";
|
|
4332
5566
|
export { npmPackageNameOf, workspacePackageOfPath } from "./workspace-registry.js";
|
|
4333
|
-
export { requireSpecOf7 as requireSpecOf, isRequireStatement7 as isRequireStatement, requiresOf7 as requiresOf, isNodeEsmFile7 as isNodeEsmFile, resolveImport7 as resolveImport, resolveNpmImport7 as resolveNpmImport, locOf7 as locOf, };
|
|
5567
|
+
export { requireSpecOf7 as requireSpecOf, isRequireStatement7 as isRequireStatement, requiresOf7 as requiresOf, isNodeEsmFile7 as isNodeEsmFile, resolveImport7 as resolveImport, resolveNpmImport7 as resolveNpmImport, locOf7 as locOf, requireEarlyReference7 as requireEarlyReference, inDeferredPosition7 as inDeferredPosition, };
|
|
4334
5568
|
/** True for JavaScript source files (.js/.mjs/.cjs) — the files whose
|
|
4335
5569
|
* types come entirely from inference (checkJs + JSDoc) and whose classes
|
|
4336
5570
|
* declare fields by constructor assignment. */
|
|
4337
5571
|
export function isJsSourceFile(sf) {
|
|
4338
5572
|
return isJsSourceFileName(sf.fileName);
|
|
4339
5573
|
}
|
|
4340
|
-
/**
|
|
4341
|
-
*
|
|
4342
|
-
*
|
|
4343
|
-
*
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
return true;
|
|
4357
|
-
return (clause.name === undefined &&
|
|
4358
|
-
clause.namedBindings !== undefined &&
|
|
4359
|
-
ts.isNamedImports(clause.namedBindings) &&
|
|
4360
|
-
clause.namedBindings.elements.length > 0 &&
|
|
4361
|
-
clause.namedBindings.elements.every((e) => e.isTypeOnly));
|
|
4362
|
-
}
|
|
4363
|
-
/** The re-export twin: `export { type X } from "./m"` with every element
|
|
4364
|
-
* `type`-qualified erases at emit exactly like `export type { X } from`
|
|
4365
|
-
* (which stmt.isTypeOnly already covers) — no module edge. */
|
|
4366
|
-
function erasedTypeOnlyReexport(stmt) {
|
|
4367
|
-
return (stmt.exportClause !== undefined &&
|
|
4368
|
-
ts.isNamedExports(stmt.exportClause) &&
|
|
4369
|
-
stmt.exportClause.elements.length > 0 &&
|
|
4370
|
-
stmt.exportClause.elements.every((e) => e.isTypeOnly));
|
|
5574
|
+
/** True for a JavaScript file of the program that TypeScript type-checks:
|
|
5575
|
+
* one with a `// @ts-check` comment before its first statement, or any
|
|
5576
|
+
* file of a project whose tsconfig sets `checkJs` unless the file has a
|
|
5577
|
+
* `// @ts-nocheck` comment. Files under node_modules are never checked. */
|
|
5578
|
+
export function isCheckedJsSourceFile(sf, projectCheckJs) {
|
|
5579
|
+
if (!isJsSourceFile(sf) || isNodeModulesPath(sf.fileName))
|
|
5580
|
+
return false;
|
|
5581
|
+
let checked = projectCheckJs;
|
|
5582
|
+
const head = sf.text.slice(0, (sf.statements.nodes.length === 0 ? undefined : ts.tokenStartOfNode(sf.statements.nodes[0])) ??
|
|
5583
|
+
sf.text.length);
|
|
5584
|
+
for (const line of head.split("\n")) {
|
|
5585
|
+
const directive = /^\s*\/\/\s*@ts-(no)?check\b/.exec(line);
|
|
5586
|
+
if (directive)
|
|
5587
|
+
checked = directive[1] === undefined;
|
|
5588
|
+
}
|
|
5589
|
+
return checked;
|
|
4371
5590
|
}
|
|
4372
5591
|
export function orderedImportsOf(program, sf) {
|
|
4373
5592
|
const out = [];
|
|
4374
|
-
for (const stmt of sf.statements) {
|
|
5593
|
+
for (const stmt of sf.statements.nodes) {
|
|
4375
5594
|
if (ts.isExportDeclaration(stmt) && isPrunedNpmReexport(program, stmt))
|
|
4376
5595
|
continue;
|
|
4377
|
-
if (ts.isExportDeclaration(stmt) &&
|
|
4378
|
-
(stmt.isTypeOnly || erasedTypeOnlyReexport(stmt) || !stmt.moduleSpecifier))
|
|
5596
|
+
if (ts.isExportDeclaration(stmt) && (stmt.isTypeOnly || !stmt.moduleSpecifier))
|
|
4379
5597
|
continue;
|
|
4380
5598
|
if (!ts.isImportDeclaration(stmt) && !ts.isExportDeclaration(stmt))
|
|
4381
5599
|
continue;
|
|
@@ -4394,6 +5612,58 @@ export function orderedImportsOf(program, sf) {
|
|
|
4394
5612
|
}
|
|
4395
5613
|
return out;
|
|
4396
5614
|
}
|
|
5615
|
+
/** The files a compiled program can load: the module order closed over
|
|
5616
|
+
* every literal require() and import() call it contains (deferred and
|
|
5617
|
+
* nested ones included) and, for opted-in package JavaScript, over every
|
|
5618
|
+
* import and export declaration as well. A package file outside this set
|
|
5619
|
+
* is reachable only through types, so whatever it spells cannot affect
|
|
5620
|
+
* the compiled program. Null when a reachable file loads a computed
|
|
5621
|
+
* specifier: then any file may load. */
|
|
5622
|
+
export function npmStaticLoadableFiles(program, moduleOrder) {
|
|
5623
|
+
const seen = new Set();
|
|
5624
|
+
const work = [];
|
|
5625
|
+
const add = (sf) => {
|
|
5626
|
+
if (sf === null || sf === undefined || seen.has(sf) || sf.isDeclarationFile)
|
|
5627
|
+
return;
|
|
5628
|
+
seen.add(sf);
|
|
5629
|
+
work.push(sf);
|
|
5630
|
+
};
|
|
5631
|
+
for (const sf of moduleOrder)
|
|
5632
|
+
add(sf);
|
|
5633
|
+
let computed = false;
|
|
5634
|
+
while (work.length > 0 && !computed) {
|
|
5635
|
+
const sf = work.pop();
|
|
5636
|
+
const packageJs = npmStaticPackageOfPath(sf.fileName) !== null && isJsSourceFileName(sf.fileName);
|
|
5637
|
+
const follow = (spec, kind) => {
|
|
5638
|
+
if (canonicalBuiltinModule(spec) !== null)
|
|
5639
|
+
return;
|
|
5640
|
+
add(resolveImport7(program, sf, spec, kind) ?? npmStaticDepSf7(program, sf, spec, kind));
|
|
5641
|
+
};
|
|
5642
|
+
ts.walkPreorder(sf, (n) => {
|
|
5643
|
+
if (computed)
|
|
5644
|
+
return "stop";
|
|
5645
|
+
if (ts.isCallExpression(n)) {
|
|
5646
|
+
const isImport = n.expression.kind === ts.SyntaxKind.ImportKeyword;
|
|
5647
|
+
const isRequire = ts.isIdentifier(n.expression) && n.expression.text === "require";
|
|
5648
|
+
if (!isImport && !isRequire)
|
|
5649
|
+
return undefined;
|
|
5650
|
+
const arg = n.arguments.nodes[0];
|
|
5651
|
+
if (arg !== undefined && ts.isStringLiteralLike(arg))
|
|
5652
|
+
follow(arg.text, isImport ? "import" : "require");
|
|
5653
|
+
else if (packageJs || isImport)
|
|
5654
|
+
computed = true;
|
|
5655
|
+
}
|
|
5656
|
+
else if (packageJs &&
|
|
5657
|
+
(ts.isImportDeclaration(n) || ts.isExportDeclaration(n)) &&
|
|
5658
|
+
n.moduleSpecifier !== undefined &&
|
|
5659
|
+
ts.isStringLiteral(n.moduleSpecifier)) {
|
|
5660
|
+
follow(n.moduleSpecifier.text, "import");
|
|
5661
|
+
}
|
|
5662
|
+
return undefined;
|
|
5663
|
+
});
|
|
5664
|
+
}
|
|
5665
|
+
return computed ? null : new Set([...seen].map((sf) => sf.fileName.split("\\").join("/")));
|
|
5666
|
+
}
|
|
4397
5667
|
/** The program source file a bare specifier reaches when it names an
|
|
4398
5668
|
* opted-in --npm-static package (the shipped-JS entry preflight admitted
|
|
4399
5669
|
* as a module edge), else null. No offender reporting here — preflight
|
|
@@ -4435,6 +5705,19 @@ export function cjsExportAssignmentOf(stmt) {
|
|
|
4435
5705
|
if (isModuleExportsAccess(e.left)) {
|
|
4436
5706
|
return { kind: "table", obj: ts.isObjectLiteralExpression(e.right) ? e.right : null, expr: e };
|
|
4437
5707
|
}
|
|
5708
|
+
if (ts.isIdentifier(e.left) && e.left.text === "exports") {
|
|
5709
|
+
let inner = e.right;
|
|
5710
|
+
while (ts.isParenthesizedExpression(inner))
|
|
5711
|
+
inner = inner.expression;
|
|
5712
|
+
if (ts.isBinaryExpression(inner) &&
|
|
5713
|
+
inner.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
5714
|
+
isModuleExportsAccess(inner.left) &&
|
|
5715
|
+
// `exports = module.exports = {}` is the fresh-table reset, which the
|
|
5716
|
+
// export walk handles on its own.
|
|
5717
|
+
!ts.isObjectLiteralExpression(inner.right)) {
|
|
5718
|
+
return { kind: "table", obj: null, expr: inner, rebindsExports: true };
|
|
5719
|
+
}
|
|
5720
|
+
}
|
|
4438
5721
|
if (ts.isPropertyAccessExpression(e.left) && !e.left.questionDotToken) {
|
|
4439
5722
|
const recv = e.left.expression;
|
|
4440
5723
|
const isExports = ts.isIdentifier(recv) && recv.text === "exports";
|
|
@@ -4444,6 +5727,85 @@ export function cjsExportAssignmentOf(stmt) {
|
|
|
4444
5727
|
}
|
|
4445
5728
|
return null;
|
|
4446
5729
|
}
|
|
5730
|
+
/** The tsc VOID-INIT PREAMBLE (`exports.a = exports.b = void 0;` with the
|
|
5731
|
+
* real `exports.a = a;` further down; every tsc-emitted dist file opens its
|
|
5732
|
+
* exports this way): when every name in the chain has a later real
|
|
5733
|
+
* assignment, the export takes its value there and the preamble lowers to
|
|
5734
|
+
* nothing. Returns those later assignments by name, or null when this is
|
|
5735
|
+
* not such a preamble (a preamble with no later real assignment keeps the
|
|
5736
|
+
* ordinary path: the export IS undefined then). */
|
|
5737
|
+
export function cjsVoidInitPreambleReals(cjs) {
|
|
5738
|
+
if (!ts.isIdentifier(cjs.name))
|
|
5739
|
+
return null;
|
|
5740
|
+
const isExportsMember = (e) => ts.isPropertyAccessExpression(e) &&
|
|
5741
|
+
ts.isIdentifier(e.name) &&
|
|
5742
|
+
((ts.isIdentifier(e.expression) && e.expression.text === "exports") ||
|
|
5743
|
+
(ts.isPropertyAccessExpression(e.expression) &&
|
|
5744
|
+
ts.isIdentifier(e.expression.expression) &&
|
|
5745
|
+
e.expression.expression.text === "module" &&
|
|
5746
|
+
ts.isIdentifier(e.expression.name) &&
|
|
5747
|
+
e.expression.name.text === "exports"));
|
|
5748
|
+
const isVoid = (e) => {
|
|
5749
|
+
while (ts.isParenthesizedExpression(e))
|
|
5750
|
+
e = e.expression;
|
|
5751
|
+
return (e.kind === ts.SyntaxKind.VoidExpression || (ts.isIdentifier(e) && e.text === "undefined"));
|
|
5752
|
+
};
|
|
5753
|
+
// chains: `exports.a = exports.b = void 0;` collects every name
|
|
5754
|
+
const names = [cjs.name.text];
|
|
5755
|
+
let tail = cjs.value;
|
|
5756
|
+
while (ts.isBinaryExpression(tail) &&
|
|
5757
|
+
tail.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
5758
|
+
isExportsMember(tail.left)) {
|
|
5759
|
+
names.push(tail.left.name.text);
|
|
5760
|
+
tail = tail.right;
|
|
5761
|
+
}
|
|
5762
|
+
if (!isVoid(tail))
|
|
5763
|
+
return null;
|
|
5764
|
+
const sf = ts.getSourceFileOfNode(cjs.expr);
|
|
5765
|
+
const myPos = ts.tokenStartOfNode(cjs.expr);
|
|
5766
|
+
const reals = new Map();
|
|
5767
|
+
for (const name of names) {
|
|
5768
|
+
const real = sf.statements.nodes
|
|
5769
|
+
.map((s) => cjsExportAssignmentOf(s))
|
|
5770
|
+
.find((other) => other?.kind === "member" &&
|
|
5771
|
+
ts.isIdentifier(other.name) &&
|
|
5772
|
+
other.name.text === name &&
|
|
5773
|
+
ts.tokenStartOfNode(other.expr) > myPos &&
|
|
5774
|
+
!isVoid(other.value));
|
|
5775
|
+
if (real?.kind !== "member")
|
|
5776
|
+
return null;
|
|
5777
|
+
reals.set(name, real);
|
|
5778
|
+
}
|
|
5779
|
+
return reals;
|
|
5780
|
+
}
|
|
5781
|
+
/** The members and shared value of a CHAINED member export
|
|
5782
|
+
* `exports.a = exports.b = module.exports.c = value` (outermost name
|
|
5783
|
+
* first), or null when the assignment is not a chain of at least two
|
|
5784
|
+
* identifier-named export members or its value is undefined. */
|
|
5785
|
+
export function cjsExportChainOf(e) {
|
|
5786
|
+
const names = [];
|
|
5787
|
+
let cur = e;
|
|
5788
|
+
for (;;) {
|
|
5789
|
+
while (ts.isParenthesizedExpression(cur))
|
|
5790
|
+
cur = cur.expression;
|
|
5791
|
+
if (!ts.isBinaryExpression(cur) || cur.operatorToken.kind !== ts.SyntaxKind.EqualsToken)
|
|
5792
|
+
break;
|
|
5793
|
+
const left = cur.left;
|
|
5794
|
+
if (!ts.isPropertyAccessExpression(left) ||
|
|
5795
|
+
left.questionDotToken ||
|
|
5796
|
+
!ts.isIdentifier(left.name))
|
|
5797
|
+
break;
|
|
5798
|
+
const recv = left.expression;
|
|
5799
|
+
if (!((ts.isIdentifier(recv) && recv.text === "exports") || isModuleExportsAccess(recv)))
|
|
5800
|
+
break;
|
|
5801
|
+
names.push(left.name);
|
|
5802
|
+
cur = cur.right;
|
|
5803
|
+
}
|
|
5804
|
+
// tsc's `exports.a = exports.b = void 0;` preamble is not a value chain
|
|
5805
|
+
// (the export-statement lowering owns it).
|
|
5806
|
+
const isVoid = cur.kind === ts.SyntaxKind.VoidExpression || (ts.isIdentifier(cur) && cur.text === "undefined");
|
|
5807
|
+
return names.length >= 2 && !isVoid ? { names, value: cur } : null;
|
|
5808
|
+
}
|
|
4447
5809
|
/** Why Node would DISCARD this CommonJS export statement, or null when it
|
|
4448
5810
|
* survives (Node's export-object identity rules — checker-free, pure
|
|
4449
5811
|
* AST): `module.exports = {...}` REPLACES the export object, so members
|
|
@@ -4459,7 +5821,7 @@ export function cjsExportDiscardReason(stmt) {
|
|
|
4459
5821
|
const mine = cjsExportAssignmentOf(stmt);
|
|
4460
5822
|
if (!mine)
|
|
4461
5823
|
return null;
|
|
4462
|
-
const stmts = sf.statements;
|
|
5824
|
+
const stmts = sf.statements.nodes;
|
|
4463
5825
|
let lastTable = -1;
|
|
4464
5826
|
for (let i = 0; i < stmts.length; i++) {
|
|
4465
5827
|
if (cjsExportAssignmentOf(stmts[i])?.kind === "table")
|
|
@@ -4477,6 +5839,9 @@ export function cjsExportDiscardReason(stmt) {
|
|
|
4477
5839
|
return "export members attached before a 'module.exports =' assignment (Node replaces the export object — importers never see this member; attach it to module.exports AFTER the table)";
|
|
4478
5840
|
}
|
|
4479
5841
|
const left = mine.expr.left;
|
|
5842
|
+
const last = cjsExportAssignmentOf(stmts[lastTable]);
|
|
5843
|
+
if (last?.kind === "table" && last.rebindsExports === true)
|
|
5844
|
+
return null;
|
|
4480
5845
|
return ts.isIdentifier(left.expression) && left.expression.text === "exports"
|
|
4481
5846
|
? "'exports.f =' after a 'module.exports =' assignment ('exports' still references the replaced object — Node discards this member; write module.exports.f instead)"
|
|
4482
5847
|
: null;
|
|
@@ -4496,16 +5861,16 @@ export function cjsExportTargetLiteral(e, sf) {
|
|
|
4496
5861
|
if (ts.isNewExpression(e) &&
|
|
4497
5862
|
ts.isIdentifier(e.expression) &&
|
|
4498
5863
|
e.expression.text === "Proxy" &&
|
|
4499
|
-
(e.arguments?.length ?? 0) >= 1) {
|
|
4500
|
-
return cjsExportTargetLiteral(e.arguments[0], sf);
|
|
5864
|
+
(e.arguments?.nodes.length ?? 0) >= 1) {
|
|
5865
|
+
return cjsExportTargetLiteral(e.arguments.nodes[0], sf);
|
|
4501
5866
|
}
|
|
4502
5867
|
if (ts.isIdentifier(e)) {
|
|
4503
|
-
for (const stmt of sf.statements) {
|
|
5868
|
+
for (const stmt of sf.statements.nodes) {
|
|
4504
5869
|
if (!ts.isVariableStatement(stmt))
|
|
4505
5870
|
continue;
|
|
4506
5871
|
if ((stmt.declarationList.flags & ts.NodeFlags.Const) === 0)
|
|
4507
5872
|
continue;
|
|
4508
|
-
for (const d of stmt.declarationList.declarations) {
|
|
5873
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
4509
5874
|
if (d.name !== undefined &&
|
|
4510
5875
|
ts.isIdentifier(d.name) &&
|
|
4511
5876
|
d.name.text === e.text &&
|
|
@@ -4527,7 +5892,7 @@ export function cjsExportTargetLiteral(e, sf) {
|
|
|
4527
5892
|
* order against it). Null when the kept export is anything else. */
|
|
4528
5893
|
export function cjsClassExprWholeExportOf(sf) {
|
|
4529
5894
|
let last = null;
|
|
4530
|
-
for (const stmt of sf.statements) {
|
|
5895
|
+
for (const stmt of sf.statements.nodes) {
|
|
4531
5896
|
const cjs = cjsExportAssignmentOf(stmt);
|
|
4532
5897
|
if (!cjs || cjs.kind !== "table")
|
|
4533
5898
|
continue;
|
|
@@ -4558,10 +5923,10 @@ export function isCjsExportTableLiteral(obj) {
|
|
|
4558
5923
|
const decl = obj.parent;
|
|
4559
5924
|
if (!ts.isVariableDeclaration(decl) || decl.initializer !== obj)
|
|
4560
5925
|
return false;
|
|
4561
|
-
const sf =
|
|
5926
|
+
const sf = ts.getSourceFileOfNode(obj);
|
|
4562
5927
|
if (!isJsSourceFile(sf))
|
|
4563
5928
|
return false;
|
|
4564
|
-
for (const stmt of sf.statements) {
|
|
5929
|
+
for (const stmt of sf.statements.nodes) {
|
|
4565
5930
|
const cjs = cjsExportAssignmentOf(stmt);
|
|
4566
5931
|
if (cjs?.kind === "table" && cjsExportDiscardReason(stmt) === null) {
|
|
4567
5932
|
return cjsExportTargetLiteral(cjs.expr.right, sf) === obj;
|
|
@@ -4668,7 +6033,7 @@ function receiverRoot(text, pos) {
|
|
|
4668
6033
|
/** Whether `name` is bound in `fileName` by an import of a Node builtin. */
|
|
4669
6034
|
function importsNodeBuiltin(load, fileName, name) {
|
|
4670
6035
|
const sf = load.program.getSourceFile(fileName);
|
|
4671
|
-
for (const stmt of sf?.statements ?? []) {
|
|
6036
|
+
for (const stmt of sf?.statements?.nodes ?? []) {
|
|
4672
6037
|
if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
4673
6038
|
continue;
|
|
4674
6039
|
if (canonicalBuiltinModule(stmt.moduleSpecifier.text) === null)
|
|
@@ -4681,7 +6046,7 @@ function importsNodeBuiltin(load, fileName, name) {
|
|
|
4681
6046
|
return true;
|
|
4682
6047
|
if (bindings &&
|
|
4683
6048
|
ts.isNamedImports(bindings) &&
|
|
4684
|
-
bindings.elements.some((e) => e.name.text === name))
|
|
6049
|
+
bindings.elements.nodes.some((e) => e.name.text === name))
|
|
4685
6050
|
return true;
|
|
4686
6051
|
}
|
|
4687
6052
|
return false;
|