@scriptc/compiler 0.3.5 → 0.4.0
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 +960 -82
- 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 +13 -0
- package/dist/backend/executable-features.js.map +1 -1
- package/dist/backend/immutability.test.js +1 -1
- package/dist/backend/library-pack.js +6 -0
- package/dist/backend/library-pack.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.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 +11 -0
- package/dist/backend/llvm/classes.js +71 -14
- package/dist/backend/llvm/classes.js.map +1 -1
- package/dist/backend/llvm/classes.test.js +58 -8
- package/dist/backend/llvm/classes.test.js.map +1 -1
- package/dist/backend/llvm/common.js +1 -0
- 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 +12 -3
- package/dist/backend/llvm/dense-array-access.js +72 -14
- package/dist/backend/llvm/dense-array-access.js.map +1 -1
- package/dist/backend/llvm/dense-array-access.test.js +59 -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 +28 -4
- package/dist/backend/llvm/dyn.js +324 -179
- 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 +1190 -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 +1535 -0
- package/dist/backend/llvm/emit-module.js.map +1 -0
- package/dist/backend/llvm/emit-statements.d.ts +58 -0
- package/dist/backend/llvm/emit-statements.js +1964 -0
- package/dist/backend/llvm/emit-statements.js.map +1 -0
- package/dist/backend/llvm/emitter.d.ts +576 -268
- package/dist/backend/llvm/emitter.js +801 -4447
- 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 +71 -53
- 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 +39 -15
- 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-dispatch.js +1 -0
- package/dist/backend/llvm/expr-dispatch.js.map +1 -1
- package/dist/backend/llvm/expr-dynamic.d.ts +3 -0
- package/dist/backend/llvm/expr-dynamic.js +92 -63
- package/dist/backend/llvm/expr-dynamic.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.d.ts +1 -1
- package/dist/backend/llvm/expr-primitives.js +132 -25
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.test.js +2 -2
- 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 +54 -12
- 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.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/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 +488 -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 +217 -24
- package/dist/backend/llvm/lib-dispatch.js.map +1 -1
- package/dist/backend/llvm/lib-filesystem.js +102 -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 +77 -25
- package/dist/backend/llvm/lib-network.js.map +1 -1
- package/dist/backend/llvm/lib-process.js +100 -50
- 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 +229 -5
- 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 +57 -8
- 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 +2 -2
- 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.js +2 -2
- 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 +151 -0
- package/dist/backend/llvm/narrow-guards.js.map +1 -0
- package/dist/backend/llvm/nullable-unions.d.ts +70 -9
- package/dist/backend/llvm/nullable-unions.js +105 -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 +4 -0
- package/dist/backend/llvm/publish.js +14 -2
- 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 +13 -2
- package/dist/backend/llvm/record-results.js +66 -6
- 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 +143 -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 +9 -6
- package/dist/backend/llvm/regions.js.map +1 -1
- package/dist/backend/llvm/regions.test.js +1 -1
- package/dist/backend/llvm/shapes.d.ts +69 -43
- package/dist/backend/llvm/shapes.js +285 -21
- 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 +74 -0
- package/dist/backend/llvm/speculative-integers.js +571 -0
- package/dist/backend/llvm/speculative-integers.js.map +1 -0
- package/dist/backend/llvm/speculative-integers.test.d.ts +1 -0
- package/dist/backend/llvm/speculative-integers.test.js +148 -0
- package/dist/backend/llvm/speculative-integers.test.js.map +1 -0
- 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-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 +110 -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 +7 -0
- package/dist/backend/mangle.js +11 -0
- package/dist/backend/mangle.js.map +1 -1
- package/dist/backend/may-throw.d.ts +3 -0
- package/dist/backend/may-throw.js +6 -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 +37 -0
- package/dist/backend/native/executable.js +192 -134
- package/dist/backend/native/executable.js.map +1 -1
- package/dist/backend/native/library.js +1 -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 +2 -0
- package/dist/backend/native/runtime-inputs.js.map +1 -1
- package/dist/backend/native-link-info-core.d.ts +30 -0
- package/dist/backend/native-link-info-core.js.map +1 -1
- package/dist/backend/publication.test.js +1 -1
- package/dist/backend/runtime-pack-core.d.ts +9 -1
- package/dist/backend/runtime-pack-core.js +10 -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 +5 -0
- package/dist/backend/runtime-pack-targets.test.js.map +1 -1
- package/dist/backend/runtime-pack.d.ts +7 -3
- package/dist/backend/runtime-pack.js +12 -6
- package/dist/backend/runtime-pack.js.map +1 -1
- package/dist/backend/runtime-pack.test.js +20 -6
- 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 +8 -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 +5 -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 +44 -4
- package/dist/cli/command.js.map +1 -1
- package/dist/cli/usage.d.ts +11 -1
- package/dist/cli/usage.js +20 -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 +13 -0
- package/dist/contracts/check.js +25 -6
- 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 +19 -6
- 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 +11 -7
- package/dist/diagnostics/diagnostic.js +35 -23
- 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 +17 -0
- package/dist/executable/executable-cache.js +13 -1
- package/dist/executable/executable-cache.js.map +1 -1
- package/dist/executable/executable-cache.test.js +7 -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/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/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/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 +72 -4
- 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 +23 -0
- package/dist/frontend/lowering/builtins/builtin-class-dyn.js +156 -0
- package/dist/frontend/lowering/builtins/builtin-class-dyn.js.map +1 -0
- package/dist/frontend/lowering/builtins/callable-aliases.js +45 -6
- 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 +18 -0
- package/dist/frontend/lowering/builtins/compression.js +230 -52
- 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 +19 -0
- package/dist/frontend/lowering/builtins/crypto.js +223 -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/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 +174 -6
- package/dist/frontend/lowering/builtins/errors.js.map +1 -1
- package/dist/frontend/lowering/builtins/filesystem-calls.d.ts +4 -0
- package/dist/frontend/lowering/builtins/filesystem-calls.js +136 -113
- package/dist/frontend/lowering/builtins/filesystem-calls.js.map +1 -1
- package/dist/frontend/lowering/builtins/filesystem.d.ts +8 -0
- package/dist/frontend/lowering/builtins/filesystem.js +213 -76
- 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/hash-stream.d.ts +12 -0
- package/dist/frontend/lowering/builtins/hash-stream.js +80 -0
- package/dist/frontend/lowering/builtins/hash-stream.js.map +1 -0
- 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 +232 -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 +67 -46
- 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 +32 -1
- package/dist/frontend/lowering/builtins/process.js +468 -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 +37 -0
- package/dist/frontend/lowering/builtins/promisify-callback.js +320 -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 +55 -13
- package/dist/frontend/lowering/builtins/readline.js +931 -69
- 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 +16 -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 +75 -30
- package/dist/frontend/lowering/builtins/timers.js.map +1 -1
- 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 +16 -0
- package/dist/frontend/lowering/builtins/workers.js +246 -3
- 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 +19 -1
- package/dist/frontend/lowering/call-signatures.js +254 -47
- 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 +528 -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 +1115 -89
- 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 +55 -0
- package/dist/frontend/lowering/class-protocols.js +738 -22
- 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 +80 -18
- 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 +261 -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/function-adapters.d.ts +16 -2
- package/dist/frontend/lowering/coercions/function-adapters.js +145 -3
- 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 +9 -0
- package/dist/frontend/lowering/containers/array-callbacks.js +266 -100
- 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 +51 -13
- package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
- package/dist/frontend/lowering/containers/array-from-async.d.ts +19 -0
- package/dist/frontend/lowering/containers/array-from-async.js +427 -0
- package/dist/frontend/lowering/containers/array-from-async.js.map +1 -0
- package/dist/frontend/lowering/containers/array-methods.js +89 -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.js +161 -101
- 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 +219 -27
- package/dist/frontend/lowering/containers/collection-grouping.js.map +1 -1
- package/dist/frontend/lowering/containers/collection-methods.js +81 -48
- 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 +419 -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 +4 -0
- package/dist/frontend/lowering/cycle-initialization.js +39 -0
- 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 +238 -128
- 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 +703 -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 +2483 -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 +1797 -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 +40 -0
- package/dist/frontend/lowering/expressions/keyed-field-targets.js +226 -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 +1322 -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 +253 -85
- package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
- package/dist/frontend/lowering/expressions/optional-chains.d.ts +2 -1
- package/dist/frontend/lowering/expressions/optional-chains.js +91 -14
- package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
- package/dist/frontend/lowering/expressions/property-access.d.ts +110 -0
- package/dist/frontend/lowering/expressions/property-access.js +3544 -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 +1679 -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 +538 -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-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 +39 -0
- package/dist/frontend/lowering/generic-functions.js +393 -75
- package/dist/frontend/lowering/generic-functions.js.map +1 -1
- 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/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-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 +32 -3
- package/dist/frontend/lowering/lower-builtin-values.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +1298 -452
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.d.ts +50 -3
- package/dist/frontend/lowering/lower-classes.js +1499 -456
- 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 +179 -8
- 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 +268 -71
- 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 +1493 -12407
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-functions.js +68 -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 +29 -16
- 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 +354 -99
- 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 +19 -2
- package/dist/frontend/lowering/lower-mock.js +557 -74
- package/dist/frontend/lowering/lower-mock.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.js +268 -61
- 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 +45 -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 +638 -105
- 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 +151 -109
- package/dist/frontend/lowering/lower-stdlib.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.d.ts +28 -2
- package/dist/frontend/lowering/lower-stmts.js +1589 -398
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lower-stream.d.ts +4 -3
- package/dist/frontend/lowering/lower-stream.js +714 -75
- 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 +574 -100
- package/dist/frontend/lowering/lower-test.js.map +1 -1
- package/dist/frontend/lowering/lower-timers.js +80 -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 +409 -26
- package/dist/frontend/lowering/lowerer.js +1918 -305
- 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/null-prototype.d.ts +13 -0
- package/dist/frontend/lowering/null-prototype.js +33 -0
- package/dist/frontend/lowering/null-prototype.js.map +1 -0
- 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/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/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 +10 -10
- 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 +15 -6
- package/dist/frontend/lowering/surfaces.js +278 -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/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.d.ts +5 -0
- package/dist/frontend/mock-shapes.js +39 -7
- 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-bundled-chunks.d.ts +51 -0
- package/dist/frontend/npm-static-bundled-chunks.js +810 -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 +287 -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 +768 -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 +207 -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-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 +17 -1
- package/dist/frontend/npm-static.js +167 -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/pipeline.js +164 -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 +92 -2
- package/dist/frontend/program.js +1557 -254
- 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 +36 -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 +20 -1
- package/dist/frontend/services.js +40 -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 +5 -1
- package/dist/frontend/ts7/program-host.js +12 -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 +54 -24
- package/dist/frontend/ts7/semantic-model.js +88 -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 +11 -11
- 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 +2612 -695
- 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 +3 -1
- package/dist/index.js +47 -10
- 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 +30 -0
- package/dist/ir/array-length-stability.js +236 -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 +113 -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 +139 -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 +655 -25
- 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 +10 -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 +119 -14
- package/dist/ir/int32-slots.js.map +1 -1
- package/dist/ir/int32-slots.test.js +29 -1
- package/dist/ir/int32-slots.test.js.map +1 -1
- package/dist/ir/integer-loop-facts.d.ts +16 -6
- package/dist/ir/integer-loop-facts.js +143 -38
- 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 +3 -0
- package/dist/ir/integer-ranges.js +4 -6
- package/dist/ir/integer-ranges.js.map +1 -1
- package/dist/ir/integer-ranges.test.js +142 -1
- 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 +234 -58
- package/dist/ir/ir.js +123 -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/jsval.d.ts +8 -0
- package/dist/ir/jsval.js +365 -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 +150 -33
- package/dist/ir/runtime-features.js +672 -339
- package/dist/ir/runtime-features.js.map +1 -1
- package/dist/ir/runtime-features.test.js +62 -0
- package/dist/ir/runtime-features.test.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 +107 -94
- 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 +220 -71
- package/dist/ir/validate.js.map +1 -1
- package/dist/ir/validate.test.js +64 -9
- 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 +18 -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 +5 -0
- package/dist/native/cli.js.map +1 -1
- package/dist/native/compiler.js +2 -2
- package/dist/native/compiler.js.map +1 -1
- package/dist/native/compiler.test.js +2 -2
- package/dist/native/prepare.js +7 -0
- package/dist/native/prepare.js.map +1 -1
- package/dist/native/sanitizer.test.js +12 -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 +21 -20
- package/surface-manifest.json +332 -36
package/dist/frontend/program.js
CHANGED
|
@@ -44,19 +44,20 @@ 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, 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
51
|
import { provenanceEntryFor, provenancePaths } from "./provenance-registry.js";
|
|
52
52
|
import { cjsLexedExportsOfFile, cjsVisibleNames } from "./cjs-syntax.js";
|
|
53
53
|
import { ambientDtsPath, fallbackDtsPath, isNodeTypesPath, overridesDtsPath, tsgoPath, } from "./dts-paths.js";
|
|
54
|
-
import { builtinDefaultImportModule, canonicalBuiltinModule, SUPPORTED_NODE_MODULES, unsupportedModuleFeatureOf, } from "./builtin-modules.js";
|
|
54
|
+
import { builtinDefaultImportModule, canonicalBuiltinModule, npmBuiltinAliasOf, SUPPORTED_NODE_MODULES, unsupportedModuleFeatureOf, TEMPORAL_GLOBAL, } from "./builtin-modules.js";
|
|
55
55
|
import { clearWorkspacePackages, isRelativeSpecifier, isWorkspacePackageName, npmPackageNameOf, registerWorkspacePackage, workspacePackageOfPath, } from "./workspace-registry.js";
|
|
56
56
|
import { ADOPTED_OPTIONS, isJsSourceFileName, JS_ANY_OPERATOR_CODES, JS_RELAXED_TSC_CODES, } from "./tsc-codes.js";
|
|
57
57
|
import { trackedFileExists, trackedReadFile, trackedRealpath } from "./input-tracker.js";
|
|
58
58
|
import { forkTargetPaths } from "./fork-target.js";
|
|
59
59
|
import { workerTargetPaths } from "./worker-target.js";
|
|
60
|
+
import { erasedTypeOnlyImport, typeOnlyNamedImport, typeOnlyReachedFiles, } from "./type-only-imports.js";
|
|
60
61
|
import { moduleSourceCandidates } from "./module-source-candidates.js";
|
|
61
62
|
import { inferredJsDiagnosticSuppressed } from "./inferred-js-diagnostics.js";
|
|
62
63
|
const BASE_OPTIONS = {
|
|
@@ -74,10 +75,16 @@ const FORCED_OPTIONS = {
|
|
|
74
75
|
// classification is intentionally independent below; this option is only
|
|
75
76
|
// the binder's scope decision.
|
|
76
77
|
moduleDetection: ts.ModuleDetectionKind.Force,
|
|
77
|
-
// Explicit resource management
|
|
78
|
-
// though Node 24 ships
|
|
79
|
-
// without widening the rest of the standard-library
|
|
80
|
-
|
|
78
|
+
// Explicit resource management, Array.fromAsync and Error.isError are
|
|
79
|
+
// ESNext library slices in TS 7 even though Node 24 ships them. Include
|
|
80
|
+
// those focused libs without widening the rest of the standard-library
|
|
81
|
+
// target past ES2025.
|
|
82
|
+
lib: [
|
|
83
|
+
"lib.es2025.d.ts",
|
|
84
|
+
"lib.esnext.disposable.d.ts",
|
|
85
|
+
"lib.esnext.array.d.ts",
|
|
86
|
+
"lib.esnext.error.d.ts",
|
|
87
|
+
],
|
|
81
88
|
types: [],
|
|
82
89
|
allowImportingTsExtensions: true,
|
|
83
90
|
allowJs: true,
|
|
@@ -220,6 +227,7 @@ function adoptProjectConfig7(host, entryPath) {
|
|
|
220
227
|
diags,
|
|
221
228
|
...(projectLib === undefined ? {} : { projectLib }),
|
|
222
229
|
forcedStrictNullChecks,
|
|
230
|
+
checkJs: parsed.options["checkJs"] === true,
|
|
223
231
|
};
|
|
224
232
|
}
|
|
225
233
|
/** The target project's @types/node, resolved with the OWN resolver's
|
|
@@ -408,12 +416,12 @@ function createRequireProgramRoots7(program) {
|
|
|
408
416
|
const calls = [];
|
|
409
417
|
for (const node of moduleSourceCandidates(program, sf).calls) {
|
|
410
418
|
if (node.questionDotToken !== undefined ||
|
|
411
|
-
node.arguments.length !== 1 ||
|
|
412
|
-
!ts.isStringLiteralLike(node.arguments[0]) ||
|
|
419
|
+
node.arguments.nodes.length !== 1 ||
|
|
420
|
+
!ts.isStringLiteralLike(node.arguments.nodes[0]) ||
|
|
413
421
|
!ts.isIdentifier(node.expression)) {
|
|
414
422
|
continue;
|
|
415
423
|
}
|
|
416
|
-
calls.push({ callee: node.expression, spec: node.arguments[0].text });
|
|
424
|
+
calls.push({ callee: node.expression, spec: node.arguments.nodes[0].text });
|
|
417
425
|
}
|
|
418
426
|
// Root discovery only needs the callee's binding. A first-miss lookup
|
|
419
427
|
// otherwise fetches symbols and types for every identifier in the file,
|
|
@@ -461,9 +469,10 @@ export function entryPackageFilePredicate(entryPath) {
|
|
|
461
469
|
};
|
|
462
470
|
}
|
|
463
471
|
/** maxNodeModuleJsDepth can omit relative imports within an admitted
|
|
464
|
-
* package
|
|
465
|
-
*
|
|
466
|
-
|
|
472
|
+
* package, and opted-in packages deep in the dependency graph. Discover
|
|
473
|
+
* their runtime sources to a fixpoint so the checker and module resolver
|
|
474
|
+
* see the same graph regardless of import traversal order or depth. */
|
|
475
|
+
function entryPackageProgramRoots7(program, entryPath, rootNpmStaticEdges) {
|
|
467
476
|
const belongsToEntry = entryPackageFilePredicate(entryPath);
|
|
468
477
|
const roots = new Set();
|
|
469
478
|
for (const sf of program.getImplementationSourceFiles()) {
|
|
@@ -479,11 +488,80 @@ function entryPackageProgramRoots7(program, entryPath) {
|
|
|
479
488
|
isJsSourceFileName(target) &&
|
|
480
489
|
program.getSourceFile(target) === undefined)
|
|
481
490
|
roots.add(target);
|
|
491
|
+
// An opted-in package's bare edge counts against the same depth
|
|
492
|
+
// budget: tsgo charges every node_modules JS hop, so express's
|
|
493
|
+
// body-parser → qs → side-channel → get-intrinsic chain runs out of
|
|
494
|
+
// depth before its leaves load. Root the runtime file this edge
|
|
495
|
+
// lowers to (preflight's own resolution and miss rule) so the leaf
|
|
496
|
+
// joins like a shallow one; complete programs add nothing. Only
|
|
497
|
+
// the shadowed lowering world does this (the authored world checks
|
|
498
|
+
// user code against declarations), and only from package files: a
|
|
499
|
+
// program file's own edges are never deeper than one hop.
|
|
500
|
+
// (resolveBareModule directly: resolveNpmImport7's workspace
|
|
501
|
+
// registration stays with preflight's own walk.)
|
|
502
|
+
if (target === null &&
|
|
503
|
+
rootNpmStaticEdges &&
|
|
504
|
+
npmStaticPackageOfPath(sf.fileName) !== null &&
|
|
505
|
+
!isRelativeSpecifier(specifier.text)) {
|
|
506
|
+
const spec = specifier.text;
|
|
507
|
+
if (spec.startsWith("#") || canonicalBuiltinModule(spec) !== null)
|
|
508
|
+
continue;
|
|
509
|
+
const npm = resolveBareModule(sf.fileName, spec, undefined, moduleSpecifierKind7(specifier));
|
|
510
|
+
if (npm !== null &&
|
|
511
|
+
isNpmStaticPackage(npm.packageName) &&
|
|
512
|
+
(isNodeModulesPath(npm.typesFile) || npm.workspaceDir !== undefined) &&
|
|
513
|
+
isJsSourceFileName(npm.typesFile) &&
|
|
514
|
+
npmStaticProgramFile(program, npm.typesFile) === null)
|
|
515
|
+
roots.add(tsgoPath(resolve(npm.typesFile)));
|
|
516
|
+
}
|
|
482
517
|
}
|
|
483
518
|
}
|
|
484
519
|
return [...roots].sort();
|
|
485
520
|
}
|
|
486
|
-
|
|
521
|
+
/** TS 7's ESNext temporal declarations: a lib slice scriptc adds only for
|
|
522
|
+
* programs whose sources name the global (programNamesTemporal7). */
|
|
523
|
+
const TEMPORAL_LIB = "lib.esnext.temporal.d.ts";
|
|
524
|
+
/** True when a program source (user code or compiled npm JavaScript)
|
|
525
|
+
* contains the temporal global's name as a whole word. A cheap syntactic
|
|
526
|
+
* scan of the implementation files root discovery already materialized; a
|
|
527
|
+
* mention in a comment or string also counts, which only adds the lib
|
|
528
|
+
* slice. */
|
|
529
|
+
function programNamesTemporal7(program) {
|
|
530
|
+
for (const sf of program.getImplementationSourceFiles()) {
|
|
531
|
+
const text = sf.text;
|
|
532
|
+
for (let at = text.indexOf(TEMPORAL_GLOBAL); at >= 0; at = text.indexOf(TEMPORAL_GLOBAL, at + 8)) {
|
|
533
|
+
if (!isIdentifierCharAt(text, at - 1) && !isIdentifierCharAt(text, at + 8))
|
|
534
|
+
return true;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
function isIdentifierCharAt(text, index) {
|
|
540
|
+
if (index < 0 || index >= text.length)
|
|
541
|
+
return false;
|
|
542
|
+
const c = text.charCodeAt(index);
|
|
543
|
+
return ((c >= 48 && c <= 57) ||
|
|
544
|
+
(c >= 65 && c <= 90) ||
|
|
545
|
+
(c >= 97 && c <= 122) ||
|
|
546
|
+
c === 36 ||
|
|
547
|
+
c === 95 ||
|
|
548
|
+
c > 127);
|
|
549
|
+
}
|
|
550
|
+
/** "require" for a CommonJS edge (`require("x")`, `import x = require("x")`),
|
|
551
|
+
* "import" for every ESM form — the resolution kind preflight uses. */
|
|
552
|
+
function moduleSpecifierKind7(specifier) {
|
|
553
|
+
const parent = specifier.parent;
|
|
554
|
+
if (ts.isExternalModuleReference(parent))
|
|
555
|
+
return "require";
|
|
556
|
+
return ts.isCallExpression(parent) &&
|
|
557
|
+
ts.isIdentifier(parent.expression) &&
|
|
558
|
+
parent.expression.text === "require"
|
|
559
|
+
? "require"
|
|
560
|
+
: "import";
|
|
561
|
+
}
|
|
562
|
+
function loadProgram7(host, entryPath, externalTypes = new Map(),
|
|
563
|
+
/** The --npm-static lowering world: root opted-in packages' deep edges. */
|
|
564
|
+
rootNpmStaticEdges = false) {
|
|
487
565
|
const config = adoptProjectConfig7(host, entryPath);
|
|
488
566
|
const configuredPaths = config.options["paths"];
|
|
489
567
|
setProjectPathMappings(configuredPaths !== undefined && typeof configuredPaths === "object" && configuredPaths !== null
|
|
@@ -529,7 +607,7 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
529
607
|
try {
|
|
530
608
|
for (let pass = 0; pass < 32; pass++) {
|
|
531
609
|
const candidates = [
|
|
532
|
-
...entryPackageProgramRoots7(program, entryPath),
|
|
610
|
+
...entryPackageProgramRoots7(program, entryPath, rootNpmStaticEdges),
|
|
533
611
|
...createRequireProgramRoots7(program),
|
|
534
612
|
...forkTargetPaths(program, program.getImplementationSourceFiles()),
|
|
535
613
|
...workerTargetPaths(program, program.getImplementationSourceFiles()),
|
|
@@ -543,6 +621,20 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
543
621
|
if (pass === 31)
|
|
544
622
|
throw new Error("static program-root discovery did not converge");
|
|
545
623
|
}
|
|
624
|
+
// Node 24 ships no temporal global, but TS 7 types it in an ESNext
|
|
625
|
+
// lib slice. Programs that name it (feature probes such as smol-toml's
|
|
626
|
+
// typeof check) get that slice so they type-check, and lower to Node's
|
|
627
|
+
// answers (typeof "undefined", ReferenceError on use). Every other
|
|
628
|
+
// program keeps the identical lib set: the slice would add globals to
|
|
629
|
+
// the checker's world for everyone.
|
|
630
|
+
if (programNamesTemporal7(program)) {
|
|
631
|
+
program.dispose();
|
|
632
|
+
options = {
|
|
633
|
+
...options,
|
|
634
|
+
lib: [...(options.lib ?? []), TEMPORAL_LIB],
|
|
635
|
+
};
|
|
636
|
+
program = host.createProgram([...programRoots, overridesDtsPath()], options);
|
|
637
|
+
}
|
|
546
638
|
const entry = program.getSourceFile(entryPath);
|
|
547
639
|
if (!entry)
|
|
548
640
|
throw new Error(`could not load ${entryPath}`);
|
|
@@ -557,6 +649,7 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
557
649
|
nodeFallback: nodeTypes === null,
|
|
558
650
|
projectLib: config.projectLib ?? null,
|
|
559
651
|
forcedStrictNullChecks: config.forcedStrictNullChecks ?? false,
|
|
652
|
+
projectCheckJs: config.checkJs ?? false,
|
|
560
653
|
},
|
|
561
654
|
externalTypes,
|
|
562
655
|
externalTypeSpecifiersByFile,
|
|
@@ -711,7 +804,7 @@ export function loadProgram(entryPath, services, opts) {
|
|
|
711
804
|
};
|
|
712
805
|
const host = services.createProgramHost({ cwd: dirname(entryPath), fsShadow });
|
|
713
806
|
try {
|
|
714
|
-
const load = loadProgram7(host, entryPath, externalTypes);
|
|
807
|
+
const load = loadProgram7(host, entryPath, externalTypes, npmStaticPackages.length > 0);
|
|
715
808
|
let authoredHost = null;
|
|
716
809
|
let authoredLoad = null;
|
|
717
810
|
return {
|
|
@@ -756,9 +849,10 @@ export function loadProgram(entryPath, services, opts) {
|
|
|
756
849
|
* preflight diagnostics. Preserve the caller's complete load shape when
|
|
757
850
|
* mutating it, including its owned services and disposal callback. */
|
|
758
851
|
export function checkPreflight(load) {
|
|
759
|
-
const { diags, moduleOrder, startupCrash } = preflight7(load);
|
|
852
|
+
const { diags, moduleOrder, startupCrash, inlineRequireCycleCalls } = preflight7(load);
|
|
760
853
|
load.moduleOrder = moduleOrder;
|
|
761
854
|
load.startupCrash = startupCrash;
|
|
855
|
+
load.inlineRequireCycleCalls = inlineRequireCycleCalls;
|
|
762
856
|
return diags;
|
|
763
857
|
}
|
|
764
858
|
/* Finding 5: tsgo's strict CommonJS modeling fires checker codes on JS
|
|
@@ -778,6 +872,13 @@ export function checkPreflight(load) {
|
|
|
778
872
|
// retains only their call signature after a factory return. Heritage
|
|
779
873
|
// lowering separately verifies the actual constructor implementation.
|
|
780
874
|
const TS7_JS_RELAXED_EXTRA = new Set([2309, 2323, 2507]);
|
|
875
|
+
/** Relaxed JavaScript codes that checked JavaScript files keep: values of
|
|
876
|
+
* another type in a typed slot (2322 and its elaborations 2740/2741/2559,
|
|
877
|
+
* 2345, 2769), call arity (2554-2556) and incompatible subclass members
|
|
878
|
+
* (2415). */
|
|
879
|
+
const CHECKED_JS_ENFORCED_CODES = new Set([
|
|
880
|
+
2322, 2345, 2415, 2554, 2555, 2556, 2559, 2740, 2741, 2769,
|
|
881
|
+
]);
|
|
781
882
|
function suppressedJsStrictness7(d) {
|
|
782
883
|
const file = d.fileName;
|
|
783
884
|
if (!file || !isJsSourceFileName(file))
|
|
@@ -811,9 +912,9 @@ function requireSpecOf7(node) {
|
|
|
811
912
|
return null;
|
|
812
913
|
if (!ts.isIdentifier(value.expression) || value.expression.text !== "require")
|
|
813
914
|
return null;
|
|
814
|
-
if (value.arguments.length !== 1)
|
|
915
|
+
if (value.arguments.nodes.length !== 1)
|
|
815
916
|
return null;
|
|
816
|
-
const arg = value.arguments[0];
|
|
917
|
+
const arg = value.arguments.nodes[0];
|
|
817
918
|
return ts.isStringLiteral(arg) ? arg.text : null;
|
|
818
919
|
}
|
|
819
920
|
/** True for statements that are CommonJS require IMPORTS at a module's top
|
|
@@ -826,7 +927,7 @@ function isRequireStatement7(stmt) {
|
|
|
826
927
|
return requireSpecOf7(stmt.expression) !== null;
|
|
827
928
|
if (!ts.isVariableStatement(stmt))
|
|
828
929
|
return false;
|
|
829
|
-
const decls = stmt.declarationList.declarations;
|
|
930
|
+
const decls = stmt.declarationList.declarations.nodes;
|
|
830
931
|
return (decls.length > 0 &&
|
|
831
932
|
decls.every((d) => d.initializer !== undefined && requireSpecOf7(d.initializer) !== null));
|
|
832
933
|
}
|
|
@@ -840,7 +941,7 @@ function requiresOf7(stmt) {
|
|
|
840
941
|
if (!ts.isVariableStatement(stmt))
|
|
841
942
|
return [];
|
|
842
943
|
const out = [];
|
|
843
|
-
for (const decl of stmt.declarationList.declarations) {
|
|
944
|
+
for (const decl of stmt.declarationList.declarations.nodes) {
|
|
844
945
|
const spec = decl.initializer !== undefined ? requireSpecOf7(decl.initializer) : null;
|
|
845
946
|
if (spec !== null)
|
|
846
947
|
out.push({ spec, node: decl, decl });
|
|
@@ -860,9 +961,9 @@ export function isEsModuleStamp(expr) {
|
|
|
860
961
|
callee.name.text !== "defineProperty") {
|
|
861
962
|
return false;
|
|
862
963
|
}
|
|
863
|
-
if (expr.arguments.length !== 3)
|
|
964
|
+
if (expr.arguments.nodes.length !== 3)
|
|
864
965
|
return false;
|
|
865
|
-
const [recv, nameArg, desc] = expr.arguments;
|
|
966
|
+
const [recv, nameArg, desc] = expr.arguments.nodes;
|
|
866
967
|
const isExports = (ts.isIdentifier(recv) && recv.text === "exports") ||
|
|
867
968
|
(ts.isPropertyAccessExpression(recv) &&
|
|
868
969
|
ts.isIdentifier(recv.expression) &&
|
|
@@ -873,9 +974,9 @@ export function isEsModuleStamp(expr) {
|
|
|
873
974
|
return false;
|
|
874
975
|
if (!ts.isStringLiteral(nameArg) || nameArg.text !== "__esModule")
|
|
875
976
|
return false;
|
|
876
|
-
if (!ts.isObjectLiteralExpression(desc) || desc.properties.length !== 1)
|
|
977
|
+
if (!ts.isObjectLiteralExpression(desc) || desc.properties.nodes.length !== 1)
|
|
877
978
|
return false;
|
|
878
|
-
const p = desc.properties[0];
|
|
979
|
+
const p = desc.properties.nodes[0];
|
|
879
980
|
return (ts.isPropertyAssignment(p) &&
|
|
880
981
|
ts.isIdentifier(p.name) &&
|
|
881
982
|
p.name.text === "value" &&
|
|
@@ -889,13 +990,13 @@ function pureCjsExport7(program, stmt) {
|
|
|
889
990
|
const cjs = cjsExportAssignmentOf(stmt);
|
|
890
991
|
if (cjs === null)
|
|
891
992
|
return false;
|
|
892
|
-
const sf =
|
|
993
|
+
const sf = ts.getSourceFileOfNode(stmt);
|
|
893
994
|
const plainMember = (left) => {
|
|
894
995
|
if (!ts.isPropertyAccessExpression(left) || left.questionDotToken)
|
|
895
996
|
return false;
|
|
896
997
|
// A replacement export can have setters or non-writable function
|
|
897
998
|
// properties. Only the wrapper's original object gets this exception.
|
|
898
|
-
if (sf.statements.some((s) => cjsExportAssignmentOf(s)?.kind === "table"))
|
|
999
|
+
if (sf.statements.nodes.some((s) => cjsExportAssignmentOf(s)?.kind === "table"))
|
|
899
1000
|
return false;
|
|
900
1001
|
if (left.name.text === "__proto__" || left.name.text === "__esModule")
|
|
901
1002
|
return false;
|
|
@@ -937,17 +1038,13 @@ function pureCjsExport7(program, stmt) {
|
|
|
937
1038
|
const checker = program.getTypeChecker();
|
|
938
1039
|
const symbol = checker.getSymbolAtLocation(value);
|
|
939
1040
|
return (symbol !== undefined &&
|
|
940
|
-
|
|
941
|
-
.declarationsOf(symbol)
|
|
942
|
-
.some((decl) => ts.isFunctionDeclaration(decl) && decl.parent === stmt.parent));
|
|
1041
|
+
symbol.declarations.some((decl) => ts.isFunctionDeclaration(decl) && decl.parent === stmt.parent));
|
|
943
1042
|
}
|
|
944
1043
|
function sourceBinding7(program, ident) {
|
|
945
1044
|
const checker = program.getTypeChecker();
|
|
946
1045
|
const symbol = checker.getSymbolAtLocation(ident);
|
|
947
1046
|
return (symbol !== undefined &&
|
|
948
|
-
|
|
949
|
-
.declarationsOf(symbol)
|
|
950
|
-
.some((decl) => !decl.getSourceFile().isDeclarationFile && !ts.isSourceFile(decl)));
|
|
1047
|
+
symbol.declarations.some((decl) => !ts.getSourceFileOfNode(decl).isDeclarationFile && !ts.isSourceFile(decl)));
|
|
951
1048
|
}
|
|
952
1049
|
function purePrefixDecl7(decl) {
|
|
953
1050
|
const init = decl.initializer;
|
|
@@ -971,11 +1068,11 @@ function purePrefixStmt7(program, s) {
|
|
|
971
1068
|
return true; // directive
|
|
972
1069
|
if (isRequireStatement7(s))
|
|
973
1070
|
return true;
|
|
974
|
-
if (isCjsJsFile7(
|
|
1071
|
+
if (isCjsJsFile7(ts.getSourceFileOfNode(s), program)) {
|
|
975
1072
|
if (ts.isExpressionStatement(s) && isEsModuleStamp(s.expression)) {
|
|
976
1073
|
const call = s.expression;
|
|
977
1074
|
const object = call.expression.expression;
|
|
978
|
-
let receiver = call.arguments[0];
|
|
1075
|
+
let receiver = call.arguments.nodes[0];
|
|
979
1076
|
if (ts.isPropertyAccessExpression(receiver))
|
|
980
1077
|
receiver = receiver.expression;
|
|
981
1078
|
if (!sourceBinding7(program, object) &&
|
|
@@ -987,7 +1084,7 @@ function purePrefixStmt7(program, s) {
|
|
|
987
1084
|
return true;
|
|
988
1085
|
}
|
|
989
1086
|
if (ts.isVariableStatement(s)) {
|
|
990
|
-
return s.declarationList.declarations.every(purePrefixDecl7);
|
|
1087
|
+
return s.declarationList.declarations.nodes.every(purePrefixDecl7);
|
|
991
1088
|
}
|
|
992
1089
|
return false;
|
|
993
1090
|
}
|
|
@@ -1011,7 +1108,7 @@ export function bindingEarlyUse7(program, sf, k, decl, precedingDecls) {
|
|
|
1011
1108
|
if (ts.isIdentifier(decl.name))
|
|
1012
1109
|
bound.push(decl.name);
|
|
1013
1110
|
else if (ts.isObjectBindingPattern(decl.name)) {
|
|
1014
|
-
for (const el of decl.name.elements)
|
|
1111
|
+
for (const el of decl.name.elements.nodes)
|
|
1015
1112
|
if (el.name !== undefined && ts.isIdentifier(el.name))
|
|
1016
1113
|
bound.push(el.name);
|
|
1017
1114
|
}
|
|
@@ -1023,7 +1120,7 @@ export function bindingEarlyUse7(program, sf, k, decl, precedingDecls) {
|
|
|
1023
1120
|
}
|
|
1024
1121
|
if (bindings.size === 0)
|
|
1025
1122
|
return null;
|
|
1026
|
-
const stmts = sf.statements;
|
|
1123
|
+
const stmts = sf.statements.nodes;
|
|
1027
1124
|
const hoisted = new Map();
|
|
1028
1125
|
for (const s of stmts) {
|
|
1029
1126
|
if ((ts.isFunctionDeclaration(s) || ts.isClassDeclaration(s)) && s.name) {
|
|
@@ -1082,6 +1179,542 @@ export function bindingEarlyUse7(program, sf, k, decl, precedingDecls) {
|
|
|
1082
1179
|
}
|
|
1083
1180
|
return hit;
|
|
1084
1181
|
}
|
|
1182
|
+
/** The first reference to a top-level require declaration's bindings that
|
|
1183
|
+
* code running before the require completes can reach, or null when no
|
|
1184
|
+
* earlier code can run or reach one. Memoized per program: preflight
|
|
1185
|
+
* decides the fence and the lowering places the initialization checks
|
|
1186
|
+
* from the same answer. */
|
|
1187
|
+
function requireEarlyReference7(program, decl) {
|
|
1188
|
+
const memo = program.analysis.requireEarlyReferences;
|
|
1189
|
+
const cached = memo.get(decl);
|
|
1190
|
+
if (cached !== undefined)
|
|
1191
|
+
return cached;
|
|
1192
|
+
let found = null;
|
|
1193
|
+
const stmt = decl.parent?.parent;
|
|
1194
|
+
const sf = ts.getSourceFileOfNode(decl);
|
|
1195
|
+
if (stmt !== undefined && ts.isVariableStatement(stmt) && ts.isSourceFile(stmt.parent)) {
|
|
1196
|
+
const stmts = sf.statements.nodes;
|
|
1197
|
+
const k = stmts.indexOf(stmt);
|
|
1198
|
+
const declarations = stmt.declarationList.declarations.nodes;
|
|
1199
|
+
// Earlier declarators run too: `const x = read(), dep = require('./dep')`.
|
|
1200
|
+
const precedingDecls = declarations.slice(0, declarations.indexOf(decl));
|
|
1201
|
+
let firstRunnable = program.analysis.requireFirstRunnable.get(sf);
|
|
1202
|
+
if (firstRunnable === undefined) {
|
|
1203
|
+
firstRunnable = stmts.findIndex((s) => !purePrefixStmt7(program, s));
|
|
1204
|
+
program.analysis.requireFirstRunnable.set(sf, firstRunnable);
|
|
1205
|
+
}
|
|
1206
|
+
const prefixCanRun = (firstRunnable >= 0 && firstRunnable < k) || precedingDecls.some((d) => !purePrefixDecl7(d));
|
|
1207
|
+
if (prefixCanRun)
|
|
1208
|
+
found = requireBindingEarlyUse7(program, sf, k, decl, precedingDecls);
|
|
1209
|
+
}
|
|
1210
|
+
memo.set(decl, found);
|
|
1211
|
+
return found;
|
|
1212
|
+
}
|
|
1213
|
+
/** The CommonJS twin of bindingEarlyUse7 for a top-level require binding:
|
|
1214
|
+
* the first reference to one of `decl`'s bindings that code running before
|
|
1215
|
+
* the require completes can reach, or null. It follows Node's evaluation
|
|
1216
|
+
* order instead of the conservative "every earlier statement" scan:
|
|
1217
|
+
* - hoisted functions and classes, and the function and class values a
|
|
1218
|
+
* var stored before the require, run only when reachable code names
|
|
1219
|
+
* them; a class statement runs only its heritage, computed keys,
|
|
1220
|
+
* decorators and static initializers;
|
|
1221
|
+
* - callbacks handed to timers, microtasks and promise reactions run after
|
|
1222
|
+
* the module body, hence after the require;
|
|
1223
|
+
* - publishing a value (`module.exports = f`, `exports.n = f`,
|
|
1224
|
+
* `Object.defineProperty(exports, "n", { get })`, `F.prototype.m = f`)
|
|
1225
|
+
* runs nothing. The published value becomes reachable only when
|
|
1226
|
+
* reachable code reads it back: an `exports.n` read reaches the values
|
|
1227
|
+
* published as `n`, any other read of the export object reaches all of
|
|
1228
|
+
* them, and naming `F` reaches what was stored on `F`. No other module
|
|
1229
|
+
* can read this module's exports before its body completes: require
|
|
1230
|
+
* cycles keep their SC1016 fence and a compiled module graph has no
|
|
1231
|
+
* reflective exports object.
|
|
1232
|
+
* Every other function-like met in reachable code counts as reachable
|
|
1233
|
+
* because it may be handed to a callee. */
|
|
1234
|
+
export function requireBindingEarlyUse7(program, sf, k, decl, precedingDecls,
|
|
1235
|
+
/** A reference of the binding whose early evaluation is known exact. */
|
|
1236
|
+
exactEarlyRead) {
|
|
1237
|
+
const checker = program.getTypeChecker();
|
|
1238
|
+
const bindings = new Set();
|
|
1239
|
+
for (const id of boundNames7(decl.name)) {
|
|
1240
|
+
const sym = checker.getSymbolAtLocation(id);
|
|
1241
|
+
if (sym)
|
|
1242
|
+
bindings.add(sym);
|
|
1243
|
+
}
|
|
1244
|
+
if (bindings.size === 0)
|
|
1245
|
+
return null;
|
|
1246
|
+
const stmts = sf.statements.nodes;
|
|
1247
|
+
const cjs = isCjsJsFile7(sf, program);
|
|
1248
|
+
const symbolOf = (id) => {
|
|
1249
|
+
const parent = id.parent;
|
|
1250
|
+
if (parent !== undefined && ts.isShorthandPropertyAssignment(parent) && parent.name === id) {
|
|
1251
|
+
return checker.getShorthandAssignmentValueSymbol(parent);
|
|
1252
|
+
}
|
|
1253
|
+
return checker.getSymbolAtLocation(id);
|
|
1254
|
+
};
|
|
1255
|
+
// Stored callables and the scans that skip them.
|
|
1256
|
+
const units = new Map();
|
|
1257
|
+
const stored = new Set();
|
|
1258
|
+
const addUnit = (name, node) => {
|
|
1259
|
+
const sym = checker.getSymbolAtLocation(name);
|
|
1260
|
+
if (sym === undefined)
|
|
1261
|
+
return;
|
|
1262
|
+
stored.add(node);
|
|
1263
|
+
const list = units.get(sym);
|
|
1264
|
+
if (list)
|
|
1265
|
+
list.push(node);
|
|
1266
|
+
else
|
|
1267
|
+
units.set(sym, [node]);
|
|
1268
|
+
};
|
|
1269
|
+
const storedCallables = (e, out) => {
|
|
1270
|
+
while (ts.isParenthesizedExpression(e))
|
|
1271
|
+
e = e.expression;
|
|
1272
|
+
if (ts.isArrowFunction(e) || ts.isFunctionExpression(e) || ts.isClassExpression(e)) {
|
|
1273
|
+
out.push(e);
|
|
1274
|
+
}
|
|
1275
|
+
else if (ts.isObjectLiteralExpression(e)) {
|
|
1276
|
+
for (const p of e.properties.nodes) {
|
|
1277
|
+
if ((ts.isMethodDeclaration(p) ||
|
|
1278
|
+
ts.isGetAccessorDeclaration(p) ||
|
|
1279
|
+
ts.isSetAccessorDeclaration(p)) &&
|
|
1280
|
+
!ts.isComputedPropertyName(p.name)) {
|
|
1281
|
+
out.push(p);
|
|
1282
|
+
}
|
|
1283
|
+
else if (ts.isPropertyAssignment(p) && !ts.isComputedPropertyName(p.name)) {
|
|
1284
|
+
storedCallables(p.initializer, out);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
};
|
|
1289
|
+
stmts.forEach((s, i) => {
|
|
1290
|
+
if ((ts.isFunctionDeclaration(s) || ts.isClassDeclaration(s)) && s.name !== undefined) {
|
|
1291
|
+
addUnit(s.name, s);
|
|
1292
|
+
}
|
|
1293
|
+
else if (i < k && ts.isVariableStatement(s)) {
|
|
1294
|
+
for (const d of s.declarationList.declarations.nodes) {
|
|
1295
|
+
if (!ts.isIdentifier(d.name) || d.initializer === undefined)
|
|
1296
|
+
continue;
|
|
1297
|
+
const out = [];
|
|
1298
|
+
storedCallables(d.initializer, out);
|
|
1299
|
+
for (const node of out)
|
|
1300
|
+
addUnit(d.name, node);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
// Callbacks that only run as later jobs never run before the require:
|
|
1305
|
+
// the timers, microtasks and promise reactions. (Event listeners can run
|
|
1306
|
+
// synchronously from an emit, so they keep the conservative rule.)
|
|
1307
|
+
const laterJob = (callee) => {
|
|
1308
|
+
while (ts.isParenthesizedExpression(callee))
|
|
1309
|
+
callee = callee.expression;
|
|
1310
|
+
const name = ts.isIdentifier(callee)
|
|
1311
|
+
? callee.text
|
|
1312
|
+
: ts.isPropertyAccessExpression(callee)
|
|
1313
|
+
? callee.name.text
|
|
1314
|
+
: null;
|
|
1315
|
+
return (name !== null &&
|
|
1316
|
+
(LATER_JOB_BUILTINS7.has(name) || name === "nextTick") &&
|
|
1317
|
+
laterJobCallee7(checker, callee));
|
|
1318
|
+
};
|
|
1319
|
+
if (!hasTopLevelAwait7(sf)) {
|
|
1320
|
+
const callbacks = (e) => {
|
|
1321
|
+
while (ts.isParenthesizedExpression(e))
|
|
1322
|
+
e = e.expression;
|
|
1323
|
+
if (ts.isArrowFunction(e) || ts.isFunctionExpression(e))
|
|
1324
|
+
stored.add(e);
|
|
1325
|
+
};
|
|
1326
|
+
for (const s of stmts.slice(0, k)) {
|
|
1327
|
+
ts.walkPreorder(s, (node) => {
|
|
1328
|
+
if ((ts.isCallExpression(node) || ts.isNewExpression(node)) && laterJob(node.expression)) {
|
|
1329
|
+
for (const arg of node.arguments?.nodes ?? [])
|
|
1330
|
+
callbacks(arg);
|
|
1331
|
+
}
|
|
1332
|
+
return undefined;
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
const isWrapperName = (e, name) => ts.isIdentifier(e) && e.text === name && !sourceBinding7(program, e);
|
|
1337
|
+
/** `this` at the module's top level: the original export object. */
|
|
1338
|
+
const isModuleThis = (e) => {
|
|
1339
|
+
if (e.kind !== ts.SyntaxKind.ThisKeyword)
|
|
1340
|
+
return false;
|
|
1341
|
+
for (let p = e.parent; p !== undefined && !ts.isSourceFile(p); p = p.parent) {
|
|
1342
|
+
if (ts.isFunctionLike(p) && !ts.isArrowFunction(p))
|
|
1343
|
+
return false;
|
|
1344
|
+
if (ts.isClassExpression(p) || ts.isClassDeclaration(p))
|
|
1345
|
+
return false;
|
|
1346
|
+
}
|
|
1347
|
+
return true;
|
|
1348
|
+
};
|
|
1349
|
+
const isExportObject = (e) => isWrapperName(e, "exports") ||
|
|
1350
|
+
isModuleThis(e) ||
|
|
1351
|
+
(isModuleExportsAccess(e) && isWrapperName(e.expression, "module"));
|
|
1352
|
+
const replacesExports = stmts.some((st) => cjsExportAssignmentOf(st)?.kind === "table");
|
|
1353
|
+
// Published values: by export name ("*" for a whole replacement), and by
|
|
1354
|
+
// the stored callable whose properties hold them.
|
|
1355
|
+
const exportLinks = new Map();
|
|
1356
|
+
const ownerLinks = new Map();
|
|
1357
|
+
const reachedKeys = new Set();
|
|
1358
|
+
const writtenKeys = new Set();
|
|
1359
|
+
const reachedUnits = new Set();
|
|
1360
|
+
const work = [];
|
|
1361
|
+
let hit = null;
|
|
1362
|
+
const reachUnit = (node) => {
|
|
1363
|
+
if (reachedUnits.has(node))
|
|
1364
|
+
return;
|
|
1365
|
+
reachedUnits.add(node);
|
|
1366
|
+
work.push(node);
|
|
1367
|
+
};
|
|
1368
|
+
const reachSymbol = (sym) => {
|
|
1369
|
+
for (const node of units.get(sym) ?? [])
|
|
1370
|
+
reachUnit(node);
|
|
1371
|
+
for (const node of ownerLinks.get(sym) ?? [])
|
|
1372
|
+
reachUnit(node);
|
|
1373
|
+
};
|
|
1374
|
+
let allReached = false;
|
|
1375
|
+
const reachKey = (key) => {
|
|
1376
|
+
if (key === null) {
|
|
1377
|
+
allReached = true;
|
|
1378
|
+
for (const list of exportLinks.values())
|
|
1379
|
+
for (const node of list)
|
|
1380
|
+
reachUnit(node);
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
reachedKeys.add(key);
|
|
1384
|
+
for (const name of [key, "*"])
|
|
1385
|
+
for (const node of exportLinks.get(name) ?? [])
|
|
1386
|
+
reachUnit(node);
|
|
1387
|
+
};
|
|
1388
|
+
const keyReached = (key) => allReached || reachedKeys.has(key) || (key === "*" && reachedKeys.size > 0);
|
|
1389
|
+
/** A read of the export object: which published names it can observe. */
|
|
1390
|
+
const exportRead = (node) => {
|
|
1391
|
+
let use = node;
|
|
1392
|
+
while (ts.isParenthesizedExpression(use.parent))
|
|
1393
|
+
use = use.parent;
|
|
1394
|
+
const parent = use.parent;
|
|
1395
|
+
// A truthiness test reads no member (tsc's `this && this.__helper`).
|
|
1396
|
+
if (ts.isBinaryExpression(parent) &&
|
|
1397
|
+
parent.left === use &&
|
|
1398
|
+
parent.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {
|
|
1399
|
+
return;
|
|
1400
|
+
}
|
|
1401
|
+
if (ts.isTypeOfExpression(parent))
|
|
1402
|
+
return;
|
|
1403
|
+
if (ts.isPropertyAccessExpression(parent) && parent.expression === use) {
|
|
1404
|
+
let target = parent;
|
|
1405
|
+
while (ts.isParenthesizedExpression(target.parent))
|
|
1406
|
+
target = target.parent;
|
|
1407
|
+
const assignment = target.parent;
|
|
1408
|
+
if (ts.isBinaryExpression(assignment) &&
|
|
1409
|
+
assignment.left === target &&
|
|
1410
|
+
assignment.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
1411
|
+
// A plain write reads no member. It can still run a setter: one
|
|
1412
|
+
// published for that name (now or later), or a static one of a
|
|
1413
|
+
// replacing class.
|
|
1414
|
+
writtenKeys.add(parent.name.text);
|
|
1415
|
+
for (const node of exportLinks.get(parent.name.text) ?? [])
|
|
1416
|
+
reachUnit(node);
|
|
1417
|
+
for (const node of exportLinks.get("*") ?? []) {
|
|
1418
|
+
if (ts.isClassDeclaration(node) || ts.isClassExpression(node))
|
|
1419
|
+
reachUnit(node);
|
|
1420
|
+
}
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
reachKey(parent.name.text);
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
if (ts.isElementAccessExpression(parent) &&
|
|
1427
|
+
parent.expression === use &&
|
|
1428
|
+
ts.isStringLiteralLike(parent.argumentExpression)) {
|
|
1429
|
+
reachKey(parent.argumentExpression.text);
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
reachKey(null);
|
|
1433
|
+
};
|
|
1434
|
+
const scan = (root) => {
|
|
1435
|
+
ts.walkPreorder(root, (n) => {
|
|
1436
|
+
if (hit !== null)
|
|
1437
|
+
return "stop";
|
|
1438
|
+
if (n !== root && stored.has(n)) {
|
|
1439
|
+
if (ts.isClassExpression(n) || ts.isClassDeclaration(n)) {
|
|
1440
|
+
for (const part of classSyncParts7(n))
|
|
1441
|
+
scan(part);
|
|
1442
|
+
}
|
|
1443
|
+
return "skip";
|
|
1444
|
+
}
|
|
1445
|
+
// A self-require answers this module's partially built exports.
|
|
1446
|
+
if (cjs && ts.isCallExpression(n)) {
|
|
1447
|
+
const spec = requireSpecOf7(n);
|
|
1448
|
+
if (spec !== null && resolveImport7(program, sf, spec, "require") === sf)
|
|
1449
|
+
reachKey(null);
|
|
1450
|
+
}
|
|
1451
|
+
if (cjs && n.kind === ts.SyntaxKind.ThisKeyword && isModuleThis(n)) {
|
|
1452
|
+
exportRead(n);
|
|
1453
|
+
return undefined;
|
|
1454
|
+
}
|
|
1455
|
+
if (!ts.isIdentifier(n))
|
|
1456
|
+
return undefined;
|
|
1457
|
+
if (inTypePosition7(n))
|
|
1458
|
+
return undefined;
|
|
1459
|
+
const named = n.parent;
|
|
1460
|
+
if ((ts.isPropertyAccessExpression(named) ||
|
|
1461
|
+
ts.isPropertyAssignment(named) ||
|
|
1462
|
+
ts.isMethodDeclaration(named) ||
|
|
1463
|
+
ts.isGetAccessorDeclaration(named) ||
|
|
1464
|
+
ts.isSetAccessorDeclaration(named) ||
|
|
1465
|
+
ts.isPropertyDeclaration(named)) &&
|
|
1466
|
+
named.name === n) {
|
|
1467
|
+
return undefined;
|
|
1468
|
+
}
|
|
1469
|
+
// A declaration's own name reads nothing.
|
|
1470
|
+
if (named !== undefined && declaredName7(named) === n)
|
|
1471
|
+
return undefined;
|
|
1472
|
+
if (cjs && isWrapperName(n, "exports")) {
|
|
1473
|
+
exportRead(n);
|
|
1474
|
+
return undefined;
|
|
1475
|
+
}
|
|
1476
|
+
if (cjs && isWrapperName(n, "module")) {
|
|
1477
|
+
const parent = n.parent;
|
|
1478
|
+
if (ts.isPropertyAccessExpression(parent) && parent.expression === n) {
|
|
1479
|
+
if (parent.name.text === "exports")
|
|
1480
|
+
exportRead(parent);
|
|
1481
|
+
return "skip";
|
|
1482
|
+
}
|
|
1483
|
+
reachKey(null);
|
|
1484
|
+
return undefined;
|
|
1485
|
+
}
|
|
1486
|
+
const sym = symbolOf(n);
|
|
1487
|
+
if (sym === undefined)
|
|
1488
|
+
return undefined;
|
|
1489
|
+
if (bindings.has(sym)) {
|
|
1490
|
+
if (exactEarlyRead?.(n) === true)
|
|
1491
|
+
return undefined;
|
|
1492
|
+
hit = n;
|
|
1493
|
+
return "stop";
|
|
1494
|
+
}
|
|
1495
|
+
reachSymbol(sym);
|
|
1496
|
+
return undefined;
|
|
1497
|
+
});
|
|
1498
|
+
};
|
|
1499
|
+
/** Links a published value: evaluating it reads identifiers, but the
|
|
1500
|
+
* callables it names run only once they are read back. */
|
|
1501
|
+
const publish = (value, link) => {
|
|
1502
|
+
while (ts.isParenthesizedExpression(value))
|
|
1503
|
+
value = value.expression;
|
|
1504
|
+
if (ts.isIdentifier(value)) {
|
|
1505
|
+
const sym = symbolOf(value);
|
|
1506
|
+
if (sym !== undefined && bindings.has(sym)) {
|
|
1507
|
+
hit = value;
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
if (sym !== undefined) {
|
|
1511
|
+
// What was stored on the value stays reachable through it.
|
|
1512
|
+
for (const node of [...(units.get(sym) ?? []), ...(ownerLinks.get(sym) ?? [])])
|
|
1513
|
+
link(node);
|
|
1514
|
+
}
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
if (ts.isFunctionExpression(value) || ts.isArrowFunction(value)) {
|
|
1518
|
+
link(value);
|
|
1519
|
+
return;
|
|
1520
|
+
}
|
|
1521
|
+
if (ts.isClassExpression(value)) {
|
|
1522
|
+
for (const part of classSyncParts7(value))
|
|
1523
|
+
scan(part);
|
|
1524
|
+
link(value);
|
|
1525
|
+
return;
|
|
1526
|
+
}
|
|
1527
|
+
if (ts.isObjectLiteralExpression(value)) {
|
|
1528
|
+
for (const p of value.properties.nodes) {
|
|
1529
|
+
if (ts.isShorthandPropertyAssignment(p)) {
|
|
1530
|
+
const sym = checker.getShorthandAssignmentValueSymbol(p);
|
|
1531
|
+
if (sym !== undefined && bindings.has(sym))
|
|
1532
|
+
hit = p.name;
|
|
1533
|
+
else if (sym !== undefined) {
|
|
1534
|
+
for (const node of [...(units.get(sym) ?? []), ...(ownerLinks.get(sym) ?? [])]) {
|
|
1535
|
+
link(node);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
else if (ts.isPropertyAssignment(p) && !ts.isComputedPropertyName(p.name)) {
|
|
1540
|
+
publish(p.initializer, link);
|
|
1541
|
+
}
|
|
1542
|
+
else if ((ts.isMethodDeclaration(p) ||
|
|
1543
|
+
ts.isGetAccessorDeclaration(p) ||
|
|
1544
|
+
ts.isSetAccessorDeclaration(p)) &&
|
|
1545
|
+
!ts.isComputedPropertyName(p.name)) {
|
|
1546
|
+
link(p);
|
|
1547
|
+
}
|
|
1548
|
+
else
|
|
1549
|
+
scan(p);
|
|
1550
|
+
}
|
|
1551
|
+
return;
|
|
1552
|
+
}
|
|
1553
|
+
if (ts.isStringLiteralLike(value) ||
|
|
1554
|
+
ts.isNumericLiteral(value) ||
|
|
1555
|
+
value.kind === ts.SyntaxKind.TrueKeyword ||
|
|
1556
|
+
value.kind === ts.SyntaxKind.FalseKeyword ||
|
|
1557
|
+
value.kind === ts.SyntaxKind.NullKeyword ||
|
|
1558
|
+
(ts.isVoidExpression(value) && ts.isNumericLiteral(value.expression))) {
|
|
1559
|
+
return;
|
|
1560
|
+
}
|
|
1561
|
+
scan(value);
|
|
1562
|
+
// Whatever an arbitrary expression evaluates to is opaque: treat it as
|
|
1563
|
+
// reachable through the target too (scan already reached its parts).
|
|
1564
|
+
};
|
|
1565
|
+
const targetOf = (left) => {
|
|
1566
|
+
if (isModuleExportsAccess(left) && isWrapperName(left.expression, "module")) {
|
|
1567
|
+
return { kind: "key", key: "*" };
|
|
1568
|
+
}
|
|
1569
|
+
const names = [];
|
|
1570
|
+
let e = left;
|
|
1571
|
+
for (;;) {
|
|
1572
|
+
if (ts.isPropertyAccessExpression(e) && !e.questionDotToken) {
|
|
1573
|
+
if (isExportObject(e))
|
|
1574
|
+
break;
|
|
1575
|
+
names.unshift(e.name.text);
|
|
1576
|
+
e = e.expression;
|
|
1577
|
+
}
|
|
1578
|
+
else if (ts.isElementAccessExpression(e) &&
|
|
1579
|
+
!e.questionDotToken &&
|
|
1580
|
+
ts.isStringLiteralLike(e.argumentExpression)) {
|
|
1581
|
+
names.unshift(e.argumentExpression.text);
|
|
1582
|
+
e = e.expression;
|
|
1583
|
+
}
|
|
1584
|
+
else
|
|
1585
|
+
break;
|
|
1586
|
+
}
|
|
1587
|
+
if (names.length === 0)
|
|
1588
|
+
return null;
|
|
1589
|
+
if (isExportObject(e)) {
|
|
1590
|
+
// __proto__ and the interop marker are not plain data slots, and a
|
|
1591
|
+
// member of a replaced export may be a read-only function property:
|
|
1592
|
+
// those writes keep the conservative scan.
|
|
1593
|
+
if (names[0] === "__proto__" || names[0] === "__esModule" || replacesExports)
|
|
1594
|
+
return null;
|
|
1595
|
+
return { kind: "key", key: names[0] };
|
|
1596
|
+
}
|
|
1597
|
+
if (ts.isIdentifier(e)) {
|
|
1598
|
+
const sym = symbolOf(e);
|
|
1599
|
+
if (sym !== undefined && units.has(sym) && !bindings.has(sym))
|
|
1600
|
+
return { kind: "owner", owner: sym };
|
|
1601
|
+
}
|
|
1602
|
+
return null;
|
|
1603
|
+
};
|
|
1604
|
+
const linkTo = (target, node) => {
|
|
1605
|
+
if (target.kind === "key") {
|
|
1606
|
+
const replacingClass = target.key === "*" &&
|
|
1607
|
+
writtenKeys.size > 0 &&
|
|
1608
|
+
(ts.isClassDeclaration(node) || ts.isClassExpression(node));
|
|
1609
|
+
if (keyReached(target.key) || writtenKeys.has(target.key) || replacingClass) {
|
|
1610
|
+
reachUnit(node);
|
|
1611
|
+
}
|
|
1612
|
+
const list = exportLinks.get(target.key);
|
|
1613
|
+
if (list)
|
|
1614
|
+
list.push(node);
|
|
1615
|
+
else
|
|
1616
|
+
exportLinks.set(target.key, [node]);
|
|
1617
|
+
}
|
|
1618
|
+
else {
|
|
1619
|
+
if ((units.get(target.owner) ?? []).some((u) => reachedUnits.has(u)))
|
|
1620
|
+
reachUnit(node);
|
|
1621
|
+
if ((units.get(target.owner) ?? []).includes(node))
|
|
1622
|
+
return;
|
|
1623
|
+
const list = ownerLinks.get(target.owner);
|
|
1624
|
+
if (list === undefined)
|
|
1625
|
+
ownerLinks.set(target.owner, [node]);
|
|
1626
|
+
else if (!list.includes(node))
|
|
1627
|
+
list.push(node);
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
/** A top-level publication statement, handled in place; false for any
|
|
1631
|
+
* other statement. */
|
|
1632
|
+
const publication = (s) => {
|
|
1633
|
+
if (!cjs || !ts.isExpressionStatement(s))
|
|
1634
|
+
return false;
|
|
1635
|
+
const e = s.expression;
|
|
1636
|
+
if (ts.isBinaryExpression(e) && e.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
1637
|
+
const targets = [];
|
|
1638
|
+
let value = e;
|
|
1639
|
+
while (ts.isBinaryExpression(value) &&
|
|
1640
|
+
value.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
1641
|
+
const target = targetOf(value.left);
|
|
1642
|
+
if (target === null)
|
|
1643
|
+
return false;
|
|
1644
|
+
targets.push(target);
|
|
1645
|
+
value = value.right;
|
|
1646
|
+
}
|
|
1647
|
+
publish(value, (node) => {
|
|
1648
|
+
for (const t of targets)
|
|
1649
|
+
linkTo(t, node);
|
|
1650
|
+
});
|
|
1651
|
+
return true;
|
|
1652
|
+
}
|
|
1653
|
+
// Object.defineProperty(exports, "name", { get() {...}, value: f, ... })
|
|
1654
|
+
if (ts.isCallExpression(e) &&
|
|
1655
|
+
ts.isPropertyAccessExpression(e.expression) &&
|
|
1656
|
+
isWrapperName(e.expression.expression, "Object") &&
|
|
1657
|
+
e.expression.name.text === "defineProperty" &&
|
|
1658
|
+
e.arguments.nodes.length === 3) {
|
|
1659
|
+
const [recv, key, desc] = e.arguments.nodes;
|
|
1660
|
+
if (!isExportObject(recv) || !ts.isStringLiteralLike(key))
|
|
1661
|
+
return false;
|
|
1662
|
+
if (!ts.isObjectLiteralExpression(desc))
|
|
1663
|
+
return false;
|
|
1664
|
+
const keyTarget = { kind: "key", key: key.text };
|
|
1665
|
+
const link = (node) => linkTo(keyTarget, node);
|
|
1666
|
+
for (const p of desc.properties.nodes) {
|
|
1667
|
+
if ((ts.isMethodDeclaration(p) || ts.isPropertyAssignment(p)) &&
|
|
1668
|
+
ts.isIdentifier(p.name) &&
|
|
1669
|
+
(p.name.text === "get" || p.name.text === "set")) {
|
|
1670
|
+
if (ts.isMethodDeclaration(p))
|
|
1671
|
+
link(p);
|
|
1672
|
+
else
|
|
1673
|
+
publish(p.initializer, link);
|
|
1674
|
+
}
|
|
1675
|
+
else if (ts.isPropertyAssignment(p) &&
|
|
1676
|
+
ts.isIdentifier(p.name) &&
|
|
1677
|
+
p.name.text === "value") {
|
|
1678
|
+
publish(p.initializer, link);
|
|
1679
|
+
}
|
|
1680
|
+
else
|
|
1681
|
+
scan(p);
|
|
1682
|
+
}
|
|
1683
|
+
return true;
|
|
1684
|
+
}
|
|
1685
|
+
return false;
|
|
1686
|
+
};
|
|
1687
|
+
const drain = () => {
|
|
1688
|
+
while (hit === null && work.length > 0) {
|
|
1689
|
+
const unit = work.pop();
|
|
1690
|
+
checker.prefetchSymbolRoots([unit]);
|
|
1691
|
+
scan(unit);
|
|
1692
|
+
}
|
|
1693
|
+
};
|
|
1694
|
+
const roots = stmts.slice(0, k);
|
|
1695
|
+
checker.prefetchSymbolRoots([...roots, ...precedingDecls]);
|
|
1696
|
+
for (const s of roots) {
|
|
1697
|
+
if (hit !== null)
|
|
1698
|
+
break;
|
|
1699
|
+
if (ts.isFunctionDeclaration(s))
|
|
1700
|
+
continue;
|
|
1701
|
+
if (ts.isClassDeclaration(s)) {
|
|
1702
|
+
for (const part of classSyncParts7(s))
|
|
1703
|
+
scan(part);
|
|
1704
|
+
}
|
|
1705
|
+
else if (!publication(s)) {
|
|
1706
|
+
scan(s);
|
|
1707
|
+
}
|
|
1708
|
+
drain();
|
|
1709
|
+
}
|
|
1710
|
+
for (const d of precedingDecls) {
|
|
1711
|
+
if (hit !== null)
|
|
1712
|
+
break;
|
|
1713
|
+
scan(d);
|
|
1714
|
+
drain();
|
|
1715
|
+
}
|
|
1716
|
+
return hit;
|
|
1717
|
+
}
|
|
1085
1718
|
/** Bare `require("...")` EXPRESSION STATEMENTS anywhere below the top
|
|
1086
1719
|
* level of a file — inside top-level ifs/blocks/loops and inside function
|
|
1087
1720
|
* bodies (the lazy-require idiom). No bindings, pure side-effect loads. */
|
|
@@ -1100,6 +1733,35 @@ function nestedBareRequiresOf7(sf) {
|
|
|
1100
1733
|
});
|
|
1101
1734
|
return out;
|
|
1102
1735
|
}
|
|
1736
|
+
/** INLINE `require("...")` calls in expression position anywhere in a file
|
|
1737
|
+
* (`require("./x").f`, `require("debug")("ns")`, `module.exports =
|
|
1738
|
+
* require("./y")`, `{ v: require("./v") }`): each evaluates its module at
|
|
1739
|
+
* that position, exactly like a bare require statement. Top-level require
|
|
1740
|
+
* statements and bare require statements are collected by their own
|
|
1741
|
+
* scans; a require that initializes a nested declaration keeps its
|
|
1742
|
+
* lowering fence and is not an edge. */
|
|
1743
|
+
function inlineRequiresOf7(sf) {
|
|
1744
|
+
const out = [];
|
|
1745
|
+
ts.walkPreorder(sf, (n) => {
|
|
1746
|
+
if (!ts.isCallExpression(n) || requireSpecOf7(n) === null)
|
|
1747
|
+
return;
|
|
1748
|
+
let outer = n;
|
|
1749
|
+
while (outer.parent !== undefined &&
|
|
1750
|
+
(ts.isParenthesizedExpression(outer.parent) ||
|
|
1751
|
+
ts.isAsExpression(outer.parent) ||
|
|
1752
|
+
ts.isTypeAssertion(outer.parent) ||
|
|
1753
|
+
ts.isNonNullExpression(outer.parent))) {
|
|
1754
|
+
outer = outer.parent;
|
|
1755
|
+
}
|
|
1756
|
+
const parent = outer.parent;
|
|
1757
|
+
if (parent !== undefined && ts.isExpressionStatement(parent))
|
|
1758
|
+
return;
|
|
1759
|
+
if (parent !== undefined && ts.isVariableDeclaration(parent) && parent.initializer === outer)
|
|
1760
|
+
return;
|
|
1761
|
+
out.push(n);
|
|
1762
|
+
});
|
|
1763
|
+
return out;
|
|
1764
|
+
}
|
|
1103
1765
|
function stripRequireCasts7(expr) {
|
|
1104
1766
|
let cur = expr;
|
|
1105
1767
|
while (ts.isParenthesizedExpression(cur) ||
|
|
@@ -1116,7 +1778,7 @@ function stripRequireCasts7(expr) {
|
|
|
1116
1778
|
function isCreateRequireImport7(program, ident) {
|
|
1117
1779
|
const checker = program.getTypeChecker();
|
|
1118
1780
|
const symbol = checker.getSymbolAtLocation(ident);
|
|
1119
|
-
const decl = symbol ?
|
|
1781
|
+
const decl = symbol ? symbol.declarations[0] : undefined;
|
|
1120
1782
|
if (decl === undefined || !ts.isImportSpecifier(decl))
|
|
1121
1783
|
return false;
|
|
1122
1784
|
const importDecl = decl.parent?.parent?.parent;
|
|
@@ -1128,11 +1790,12 @@ function isCreateRequireImport7(program, ident) {
|
|
|
1128
1790
|
}
|
|
1129
1791
|
if (symbol !== undefined && (symbol.flags & ts.SymbolFlags.Alias) !== 0) {
|
|
1130
1792
|
const target = checker.getAliasedSymbol(symbol);
|
|
1131
|
-
const targetDecl =
|
|
1132
|
-
if (targetDecl !== undefined &&
|
|
1793
|
+
const targetDecl = target.declarations[0];
|
|
1794
|
+
if (targetDecl !== undefined && ts.getSourceFileOfNode(targetDecl).isDeclarationFile) {
|
|
1133
1795
|
for (let p = targetDecl.parent; p !== undefined && !ts.isSourceFile(p); p = p.parent) {
|
|
1134
1796
|
if (ts.isModuleDeclaration(p) && ts.isStringLiteral(p.name)) {
|
|
1135
|
-
return (canonicalBuiltinModule(p.name.text) === "module" &&
|
|
1797
|
+
return (canonicalBuiltinModule(p.name.text) === "module" &&
|
|
1798
|
+
ts.symbolName(target) === "createRequire");
|
|
1136
1799
|
}
|
|
1137
1800
|
}
|
|
1138
1801
|
}
|
|
@@ -1146,9 +1809,7 @@ export function isCreateRequireBinding7(program, callee) {
|
|
|
1146
1809
|
const checker = program.getTypeChecker();
|
|
1147
1810
|
const symbol = checker.getSymbolAtLocation(callee);
|
|
1148
1811
|
const decl = symbol
|
|
1149
|
-
?
|
|
1150
|
-
.declarationsOf(symbol)
|
|
1151
|
-
.find((d) => ts.isVariableDeclaration(d))
|
|
1812
|
+
? symbol.declarations.find((d) => ts.isVariableDeclaration(d))
|
|
1152
1813
|
: undefined;
|
|
1153
1814
|
if (decl === undefined ||
|
|
1154
1815
|
decl.initializer === undefined ||
|
|
@@ -1181,8 +1842,8 @@ function staticCreateRequireUse7(expr) {
|
|
|
1181
1842
|
return (ts.isCallExpression(call) &&
|
|
1182
1843
|
call.expression === use &&
|
|
1183
1844
|
!call.questionDotToken &&
|
|
1184
|
-
call.arguments.length === 1 &&
|
|
1185
|
-
ts.isStringLiteralLike(call.arguments[0]));
|
|
1845
|
+
call.arguments.nodes.length === 1 &&
|
|
1846
|
+
ts.isStringLiteralLike(call.arguments.nodes[0]));
|
|
1186
1847
|
}
|
|
1187
1848
|
function stableCreateRequireBindingReason7(program, decl) {
|
|
1188
1849
|
const cache = program.analysis.createRequireReasons;
|
|
@@ -1197,11 +1858,11 @@ function stableCreateRequireBindingReason7(program, decl) {
|
|
|
1197
1858
|
}
|
|
1198
1859
|
const checker = program.getTypeChecker();
|
|
1199
1860
|
const symbol = checker.getSymbolAtLocation(decl.name);
|
|
1200
|
-
if (!symbol ||
|
|
1861
|
+
if (!symbol || symbol.declarations.length !== 1)
|
|
1201
1862
|
return "its createRequire binding is redeclared";
|
|
1202
1863
|
if ((ts.getCombinedModifierFlags(decl) & ts.ModifierFlags.Export) !== 0)
|
|
1203
1864
|
return "its createRequire result escapes through an exported binding";
|
|
1204
|
-
const sf =
|
|
1865
|
+
const sf = ts.getSourceFileOfNode(decl);
|
|
1205
1866
|
const refs = identifierOccurrences7(sf, decl.name.text);
|
|
1206
1867
|
checker.prefetchSymbolNodesExact(refs);
|
|
1207
1868
|
for (const ref of refs) {
|
|
@@ -1216,8 +1877,8 @@ function stableCreateRequireBindingReason7(program, decl) {
|
|
|
1216
1877
|
return "its createRequire binding is reassigned, escapes, or uses a computed specifier";
|
|
1217
1878
|
}
|
|
1218
1879
|
}
|
|
1219
|
-
const preceding = stmt.declarationList.declarations.slice(0, stmt.declarationList.declarations.indexOf(decl));
|
|
1220
|
-
if (bindingEarlyUse7(program, sf, sf.statements.indexOf(stmt), decl, preceding) !== null) {
|
|
1880
|
+
const preceding = stmt.declarationList.declarations.nodes.slice(0, stmt.declarationList.declarations.nodes.indexOf(decl));
|
|
1881
|
+
if (bindingEarlyUse7(program, sf, sf.statements.nodes.indexOf(stmt), decl, preceding) !== null) {
|
|
1221
1882
|
return "its createRequire binding can be used before initialization";
|
|
1222
1883
|
}
|
|
1223
1884
|
return null;
|
|
@@ -1232,10 +1893,10 @@ function isCreateRequireBaseCall7(program, expr) {
|
|
|
1232
1893
|
init.questionDotToken !== undefined ||
|
|
1233
1894
|
!ts.isIdentifier(init.expression) ||
|
|
1234
1895
|
!isCreateRequireImport7(program, init.expression) ||
|
|
1235
|
-
init.arguments.length !== 1) {
|
|
1896
|
+
init.arguments.nodes.length !== 1) {
|
|
1236
1897
|
return false;
|
|
1237
1898
|
}
|
|
1238
|
-
const base = stripRequireCasts7(init.arguments[0]);
|
|
1899
|
+
const base = stripRequireCasts7(init.arguments.nodes[0]);
|
|
1239
1900
|
if (ts.isIdentifier(base) && base.text === "__filename")
|
|
1240
1901
|
return !sourceBinding7(program, base);
|
|
1241
1902
|
return (ts.isPropertyAccessExpression(base) &&
|
|
@@ -1258,8 +1919,8 @@ function npmStaticModuleImportReason7(program, stmt) {
|
|
|
1258
1919
|
if (!bindings || !ts.isNamedImports(bindings))
|
|
1259
1920
|
return null;
|
|
1260
1921
|
const checker = program.getTypeChecker();
|
|
1261
|
-
const sf =
|
|
1262
|
-
for (const specifier of bindings.elements) {
|
|
1922
|
+
const sf = ts.getSourceFileOfNode(stmt);
|
|
1923
|
+
for (const specifier of bindings.elements.nodes) {
|
|
1263
1924
|
if ((specifier.propertyName?.text ?? specifier.name.text) !== "createRequire")
|
|
1264
1925
|
continue;
|
|
1265
1926
|
const imported = checker.getSymbolAtLocation(specifier.name);
|
|
@@ -1334,8 +1995,8 @@ function requireCallBindingKind7(program, node) {
|
|
|
1334
1995
|
const symbol = checker.getSymbolAtLocation(call.expression);
|
|
1335
1996
|
if (symbol === undefined)
|
|
1336
1997
|
return "ambient";
|
|
1337
|
-
const decls =
|
|
1338
|
-
if (decls.every((d) =>
|
|
1998
|
+
const decls = symbol.declarations;
|
|
1999
|
+
if (decls.every((d) => ts.getSourceFileOfNode(d).isDeclarationFile))
|
|
1339
2000
|
return "ambient";
|
|
1340
2001
|
return isCreateRequireBinding7(program, call.expression) ? "createRequire" : "source";
|
|
1341
2002
|
}
|
|
@@ -1348,7 +2009,7 @@ const CJS_WRAPPER_NAMES = new Set(["require", "module", "exports", "__dirname",
|
|
|
1348
2009
|
function bindingDeclaresCjsWrapper7(name) {
|
|
1349
2010
|
if (ts.isIdentifier(name))
|
|
1350
2011
|
return CJS_WRAPPER_NAMES.has(name.text) ? name : null;
|
|
1351
|
-
for (const el of name.elements) {
|
|
2012
|
+
for (const el of name.elements.nodes) {
|
|
1352
2013
|
if (el.name === undefined)
|
|
1353
2014
|
continue;
|
|
1354
2015
|
const hit = bindingDeclaresCjsWrapper7(el.name);
|
|
@@ -1371,10 +2032,10 @@ function insideFunctionLike7(node) {
|
|
|
1371
2032
|
* import/export forms, import.meta, top-level await/for-await, or a top-level
|
|
1372
2033
|
* lexical declaration that would redeclare a CommonJS wrapper binding. */
|
|
1373
2034
|
function nodeEsmSyntaxMarker7(sf) {
|
|
1374
|
-
for (const stmt of sf.statements) {
|
|
2035
|
+
for (const stmt of sf.statements.nodes) {
|
|
1375
2036
|
if (ts.isImportDeclaration(stmt) && !erasedTypeOnlyImport(stmt))
|
|
1376
2037
|
return stmt;
|
|
1377
|
-
if (ts.isExportDeclaration(stmt) && !stmt.isTypeOnly
|
|
2038
|
+
if (ts.isExportDeclaration(stmt) && !stmt.isTypeOnly) {
|
|
1378
2039
|
return stmt;
|
|
1379
2040
|
}
|
|
1380
2041
|
if (ts.isExportAssignment(stmt))
|
|
@@ -1385,7 +2046,7 @@ function nodeEsmSyntaxMarker7(sf) {
|
|
|
1385
2046
|
}
|
|
1386
2047
|
if (ts.isVariableStatement(stmt) &&
|
|
1387
2048
|
(stmt.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) !== 0) {
|
|
1388
|
-
for (const decl of stmt.declarationList.declarations) {
|
|
2049
|
+
for (const decl of stmt.declarationList.declarations.nodes) {
|
|
1389
2050
|
const hit = bindingDeclaresCjsWrapper7(decl.name);
|
|
1390
2051
|
if (hit !== null)
|
|
1391
2052
|
return hit;
|
|
@@ -1478,15 +2139,15 @@ function selfImportTdzFences7(program, sf, clause, diags) {
|
|
|
1478
2139
|
// The aliased declaration's TDZ horizon: the position after which reads
|
|
1479
2140
|
// are initialized. Hoisted functions have none.
|
|
1480
2141
|
const tdzEndOf = (aliased) => {
|
|
1481
|
-
const d =
|
|
1482
|
-
if (d === undefined ||
|
|
2142
|
+
const d = aliased.valueDeclaration ?? aliased.declarations[0];
|
|
2143
|
+
if (d === undefined || ts.getSourceFileOfNode(d) !== sf)
|
|
1483
2144
|
return null;
|
|
1484
2145
|
if (ts.isFunctionDeclaration(d))
|
|
1485
2146
|
return null;
|
|
1486
|
-
return d.
|
|
2147
|
+
return d.end;
|
|
1487
2148
|
};
|
|
1488
2149
|
const fence = (ref, name) => {
|
|
1489
|
-
diags.push(unsupportedDiag("SC1030", { file: sf.fileName, start:
|
|
2150
|
+
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)`));
|
|
1490
2151
|
};
|
|
1491
2152
|
const checkNamed = (bindingName) => {
|
|
1492
2153
|
const sym = checker.getSymbolAtLocation(bindingName);
|
|
@@ -1500,7 +2161,7 @@ function selfImportTdzFences7(program, sf, clause, diags) {
|
|
|
1500
2161
|
if (ts.isIdentifier(node) &&
|
|
1501
2162
|
node !== bindingName &&
|
|
1502
2163
|
node.text === bindingName.text &&
|
|
1503
|
-
|
|
2164
|
+
ts.tokenStartOfNode(node) < end &&
|
|
1504
2165
|
!insideFunction(node) &&
|
|
1505
2166
|
checker.getSymbolAtLocation(node) === sym) {
|
|
1506
2167
|
fence(node, bindingName.text);
|
|
@@ -1512,7 +2173,7 @@ function selfImportTdzFences7(program, sf, clause, diags) {
|
|
|
1512
2173
|
if (clause.name !== undefined)
|
|
1513
2174
|
checkNamed(clause.name);
|
|
1514
2175
|
if (clause.namedBindings !== undefined && ts.isNamedImports(clause.namedBindings)) {
|
|
1515
|
-
for (const el of clause.namedBindings.elements) {
|
|
2176
|
+
for (const el of clause.namedBindings.elements.nodes) {
|
|
1516
2177
|
if (!el.isTypeOnly)
|
|
1517
2178
|
checkNamed(el.name);
|
|
1518
2179
|
}
|
|
@@ -1533,7 +2194,7 @@ function selfImportTdzFences7(program, sf, clause, diags) {
|
|
|
1533
2194
|
const memberSym = checker.getSymbolAtLocation(node.name);
|
|
1534
2195
|
if (memberSym !== undefined) {
|
|
1535
2196
|
const end = tdzEndOf(memberSym);
|
|
1536
|
-
if (end !== null &&
|
|
2197
|
+
if (end !== null && ts.tokenStartOfNode(node) < end)
|
|
1537
2198
|
fence(node.expression, `${nsName.text}.${node.name.text}`);
|
|
1538
2199
|
}
|
|
1539
2200
|
}
|
|
@@ -1631,7 +2292,7 @@ function inTypePosition7(node) {
|
|
|
1631
2292
|
* coercion of a user object) disqualifies the module's cycles. */
|
|
1632
2293
|
function nonInertTopLevel7(program, sf) {
|
|
1633
2294
|
const nonInert = topLevelInertness7(program);
|
|
1634
|
-
for (const stmt of sf.statements) {
|
|
2295
|
+
for (const stmt of sf.statements.nodes) {
|
|
1635
2296
|
const offence = nonInert(stmt);
|
|
1636
2297
|
if (offence !== null)
|
|
1637
2298
|
return offence;
|
|
@@ -1676,10 +2337,10 @@ function topLevelInertness7(program) {
|
|
|
1676
2337
|
return false;
|
|
1677
2338
|
if (sym.flags & ts.SymbolFlags.Alias)
|
|
1678
2339
|
sym = checker.getAliasedSymbol(sym);
|
|
1679
|
-
const decls =
|
|
1680
|
-
return decls.length > 0 && decls.every((d) =>
|
|
2340
|
+
const decls = sym.declarations;
|
|
2341
|
+
return decls.length > 0 && decls.every((d) => ts.getSourceFileOfNode(d).isDeclarationFile);
|
|
1681
2342
|
};
|
|
1682
|
-
const hasDecorator = (n) => (n.modifiers ?? []).some((m) => m.kind === ts.SyntaxKind.Decorator);
|
|
2343
|
+
const hasDecorator = (n) => (n.modifiers?.nodes ?? []).some((m) => m.kind === ts.SyntaxKind.Decorator);
|
|
1683
2344
|
/** No function-like node anywhere in the subtree — arguments to builtin
|
|
1684
2345
|
* calls must not smuggle a callback the builtin could invoke. */
|
|
1685
2346
|
const containsFunctionLike = (n) => {
|
|
@@ -1696,14 +2357,14 @@ function topLevelInertness7(program) {
|
|
|
1696
2357
|
const inertClass = (c) => {
|
|
1697
2358
|
if (hasDecorator(c))
|
|
1698
2359
|
return c;
|
|
1699
|
-
for (const h of c.heritageClauses ?? []) {
|
|
2360
|
+
for (const h of c.heritageClauses?.nodes ?? []) {
|
|
1700
2361
|
if (h.token !== ts.SyntaxKind.ExtendsKeyword)
|
|
1701
2362
|
continue;
|
|
1702
|
-
for (const t of h.types)
|
|
2363
|
+
for (const t of h.types.nodes)
|
|
1703
2364
|
if (!inert(t.expression))
|
|
1704
2365
|
return t.expression;
|
|
1705
2366
|
}
|
|
1706
|
-
for (const m of c.members) {
|
|
2367
|
+
for (const m of c.members.nodes) {
|
|
1707
2368
|
if (ts.isClassStaticBlockDeclaration(m))
|
|
1708
2369
|
return m;
|
|
1709
2370
|
if (hasDecorator(m))
|
|
@@ -1760,7 +2421,7 @@ function topLevelInertness7(program) {
|
|
|
1760
2421
|
return dtsRooted(e) && inert(e.argumentExpression) && primitiveTyped(e.argumentExpression);
|
|
1761
2422
|
}
|
|
1762
2423
|
if (ts.isTemplateExpression(e)) {
|
|
1763
|
-
return e.templateSpans.every((s) => inert(s.expression) && primitiveTyped(s.expression));
|
|
2424
|
+
return e.templateSpans.nodes.every((s) => inert(s.expression) && primitiveTyped(s.expression));
|
|
1764
2425
|
}
|
|
1765
2426
|
if (ts.isVoidExpression(e) || ts.isTypeOfExpression(e))
|
|
1766
2427
|
return inert(e.expression);
|
|
@@ -1784,9 +2445,9 @@ function topLevelInertness7(program) {
|
|
|
1784
2445
|
if (ts.isConditionalExpression(e))
|
|
1785
2446
|
return inert(e.condition) && inert(e.whenTrue) && inert(e.whenFalse);
|
|
1786
2447
|
if (ts.isArrayLiteralExpression(e))
|
|
1787
|
-
return e.elements.every((el) => !ts.isSpreadElement(el) && inert(el));
|
|
2448
|
+
return e.elements.nodes.every((el) => !ts.isSpreadElement(el) && inert(el));
|
|
1788
2449
|
if (ts.isObjectLiteralExpression(e)) {
|
|
1789
|
-
return e.properties.every((p) => {
|
|
2450
|
+
return e.properties.nodes.every((p) => {
|
|
1790
2451
|
if (ts.isShorthandPropertyAssignment(p))
|
|
1791
2452
|
return true;
|
|
1792
2453
|
if (!ts.isPropertyAssignment(p) || ts.isComputedPropertyName(p.name))
|
|
@@ -1797,7 +2458,7 @@ function topLevelInertness7(program) {
|
|
|
1797
2458
|
if (ts.isCallExpression(e) || ts.isNewExpression(e)) {
|
|
1798
2459
|
if (!dtsRooted(e.expression) || !ts.isIdentifier(chainRoot7(e.expression)))
|
|
1799
2460
|
return false;
|
|
1800
|
-
const args = e.arguments ?? [];
|
|
2461
|
+
const args = e.arguments?.nodes ?? [];
|
|
1801
2462
|
// A CALLABLE argument is admissible when it is itself dts-rooted:
|
|
1802
2463
|
// a builtin-owned function value (the `promisify(fs.readFile)`
|
|
1803
2464
|
// at every cycle member's top level) is runtime-implemented — even
|
|
@@ -1824,12 +2485,12 @@ function topLevelInertness7(program) {
|
|
|
1824
2485
|
return null;
|
|
1825
2486
|
}
|
|
1826
2487
|
if (ts.isEnumDeclaration(stmt)) {
|
|
1827
|
-
return stmt.members.find((m) => m.initializer !== undefined && !inert(m.initializer)) ?? null;
|
|
2488
|
+
return (stmt.members.nodes.find((m) => m.initializer !== undefined && !inert(m.initializer)) ?? null);
|
|
1828
2489
|
}
|
|
1829
2490
|
if (ts.isClassDeclaration(stmt))
|
|
1830
2491
|
return inertClass(stmt);
|
|
1831
2492
|
if (ts.isVariableStatement(stmt)) {
|
|
1832
|
-
for (const d of stmt.declarationList.declarations) {
|
|
2493
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
1833
2494
|
if (!ts.isIdentifier(d.name))
|
|
1834
2495
|
return d.name; // patterns can invoke getters/iterators
|
|
1835
2496
|
if (d.initializer !== undefined && !inert(d.initializer))
|
|
@@ -1882,7 +2543,7 @@ function backEdgeUseOffence7(program, stmt, occurrences) {
|
|
|
1882
2543
|
if (ts.isNamespaceImport(clause.namedBindings))
|
|
1883
2544
|
bindingNames.push(clause.namedBindings.name);
|
|
1884
2545
|
else
|
|
1885
|
-
for (const el of clause.namedBindings.elements)
|
|
2546
|
+
for (const el of clause.namedBindings.elements.nodes)
|
|
1886
2547
|
if (!el.isTypeOnly)
|
|
1887
2548
|
bindingNames.push(el.name);
|
|
1888
2549
|
}
|
|
@@ -1947,8 +2608,8 @@ export function makeCycleAdmission(program, edgesOf) {
|
|
|
1947
2608
|
}
|
|
1948
2609
|
};
|
|
1949
2610
|
const lineOf = (node) => {
|
|
1950
|
-
const nsf =
|
|
1951
|
-
return `${nsf.fileName}:${ts.getLineAndCharacterOfPosition(nsf,
|
|
2611
|
+
const nsf = ts.getSourceFileOfNode(node);
|
|
2612
|
+
return `${nsf.fileName}:${ts.getLineAndCharacterOfPosition(nsf, ts.tokenStartOfNode(node)).line + 1}`;
|
|
1952
2613
|
};
|
|
1953
2614
|
// Cluster verdict memo (keyed by the component array identity): true
|
|
1954
2615
|
// when every member is an ES module passing the inert-top-level bar.
|
|
@@ -1979,13 +2640,26 @@ export function makeCycleAdmission(program, edgesOf) {
|
|
|
1979
2640
|
bindingUses.set(sf, uses);
|
|
1980
2641
|
return uses;
|
|
1981
2642
|
};
|
|
2643
|
+
// The CommonJS cluster verdict, same keying (cjsCycleRefusal7).
|
|
2644
|
+
const cjsVerdict = new Map();
|
|
1982
2645
|
return (importer, e) => {
|
|
1983
|
-
if (e.stmt === undefined)
|
|
1984
|
-
|
|
2646
|
+
if (e.stmt === undefined) {
|
|
2647
|
+
if (!index.has(importer))
|
|
2648
|
+
strongconnect(importer);
|
|
2649
|
+
const comp = sccOf.get(e.dep);
|
|
2650
|
+
if (comp === undefined || comp.length < 2 || !comp.includes(importer)) {
|
|
2651
|
+
return "the cycle closes through a require() edge";
|
|
2652
|
+
}
|
|
2653
|
+
if (!cjsVerdict.has(comp))
|
|
2654
|
+
cjsVerdict.set(comp, cjsCycleRefusal7(program, comp, lineOf));
|
|
2655
|
+
const reason = cjsVerdict.get(comp) ?? null;
|
|
2656
|
+
return reason === null ? null : `the cycle closes through a require() edge: ${reason}`;
|
|
2657
|
+
}
|
|
1985
2658
|
// Cheap per-edge admission: nothing readable binds through the edge.
|
|
1986
2659
|
if (ts.isImportDeclaration(e.stmt)) {
|
|
1987
2660
|
const clause = e.stmt.importClause;
|
|
1988
2661
|
if (clause === undefined ||
|
|
2662
|
+
typeOnlyNamedImport(e.stmt) ||
|
|
1989
2663
|
(clause.name === undefined &&
|
|
1990
2664
|
(clause.namedBindings === undefined ||
|
|
1991
2665
|
(ts.isNamespaceImport(clause.namedBindings) &&
|
|
@@ -2021,6 +2695,364 @@ export function makeCycleAdmission(program, edgesOf) {
|
|
|
2021
2695
|
return exactVerdict.get(comp) ?? null;
|
|
2022
2696
|
};
|
|
2023
2697
|
}
|
|
2698
|
+
/** The reason a strongly-connected cluster of CommonJS modules cannot be
|
|
2699
|
+
* initialized exactly through its require() cycle, or null when it can.
|
|
2700
|
+
* Node answers a require of a module that is still evaluating with that
|
|
2701
|
+
* module's exports object as it stands, while the compiled bindings alias
|
|
2702
|
+
* the exporter's final declarations. The two agree when:
|
|
2703
|
+
* - every member settles its exports before anything can enter the
|
|
2704
|
+
* cycle: all of its export statements come before its first top-level
|
|
2705
|
+
* statement that can run another module's code (a require, or anything
|
|
2706
|
+
* but literals, plain reads, function and class values, and
|
|
2707
|
+
* standard-library globals called with literal arguments), and every
|
|
2708
|
+
* other use of its export object is a plain member read; and
|
|
2709
|
+
* - no member's top-level code can reach its binding of another member,
|
|
2710
|
+
* so no member runs another member's code while the cluster is still
|
|
2711
|
+
* initializing. Each module then initializes exactly as it would
|
|
2712
|
+
* outside the cycle, and its own require bindings keep the acyclic
|
|
2713
|
+
* analysis (requireEarlyReference).
|
|
2714
|
+
* Other cycles keep the SC1016 fence. */
|
|
2715
|
+
function cjsCycleRefusal7(program, comp, lineOf) {
|
|
2716
|
+
const members = new Set(comp);
|
|
2717
|
+
const builtinRoot = (e) => {
|
|
2718
|
+
while (ts.isPropertyAccessExpression(e))
|
|
2719
|
+
e = e.expression;
|
|
2720
|
+
return ts.isIdentifier(e) && !sourceBinding7(program, e);
|
|
2721
|
+
};
|
|
2722
|
+
const literal = (e) => ts.isStringLiteralLike(e) ||
|
|
2723
|
+
ts.isNumericLiteral(e) ||
|
|
2724
|
+
ts.isRegularExpressionLiteral(e) ||
|
|
2725
|
+
e.kind === ts.SyntaxKind.TrueKeyword ||
|
|
2726
|
+
e.kind === ts.SyntaxKind.FalseKeyword ||
|
|
2727
|
+
e.kind === ts.SyntaxKind.NullKeyword;
|
|
2728
|
+
/** An expression whose evaluation runs no user code and requires
|
|
2729
|
+
* nothing: literals, plain reads, function and class values, literal
|
|
2730
|
+
* containers of those, and standard-library globals called with
|
|
2731
|
+
* literal arguments. */
|
|
2732
|
+
const inertExpr = (e) => {
|
|
2733
|
+
while (ts.isParenthesizedExpression(e))
|
|
2734
|
+
e = e.expression;
|
|
2735
|
+
if (literal(e) || ts.isIdentifier(e))
|
|
2736
|
+
return true;
|
|
2737
|
+
if (ts.isFunctionExpression(e) || ts.isArrowFunction(e))
|
|
2738
|
+
return true;
|
|
2739
|
+
if (ts.isClassExpression(e))
|
|
2740
|
+
return classSyncParts7(e).every(inertPart);
|
|
2741
|
+
if (ts.isObjectLiteralExpression(e)) {
|
|
2742
|
+
return e.properties.nodes.every((p) => ts.isShorthandPropertyAssignment(p)
|
|
2743
|
+
? true
|
|
2744
|
+
: ts.isPropertyAssignment(p)
|
|
2745
|
+
? !ts.isComputedPropertyName(p.name) && inertExpr(p.initializer)
|
|
2746
|
+
: (ts.isMethodDeclaration(p) ||
|
|
2747
|
+
ts.isGetAccessorDeclaration(p) ||
|
|
2748
|
+
ts.isSetAccessorDeclaration(p)) &&
|
|
2749
|
+
!ts.isComputedPropertyName(p.name));
|
|
2750
|
+
}
|
|
2751
|
+
if (ts.isArrayLiteralExpression(e)) {
|
|
2752
|
+
return e.elements.nodes.every((el) => !ts.isSpreadElement(el) && inertExpr(el));
|
|
2753
|
+
}
|
|
2754
|
+
if (ts.isPropertyAccessExpression(e))
|
|
2755
|
+
return builtinRoot(e);
|
|
2756
|
+
if (ts.isVoidExpression(e))
|
|
2757
|
+
return literal(e.expression);
|
|
2758
|
+
if (ts.isCallExpression(e) || ts.isNewExpression(e)) {
|
|
2759
|
+
return (requireSpecOf7(e) === null &&
|
|
2760
|
+
builtinRoot(e.expression) &&
|
|
2761
|
+
(e.arguments?.nodes ?? []).every(literal));
|
|
2762
|
+
}
|
|
2763
|
+
return false;
|
|
2764
|
+
};
|
|
2765
|
+
const inertPart = (part) => {
|
|
2766
|
+
if (ts.isHeritageClause(part))
|
|
2767
|
+
return part.types.nodes.every((t) => inertExpr(t.expression));
|
|
2768
|
+
if (ts.isComputedPropertyName(part))
|
|
2769
|
+
return inertExpr(part.expression);
|
|
2770
|
+
return ts.isExpression(part) && inertExpr(part);
|
|
2771
|
+
};
|
|
2772
|
+
const exportObject = (e) => (ts.isIdentifier(e) && e.text === "exports" && !sourceBinding7(program, e)) ||
|
|
2773
|
+
(isModuleExportsAccess(e) &&
|
|
2774
|
+
ts.isIdentifier(e.expression) &&
|
|
2775
|
+
!sourceBinding7(program, e.expression));
|
|
2776
|
+
/** A top-level statement that only publishes inert values. */
|
|
2777
|
+
const exportStatement = (stmt) => {
|
|
2778
|
+
if (!ts.isExpressionStatement(stmt))
|
|
2779
|
+
return false;
|
|
2780
|
+
if (isEsModuleStamp(stmt.expression))
|
|
2781
|
+
return true;
|
|
2782
|
+
const cjs = cjsExportAssignmentOf(stmt);
|
|
2783
|
+
if (cjs !== null) {
|
|
2784
|
+
let value = cjs.expr;
|
|
2785
|
+
while (ts.isBinaryExpression(value) &&
|
|
2786
|
+
value.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
2787
|
+
const left = value.left;
|
|
2788
|
+
if (!isModuleExportsAccess(left) &&
|
|
2789
|
+
!(ts.isPropertyAccessExpression(left) && exportObject(left.expression)))
|
|
2790
|
+
return false;
|
|
2791
|
+
value = value.right;
|
|
2792
|
+
}
|
|
2793
|
+
return inertExpr(value);
|
|
2794
|
+
}
|
|
2795
|
+
const call = stmt.expression;
|
|
2796
|
+
return (ts.isCallExpression(call) &&
|
|
2797
|
+
ts.isPropertyAccessExpression(call.expression) &&
|
|
2798
|
+
ts.isIdentifier(call.expression.expression) &&
|
|
2799
|
+
call.expression.expression.text === "Object" &&
|
|
2800
|
+
!sourceBinding7(program, call.expression.expression) &&
|
|
2801
|
+
call.expression.name.text === "defineProperty" &&
|
|
2802
|
+
call.arguments.nodes.length === 3 &&
|
|
2803
|
+
exportObject(call.arguments.nodes[0]) &&
|
|
2804
|
+
ts.isStringLiteralLike(call.arguments.nodes[1]) &&
|
|
2805
|
+
inertExpr(call.arguments.nodes[2]));
|
|
2806
|
+
};
|
|
2807
|
+
for (const m of comp) {
|
|
2808
|
+
if (!isCjsJsFile7(m, program)) {
|
|
2809
|
+
return `${m.fileName} is not a CommonJS module — require cycles are admitted between CommonJS modules only`;
|
|
2810
|
+
}
|
|
2811
|
+
const stmts = m.statements.nodes;
|
|
2812
|
+
// The first statement that can run another module's code.
|
|
2813
|
+
let firstEntry = stmts.length;
|
|
2814
|
+
for (let i = 0; i < stmts.length; i++) {
|
|
2815
|
+
const st = stmts[i];
|
|
2816
|
+
const inert = ts.isFunctionDeclaration(st) ||
|
|
2817
|
+
ts.isEmptyStatement(st) ||
|
|
2818
|
+
(ts.isExpressionStatement(st) && ts.isStringLiteral(st.expression)) ||
|
|
2819
|
+
(ts.isClassDeclaration(st) && classSyncParts7(st).every(inertPart)) ||
|
|
2820
|
+
(ts.isVariableStatement(st) &&
|
|
2821
|
+
st.declarationList.declarations.nodes.every((d) => ts.isIdentifier(d.name) && (d.initializer === undefined || inertExpr(d.initializer)))) ||
|
|
2822
|
+
exportStatement(st);
|
|
2823
|
+
if (!inert) {
|
|
2824
|
+
firstEntry = i;
|
|
2825
|
+
break;
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
// Every other use of the export object must be a plain member read:
|
|
2829
|
+
// anything else can change what a module of the cycle observes.
|
|
2830
|
+
let stray = null;
|
|
2831
|
+
const settled = new Set(stmts.slice(0, firstEntry).filter(exportStatement));
|
|
2832
|
+
// A bundler export table the rewrite certified (npmStaticLiveExportTable)
|
|
2833
|
+
// stands for the live getter object the original installed before its
|
|
2834
|
+
// first require: the tail table settles as if it ran there.
|
|
2835
|
+
const tail = stmts[stmts.length - 1];
|
|
2836
|
+
if (tail !== undefined &&
|
|
2837
|
+
npmStaticLiveExportTable(m.fileName) &&
|
|
2838
|
+
cjsExportAssignmentOf(tail)?.kind === "table")
|
|
2839
|
+
settled.add(tail);
|
|
2840
|
+
ts.walkPreorder(m, (n) => {
|
|
2841
|
+
if (stray !== null)
|
|
2842
|
+
return "stop";
|
|
2843
|
+
if (ts.isStatement(n) && settled.has(n))
|
|
2844
|
+
return "skip";
|
|
2845
|
+
let use = null;
|
|
2846
|
+
if (n.kind === ts.SyntaxKind.ThisKeyword) {
|
|
2847
|
+
let moduleThis = true;
|
|
2848
|
+
for (let p = n.parent; p !== undefined && !ts.isSourceFile(p); p = p.parent) {
|
|
2849
|
+
if ((ts.isFunctionLike(p) && !ts.isArrowFunction(p)) ||
|
|
2850
|
+
ts.isClassDeclaration(p) ||
|
|
2851
|
+
ts.isClassExpression(p)) {
|
|
2852
|
+
moduleThis = false;
|
|
2853
|
+
break;
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
if (moduleThis)
|
|
2857
|
+
use = n;
|
|
2858
|
+
}
|
|
2859
|
+
else if (ts.isIdentifier(n) &&
|
|
2860
|
+
(n.text === "exports" || n.text === "module") &&
|
|
2861
|
+
!(ts.isPropertyAccessExpression(n.parent) && n.parent.name === n) &&
|
|
2862
|
+
!sourceBinding7(program, n)) {
|
|
2863
|
+
if (n.text === "exports")
|
|
2864
|
+
use = n;
|
|
2865
|
+
else if (!ts.isPropertyAccessExpression(n.parent) || n.parent.expression !== n)
|
|
2866
|
+
stray = n;
|
|
2867
|
+
else if (n.parent.name.text === "exports")
|
|
2868
|
+
use = n.parent;
|
|
2869
|
+
}
|
|
2870
|
+
if (use === null)
|
|
2871
|
+
return undefined;
|
|
2872
|
+
const parent = use.parent;
|
|
2873
|
+
const read = ts.isPropertyAccessExpression(parent) &&
|
|
2874
|
+
parent.expression === use &&
|
|
2875
|
+
!(ts.isBinaryExpression(parent.parent) &&
|
|
2876
|
+
parent.parent.left === parent &&
|
|
2877
|
+
parent.parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&
|
|
2878
|
+
parent.parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment) &&
|
|
2879
|
+
!(ts.isCallExpression(parent.parent) && parent.parent.expression === parent) &&
|
|
2880
|
+
!ts.isDeleteExpression(parent.parent);
|
|
2881
|
+
if (!read)
|
|
2882
|
+
stray = use;
|
|
2883
|
+
return undefined;
|
|
2884
|
+
});
|
|
2885
|
+
if (stray !== null) {
|
|
2886
|
+
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`;
|
|
2887
|
+
}
|
|
2888
|
+
// Bindings of other members must stay unreachable from top-level code.
|
|
2889
|
+
for (const st of stmts) {
|
|
2890
|
+
for (const req of requiresOf7(st)) {
|
|
2891
|
+
if (req.decl === null)
|
|
2892
|
+
continue;
|
|
2893
|
+
const dep = resolveImport7(program, m, req.spec, "require");
|
|
2894
|
+
if (dep === null || !members.has(dep))
|
|
2895
|
+
continue;
|
|
2896
|
+
const reached = requireBindingEarlyUse7(program, m, stmts.length, req.decl, [], (id) => functionExportRead7(id, dep));
|
|
2897
|
+
if (reached !== null) {
|
|
2898
|
+
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`;
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
return null;
|
|
2904
|
+
}
|
|
2905
|
+
/** True when `use` initializes a top-level const whose every other
|
|
2906
|
+
* reference is a value of an export statement (`module.exports = { … }`
|
|
2907
|
+
* or `exports.n = …`). */
|
|
2908
|
+
function publishedAlias7(use, decl) {
|
|
2909
|
+
if (decl === undefined ||
|
|
2910
|
+
!ts.isVariableDeclaration(decl) ||
|
|
2911
|
+
decl.initializer !== use ||
|
|
2912
|
+
!ts.isIdentifier(decl.name))
|
|
2913
|
+
return false;
|
|
2914
|
+
const list = decl.parent;
|
|
2915
|
+
const stmt = list?.parent;
|
|
2916
|
+
const sf = stmt?.parent;
|
|
2917
|
+
if (list === undefined ||
|
|
2918
|
+
(list.flags & ts.NodeFlags.Const) === 0 ||
|
|
2919
|
+
stmt === undefined ||
|
|
2920
|
+
!ts.isVariableStatement(stmt) ||
|
|
2921
|
+
sf === undefined ||
|
|
2922
|
+
!ts.isSourceFile(sf))
|
|
2923
|
+
return false;
|
|
2924
|
+
const alias = decl.name;
|
|
2925
|
+
const published = new Set();
|
|
2926
|
+
for (const st of sf.statements.nodes) {
|
|
2927
|
+
const cjs = cjsExportAssignmentOf(st);
|
|
2928
|
+
if (cjs === null)
|
|
2929
|
+
continue;
|
|
2930
|
+
if (cjs.kind === "member")
|
|
2931
|
+
published.add(cjs.value);
|
|
2932
|
+
else if (cjs.obj !== null) {
|
|
2933
|
+
for (const p of cjs.obj.properties.nodes) {
|
|
2934
|
+
if (ts.isPropertyAssignment(p) && !ts.isComputedPropertyName(p.name))
|
|
2935
|
+
published.add(p.initializer);
|
|
2936
|
+
else if (ts.isShorthandPropertyAssignment(p))
|
|
2937
|
+
published.add(p.name);
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
let kept = false;
|
|
2942
|
+
ts.walkPreorder(sf, (n) => {
|
|
2943
|
+
if (kept)
|
|
2944
|
+
return "stop";
|
|
2945
|
+
if (!ts.isIdentifier(n) || n === alias || n.text !== alias.text)
|
|
2946
|
+
return undefined;
|
|
2947
|
+
const p = n.parent;
|
|
2948
|
+
if (p !== undefined &&
|
|
2949
|
+
((ts.isPropertyAccessExpression(p) && p.name === n) ||
|
|
2950
|
+
(ts.isPropertyAssignment(p) && p.name === n)))
|
|
2951
|
+
return undefined;
|
|
2952
|
+
if (!published.has(n))
|
|
2953
|
+
kept = true;
|
|
2954
|
+
return undefined;
|
|
2955
|
+
});
|
|
2956
|
+
return !kept;
|
|
2957
|
+
}
|
|
2958
|
+
/** True for a plain read `binding.name` (not a call, not a write, not a
|
|
2959
|
+
* value that is stored or passed on) of the cycle member `dep` whose
|
|
2960
|
+
* export `name` is a top-level function declaration nothing reassigns.
|
|
2961
|
+
* Every member settles its exports before entering the cycle, so Node
|
|
2962
|
+
* reads that same function whenever the read runs, and the compiled read
|
|
2963
|
+
* resolves to the declaration itself. */
|
|
2964
|
+
function functionExportRead7(id, dep) {
|
|
2965
|
+
const access = id.parent;
|
|
2966
|
+
if (!ts.isPropertyAccessExpression(access) || access.expression !== id)
|
|
2967
|
+
return false;
|
|
2968
|
+
// The value the read yields: through parentheses and the right operand
|
|
2969
|
+
// of a comma, so `(0, binding.name)(...)` is the call it spells.
|
|
2970
|
+
let use = access;
|
|
2971
|
+
for (;;) {
|
|
2972
|
+
const p = use.parent;
|
|
2973
|
+
if (ts.isParenthesizedExpression(p))
|
|
2974
|
+
use = p;
|
|
2975
|
+
else if (ts.isBinaryExpression(p) &&
|
|
2976
|
+
p.operatorToken.kind === ts.SyntaxKind.CommaToken &&
|
|
2977
|
+
p.right === use)
|
|
2978
|
+
use = p;
|
|
2979
|
+
else
|
|
2980
|
+
break;
|
|
2981
|
+
}
|
|
2982
|
+
const parent = use.parent;
|
|
2983
|
+
// Only a use that neither runs the function nor keeps it is a read: a
|
|
2984
|
+
// stored alias (`const f = binding.name`, `{ f: binding.name }`) or an
|
|
2985
|
+
// argument can be called while the cycle initializes. A top-level const
|
|
2986
|
+
// that only publishes it (`module.exports = { name: f }`, the static
|
|
2987
|
+
// rewrite's re-export spelling) runs nothing: a module that reads the
|
|
2988
|
+
// export back checks that read itself.
|
|
2989
|
+
const observes = publishedAlias7(use, parent) ||
|
|
2990
|
+
ts.isExpressionStatement(parent) ||
|
|
2991
|
+
ts.isTypeOfExpression(parent) ||
|
|
2992
|
+
ts.isVoidExpression(parent) ||
|
|
2993
|
+
(ts.isPrefixUnaryExpression(parent) && parent.operator === ts.SyntaxKind.ExclamationToken) ||
|
|
2994
|
+
(ts.isBinaryExpression(parent) &&
|
|
2995
|
+
(parent.operatorToken.kind === ts.SyntaxKind.EqualsEqualsEqualsToken ||
|
|
2996
|
+
parent.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsEqualsToken ||
|
|
2997
|
+
parent.operatorToken.kind === ts.SyntaxKind.EqualsEqualsToken ||
|
|
2998
|
+
parent.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsToken)) ||
|
|
2999
|
+
((ts.isIfStatement(parent) || ts.isWhileStatement(parent) || ts.isDoStatement(parent)) &&
|
|
3000
|
+
parent.expression === use) ||
|
|
3001
|
+
(ts.isConditionalExpression(parent) && parent.condition === use);
|
|
3002
|
+
if (!observes)
|
|
3003
|
+
return false;
|
|
3004
|
+
const name = access.name.text;
|
|
3005
|
+
// The exported value's identifier: a table entry or a member export.
|
|
3006
|
+
const values = [];
|
|
3007
|
+
for (const stmt of dep.statements.nodes) {
|
|
3008
|
+
if (!ts.isExpressionStatement(stmt) || !ts.isBinaryExpression(stmt.expression))
|
|
3009
|
+
continue;
|
|
3010
|
+
const e = stmt.expression;
|
|
3011
|
+
if (e.operatorToken.kind !== ts.SyntaxKind.EqualsToken)
|
|
3012
|
+
continue;
|
|
3013
|
+
if (isModuleExportsAccess(e.left)) {
|
|
3014
|
+
if (!ts.isObjectLiteralExpression(e.right))
|
|
3015
|
+
return false;
|
|
3016
|
+
for (const p of e.right.properties.nodes) {
|
|
3017
|
+
if (ts.isSpreadAssignment(p))
|
|
3018
|
+
return false;
|
|
3019
|
+
if (ts.isShorthandPropertyAssignment(p) && p.name.text === name)
|
|
3020
|
+
values.push(p.name);
|
|
3021
|
+
else if (ts.isPropertyAssignment(p) &&
|
|
3022
|
+
(ts.isIdentifier(p.name) || ts.isStringLiteral(p.name)) &&
|
|
3023
|
+
p.name.text === name)
|
|
3024
|
+
values.push(p.initializer);
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
else if (ts.isPropertyAccessExpression(e.left) &&
|
|
3028
|
+
e.left.name.text === name &&
|
|
3029
|
+
((ts.isIdentifier(e.left.expression) && e.left.expression.text === "exports") ||
|
|
3030
|
+
isModuleExportsAccess(e.left.expression))) {
|
|
3031
|
+
values.push(e.right);
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
const value = values.length === 1 ? values[0] : null;
|
|
3035
|
+
if (value === null || !ts.isIdentifier(value))
|
|
3036
|
+
return false;
|
|
3037
|
+
const fnName = value.text;
|
|
3038
|
+
if (!dep.statements.nodes.some((st) => ts.isFunctionDeclaration(st) && st.name?.text === fnName && st.body !== undefined))
|
|
3039
|
+
return false;
|
|
3040
|
+
let rebound = false;
|
|
3041
|
+
ts.walkPreorder(dep, (n) => {
|
|
3042
|
+
if (rebound)
|
|
3043
|
+
return "stop";
|
|
3044
|
+
if ((ts.isBinaryExpression(n) &&
|
|
3045
|
+
ts.isIdentifier(n.left) &&
|
|
3046
|
+
n.left.text === fnName &&
|
|
3047
|
+
n.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&
|
|
3048
|
+
n.operatorToken.kind <= ts.SyntaxKind.LastAssignment) ||
|
|
3049
|
+
(ts.isVariableDeclaration(n) && ts.isIdentifier(n.name) && n.name.text === fnName) ||
|
|
3050
|
+
(ts.isFunctionDeclaration(n) && n.name?.text === fnName && !ts.isSourceFile(n.parent)))
|
|
3051
|
+
rebound = true;
|
|
3052
|
+
return undefined;
|
|
3053
|
+
});
|
|
3054
|
+
return !rebound;
|
|
3055
|
+
}
|
|
2024
3056
|
/* ── exact cyclic initialization ─────────────────────────────────────────
|
|
2025
3057
|
* Cycles that fail the declaration-only rule still evaluate exactly like
|
|
2026
3058
|
* Node when their shape is representable: the guarded %init calls already
|
|
@@ -2064,7 +3096,7 @@ function exactCycleRefusal7(program, comp, lineOf) {
|
|
|
2064
3096
|
const spec = stmt.moduleSpecifier;
|
|
2065
3097
|
if (spec === undefined || !ts.isStringLiteral(spec))
|
|
2066
3098
|
return null;
|
|
2067
|
-
const sf =
|
|
3099
|
+
const sf = ts.getSourceFileOfNode(stmt);
|
|
2068
3100
|
return resolveImport7(program, sf, spec.text) ?? npmStaticDepSf7(program, sf, spec.text);
|
|
2069
3101
|
};
|
|
2070
3102
|
for (const m of comp) {
|
|
@@ -2074,7 +3106,7 @@ function exactCycleRefusal7(program, comp, lineOf) {
|
|
|
2074
3106
|
if (hasTopLevelAwait7(m)) {
|
|
2075
3107
|
return `${m.fileName} uses top-level await inside the cycle`;
|
|
2076
3108
|
}
|
|
2077
|
-
for (const stmt of m.statements) {
|
|
3109
|
+
for (const stmt of m.statements.nodes) {
|
|
2078
3110
|
if (ts.isExportAssignment(stmt) && !stmt.isExportEquals) {
|
|
2079
3111
|
return `the default export expression at ${lineOf(stmt)} has no initialization state inside the cycle`;
|
|
2080
3112
|
}
|
|
@@ -2222,7 +3254,7 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2222
3254
|
const names = new Set();
|
|
2223
3255
|
let dirty = !known;
|
|
2224
3256
|
evaluation.forEach((m, rank) => {
|
|
2225
|
-
for (const stmt of m.statements) {
|
|
3257
|
+
for (const stmt of m.statements.nodes) {
|
|
2226
3258
|
const offence = nonInert(stmt);
|
|
2227
3259
|
const exposed = dirty || offence !== null;
|
|
2228
3260
|
const declared = [];
|
|
@@ -2231,7 +3263,7 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2231
3263
|
ts.ModifierFlags.Ambient) ===
|
|
2232
3264
|
0) {
|
|
2233
3265
|
const lexical = (stmt.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) !== 0;
|
|
2234
|
-
for (const d of stmt.declarationList.declarations) {
|
|
3266
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
2235
3267
|
for (const name of boundNames7(d.name)) {
|
|
2236
3268
|
declared.push({ name, kind: lexical ? "lexical" : "var" });
|
|
2237
3269
|
}
|
|
@@ -2251,8 +3283,8 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2251
3283
|
module: m,
|
|
2252
3284
|
exposed,
|
|
2253
3285
|
rank,
|
|
2254
|
-
start:
|
|
2255
|
-
end: stmt.
|
|
3286
|
+
start: ts.tokenStartOfNode(stmt),
|
|
3287
|
+
end: stmt.end,
|
|
2256
3288
|
reference: null,
|
|
2257
3289
|
folded: null,
|
|
2258
3290
|
});
|
|
@@ -2304,14 +3336,14 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2304
3336
|
// A class body names its own inner binding, initialized throughout.
|
|
2305
3337
|
if (c.kind === "class" &&
|
|
2306
3338
|
sf === c.module &&
|
|
2307
|
-
|
|
2308
|
-
ref.
|
|
3339
|
+
ts.tokenStartOfNode(ref) >= c.start &&
|
|
3340
|
+
ref.end <= c.end)
|
|
2309
3341
|
continue;
|
|
2310
3342
|
let early;
|
|
2311
3343
|
if (inDeferredPosition7(ref))
|
|
2312
3344
|
early = c.exposed;
|
|
2313
3345
|
else if (sf === c.module)
|
|
2314
|
-
early =
|
|
3346
|
+
early = ts.tokenStartOfNode(ref) < c.start;
|
|
2315
3347
|
else if (!memberSet.has(sf) || !rankOf.has(sf))
|
|
2316
3348
|
early = false;
|
|
2317
3349
|
else
|
|
@@ -2405,7 +3437,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2405
3437
|
immediate.set(e, classSyncParts7(e));
|
|
2406
3438
|
}
|
|
2407
3439
|
else if (ts.isObjectLiteralExpression(e)) {
|
|
2408
|
-
for (const p of e.properties) {
|
|
3440
|
+
for (const p of e.properties.nodes) {
|
|
2409
3441
|
if (ts.isMethodDeclaration(p) ||
|
|
2410
3442
|
ts.isGetAccessorDeclaration(p) ||
|
|
2411
3443
|
ts.isSetAccessorDeclaration(p)) {
|
|
@@ -2423,14 +3455,14 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2423
3455
|
}
|
|
2424
3456
|
}
|
|
2425
3457
|
else if (ts.isArrayLiteralExpression(e)) {
|
|
2426
|
-
for (const el of e.elements)
|
|
3458
|
+
for (const el of e.elements.nodes)
|
|
2427
3459
|
if (!ts.isSpreadElement(el))
|
|
2428
3460
|
storedIn(el, units);
|
|
2429
3461
|
}
|
|
2430
3462
|
else if (ts.isCallExpression(e)) {
|
|
2431
3463
|
// `const f = wrap(callback)` where wrap only returns closures over
|
|
2432
3464
|
// the callback: it runs when the stored result is called.
|
|
2433
|
-
e.arguments.forEach((arg, index) => {
|
|
3465
|
+
e.arguments.nodes.forEach((arg, index) => {
|
|
2434
3466
|
let fn = arg;
|
|
2435
3467
|
while (ts.isParenthesizedExpression(fn))
|
|
2436
3468
|
fn = fn.expression;
|
|
@@ -2440,7 +3472,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2440
3472
|
});
|
|
2441
3473
|
}
|
|
2442
3474
|
};
|
|
2443
|
-
sf.statements.forEach((stmt, index) => {
|
|
3475
|
+
sf.statements.nodes.forEach((stmt, index) => {
|
|
2444
3476
|
if (ambient(stmt))
|
|
2445
3477
|
return;
|
|
2446
3478
|
if (ts.isFunctionDeclaration(stmt) && stmt.name !== undefined && stmt.body !== undefined) {
|
|
@@ -2448,12 +3480,12 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2448
3480
|
}
|
|
2449
3481
|
else if (ts.isClassDeclaration(stmt) && stmt.name !== undefined) {
|
|
2450
3482
|
store(stmt.name, [stmt]);
|
|
2451
|
-
candidates.push({ name: stmt.name, index, start:
|
|
3483
|
+
candidates.push({ name: stmt.name, index, start: ts.tokenStartOfNode(stmt), cls: stmt });
|
|
2452
3484
|
candidateNames.add(stmt.name.text);
|
|
2453
3485
|
}
|
|
2454
3486
|
else if (ts.isVariableStatement(stmt)) {
|
|
2455
3487
|
const lexical = (stmt.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) !== 0;
|
|
2456
|
-
for (const d of stmt.declarationList.declarations) {
|
|
3488
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
2457
3489
|
if (ts.isIdentifier(d.name) && d.initializer !== undefined) {
|
|
2458
3490
|
const units = [];
|
|
2459
3491
|
storedIn(d.initializer, units);
|
|
@@ -2462,7 +3494,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2462
3494
|
if (!lexical)
|
|
2463
3495
|
continue;
|
|
2464
3496
|
for (const name of boundNames7(d.name)) {
|
|
2465
|
-
candidates.push({ name, index, start:
|
|
3497
|
+
candidates.push({ name, index, start: ts.tokenStartOfNode(stmt) });
|
|
2466
3498
|
candidateNames.add(name.text);
|
|
2467
3499
|
}
|
|
2468
3500
|
}
|
|
@@ -2505,7 +3537,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2505
3537
|
if (ts.isArrowFunction(e) || ts.isFunctionExpression(e))
|
|
2506
3538
|
stored.add(e);
|
|
2507
3539
|
else if (ts.isObjectLiteralExpression(e)) {
|
|
2508
|
-
for (const p of e.properties) {
|
|
3540
|
+
for (const p of e.properties.nodes) {
|
|
2509
3541
|
if (ts.isMethodDeclaration(p))
|
|
2510
3542
|
stored.add(p);
|
|
2511
3543
|
else if (ts.isPropertyAssignment(p))
|
|
@@ -2516,7 +3548,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2516
3548
|
ts.walkPreorder(sf, (node) => {
|
|
2517
3549
|
if ((ts.isCallExpression(node) || ts.isNewExpression(node)) &&
|
|
2518
3550
|
laterJobCallee7(checker, node.expression)) {
|
|
2519
|
-
for (const arg of node.arguments ?? [])
|
|
3551
|
+
for (const arg of node.arguments?.nodes ?? [])
|
|
2520
3552
|
callbacks(arg);
|
|
2521
3553
|
}
|
|
2522
3554
|
return undefined;
|
|
@@ -2568,8 +3600,8 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2568
3600
|
if (c !== undefined &&
|
|
2569
3601
|
node !== c.name &&
|
|
2570
3602
|
!reachedRefs.has(symbol) &&
|
|
2571
|
-
!(c.cls !== undefined &&
|
|
2572
|
-
if (inDeferredPosition7(node) ||
|
|
3603
|
+
!(c.cls !== undefined && ts.tokenStartOfNode(node) >= c.cls.pos && node.end <= c.cls.end)) {
|
|
3604
|
+
if (inDeferredPosition7(node) || ts.tokenStartOfNode(node) < c.start)
|
|
2573
3605
|
reachedRefs.set(symbol, node);
|
|
2574
3606
|
}
|
|
2575
3607
|
for (const unit of unitsBySymbol.get(symbol) ?? []) {
|
|
@@ -2590,8 +3622,8 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2590
3622
|
let next = 0;
|
|
2591
3623
|
const report = (declaration) => {
|
|
2592
3624
|
while (next < candidates.length &&
|
|
2593
|
-
candidates[next].name
|
|
2594
|
-
candidates[next].name.
|
|
3625
|
+
ts.tokenStartOfNode(candidates[next].name) >= ts.tokenStartOfNode(declaration) &&
|
|
3626
|
+
candidates[next].name.end <= declaration.end) {
|
|
2595
3627
|
const c = candidates[next++];
|
|
2596
3628
|
const symbol = checker.getSymbolAtLocation(c.name);
|
|
2597
3629
|
const reference = symbol === undefined ? undefined : reachedRefs.get(symbol);
|
|
@@ -2607,7 +3639,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2607
3639
|
});
|
|
2608
3640
|
}
|
|
2609
3641
|
};
|
|
2610
|
-
for (const stmt of sf.statements) {
|
|
3642
|
+
for (const stmt of sf.statements.nodes) {
|
|
2611
3643
|
if (ts.isClassDeclaration(stmt)) {
|
|
2612
3644
|
// The binding initializes once the class definition, static
|
|
2613
3645
|
// initializers included, has run.
|
|
@@ -2619,7 +3651,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2619
3651
|
else if (ts.isVariableStatement(stmt)) {
|
|
2620
3652
|
// Declarators run in order: a later declarator's initializer cannot
|
|
2621
3653
|
// observe an earlier binding before it was initialized.
|
|
2622
|
-
for (const d of stmt.declarationList.declarations) {
|
|
3654
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
2623
3655
|
visit(d);
|
|
2624
3656
|
drain();
|
|
2625
3657
|
report(d);
|
|
@@ -2649,11 +3681,11 @@ function returnsOnlyClosuresOver7(checker, callee, index) {
|
|
|
2649
3681
|
if (symbol !== undefined && symbol.flags & ts.SymbolFlags.Alias) {
|
|
2650
3682
|
symbol = checker.getAliasedSymbol(symbol);
|
|
2651
3683
|
}
|
|
2652
|
-
const decls = symbol === undefined ? [] :
|
|
3684
|
+
const decls = symbol === undefined ? [] : symbol.declarations;
|
|
2653
3685
|
if (decls.length !== 1)
|
|
2654
3686
|
return false;
|
|
2655
3687
|
const decl = decls[0];
|
|
2656
|
-
if (
|
|
3688
|
+
if (ts.getSourceFileOfNode(decl).isDeclarationFile)
|
|
2657
3689
|
return false;
|
|
2658
3690
|
let fn;
|
|
2659
3691
|
if (ts.isFunctionDeclaration(decl))
|
|
@@ -2669,12 +3701,12 @@ function returnsOnlyClosuresOver7(checker, callee, index) {
|
|
|
2669
3701
|
return false;
|
|
2670
3702
|
const like = fn;
|
|
2671
3703
|
const body = like.body;
|
|
2672
|
-
const param = like.parameters[index];
|
|
3704
|
+
const param = like.parameters.nodes[index];
|
|
2673
3705
|
if (body === undefined || !ts.isBlock(body) || param === undefined)
|
|
2674
3706
|
return false;
|
|
2675
3707
|
if (!ts.isIdentifier(param.name) || param.dotDotDotToken !== undefined)
|
|
2676
3708
|
return false;
|
|
2677
|
-
if (like.parameters.slice(0, index).some((p) => p.dotDotDotToken !== undefined))
|
|
3709
|
+
if (like.parameters.nodes.slice(0, index).some((p) => p.dotDotDotToken !== undefined))
|
|
2678
3710
|
return false;
|
|
2679
3711
|
const paramName = param.name.text;
|
|
2680
3712
|
let deferred = true;
|
|
@@ -2722,9 +3754,9 @@ function returnsOnlyClosuresOver7(checker, callee, index) {
|
|
|
2722
3754
|
* initializers and static blocks. Methods and instance fields wait for a
|
|
2723
3755
|
* call or a construction. */
|
|
2724
3756
|
function classSyncParts7(c) {
|
|
2725
|
-
const decorators = (n) => (n.modifiers ?? []).filter((m) => m.kind === ts.SyntaxKind.Decorator);
|
|
2726
|
-
const parts = [...decorators(c), ...(c.heritageClauses ?? [])];
|
|
2727
|
-
for (const m of c.members) {
|
|
3757
|
+
const decorators = (n) => (n.modifiers?.nodes ?? []).filter((m) => m.kind === ts.SyntaxKind.Decorator);
|
|
3758
|
+
const parts = [...decorators(c), ...(c.heritageClauses?.nodes ?? [])];
|
|
3759
|
+
for (const m of c.members.nodes) {
|
|
2728
3760
|
parts.push(...decorators(m));
|
|
2729
3761
|
const memberName = m.name;
|
|
2730
3762
|
if (memberName !== undefined && ts.isComputedPropertyName(memberName))
|
|
@@ -2783,15 +3815,15 @@ function laterJobCallee7(checker, callee) {
|
|
|
2783
3815
|
}
|
|
2784
3816
|
if (symbol === undefined)
|
|
2785
3817
|
return false;
|
|
2786
|
-
const decls =
|
|
2787
|
-
if (decls.length === 0 || !decls.every((d) =>
|
|
3818
|
+
const decls = symbol.declarations;
|
|
3819
|
+
if (decls.length === 0 || !decls.every((d) => ts.getSourceFileOfNode(d).isDeclarationFile))
|
|
2788
3820
|
return false;
|
|
2789
3821
|
if (LATER_JOB_BUILTINS7.has(name.text))
|
|
2790
3822
|
return true;
|
|
2791
3823
|
// The JavaScript standard library's callbacks mostly run synchronously;
|
|
2792
3824
|
// package declarations describe user code.
|
|
2793
3825
|
return decls.every((d) => {
|
|
2794
|
-
const file =
|
|
3826
|
+
const file = ts.getSourceFileOfNode(d).fileName;
|
|
2795
3827
|
return isNodeTypesPath(file) || file === fallbackDtsPath();
|
|
2796
3828
|
});
|
|
2797
3829
|
}
|
|
@@ -2854,7 +3886,7 @@ function boundNames7(name) {
|
|
|
2854
3886
|
if (ts.isIdentifier(name))
|
|
2855
3887
|
return [name];
|
|
2856
3888
|
const out = [];
|
|
2857
|
-
for (const el of name.elements) {
|
|
3889
|
+
for (const el of name.elements.nodes) {
|
|
2858
3890
|
if (ts.isOmittedExpression(el) || el.name === undefined)
|
|
2859
3891
|
continue;
|
|
2860
3892
|
out.push(...boundNames7(el.name));
|
|
@@ -2869,7 +3901,7 @@ function typeOnlyNamespace7(decl) {
|
|
|
2869
3901
|
body = body.body;
|
|
2870
3902
|
if (body === undefined || !ts.isModuleBlock(body))
|
|
2871
3903
|
return true;
|
|
2872
|
-
return body.statements.every((s) => ts.isInterfaceDeclaration(s) ||
|
|
3904
|
+
return body.statements.nodes.every((s) => ts.isInterfaceDeclaration(s) ||
|
|
2873
3905
|
ts.isTypeAliasDeclaration(s) ||
|
|
2874
3906
|
(ts.isModuleDeclaration(s) && typeOnlyNamespace7(s)));
|
|
2875
3907
|
}
|
|
@@ -2890,6 +3922,13 @@ function resolveNpmImport7(fromFileName, specifier, resolutionKind = "import") {
|
|
|
2890
3922
|
if (isRelativeSpecifier(specifier) || specifier.startsWith("node:")) {
|
|
2891
3923
|
return null;
|
|
2892
3924
|
}
|
|
3925
|
+
// Node resolves a bare core-module name (`string_decoder`, `events`,
|
|
3926
|
+
// `fs/promises`) to the builtin before it looks in node_modules, so an
|
|
3927
|
+
// installed npm package of the same name never answers it. Prefix-only
|
|
3928
|
+
// builtins (`node:test`) are listed with their prefix, so a bare `test`
|
|
3929
|
+
// still names the package.
|
|
3930
|
+
if (nodeBuiltinNames.has(specifier))
|
|
3931
|
+
return null;
|
|
2893
3932
|
// --provenance-sources: a registered specifier is NOT an npm import —
|
|
2894
3933
|
// its attested source compiles as program modules (resolveProjectModule
|
|
2895
3934
|
if (provenanceEntryFor(specifier) !== null)
|
|
@@ -2916,18 +3955,12 @@ function resolveNpmImport7(fromFileName, specifier, resolutionKind = "import") {
|
|
|
2916
3955
|
};
|
|
2917
3956
|
}
|
|
2918
3957
|
function locOf7(node) {
|
|
2919
|
-
const sf =
|
|
2920
|
-
return { file: sf.fileName, start:
|
|
3958
|
+
const sf = ts.getSourceFileOfNode(node);
|
|
3959
|
+
return { file: sf.fileName, start: ts.tokenStartOfNode(node), end: node.end };
|
|
2921
3960
|
}
|
|
2922
|
-
/** The
|
|
2923
|
-
*
|
|
2924
|
-
|
|
2925
|
-
* program — a path-identity mismatch between the two resolvers). */
|
|
2926
|
-
function npmStaticProgramDep(program, packageName, resolvedFile) {
|
|
2927
|
-
if (!isJsSourceFileName(resolvedFile)) {
|
|
2928
|
-
reportNpmStaticOffender(packageName, `its import resolves to '${resolvedFile}', not to runtime JavaScript`);
|
|
2929
|
-
return null;
|
|
2930
|
-
}
|
|
3961
|
+
/** The program file holding an opted-in package's resolved runtime JS:
|
|
3962
|
+
* the file itself, or its same-stem TypeScript twin. */
|
|
3963
|
+
function npmStaticProgramFile(program, resolvedFile) {
|
|
2931
3964
|
let dep = program.getSourceFile(resolvedFile) ?? null;
|
|
2932
3965
|
if (dep === null) {
|
|
2933
3966
|
// A workspace-linked package shipping its .ts SOURCE beside the
|
|
@@ -2941,6 +3974,18 @@ function npmStaticProgramDep(program, packageName, resolvedFile) {
|
|
|
2941
3974
|
break;
|
|
2942
3975
|
}
|
|
2943
3976
|
}
|
|
3977
|
+
return dep;
|
|
3978
|
+
}
|
|
3979
|
+
/** The PROGRAM source file an opted-in --npm-static package's resolved
|
|
3980
|
+
* entry maps to, or null with the package marked an offender (resolution
|
|
3981
|
+
* still answering declarations, or the file missing from the type-checked
|
|
3982
|
+
* program — a path-identity mismatch between the two resolvers). */
|
|
3983
|
+
function npmStaticProgramDep(program, packageName, resolvedFile) {
|
|
3984
|
+
if (!isJsSourceFileName(resolvedFile)) {
|
|
3985
|
+
reportNpmStaticOffender(packageName, `its import resolves to '${resolvedFile}', not to runtime JavaScript`);
|
|
3986
|
+
return null;
|
|
3987
|
+
}
|
|
3988
|
+
const dep = npmStaticProgramFile(program, resolvedFile);
|
|
2944
3989
|
if (dep === null) {
|
|
2945
3990
|
reportNpmStaticOffender(packageName, `its entry '${resolvedFile}' did not join the type-checked program`);
|
|
2946
3991
|
return null;
|
|
@@ -3063,7 +4108,7 @@ function preflight7(load) {
|
|
|
3063
4108
|
names = new Set();
|
|
3064
4109
|
builtinNamespaceNames.set(d.fileName, names);
|
|
3065
4110
|
const sf = p.getSourceFile(d.fileName);
|
|
3066
|
-
for (const stmt of sf?.statements ?? []) {
|
|
4111
|
+
for (const stmt of sf?.statements?.nodes ?? []) {
|
|
3067
4112
|
if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
3068
4113
|
continue;
|
|
3069
4114
|
if (canonicalBuiltinModule(stmt.moduleSpecifier.text) === null)
|
|
@@ -3127,6 +4172,17 @@ function preflight7(load) {
|
|
|
3127
4172
|
: spec.split("/")[0];
|
|
3128
4173
|
return isWorkspacePackageName(prefix);
|
|
3129
4174
|
};
|
|
4175
|
+
// A JavaScript file that TypeScript checks keeps the type errors that
|
|
4176
|
+
// protect its JSDoc types: a value of another type reaching a typed slot,
|
|
4177
|
+
// a call with the wrong arity, and a subclass member that does not
|
|
4178
|
+
// match its base.
|
|
4179
|
+
const projectCheckJs = load.typeWorld?.projectCheckJs ?? false;
|
|
4180
|
+
const enforcedInCheckedJs = (p, d) => {
|
|
4181
|
+
if (!CHECKED_JS_ENFORCED_CODES.has(d.code) || d.fileName === undefined)
|
|
4182
|
+
return false;
|
|
4183
|
+
const sf = p.getSourceFile(d.fileName);
|
|
4184
|
+
return sf !== undefined && isCheckedJsSourceFile(sf, projectCheckJs);
|
|
4185
|
+
};
|
|
3130
4186
|
const errorsOf = (p) => {
|
|
3131
4187
|
const all = ts.getPreEmitDiagnostics(p);
|
|
3132
4188
|
// First pass: every comment-side 2300's (file, name) — the partners
|
|
@@ -3142,7 +4198,7 @@ function preflight7(load) {
|
|
|
3142
4198
|
commentDup.add(`${d.fileName}:${sf.text.slice(d.pos, d.end)}`);
|
|
3143
4199
|
}
|
|
3144
4200
|
return all.filter((d) => d.category === ts.DiagnosticCategory.Error &&
|
|
3145
|
-
!suppressedJsStrictness7(d) &&
|
|
4201
|
+
(!suppressedJsStrictness7(d) || enforcedInCheckedJs(p, d)) &&
|
|
3146
4202
|
!npmStaticFileSuppressed(d) &&
|
|
3147
4203
|
!nodeModulesJsSuppressed(d) &&
|
|
3148
4204
|
!namespaceCalleeSuppressed(p, d) &&
|
|
@@ -3184,14 +4240,23 @@ function preflight7(load) {
|
|
|
3184
4240
|
entryPackageFile(sf.fileName) ||
|
|
3185
4241
|
npmStaticPackageOfPath(sf.fileName) !== null) &&
|
|
3186
4242
|
!unselectedPackageJsFile(sf.fileName));
|
|
4243
|
+
// Files reached only through `import type` / `export type … from` are
|
|
4244
|
+
// checker input, never program modules: Node does not load them, so
|
|
4245
|
+
// their imports and syntax must not fence the program.
|
|
4246
|
+
const resolveRuntimeEdge = (sf, spec, resolutionKind) => resolveImport7(program, sf, spec, resolutionKind) ??
|
|
4247
|
+
npmStaticDepSf7(program, sf, spec, resolutionKind);
|
|
4248
|
+
const typeOnlyFiles = typeOnlyReachedFiles(program, entry, programFiles, () => [
|
|
4249
|
+
...forkTargetPaths(program, program.getImplementationSourceFiles()),
|
|
4250
|
+
...workerTargetPaths(program, program.getImplementationSourceFiles()),
|
|
4251
|
+
], resolveRuntimeEdge);
|
|
4252
|
+
const runtimeFiles = typeOnlyFiles.size === 0 ? programFiles : programFiles.filter((sf) => !typeOnlyFiles.has(sf));
|
|
3187
4253
|
const userFiles = npmStaticActive()
|
|
3188
|
-
? planNpmStaticReexports(program, entry,
|
|
4254
|
+
? planNpmStaticReexports(program, entry, runtimeFiles, [
|
|
3189
4255
|
...createRequireProgramRoots7(program),
|
|
3190
4256
|
...forkTargetPaths(program, program.getImplementationSourceFiles()),
|
|
3191
4257
|
...workerTargetPaths(program, program.getImplementationSourceFiles()),
|
|
3192
|
-
],
|
|
3193
|
-
|
|
3194
|
-
: programFiles;
|
|
4258
|
+
], resolveRuntimeEdge)
|
|
4259
|
+
: runtimeFiles;
|
|
3195
4260
|
program.getTypeChecker().prefetchSourceFileStructures(userFiles);
|
|
3196
4261
|
// Unselected node_modules JS is not native program source even when
|
|
3197
4262
|
// maxNodeModuleJsDepth pulled it into the checker (nodeModulesJsSuppressed).
|
|
@@ -3228,7 +4293,7 @@ function preflight7(load) {
|
|
|
3228
4293
|
if (ambientModuleDecls === null) {
|
|
3229
4294
|
ambientModuleDecls = { names: new Set(), patterns: [] };
|
|
3230
4295
|
for (const f of program.getSourceFiles()) {
|
|
3231
|
-
for (const s of f.statements) {
|
|
4296
|
+
for (const s of f.statements.nodes) {
|
|
3232
4297
|
if (!ts.isModuleDeclaration(s) || !ts.isStringLiteral(s.name))
|
|
3233
4298
|
continue;
|
|
3234
4299
|
const name = s.name.text;
|
|
@@ -3269,7 +4334,7 @@ function preflight7(load) {
|
|
|
3269
4334
|
edges.set(sf, deps);
|
|
3270
4335
|
refusals.set(sf, []);
|
|
3271
4336
|
depPositions.set(sf, []);
|
|
3272
|
-
for (const stmt of sf.statements) {
|
|
4337
|
+
for (const stmt of sf.statements.nodes) {
|
|
3273
4338
|
if (ts.isImportEqualsDeclaration(stmt)) {
|
|
3274
4339
|
// The ENTITY form (`import a = A`, `import x = N.y`) is namespace
|
|
3275
4340
|
// alias plumbing — the lowerer resolves references through it and
|
|
@@ -3299,7 +4364,7 @@ function preflight7(load) {
|
|
|
3299
4364
|
continue;
|
|
3300
4365
|
}
|
|
3301
4366
|
if (ts.isExportDeclaration(stmt)) {
|
|
3302
|
-
if (stmt.isTypeOnly ||
|
|
4367
|
+
if (stmt.isTypeOnly || isPrunedNpmReexport(program, stmt))
|
|
3303
4368
|
continue;
|
|
3304
4369
|
if (!stmt.moduleSpecifier)
|
|
3305
4370
|
continue;
|
|
@@ -3352,7 +4417,7 @@ function preflight7(load) {
|
|
|
3352
4417
|
}
|
|
3353
4418
|
if (reDep && !reDep.fileName.endsWith(".json")) {
|
|
3354
4419
|
deps.push({ dep: reDep, stmt });
|
|
3355
|
-
depPositions.get(sf).push({ dep: reDep, pos:
|
|
4420
|
+
depPositions.get(sf).push({ dep: reDep, pos: ts.tokenStartOfNode(stmt) });
|
|
3356
4421
|
}
|
|
3357
4422
|
continue;
|
|
3358
4423
|
}
|
|
@@ -3399,7 +4464,7 @@ function preflight7(load) {
|
|
|
3399
4464
|
refusals.get(sf).push({
|
|
3400
4465
|
crash: { message, className, loc: locOf7(stmt) },
|
|
3401
4466
|
fallback: unsupportedDiag("SC1010", locOf7(stmt), fallbackFeature),
|
|
3402
|
-
pos:
|
|
4467
|
+
pos: ts.tokenStartOfNode(stmt),
|
|
3403
4468
|
});
|
|
3404
4469
|
};
|
|
3405
4470
|
// Project modules win before npm fallback: this is the source graph
|
|
@@ -3565,21 +4630,39 @@ function preflight7(load) {
|
|
|
3565
4630
|
}
|
|
3566
4631
|
if (dep && !isJson) {
|
|
3567
4632
|
deps.push({ dep, stmt });
|
|
3568
|
-
depPositions.get(sf).push({ dep, pos:
|
|
4633
|
+
depPositions.get(sf).push({ dep, pos: ts.tokenStartOfNode(stmt) });
|
|
3569
4634
|
}
|
|
3570
4635
|
}
|
|
3571
4636
|
{
|
|
3572
4637
|
const jsRequireFile = isJsSourceFileName(sf.fileName);
|
|
3573
|
-
const stmts = sf.statements;
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
4638
|
+
const stmts = sf.statements.nodes;
|
|
4639
|
+
// A binding that code running before the require can reach. Node
|
|
4640
|
+
// initializes it AT the require: a const/let read earlier throws
|
|
4641
|
+
// ReferenceError, which the lowering reproduces with an
|
|
4642
|
+
// initialization check at every reference that can run early
|
|
4643
|
+
// (require-initialization.ts). A var reads undefined there, which
|
|
4644
|
+
// module aliases cannot represent; createRequire bindings have no
|
|
4645
|
+
// checked form either.
|
|
4646
|
+
const earlyRequireFence = (req, bindingKind, loc) => {
|
|
4647
|
+
const early = req.decl !== null ? requireEarlyReference7(program, req.decl) : null;
|
|
4648
|
+
if (early === null ||
|
|
4649
|
+
(bindingKind !== "createRequire" &&
|
|
4650
|
+
((req.decl.parent?.flags ?? 0) & (ts.NodeFlags.Const | ts.NodeFlags.Let)) !== 0)) {
|
|
4651
|
+
return false;
|
|
4652
|
+
}
|
|
4653
|
+
diags.push(unsupportedDiag("SC1013", loc, bindingKind === "createRequire"
|
|
4654
|
+
? `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)`
|
|
4655
|
+
: `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)`));
|
|
4656
|
+
return true;
|
|
4657
|
+
};
|
|
3579
4658
|
for (let k = 0; k < stmts.length; k++) {
|
|
3580
4659
|
const stmt = stmts[k];
|
|
3581
4660
|
for (const req of requiresOf7(stmt)) {
|
|
3582
|
-
const loc = {
|
|
4661
|
+
const loc = {
|
|
4662
|
+
file: sf.fileName,
|
|
4663
|
+
start: ts.tokenStartOfNode(req.node),
|
|
4664
|
+
end: req.node.end,
|
|
4665
|
+
};
|
|
3583
4666
|
const bindingKind = requireCallBindingKind7(program, req.node);
|
|
3584
4667
|
// TypeScript source files join this scan only through the
|
|
3585
4668
|
// canonical createRequire bridge. Their ordinary require-shaped
|
|
@@ -3596,20 +4679,72 @@ function preflight7(load) {
|
|
|
3596
4679
|
if (load.externalTypes.has(req.spec)) {
|
|
3597
4680
|
continue;
|
|
3598
4681
|
}
|
|
4682
|
+
// A JSON document: the require answers its cached parsed object
|
|
4683
|
+
// (json-require.ts), an ordinary value the binding stores, so
|
|
4684
|
+
// every destructuring form lowers as usual. No module edge.
|
|
4685
|
+
const jsonDep = resolveImport7(program, sf, req.spec, "require");
|
|
4686
|
+
if (jsonDep !== null && jsonDep.fileName.endsWith(".json")) {
|
|
4687
|
+
if (bindingKind === "createRequire")
|
|
4688
|
+
continue;
|
|
4689
|
+
if (ts.isVariableStatement(stmt) && requiresOf7(stmt).length > 1) {
|
|
4690
|
+
const others = requiresOf7(stmt).some((r) => {
|
|
4691
|
+
const d = resolveImport7(program, sf, r.spec, "require");
|
|
4692
|
+
return d === null || !d.fileName.endsWith(".json");
|
|
4693
|
+
});
|
|
4694
|
+
if (others) {
|
|
4695
|
+
diags.push(unsupportedDiag("SC1012", loc, "require() of a JSON module declared together with other require() bindings"));
|
|
4696
|
+
continue;
|
|
4697
|
+
}
|
|
4698
|
+
}
|
|
4699
|
+
earlyRequireFence(req, bindingKind, loc);
|
|
4700
|
+
continue;
|
|
4701
|
+
}
|
|
3599
4702
|
if (req.decl && ts.isArrayBindingPattern(req.decl.name)) {
|
|
3600
4703
|
diags.push(unsupportedDiag("SC1012", loc, "array-destructuring require() bindings"));
|
|
3601
4704
|
continue;
|
|
3602
4705
|
}
|
|
3603
4706
|
if (req.decl && ts.isObjectBindingPattern(req.decl.name)) {
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
4707
|
+
// A nested pattern of a builtin binds members of the sub-module
|
|
4708
|
+
// its key names (`const { types: { isPromise } } =
|
|
4709
|
+
// require("util")` — util.types IS util/types).
|
|
4710
|
+
const builtin = canonicalBuiltinModule(req.spec);
|
|
4711
|
+
const plainElements = (pattern, module) => pattern.elements.nodes.every((e) => {
|
|
4712
|
+
if (e.initializer !== undefined || e.dotDotDotToken !== undefined)
|
|
4713
|
+
return false;
|
|
4714
|
+
if (e.name !== undefined && ts.isIdentifier(e.name))
|
|
4715
|
+
return true;
|
|
4716
|
+
// A nested pattern under a named export of a program module
|
|
4717
|
+
// destructures that export's VALUE at the require
|
|
4718
|
+
// (`const { codes: { ERR_X } } = require("./errors")`): the
|
|
4719
|
+
// inner bindings are ordinary destructured storage.
|
|
4720
|
+
if (module === null &&
|
|
4721
|
+
builtin === null &&
|
|
4722
|
+
bindingKind !== "createRequire" &&
|
|
4723
|
+
pattern === req.decl.name &&
|
|
4724
|
+
e.name !== undefined &&
|
|
4725
|
+
ts.isObjectBindingPattern(e.name) &&
|
|
4726
|
+
e.propertyName !== undefined &&
|
|
4727
|
+
ts.isIdentifier(e.propertyName))
|
|
4728
|
+
return true;
|
|
4729
|
+
if (module === null || e.name === undefined || !ts.isObjectBindingPattern(e.name))
|
|
4730
|
+
return false;
|
|
4731
|
+
const key = e.propertyName;
|
|
4732
|
+
if (key === undefined || !ts.isIdentifier(key))
|
|
4733
|
+
return false;
|
|
4734
|
+
const sub = canonicalBuiltinModule(`${module}/${key.text}`);
|
|
4735
|
+
return sub !== null && plainElements(e.name, sub);
|
|
4736
|
+
});
|
|
4737
|
+
if (!plainElements(req.decl.name, builtin)) {
|
|
4738
|
+
diags.push(unsupportedDiag("SC1012", loc, builtin !== null
|
|
4739
|
+
? "require() destructuring with defaults, rest, or nested patterns other than builtin sub-modules"
|
|
4740
|
+
: "require() destructuring with defaults, rest, or nested patterns of program modules (JSON documents and builtin sub-modules destructure fully)"));
|
|
3610
4741
|
continue;
|
|
3611
4742
|
}
|
|
3612
4743
|
}
|
|
4744
|
+
// An npm package served as a builtin (graceful-fs as fs) is never
|
|
4745
|
+
// a program-module edge, even when --npm-static names it.
|
|
4746
|
+
if (npmBuiltinAliasOf(req.spec) !== null)
|
|
4747
|
+
continue;
|
|
3613
4748
|
const isRelative = isRelativeSpecifier(req.spec);
|
|
3614
4749
|
let dep = resolveImport7(program, sf, req.spec, "require");
|
|
3615
4750
|
if (dep === null && !isRelative) {
|
|
@@ -3648,27 +4783,8 @@ function preflight7(load) {
|
|
|
3648
4783
|
continue;
|
|
3649
4784
|
}
|
|
3650
4785
|
}
|
|
3651
|
-
if (
|
|
3652
|
-
if (bindingKind === "createRequire")
|
|
3653
|
-
continue;
|
|
3654
|
-
diags.push(unsupportedDiag("SC1012", loc, "require() of JSON modules"));
|
|
3655
|
-
continue;
|
|
3656
|
-
}
|
|
3657
|
-
// Earlier declarators run too: `const x = read(), dep =
|
|
3658
|
-
// require('./dep')` must not lose the guard merely because both
|
|
3659
|
-
// initializers share one VariableStatement.
|
|
3660
|
-
const precedingDecls = req.decl && ts.isVariableStatement(stmt)
|
|
3661
|
-
? stmt.declarationList.declarations.slice(0, stmt.declarationList.declarations.indexOf(req.decl))
|
|
3662
|
-
: [];
|
|
3663
|
-
const prefixCanRun = (firstRunnable >= 0 && firstRunnable < k) ||
|
|
3664
|
-
precedingDecls.some((decl) => !purePrefixDecl7(decl));
|
|
3665
|
-
const tdzName = prefixCanRun && req.decl
|
|
3666
|
-
? bindingEarlyUse7(program, sf, k, req.decl, precedingDecls)
|
|
3667
|
-
: null;
|
|
3668
|
-
if (tdzName !== null) {
|
|
3669
|
-
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)`));
|
|
4786
|
+
if (earlyRequireFence(req, bindingKind, loc))
|
|
3670
4787
|
continue;
|
|
3671
|
-
}
|
|
3672
4788
|
if (dep)
|
|
3673
4789
|
deps.push({ dep });
|
|
3674
4790
|
}
|
|
@@ -3679,7 +4795,7 @@ function preflight7(load) {
|
|
|
3679
4795
|
.prefetchSymbolNodesExact(nestedBareRequires.flatMap((call) => ts.isIdentifier(call.expression) ? [call.expression] : []));
|
|
3680
4796
|
for (const call of nestedBareRequires) {
|
|
3681
4797
|
const spec = requireSpecOf7(call);
|
|
3682
|
-
const loc = { file: sf.fileName, start:
|
|
4798
|
+
const loc = { file: sf.fileName, start: ts.tokenStartOfNode(call), end: call.end };
|
|
3683
4799
|
const bindingKind = requireCallBindingKind7(program, call);
|
|
3684
4800
|
if (!jsRequireFile && bindingKind !== "createRequire")
|
|
3685
4801
|
continue;
|
|
@@ -3692,14 +4808,14 @@ function preflight7(load) {
|
|
|
3692
4808
|
if (load.externalTypes.has(spec)) {
|
|
3693
4809
|
continue;
|
|
3694
4810
|
}
|
|
4811
|
+
if (npmBuiltinAliasOf(spec) !== null)
|
|
4812
|
+
continue;
|
|
3695
4813
|
const projectDep = resolveImport7(program, sf, spec, "require");
|
|
3696
4814
|
if (projectDep !== null) {
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
diags.push(unsupportedDiag("SC1012", loc, "require() of JSON modules"));
|
|
4815
|
+
// A bare require of a JSON document only parses it: nothing to
|
|
4816
|
+
// evaluate (json-require.ts creates the cached object).
|
|
4817
|
+
if (projectDep.fileName.endsWith(".json"))
|
|
3701
4818
|
continue;
|
|
3702
|
-
}
|
|
3703
4819
|
deps.push({ dep: projectDep });
|
|
3704
4820
|
continue;
|
|
3705
4821
|
}
|
|
@@ -3727,6 +4843,36 @@ function preflight7(load) {
|
|
|
3727
4843
|
continue;
|
|
3728
4844
|
}
|
|
3729
4845
|
}
|
|
4846
|
+
// Inline requires of program modules are module edges like the bare
|
|
4847
|
+
// statements above (cjs-inline-require.ts lowers each to the module's
|
|
4848
|
+
// %init at its position). Only the CommonJS global in a CommonJS file
|
|
4849
|
+
// counts, and targets outside the compiled graph add nothing here:
|
|
4850
|
+
// their use sites keep their existing lowering fences.
|
|
4851
|
+
if (jsRequireFile && !isNodeEsmFile7(sf, program)) {
|
|
4852
|
+
for (const call of inlineRequiresOf7(sf)) {
|
|
4853
|
+
if (requireCallBindingKind7(program, call) !== "ambient")
|
|
4854
|
+
continue;
|
|
4855
|
+
const spec = requireSpecOf7(call);
|
|
4856
|
+
if (load.externalTypes.has(spec) || canonicalBuiltinModule(spec) !== null)
|
|
4857
|
+
continue;
|
|
4858
|
+
const lazy = inDeferredPosition7(call);
|
|
4859
|
+
const edgeTo = (dep) => lazy ? { dep, lazy: true, call } : { dep, call };
|
|
4860
|
+
const projectDep = resolveImport7(program, sf, spec, "require");
|
|
4861
|
+
if (projectDep !== null) {
|
|
4862
|
+
if (!projectDep.fileName.endsWith(".json"))
|
|
4863
|
+
deps.push(edgeTo(projectDep));
|
|
4864
|
+
continue;
|
|
4865
|
+
}
|
|
4866
|
+
if (isRelativeSpecifier(spec) || spec.startsWith("#"))
|
|
4867
|
+
continue;
|
|
4868
|
+
const npmReq = resolveNpmImport7(sf.fileName, spec, "require");
|
|
4869
|
+
if (npmReq !== null && isNpmStaticPackage(npmReq.packageName)) {
|
|
4870
|
+
const nDep = npmStaticProgramDep(program, npmReq.packageName, npmReq.typesFile);
|
|
4871
|
+
if (nDep !== null)
|
|
4872
|
+
deps.push(edgeTo(nDep));
|
|
4873
|
+
}
|
|
4874
|
+
}
|
|
4875
|
+
}
|
|
3730
4876
|
}
|
|
3731
4877
|
}
|
|
3732
4878
|
// Node's evaluation order: depth-first postorder from the entry, each
|
|
@@ -3752,8 +4898,12 @@ function preflight7(load) {
|
|
|
3752
4898
|
// reads are all let/const bindings with module storage — the
|
|
3753
4899
|
// lowering checks each one (cycleEarlyBindings) and throws Node's
|
|
3754
4900
|
// ReferenceError on a read before the declaration ran.
|
|
3755
|
-
const cycleAdmissionReason = makeCycleAdmission(program, (sf) =>
|
|
4901
|
+
const cycleAdmissionReason = makeCycleAdmission(program, (sf) => {
|
|
4902
|
+
const all = edges.get(sf) ?? [];
|
|
4903
|
+
return all.some((e) => e.call !== undefined) ? all.filter((e) => e.call === undefined) : all;
|
|
4904
|
+
});
|
|
3756
4905
|
const order = [];
|
|
4906
|
+
const inlineRequireCycleCalls = new Set();
|
|
3757
4907
|
const state = new Map();
|
|
3758
4908
|
const stack = [];
|
|
3759
4909
|
const visit = (sf) => {
|
|
@@ -3762,10 +4912,16 @@ function preflight7(load) {
|
|
|
3762
4912
|
for (const e of edges.get(sf) ?? []) {
|
|
3763
4913
|
if (e.dep === sf)
|
|
3764
4914
|
continue; // self-import: a Node cache hit, not a cycle
|
|
4915
|
+
if (e.lazy === true)
|
|
4916
|
+
continue; // visited after this module completes
|
|
3765
4917
|
const s = state.get(e.dep);
|
|
3766
4918
|
if (s === "done")
|
|
3767
4919
|
continue;
|
|
3768
4920
|
if (s === "visiting") {
|
|
4921
|
+
if (e.call !== undefined) {
|
|
4922
|
+
inlineRequireCycleCalls.add(e.call);
|
|
4923
|
+
continue;
|
|
4924
|
+
}
|
|
3769
4925
|
// A back-edge: Node answers it from the cache (the module is
|
|
3770
4926
|
// already evaluating) — admitted by the cheap per-edge rule, the
|
|
3771
4927
|
// declaration-only init window rule, or the exact initialization
|
|
@@ -3783,6 +4939,12 @@ function preflight7(load) {
|
|
|
3783
4939
|
stack.pop();
|
|
3784
4940
|
state.set(sf, "done");
|
|
3785
4941
|
order.push(sf);
|
|
4942
|
+
// Lazy inline requires run after this module's top level: their
|
|
4943
|
+
// modules join the order afterwards (cache hits when already loaded).
|
|
4944
|
+
for (const e of edges.get(sf) ?? []) {
|
|
4945
|
+
if (e.lazy === true && state.get(e.dep) === undefined)
|
|
4946
|
+
visit(e.dep);
|
|
4947
|
+
}
|
|
3786
4948
|
};
|
|
3787
4949
|
visit(entry);
|
|
3788
4950
|
// The startup crash Node's RESOLUTION phase reports: modules resolve
|
|
@@ -3832,7 +4994,12 @@ function preflight7(load) {
|
|
|
3832
4994
|
const linkCrash = resolveCrash !== null
|
|
3833
4995
|
? null
|
|
3834
4996
|
: earlierLinkCrash(order, cjsNamedImportLinkCheck(program, entry, order, diags), esmNamedImportLinkCheck(program, entry, order, diags));
|
|
3835
|
-
return {
|
|
4997
|
+
return {
|
|
4998
|
+
diags,
|
|
4999
|
+
moduleOrder: order,
|
|
5000
|
+
startupCrash: resolveCrash ?? linkCrash,
|
|
5001
|
+
inlineRequireCycleCalls,
|
|
5002
|
+
};
|
|
3836
5003
|
}
|
|
3837
5004
|
/** Walks the entry's ESM instantiate graph exactly as V8 does — children
|
|
3838
5005
|
* in request order, each module's own imports checked AFTER its children
|
|
@@ -3866,12 +5033,19 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3866
5033
|
npmStaticDepSf7(program, from, spec, "require");
|
|
3867
5034
|
return dep !== null && isCjsJsFile7(dep, program) ? dep : null;
|
|
3868
5035
|
};
|
|
5036
|
+
// A bundler rewrite spells some lexer-visible names as accessors.
|
|
5037
|
+
const lexWithAccessorNames = (sf) => {
|
|
5038
|
+
const lexed = cjsLexedExportsOfFile(sf);
|
|
5039
|
+
for (const name of npmStaticLexerVisibleNames(sf.fileName))
|
|
5040
|
+
lexed.exports.add(name);
|
|
5041
|
+
return lexed;
|
|
5042
|
+
};
|
|
3869
5043
|
const visible = (dep, name) =>
|
|
3870
5044
|
// `default` is the module.exports binding itself — always provided.
|
|
3871
5045
|
// The program already owns native source ASTs; reuse them without
|
|
3872
5046
|
// starting another syntax session or reparsing their source text.
|
|
3873
5047
|
name === "default" ||
|
|
3874
|
-
cjsVisibleNames(dep,
|
|
5048
|
+
cjsVisibleNames(dep, lexWithAccessorNames, resolveCjsDep, lexMemo).has(name);
|
|
3875
5049
|
/** The statement's resolved LOCAL CommonJS dependency, when it is an
|
|
3876
5050
|
* import/re-export from one. */
|
|
3877
5051
|
const cjsDepOf = (sf, spec) => {
|
|
@@ -3883,7 +5057,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3883
5057
|
* then `export { x } from` elements in source order. */
|
|
3884
5058
|
const firstInvisibleOf = (sf) => {
|
|
3885
5059
|
const entries = [];
|
|
3886
|
-
for (const stmt of sf.statements) {
|
|
5060
|
+
for (const stmt of sf.statements.nodes) {
|
|
3887
5061
|
if (!ts.isImportDeclaration(stmt) ||
|
|
3888
5062
|
stmt.moduleSpecifier === undefined ||
|
|
3889
5063
|
!ts.isStringLiteral(stmt.moduleSpecifier))
|
|
@@ -3897,7 +5071,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3897
5071
|
const dep = cjsDepOf(sf, spec);
|
|
3898
5072
|
if (dep === null)
|
|
3899
5073
|
continue;
|
|
3900
|
-
for (const e of clause.namedBindings.elements) {
|
|
5074
|
+
for (const e of clause.namedBindings.elements.nodes) {
|
|
3901
5075
|
if (e.isTypeOnly)
|
|
3902
5076
|
continue;
|
|
3903
5077
|
const nameNode = e.propertyName ?? e.name;
|
|
@@ -3909,7 +5083,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3909
5083
|
if (!visible(e.dep, e.exportName))
|
|
3910
5084
|
return { exportName: e.exportName, spec: e.spec, nameNode: e.nameNode, sf };
|
|
3911
5085
|
}
|
|
3912
|
-
for (const stmt of sf.statements) {
|
|
5086
|
+
for (const stmt of sf.statements.nodes) {
|
|
3913
5087
|
if (!ts.isExportDeclaration(stmt) || stmt.isTypeOnly)
|
|
3914
5088
|
continue;
|
|
3915
5089
|
if (stmt.moduleSpecifier === undefined || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
@@ -3920,7 +5094,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3920
5094
|
const dep = cjsDepOf(sf, spec);
|
|
3921
5095
|
if (dep === null)
|
|
3922
5096
|
continue;
|
|
3923
|
-
for (const e of stmt.exportClause.elements) {
|
|
5097
|
+
for (const e of stmt.exportClause.elements.nodes) {
|
|
3924
5098
|
if (e.isTypeOnly)
|
|
3925
5099
|
continue;
|
|
3926
5100
|
const nameNode = e.propertyName ?? e.name;
|
|
@@ -3939,7 +5113,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3939
5113
|
if (visited.has(sf))
|
|
3940
5114
|
return null;
|
|
3941
5115
|
visited.add(sf);
|
|
3942
|
-
for (const stmt of sf.statements) {
|
|
5116
|
+
for (const stmt of sf.statements.nodes) {
|
|
3943
5117
|
if (!ts.isImportDeclaration(stmt) && !(ts.isExportDeclaration(stmt) && !stmt.isTypeOnly))
|
|
3944
5118
|
continue;
|
|
3945
5119
|
if (ts.isExportDeclaration(stmt) && isPrunedNpmReexport(program, stmt))
|
|
@@ -3980,7 +5154,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3980
5154
|
// it is CommonJS (module_job.js consults the ROOT job's moduleRequests/
|
|
3981
5155
|
// commonJsDeps — a deep module's failure keeps the generic wording).
|
|
3982
5156
|
let flavored = false;
|
|
3983
|
-
for (const stmt of entry.statements) {
|
|
5157
|
+
for (const stmt of entry.statements.nodes) {
|
|
3984
5158
|
if (!ts.isImportDeclaration(stmt) && !(ts.isExportDeclaration(stmt) && !stmt.isTypeOnly))
|
|
3985
5159
|
continue;
|
|
3986
5160
|
if (ts.isImportDeclaration(stmt) &&
|
|
@@ -4007,7 +5181,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
4007
5181
|
// swaps ` as ` for `: ` — reproduced exactly, quirks included
|
|
4008
5182
|
// (multi-line import statements simply lose the hint).
|
|
4009
5183
|
const text = bad.sf.text;
|
|
4010
|
-
const pos =
|
|
5184
|
+
const pos = ts.tokenStartOfNode(bad.nameNode);
|
|
4011
5185
|
const lineStart = text.lastIndexOf("\n", pos - 1) + 1;
|
|
4012
5186
|
const lineEnd = text.indexOf("\n", pos);
|
|
4013
5187
|
let line = text.slice(lineStart, lineEnd < 0 ? text.length : lineEnd);
|
|
@@ -4065,9 +5239,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4065
5239
|
// type-only, but the native ESM linker sees the runtime placeholder.
|
|
4066
5240
|
if (name === "default" &&
|
|
4067
5241
|
hasNodeTsDefaultInterfacePlaceholder7(dep) &&
|
|
4068
|
-
|
|
4069
|
-
.declarationsOf(resolved)
|
|
4070
|
-
.some((declaration) => ts.isInterfaceDeclaration(declaration) &&
|
|
5242
|
+
resolved.declarations.some((declaration) => ts.isInterfaceDeclaration(declaration) &&
|
|
4071
5243
|
ts
|
|
4072
5244
|
.getModifiers(declaration)
|
|
4073
5245
|
?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) === true &&
|
|
@@ -4086,7 +5258,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4086
5258
|
if (name === "default")
|
|
4087
5259
|
return undefined;
|
|
4088
5260
|
let starExport;
|
|
4089
|
-
for (const stmt of dep.statements) {
|
|
5261
|
+
for (const stmt of dep.statements.nodes) {
|
|
4090
5262
|
if (!ts.isExportDeclaration(stmt) || stmt.isTypeOnly || stmt.exportClause !== undefined)
|
|
4091
5263
|
continue;
|
|
4092
5264
|
if (stmt.moduleSpecifier === undefined || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
@@ -4105,7 +5277,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4105
5277
|
};
|
|
4106
5278
|
const firstMissingOf = (sf) => {
|
|
4107
5279
|
const imports = [];
|
|
4108
|
-
for (const stmt of sf.statements) {
|
|
5280
|
+
for (const stmt of sf.statements.nodes) {
|
|
4109
5281
|
if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
4110
5282
|
continue;
|
|
4111
5283
|
const clause = stmt.importClause;
|
|
@@ -4126,7 +5298,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4126
5298
|
}
|
|
4127
5299
|
if (clause.namedBindings === undefined || !ts.isNamedImports(clause.namedBindings))
|
|
4128
5300
|
continue;
|
|
4129
|
-
for (const element of clause.namedBindings.elements) {
|
|
5301
|
+
for (const element of clause.namedBindings.elements.nodes) {
|
|
4130
5302
|
if (element.isTypeOnly)
|
|
4131
5303
|
continue;
|
|
4132
5304
|
const nameNode = element.propertyName ?? element.name;
|
|
@@ -4153,7 +5325,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4153
5325
|
};
|
|
4154
5326
|
}
|
|
4155
5327
|
}
|
|
4156
|
-
for (const stmt of sf.statements) {
|
|
5328
|
+
for (const stmt of sf.statements.nodes) {
|
|
4157
5329
|
if (!ts.isExportDeclaration(stmt) || stmt.isTypeOnly)
|
|
4158
5330
|
continue;
|
|
4159
5331
|
const moduleSpecifier = stmt.moduleSpecifier;
|
|
@@ -4166,7 +5338,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4166
5338
|
const dep = resolveEdge(sf, spec);
|
|
4167
5339
|
if (dep === null || dep.fileName.endsWith(".json") || !isNodeEsmFile7(dep, program))
|
|
4168
5340
|
continue;
|
|
4169
|
-
for (const element of exportClause.elements) {
|
|
5341
|
+
for (const element of exportClause.elements.nodes) {
|
|
4170
5342
|
if (element.isTypeOnly)
|
|
4171
5343
|
continue;
|
|
4172
5344
|
const nameNode = element.propertyName ?? element.name;
|
|
@@ -4185,7 +5357,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4185
5357
|
if (visited.has(sf))
|
|
4186
5358
|
return null;
|
|
4187
5359
|
visited.add(sf);
|
|
4188
|
-
for (const stmt of sf.statements) {
|
|
5360
|
+
for (const stmt of sf.statements.nodes) {
|
|
4189
5361
|
if (!ts.isImportDeclaration(stmt) && !(ts.isExportDeclaration(stmt) && !stmt.isTypeOnly))
|
|
4190
5362
|
continue;
|
|
4191
5363
|
if (ts.isExportDeclaration(stmt) && isPrunedNpmReexport(program, stmt))
|
|
@@ -4267,17 +5439,17 @@ function earlierLinkCrash(moduleOrder, first, second) {
|
|
|
4267
5439
|
return first.loc.start < second.loc.start ? first : second;
|
|
4268
5440
|
const rank = (crash) => {
|
|
4269
5441
|
const entries = [];
|
|
4270
|
-
for (const stmt of sf.statements) {
|
|
5442
|
+
for (const stmt of sf.statements.nodes) {
|
|
4271
5443
|
if (ts.isImportDeclaration(stmt) && ts.isStringLiteral(stmt.moduleSpecifier)) {
|
|
4272
5444
|
const clause = stmt.importClause;
|
|
4273
5445
|
if (clause?.phaseModifier === ts.SyntaxKind.TypeKeyword)
|
|
4274
5446
|
continue;
|
|
4275
5447
|
if (clause?.namedBindings && ts.isNamedImports(clause.namedBindings)) {
|
|
4276
|
-
for (const element of clause.namedBindings.elements) {
|
|
5448
|
+
for (const element of clause.namedBindings.elements.nodes) {
|
|
4277
5449
|
if (!element.isTypeOnly) {
|
|
4278
5450
|
entries.push({
|
|
4279
5451
|
local: element.name.text,
|
|
4280
|
-
start: (element.propertyName ?? element.name)
|
|
5452
|
+
start: ts.tokenStartOfNode(element.propertyName ?? element.name),
|
|
4281
5453
|
kind: 0,
|
|
4282
5454
|
});
|
|
4283
5455
|
}
|
|
@@ -4290,16 +5462,16 @@ function earlierLinkCrash(moduleOrder, first, second) {
|
|
|
4290
5462
|
if (direct >= 0)
|
|
4291
5463
|
return [0, direct];
|
|
4292
5464
|
let reexport = 0;
|
|
4293
|
-
for (const stmt of sf.statements) {
|
|
5465
|
+
for (const stmt of sf.statements.nodes) {
|
|
4294
5466
|
const exportClause = ts.isExportDeclaration(stmt) ? stmt.exportClause : undefined;
|
|
4295
5467
|
if (!ts.isExportDeclaration(stmt) ||
|
|
4296
5468
|
stmt.isTypeOnly ||
|
|
4297
5469
|
exportClause === undefined ||
|
|
4298
5470
|
!ts.isNamedExports(exportClause))
|
|
4299
5471
|
continue;
|
|
4300
|
-
for (const element of exportClause.elements) {
|
|
5472
|
+
for (const element of exportClause.elements.nodes) {
|
|
4301
5473
|
if (!element.isTypeOnly &&
|
|
4302
|
-
(element.propertyName ?? element.name)
|
|
5474
|
+
ts.tokenStartOfNode(element.propertyName ?? element.name) === crash.loc.start) {
|
|
4303
5475
|
return [1, reexport];
|
|
4304
5476
|
}
|
|
4305
5477
|
if (!element.isTypeOnly)
|
|
@@ -4327,54 +5499,38 @@ const nodeBuiltinNames = new Set(builtinModules);
|
|
|
4327
5499
|
* established (the phase-2 port kept every spelling); the world-neutral
|
|
4328
5500
|
* helpers re-export from their focused modules. */
|
|
4329
5501
|
export { ambientDtsPath, fallbackDtsPath, isNodeTypesPath, overridesDtsPath } from "./dts-paths.js";
|
|
4330
|
-
export { builtinDefaultImportModule, canonicalBuiltinModule, SUPPORTED_BUILTIN_MODULES, } from "./builtin-modules.js";
|
|
5502
|
+
export { builtinDefaultImportModule, canonicalBuiltinModule, npmBuiltinAliasOf, SUPPORTED_BUILTIN_MODULES, } from "./builtin-modules.js";
|
|
4331
5503
|
export { npmPackageNameOf, workspacePackageOfPath } from "./workspace-registry.js";
|
|
4332
|
-
export { requireSpecOf7 as requireSpecOf, isRequireStatement7 as isRequireStatement, requiresOf7 as requiresOf, isNodeEsmFile7 as isNodeEsmFile, resolveImport7 as resolveImport, resolveNpmImport7 as resolveNpmImport, locOf7 as locOf, };
|
|
5504
|
+
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, };
|
|
4333
5505
|
/** True for JavaScript source files (.js/.mjs/.cjs) — the files whose
|
|
4334
5506
|
* types come entirely from inference (checkJs + JSDoc) and whose classes
|
|
4335
5507
|
* declare fields by constructor assignment. */
|
|
4336
5508
|
export function isJsSourceFile(sf) {
|
|
4337
5509
|
return isJsSourceFileName(sf.fileName);
|
|
4338
5510
|
}
|
|
4339
|
-
/**
|
|
4340
|
-
*
|
|
4341
|
-
*
|
|
4342
|
-
*
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
return true;
|
|
4356
|
-
return (clause.name === undefined &&
|
|
4357
|
-
clause.namedBindings !== undefined &&
|
|
4358
|
-
ts.isNamedImports(clause.namedBindings) &&
|
|
4359
|
-
clause.namedBindings.elements.length > 0 &&
|
|
4360
|
-
clause.namedBindings.elements.every((e) => e.isTypeOnly));
|
|
4361
|
-
}
|
|
4362
|
-
/** The re-export twin: `export { type X } from "./m"` with every element
|
|
4363
|
-
* `type`-qualified erases at emit exactly like `export type { X } from`
|
|
4364
|
-
* (which stmt.isTypeOnly already covers) — no module edge. */
|
|
4365
|
-
function erasedTypeOnlyReexport(stmt) {
|
|
4366
|
-
return (stmt.exportClause !== undefined &&
|
|
4367
|
-
ts.isNamedExports(stmt.exportClause) &&
|
|
4368
|
-
stmt.exportClause.elements.length > 0 &&
|
|
4369
|
-
stmt.exportClause.elements.every((e) => e.isTypeOnly));
|
|
5511
|
+
/** True for a JavaScript file of the program that TypeScript type-checks:
|
|
5512
|
+
* one with a `// @ts-check` comment before its first statement, or any
|
|
5513
|
+
* file of a project whose tsconfig sets `checkJs` unless the file has a
|
|
5514
|
+
* `// @ts-nocheck` comment. Files under node_modules are never checked. */
|
|
5515
|
+
export function isCheckedJsSourceFile(sf, projectCheckJs) {
|
|
5516
|
+
if (!isJsSourceFile(sf) || isNodeModulesPath(sf.fileName))
|
|
5517
|
+
return false;
|
|
5518
|
+
let checked = projectCheckJs;
|
|
5519
|
+
const head = sf.text.slice(0, (sf.statements.nodes.length === 0 ? undefined : ts.tokenStartOfNode(sf.statements.nodes[0])) ??
|
|
5520
|
+
sf.text.length);
|
|
5521
|
+
for (const line of head.split("\n")) {
|
|
5522
|
+
const directive = /^\s*\/\/\s*@ts-(no)?check\b/.exec(line);
|
|
5523
|
+
if (directive)
|
|
5524
|
+
checked = directive[1] === undefined;
|
|
5525
|
+
}
|
|
5526
|
+
return checked;
|
|
4370
5527
|
}
|
|
4371
5528
|
export function orderedImportsOf(program, sf) {
|
|
4372
5529
|
const out = [];
|
|
4373
|
-
for (const stmt of sf.statements) {
|
|
5530
|
+
for (const stmt of sf.statements.nodes) {
|
|
4374
5531
|
if (ts.isExportDeclaration(stmt) && isPrunedNpmReexport(program, stmt))
|
|
4375
5532
|
continue;
|
|
4376
|
-
if (ts.isExportDeclaration(stmt) &&
|
|
4377
|
-
(stmt.isTypeOnly || erasedTypeOnlyReexport(stmt) || !stmt.moduleSpecifier))
|
|
5533
|
+
if (ts.isExportDeclaration(stmt) && (stmt.isTypeOnly || !stmt.moduleSpecifier))
|
|
4378
5534
|
continue;
|
|
4379
5535
|
if (!ts.isImportDeclaration(stmt) && !ts.isExportDeclaration(stmt))
|
|
4380
5536
|
continue;
|
|
@@ -4393,6 +5549,58 @@ export function orderedImportsOf(program, sf) {
|
|
|
4393
5549
|
}
|
|
4394
5550
|
return out;
|
|
4395
5551
|
}
|
|
5552
|
+
/** The files a compiled program can load: the module order closed over
|
|
5553
|
+
* every literal require() and import() call it contains (deferred and
|
|
5554
|
+
* nested ones included) and, for opted-in package JavaScript, over every
|
|
5555
|
+
* import and export declaration as well. A package file outside this set
|
|
5556
|
+
* is reachable only through types, so whatever it spells cannot affect
|
|
5557
|
+
* the compiled program. Null when a reachable file loads a computed
|
|
5558
|
+
* specifier: then any file may load. */
|
|
5559
|
+
export function npmStaticLoadableFiles(program, moduleOrder) {
|
|
5560
|
+
const seen = new Set();
|
|
5561
|
+
const work = [];
|
|
5562
|
+
const add = (sf) => {
|
|
5563
|
+
if (sf === null || sf === undefined || seen.has(sf) || sf.isDeclarationFile)
|
|
5564
|
+
return;
|
|
5565
|
+
seen.add(sf);
|
|
5566
|
+
work.push(sf);
|
|
5567
|
+
};
|
|
5568
|
+
for (const sf of moduleOrder)
|
|
5569
|
+
add(sf);
|
|
5570
|
+
let computed = false;
|
|
5571
|
+
while (work.length > 0 && !computed) {
|
|
5572
|
+
const sf = work.pop();
|
|
5573
|
+
const packageJs = npmStaticPackageOfPath(sf.fileName) !== null && isJsSourceFileName(sf.fileName);
|
|
5574
|
+
const follow = (spec, kind) => {
|
|
5575
|
+
if (canonicalBuiltinModule(spec) !== null)
|
|
5576
|
+
return;
|
|
5577
|
+
add(resolveImport7(program, sf, spec, kind) ?? npmStaticDepSf7(program, sf, spec, kind));
|
|
5578
|
+
};
|
|
5579
|
+
ts.walkPreorder(sf, (n) => {
|
|
5580
|
+
if (computed)
|
|
5581
|
+
return "stop";
|
|
5582
|
+
if (ts.isCallExpression(n)) {
|
|
5583
|
+
const isImport = n.expression.kind === ts.SyntaxKind.ImportKeyword;
|
|
5584
|
+
const isRequire = ts.isIdentifier(n.expression) && n.expression.text === "require";
|
|
5585
|
+
if (!isImport && !isRequire)
|
|
5586
|
+
return undefined;
|
|
5587
|
+
const arg = n.arguments.nodes[0];
|
|
5588
|
+
if (arg !== undefined && ts.isStringLiteralLike(arg))
|
|
5589
|
+
follow(arg.text, isImport ? "import" : "require");
|
|
5590
|
+
else if (packageJs || isImport)
|
|
5591
|
+
computed = true;
|
|
5592
|
+
}
|
|
5593
|
+
else if (packageJs &&
|
|
5594
|
+
(ts.isImportDeclaration(n) || ts.isExportDeclaration(n)) &&
|
|
5595
|
+
n.moduleSpecifier !== undefined &&
|
|
5596
|
+
ts.isStringLiteral(n.moduleSpecifier)) {
|
|
5597
|
+
follow(n.moduleSpecifier.text, "import");
|
|
5598
|
+
}
|
|
5599
|
+
return undefined;
|
|
5600
|
+
});
|
|
5601
|
+
}
|
|
5602
|
+
return computed ? null : new Set([...seen].map((sf) => sf.fileName.split("\\").join("/")));
|
|
5603
|
+
}
|
|
4396
5604
|
/** The program source file a bare specifier reaches when it names an
|
|
4397
5605
|
* opted-in --npm-static package (the shipped-JS entry preflight admitted
|
|
4398
5606
|
* as a module edge), else null. No offender reporting here — preflight
|
|
@@ -4434,6 +5642,19 @@ export function cjsExportAssignmentOf(stmt) {
|
|
|
4434
5642
|
if (isModuleExportsAccess(e.left)) {
|
|
4435
5643
|
return { kind: "table", obj: ts.isObjectLiteralExpression(e.right) ? e.right : null, expr: e };
|
|
4436
5644
|
}
|
|
5645
|
+
if (ts.isIdentifier(e.left) && e.left.text === "exports") {
|
|
5646
|
+
let inner = e.right;
|
|
5647
|
+
while (ts.isParenthesizedExpression(inner))
|
|
5648
|
+
inner = inner.expression;
|
|
5649
|
+
if (ts.isBinaryExpression(inner) &&
|
|
5650
|
+
inner.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
5651
|
+
isModuleExportsAccess(inner.left) &&
|
|
5652
|
+
// `exports = module.exports = {}` is the fresh-table reset, which the
|
|
5653
|
+
// export walk handles on its own.
|
|
5654
|
+
!ts.isObjectLiteralExpression(inner.right)) {
|
|
5655
|
+
return { kind: "table", obj: null, expr: inner, rebindsExports: true };
|
|
5656
|
+
}
|
|
5657
|
+
}
|
|
4437
5658
|
if (ts.isPropertyAccessExpression(e.left) && !e.left.questionDotToken) {
|
|
4438
5659
|
const recv = e.left.expression;
|
|
4439
5660
|
const isExports = ts.isIdentifier(recv) && recv.text === "exports";
|
|
@@ -4443,6 +5664,85 @@ export function cjsExportAssignmentOf(stmt) {
|
|
|
4443
5664
|
}
|
|
4444
5665
|
return null;
|
|
4445
5666
|
}
|
|
5667
|
+
/** The tsc VOID-INIT PREAMBLE (`exports.a = exports.b = void 0;` with the
|
|
5668
|
+
* real `exports.a = a;` further down; every tsc-emitted dist file opens its
|
|
5669
|
+
* exports this way): when every name in the chain has a later real
|
|
5670
|
+
* assignment, the export takes its value there and the preamble lowers to
|
|
5671
|
+
* nothing. Returns those later assignments by name, or null when this is
|
|
5672
|
+
* not such a preamble (a preamble with no later real assignment keeps the
|
|
5673
|
+
* ordinary path: the export IS undefined then). */
|
|
5674
|
+
export function cjsVoidInitPreambleReals(cjs) {
|
|
5675
|
+
if (!ts.isIdentifier(cjs.name))
|
|
5676
|
+
return null;
|
|
5677
|
+
const isExportsMember = (e) => ts.isPropertyAccessExpression(e) &&
|
|
5678
|
+
ts.isIdentifier(e.name) &&
|
|
5679
|
+
((ts.isIdentifier(e.expression) && e.expression.text === "exports") ||
|
|
5680
|
+
(ts.isPropertyAccessExpression(e.expression) &&
|
|
5681
|
+
ts.isIdentifier(e.expression.expression) &&
|
|
5682
|
+
e.expression.expression.text === "module" &&
|
|
5683
|
+
ts.isIdentifier(e.expression.name) &&
|
|
5684
|
+
e.expression.name.text === "exports"));
|
|
5685
|
+
const isVoid = (e) => {
|
|
5686
|
+
while (ts.isParenthesizedExpression(e))
|
|
5687
|
+
e = e.expression;
|
|
5688
|
+
return (e.kind === ts.SyntaxKind.VoidExpression || (ts.isIdentifier(e) && e.text === "undefined"));
|
|
5689
|
+
};
|
|
5690
|
+
// chains: `exports.a = exports.b = void 0;` collects every name
|
|
5691
|
+
const names = [cjs.name.text];
|
|
5692
|
+
let tail = cjs.value;
|
|
5693
|
+
while (ts.isBinaryExpression(tail) &&
|
|
5694
|
+
tail.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
5695
|
+
isExportsMember(tail.left)) {
|
|
5696
|
+
names.push(tail.left.name.text);
|
|
5697
|
+
tail = tail.right;
|
|
5698
|
+
}
|
|
5699
|
+
if (!isVoid(tail))
|
|
5700
|
+
return null;
|
|
5701
|
+
const sf = ts.getSourceFileOfNode(cjs.expr);
|
|
5702
|
+
const myPos = ts.tokenStartOfNode(cjs.expr);
|
|
5703
|
+
const reals = new Map();
|
|
5704
|
+
for (const name of names) {
|
|
5705
|
+
const real = sf.statements.nodes
|
|
5706
|
+
.map((s) => cjsExportAssignmentOf(s))
|
|
5707
|
+
.find((other) => other?.kind === "member" &&
|
|
5708
|
+
ts.isIdentifier(other.name) &&
|
|
5709
|
+
other.name.text === name &&
|
|
5710
|
+
ts.tokenStartOfNode(other.expr) > myPos &&
|
|
5711
|
+
!isVoid(other.value));
|
|
5712
|
+
if (real?.kind !== "member")
|
|
5713
|
+
return null;
|
|
5714
|
+
reals.set(name, real);
|
|
5715
|
+
}
|
|
5716
|
+
return reals;
|
|
5717
|
+
}
|
|
5718
|
+
/** The members and shared value of a CHAINED member export
|
|
5719
|
+
* `exports.a = exports.b = module.exports.c = value` (outermost name
|
|
5720
|
+
* first), or null when the assignment is not a chain of at least two
|
|
5721
|
+
* identifier-named export members or its value is undefined. */
|
|
5722
|
+
export function cjsExportChainOf(e) {
|
|
5723
|
+
const names = [];
|
|
5724
|
+
let cur = e;
|
|
5725
|
+
for (;;) {
|
|
5726
|
+
while (ts.isParenthesizedExpression(cur))
|
|
5727
|
+
cur = cur.expression;
|
|
5728
|
+
if (!ts.isBinaryExpression(cur) || cur.operatorToken.kind !== ts.SyntaxKind.EqualsToken)
|
|
5729
|
+
break;
|
|
5730
|
+
const left = cur.left;
|
|
5731
|
+
if (!ts.isPropertyAccessExpression(left) ||
|
|
5732
|
+
left.questionDotToken ||
|
|
5733
|
+
!ts.isIdentifier(left.name))
|
|
5734
|
+
break;
|
|
5735
|
+
const recv = left.expression;
|
|
5736
|
+
if (!((ts.isIdentifier(recv) && recv.text === "exports") || isModuleExportsAccess(recv)))
|
|
5737
|
+
break;
|
|
5738
|
+
names.push(left.name);
|
|
5739
|
+
cur = cur.right;
|
|
5740
|
+
}
|
|
5741
|
+
// tsc's `exports.a = exports.b = void 0;` preamble is not a value chain
|
|
5742
|
+
// (the export-statement lowering owns it).
|
|
5743
|
+
const isVoid = cur.kind === ts.SyntaxKind.VoidExpression || (ts.isIdentifier(cur) && cur.text === "undefined");
|
|
5744
|
+
return names.length >= 2 && !isVoid ? { names, value: cur } : null;
|
|
5745
|
+
}
|
|
4446
5746
|
/** Why Node would DISCARD this CommonJS export statement, or null when it
|
|
4447
5747
|
* survives (Node's export-object identity rules — checker-free, pure
|
|
4448
5748
|
* AST): `module.exports = {...}` REPLACES the export object, so members
|
|
@@ -4458,7 +5758,7 @@ export function cjsExportDiscardReason(stmt) {
|
|
|
4458
5758
|
const mine = cjsExportAssignmentOf(stmt);
|
|
4459
5759
|
if (!mine)
|
|
4460
5760
|
return null;
|
|
4461
|
-
const stmts = sf.statements;
|
|
5761
|
+
const stmts = sf.statements.nodes;
|
|
4462
5762
|
let lastTable = -1;
|
|
4463
5763
|
for (let i = 0; i < stmts.length; i++) {
|
|
4464
5764
|
if (cjsExportAssignmentOf(stmts[i])?.kind === "table")
|
|
@@ -4476,6 +5776,9 @@ export function cjsExportDiscardReason(stmt) {
|
|
|
4476
5776
|
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)";
|
|
4477
5777
|
}
|
|
4478
5778
|
const left = mine.expr.left;
|
|
5779
|
+
const last = cjsExportAssignmentOf(stmts[lastTable]);
|
|
5780
|
+
if (last?.kind === "table" && last.rebindsExports === true)
|
|
5781
|
+
return null;
|
|
4479
5782
|
return ts.isIdentifier(left.expression) && left.expression.text === "exports"
|
|
4480
5783
|
? "'exports.f =' after a 'module.exports =' assignment ('exports' still references the replaced object — Node discards this member; write module.exports.f instead)"
|
|
4481
5784
|
: null;
|
|
@@ -4495,16 +5798,16 @@ export function cjsExportTargetLiteral(e, sf) {
|
|
|
4495
5798
|
if (ts.isNewExpression(e) &&
|
|
4496
5799
|
ts.isIdentifier(e.expression) &&
|
|
4497
5800
|
e.expression.text === "Proxy" &&
|
|
4498
|
-
(e.arguments?.length ?? 0) >= 1) {
|
|
4499
|
-
return cjsExportTargetLiteral(e.arguments[0], sf);
|
|
5801
|
+
(e.arguments?.nodes.length ?? 0) >= 1) {
|
|
5802
|
+
return cjsExportTargetLiteral(e.arguments.nodes[0], sf);
|
|
4500
5803
|
}
|
|
4501
5804
|
if (ts.isIdentifier(e)) {
|
|
4502
|
-
for (const stmt of sf.statements) {
|
|
5805
|
+
for (const stmt of sf.statements.nodes) {
|
|
4503
5806
|
if (!ts.isVariableStatement(stmt))
|
|
4504
5807
|
continue;
|
|
4505
5808
|
if ((stmt.declarationList.flags & ts.NodeFlags.Const) === 0)
|
|
4506
5809
|
continue;
|
|
4507
|
-
for (const d of stmt.declarationList.declarations) {
|
|
5810
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
4508
5811
|
if (d.name !== undefined &&
|
|
4509
5812
|
ts.isIdentifier(d.name) &&
|
|
4510
5813
|
d.name.text === e.text &&
|
|
@@ -4526,7 +5829,7 @@ export function cjsExportTargetLiteral(e, sf) {
|
|
|
4526
5829
|
* order against it). Null when the kept export is anything else. */
|
|
4527
5830
|
export function cjsClassExprWholeExportOf(sf) {
|
|
4528
5831
|
let last = null;
|
|
4529
|
-
for (const stmt of sf.statements) {
|
|
5832
|
+
for (const stmt of sf.statements.nodes) {
|
|
4530
5833
|
const cjs = cjsExportAssignmentOf(stmt);
|
|
4531
5834
|
if (!cjs || cjs.kind !== "table")
|
|
4532
5835
|
continue;
|
|
@@ -4557,10 +5860,10 @@ export function isCjsExportTableLiteral(obj) {
|
|
|
4557
5860
|
const decl = obj.parent;
|
|
4558
5861
|
if (!ts.isVariableDeclaration(decl) || decl.initializer !== obj)
|
|
4559
5862
|
return false;
|
|
4560
|
-
const sf =
|
|
5863
|
+
const sf = ts.getSourceFileOfNode(obj);
|
|
4561
5864
|
if (!isJsSourceFile(sf))
|
|
4562
5865
|
return false;
|
|
4563
|
-
for (const stmt of sf.statements) {
|
|
5866
|
+
for (const stmt of sf.statements.nodes) {
|
|
4564
5867
|
const cjs = cjsExportAssignmentOf(stmt);
|
|
4565
5868
|
if (cjs?.kind === "table" && cjsExportDiscardReason(stmt) === null) {
|
|
4566
5869
|
return cjsExportTargetLiteral(cjs.expr.right, sf) === obj;
|
|
@@ -4667,7 +5970,7 @@ function receiverRoot(text, pos) {
|
|
|
4667
5970
|
/** Whether `name` is bound in `fileName` by an import of a Node builtin. */
|
|
4668
5971
|
function importsNodeBuiltin(load, fileName, name) {
|
|
4669
5972
|
const sf = load.program.getSourceFile(fileName);
|
|
4670
|
-
for (const stmt of sf?.statements ?? []) {
|
|
5973
|
+
for (const stmt of sf?.statements?.nodes ?? []) {
|
|
4671
5974
|
if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
4672
5975
|
continue;
|
|
4673
5976
|
if (canonicalBuiltinModule(stmt.moduleSpecifier.text) === null)
|
|
@@ -4680,7 +5983,7 @@ function importsNodeBuiltin(load, fileName, name) {
|
|
|
4680
5983
|
return true;
|
|
4681
5984
|
if (bindings &&
|
|
4682
5985
|
ts.isNamedImports(bindings) &&
|
|
4683
|
-
bindings.elements.some((e) => e.name.text === name))
|
|
5986
|
+
bindings.elements.nodes.some((e) => e.name.text === name))
|
|
4684
5987
|
return true;
|
|
4685
5988
|
}
|
|
4686
5989
|
return false;
|