@scriptc/compiler 0.3.6 → 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 +682 -50
- 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 +293 -178
- 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 +547 -283
- package/dist/backend/llvm/emitter.js +689 -4643
- 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-dynamic.d.ts +3 -0
- package/dist/backend/llvm/expr-dynamic.js +67 -62
- package/dist/backend/llvm/expr-dynamic.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.js +121 -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 +189 -23
- package/dist/backend/llvm/lib-dispatch.js.map +1 -1
- package/dist/backend/llvm/lib-filesystem.js +42 -13
- package/dist/backend/llvm/lib-filesystem.js.map +1 -1
- package/dist/backend/llvm/lib-http2.js +3 -3
- package/dist/backend/llvm/lib-http2.js.map +1 -1
- package/dist/backend/llvm/lib-lookup.js +2 -2
- package/dist/backend/llvm/lib-lookup.js.map +1 -1
- package/dist/backend/llvm/lib-network.js +56 -22
- package/dist/backend/llvm/lib-network.js.map +1 -1
- package/dist/backend/llvm/lib-process.js +90 -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 +187 -6
- package/dist/backend/llvm/lib-shared.js.map +1 -1
- package/dist/backend/llvm/lib-stream.js +46 -16
- package/dist/backend/llvm/lib-stream.js.map +1 -1
- package/dist/backend/llvm/lib-test.js +43 -7
- package/dist/backend/llvm/lib-test.js.map +1 -1
- package/dist/backend/llvm/lib-tls.js +4 -9
- package/dist/backend/llvm/lib-tls.js.map +1 -1
- package/dist/backend/llvm/local-array-reads.js +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 +64 -6
- package/dist/backend/llvm/nullable-unions.js +103 -6
- package/dist/backend/llvm/nullable-unions.js.map +1 -1
- package/dist/backend/llvm/nullable-unions.test.d.ts +1 -0
- package/dist/backend/llvm/nullable-unions.test.js +65 -0
- package/dist/backend/llvm/nullable-unions.test.js.map +1 -0
- package/dist/backend/llvm/publish.d.ts +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 +12 -1
- package/dist/backend/llvm/record-results.js +64 -4
- package/dist/backend/llvm/record-results.js.map +1 -1
- package/dist/backend/llvm/reference-effects.js +9 -0
- package/dist/backend/llvm/reference-effects.js.map +1 -1
- package/dist/backend/llvm/reference-writes.d.ts +4 -0
- package/dist/backend/llvm/reference-writes.js +142 -6
- package/dist/backend/llvm/reference-writes.js.map +1 -1
- package/dist/backend/llvm/reference-writes.test.d.ts +1 -0
- package/dist/backend/llvm/reference-writes.test.js +88 -0
- package/dist/backend/llvm/reference-writes.test.js.map +1 -0
- package/dist/backend/llvm/regex-matchers.d.ts +8 -0
- package/dist/backend/llvm/regex-matchers.js +33 -0
- package/dist/backend/llvm/regex-matchers.js.map +1 -1
- package/dist/backend/llvm/regex-matchers.test.js +23 -1
- package/dist/backend/llvm/regex-matchers.test.js.map +1 -1
- package/dist/backend/llvm/regions.d.ts +1 -1
- package/dist/backend/llvm/regions.js +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 +66 -43
- package/dist/backend/llvm/shapes.js +280 -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/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 +4 -2
- package/dist/backend/may-throw.js.map +1 -1
- package/dist/backend/may-throw.test.js +1 -1
- package/dist/backend/native/contracts.d.ts +37 -0
- package/dist/backend/native/executable.js +192 -137
- 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 +1 -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.test.js +5 -0
- 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 +24 -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 +16 -3
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/coverage/verdict-cache.d.ts +2 -0
- package/dist/coverage/verdict-cache.js +12 -0
- package/dist/coverage/verdict-cache.js.map +1 -1
- package/dist/coverage/verdict-cache.test.js +2 -1
- package/dist/coverage/verdict-cache.test.js.map +1 -1
- package/dist/diagnostics/diagnostic.d.ts +10 -6
- package/dist/diagnostics/diagnostic.js +29 -21
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/diagnostics/envelope.d.ts +39 -2
- package/dist/diagnostics/envelope.js.map +1 -1
- package/dist/diagnostics/render.d.ts +7 -0
- package/dist/diagnostics/render.js +50 -13
- package/dist/diagnostics/render.js.map +1 -1
- package/dist/diagnostics/render.test.d.ts +1 -0
- package/dist/diagnostics/render.test.js +49 -0
- package/dist/diagnostics/render.test.js.map +1 -0
- package/dist/executable/executable-cache.d.ts +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 +63 -5
- package/dist/frontend/lowering/builtin-calls.js.map +1 -1
- package/dist/frontend/lowering/builtin-function-fences.d.ts +14 -0
- package/dist/frontend/lowering/builtin-function-fences.js +42 -0
- package/dist/frontend/lowering/builtin-function-fences.js.map +1 -0
- package/dist/frontend/lowering/builtins/arguments.js +1 -1
- package/dist/frontend/lowering/builtins/arguments.js.map +1 -1
- package/dist/frontend/lowering/builtins/async-context.js +53 -52
- package/dist/frontend/lowering/builtins/async-context.js.map +1 -1
- package/dist/frontend/lowering/builtins/atomics.js +6 -6
- package/dist/frontend/lowering/builtins/atomics.js.map +1 -1
- package/dist/frontend/lowering/builtins/blob.js +8 -6
- package/dist/frontend/lowering/builtins/blob.js.map +1 -1
- package/dist/frontend/lowering/builtins/builtin-class-dyn.d.ts +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 +16 -5
- package/dist/frontend/lowering/builtins/callable-aliases.js.map +1 -1
- package/dist/frontend/lowering/builtins/child-process-async.js +7 -7
- package/dist/frontend/lowering/builtins/child-process-async.js.map +1 -1
- package/dist/frontend/lowering/builtins/child-process-methods.d.ts +6 -4
- package/dist/frontend/lowering/builtins/child-process-methods.js +310 -57
- package/dist/frontend/lowering/builtins/child-process-methods.js.map +1 -1
- package/dist/frontend/lowering/builtins/child-process-sync.js +16 -10
- package/dist/frontend/lowering/builtins/child-process-sync.js.map +1 -1
- package/dist/frontend/lowering/builtins/child-process.d.ts +6 -4
- package/dist/frontend/lowering/builtins/child-process.js +85 -61
- package/dist/frontend/lowering/builtins/child-process.js.map +1 -1
- package/dist/frontend/lowering/builtins/class-values.d.ts +60 -0
- package/dist/frontend/lowering/builtins/class-values.js +226 -0
- package/dist/frontend/lowering/builtins/class-values.js.map +1 -0
- package/dist/frontend/lowering/builtins/compression.d.ts +9 -0
- package/dist/frontend/lowering/builtins/compression.js +107 -44
- package/dist/frontend/lowering/builtins/compression.js.map +1 -1
- package/dist/frontend/lowering/builtins/constants.d.ts +9 -1
- package/dist/frontend/lowering/builtins/constants.js +28 -7
- package/dist/frontend/lowering/builtins/constants.js.map +1 -1
- package/dist/frontend/lowering/builtins/crypto.d.ts +19 -0
- package/dist/frontend/lowering/builtins/crypto.js +211 -37
- 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 +169 -3
- package/dist/frontend/lowering/builtins/errors.js.map +1 -1
- package/dist/frontend/lowering/builtins/filesystem-calls.js +128 -116
- package/dist/frontend/lowering/builtins/filesystem-calls.js.map +1 -1
- package/dist/frontend/lowering/builtins/filesystem.js +77 -77
- package/dist/frontend/lowering/builtins/filesystem.js.map +1 -1
- package/dist/frontend/lowering/builtins/fs-glob.js +3 -3
- package/dist/frontend/lowering/builtins/fs-glob.js.map +1 -1
- package/dist/frontend/lowering/builtins/fs-streams.js +10 -11
- package/dist/frontend/lowering/builtins/fs-streams.js.map +1 -1
- package/dist/frontend/lowering/builtins/ipc.js +45 -8
- package/dist/frontend/lowering/builtins/ipc.js.map +1 -1
- package/dist/frontend/lowering/builtins/json.js +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 +55 -44
- package/dist/frontend/lowering/builtins/module-calls.js.map +1 -1
- package/dist/frontend/lowering/builtins/module-resolution.d.ts +4 -3
- package/dist/frontend/lowering/builtins/module-resolution.js +24 -23
- package/dist/frontend/lowering/builtins/module-resolution.js.map +1 -1
- package/dist/frontend/lowering/builtins/navigator.d.ts +13 -0
- package/dist/frontend/lowering/builtins/navigator.js +40 -0
- package/dist/frontend/lowering/builtins/navigator.js.map +1 -0
- package/dist/frontend/lowering/builtins/net-address.d.ts +19 -0
- package/dist/frontend/lowering/builtins/net-address.js +156 -0
- package/dist/frontend/lowering/builtins/net-address.js.map +1 -0
- package/dist/frontend/lowering/builtins/numbers.js +25 -9
- package/dist/frontend/lowering/builtins/numbers.js.map +1 -1
- package/dist/frontend/lowering/builtins/operating-system.d.ts +4 -0
- package/dist/frontend/lowering/builtins/operating-system.js +25 -12
- package/dist/frontend/lowering/builtins/operating-system.js.map +1 -1
- package/dist/frontend/lowering/builtins/performance.d.ts +12 -0
- package/dist/frontend/lowering/builtins/performance.js +259 -8
- package/dist/frontend/lowering/builtins/performance.js.map +1 -1
- package/dist/frontend/lowering/builtins/process.d.ts +32 -1
- package/dist/frontend/lowering/builtins/process.js +461 -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 +12 -2
- package/dist/frontend/lowering/builtins/readline.js +136 -39
- package/dist/frontend/lowering/builtins/readline.js.map +1 -1
- package/dist/frontend/lowering/builtins/receiver-types.js +3 -5
- package/dist/frontend/lowering/builtins/receiver-types.js.map +1 -1
- package/dist/frontend/lowering/builtins/reflection.js +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 +12 -0
- package/dist/frontend/lowering/builtins/workers.js +193 -8
- package/dist/frontend/lowering/builtins/workers.js.map +1 -1
- package/dist/frontend/lowering/call-arguments.js +69 -14
- package/dist/frontend/lowering/call-arguments.js.map +1 -1
- package/dist/frontend/lowering/call-signatures.d.ts +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.js +25 -44
- 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 +6 -5
- package/dist/frontend/lowering/containers/array-from-async.js +159 -14
- package/dist/frontend/lowering/containers/array-from-async.js.map +1 -1
- package/dist/frontend/lowering/containers/array-methods.js +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 +217 -26
- package/dist/frontend/lowering/containers/collection-grouping.js.map +1 -1
- package/dist/frontend/lowering/containers/collection-methods.js +54 -25
- 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 +62 -125
- package/dist/frontend/lowering/divergences.js.map +1 -1
- package/dist/frontend/lowering/dyn-streams.d.ts +25 -0
- package/dist/frontend/lowering/dyn-streams.js +257 -0
- package/dist/frontend/lowering/dyn-streams.js.map +1 -0
- package/dist/frontend/lowering/error-methods.js +4 -1
- package/dist/frontend/lowering/error-methods.js.map +1 -1
- package/dist/frontend/lowering/error-name-order.d.ts +19 -0
- package/dist/frontend/lowering/error-name-order.js +93 -0
- package/dist/frontend/lowering/error-name-order.js.map +1 -0
- package/dist/frontend/lowering/expressions/array-literals.d.ts +21 -0
- package/dist/frontend/lowering/expressions/array-literals.js +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 +1239 -442
- 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 +1473 -468
- 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 +258 -70
- package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
- package/dist/frontend/lowering/lower-event-target.js +2 -2
- package/dist/frontend/lowering/lower-event-target.js.map +1 -1
- package/dist/frontend/lowering/lower-expando.js +17 -13
- package/dist/frontend/lowering/lower-expando.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.d.ts +188 -186
- package/dist/frontend/lowering/lower-exprs.js +1481 -12489
- 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 +331 -96
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-mixins.js +23 -20
- package/dist/frontend/lowering/lower-mixins.js.map +1 -1
- package/dist/frontend/lowering/lower-mock.d.ts +8 -1
- package/dist/frontend/lowering/lower-mock.js +185 -18
- package/dist/frontend/lowering/lower-mock.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.js +267 -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 +488 -100
- 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 +1541 -391
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lower-stream.d.ts +3 -0
- package/dist/frontend/lowering/lower-stream.js +398 -56
- package/dist/frontend/lowering/lower-stream.js.map +1 -1
- package/dist/frontend/lowering/lower-test.d.ts +3 -0
- package/dist/frontend/lowering/lower-test.js +437 -62
- package/dist/frontend/lowering/lower-test.js.map +1 -1
- package/dist/frontend/lowering/lower-timers.js +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 +399 -26
- package/dist/frontend/lowering/lowerer.js +1910 -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/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 +12 -3
- package/dist/frontend/lowering/surfaces.js +252 -41
- 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.js +13 -6
- package/dist/frontend/mock-shapes.js.map +1 -1
- package/dist/frontend/module-source-candidates.js +1 -1
- package/dist/frontend/module-source-candidates.js.map +1 -1
- package/dist/frontend/module-source-candidates.test.js +2 -1
- package/dist/frontend/module-source-candidates.test.js.map +1 -1
- package/dist/frontend/module-syntax.js +8 -8
- package/dist/frontend/module-syntax.js.map +1 -1
- package/dist/frontend/npm-static-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 -255
- 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 +2545 -719
- 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 +29 -2
- 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 +103 -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 +494 -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 +9 -1
- package/dist/ir/function-references.test.js.map +1 -1
- package/dist/ir/init-only-globals.test.js +1 -1
- package/dist/ir/initializer-bindings.test.js +1 -1
- package/dist/ir/int32-slots.d.ts +14 -0
- package/dist/ir/int32-slots.js +97 -14
- package/dist/ir/int32-slots.js.map +1 -1
- package/dist/ir/int32-slots.test.js +1 -1
- package/dist/ir/integer-loop-facts.d.ts +2 -0
- package/dist/ir/integer-loop-facts.js +24 -3
- 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 +3 -1
- package/dist/ir/integer-ranges.js.map +1 -1
- package/dist/ir/integer-ranges.test.js +82 -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 +221 -58
- package/dist/ir/ir.js +119 -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 +148 -33
- package/dist/ir/runtime-features.js +629 -386
- package/dist/ir/runtime-features.js.map +1 -1
- package/dist/ir/scalar-records.test.js +1 -1
- package/dist/ir/self-captures.d.ts +33 -0
- package/dist/ir/self-captures.js +245 -0
- package/dist/ir/self-captures.js.map +1 -0
- package/dist/ir/self-captures.test.d.ts +1 -0
- package/dist/ir/self-captures.test.js +135 -0
- package/dist/ir/self-captures.test.js.map +1 -0
- package/dist/ir/serialize.d.ts +1 -1
- package/dist/ir/serialize.js +7 -4
- package/dist/ir/serialize.js.map +1 -1
- package/dist/ir/tiers.d.ts +26 -0
- package/dist/ir/tiers.js +101 -0
- package/dist/ir/tiers.js.map +1 -0
- package/dist/ir/tiers.test.d.ts +1 -0
- package/dist/ir/tiers.test.js +140 -0
- package/dist/ir/tiers.test.js.map +1 -0
- package/dist/ir/traverse.js +103 -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 +175 -68
- package/dist/ir/validate.js.map +1 -1
- package/dist/ir/validate.test.js +26 -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 +13 -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 +303 -19
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,11 +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
|
-
// slices in TS 7 even though Node 24 ships them. Include
|
|
79
|
-
// libs without widening the rest of the standard-library
|
|
80
|
-
// ES2025.
|
|
81
|
-
lib: [
|
|
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
|
+
],
|
|
82
88
|
types: [],
|
|
83
89
|
allowImportingTsExtensions: true,
|
|
84
90
|
allowJs: true,
|
|
@@ -221,6 +227,7 @@ function adoptProjectConfig7(host, entryPath) {
|
|
|
221
227
|
diags,
|
|
222
228
|
...(projectLib === undefined ? {} : { projectLib }),
|
|
223
229
|
forcedStrictNullChecks,
|
|
230
|
+
checkJs: parsed.options["checkJs"] === true,
|
|
224
231
|
};
|
|
225
232
|
}
|
|
226
233
|
/** The target project's @types/node, resolved with the OWN resolver's
|
|
@@ -409,12 +416,12 @@ function createRequireProgramRoots7(program) {
|
|
|
409
416
|
const calls = [];
|
|
410
417
|
for (const node of moduleSourceCandidates(program, sf).calls) {
|
|
411
418
|
if (node.questionDotToken !== undefined ||
|
|
412
|
-
node.arguments.length !== 1 ||
|
|
413
|
-
!ts.isStringLiteralLike(node.arguments[0]) ||
|
|
419
|
+
node.arguments.nodes.length !== 1 ||
|
|
420
|
+
!ts.isStringLiteralLike(node.arguments.nodes[0]) ||
|
|
414
421
|
!ts.isIdentifier(node.expression)) {
|
|
415
422
|
continue;
|
|
416
423
|
}
|
|
417
|
-
calls.push({ callee: node.expression, spec: node.arguments[0].text });
|
|
424
|
+
calls.push({ callee: node.expression, spec: node.arguments.nodes[0].text });
|
|
418
425
|
}
|
|
419
426
|
// Root discovery only needs the callee's binding. A first-miss lookup
|
|
420
427
|
// otherwise fetches symbols and types for every identifier in the file,
|
|
@@ -462,9 +469,10 @@ export function entryPackageFilePredicate(entryPath) {
|
|
|
462
469
|
};
|
|
463
470
|
}
|
|
464
471
|
/** maxNodeModuleJsDepth can omit relative imports within an admitted
|
|
465
|
-
* package
|
|
466
|
-
*
|
|
467
|
-
|
|
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) {
|
|
468
476
|
const belongsToEntry = entryPackageFilePredicate(entryPath);
|
|
469
477
|
const roots = new Set();
|
|
470
478
|
for (const sf of program.getImplementationSourceFiles()) {
|
|
@@ -480,11 +488,80 @@ function entryPackageProgramRoots7(program, entryPath) {
|
|
|
480
488
|
isJsSourceFileName(target) &&
|
|
481
489
|
program.getSourceFile(target) === undefined)
|
|
482
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
|
+
}
|
|
483
517
|
}
|
|
484
518
|
}
|
|
485
519
|
return [...roots].sort();
|
|
486
520
|
}
|
|
487
|
-
|
|
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) {
|
|
488
565
|
const config = adoptProjectConfig7(host, entryPath);
|
|
489
566
|
const configuredPaths = config.options["paths"];
|
|
490
567
|
setProjectPathMappings(configuredPaths !== undefined && typeof configuredPaths === "object" && configuredPaths !== null
|
|
@@ -530,7 +607,7 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
530
607
|
try {
|
|
531
608
|
for (let pass = 0; pass < 32; pass++) {
|
|
532
609
|
const candidates = [
|
|
533
|
-
...entryPackageProgramRoots7(program, entryPath),
|
|
610
|
+
...entryPackageProgramRoots7(program, entryPath, rootNpmStaticEdges),
|
|
534
611
|
...createRequireProgramRoots7(program),
|
|
535
612
|
...forkTargetPaths(program, program.getImplementationSourceFiles()),
|
|
536
613
|
...workerTargetPaths(program, program.getImplementationSourceFiles()),
|
|
@@ -544,6 +621,20 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
544
621
|
if (pass === 31)
|
|
545
622
|
throw new Error("static program-root discovery did not converge");
|
|
546
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
|
+
}
|
|
547
638
|
const entry = program.getSourceFile(entryPath);
|
|
548
639
|
if (!entry)
|
|
549
640
|
throw new Error(`could not load ${entryPath}`);
|
|
@@ -558,6 +649,7 @@ function loadProgram7(host, entryPath, externalTypes = new Map()) {
|
|
|
558
649
|
nodeFallback: nodeTypes === null,
|
|
559
650
|
projectLib: config.projectLib ?? null,
|
|
560
651
|
forcedStrictNullChecks: config.forcedStrictNullChecks ?? false,
|
|
652
|
+
projectCheckJs: config.checkJs ?? false,
|
|
561
653
|
},
|
|
562
654
|
externalTypes,
|
|
563
655
|
externalTypeSpecifiersByFile,
|
|
@@ -712,7 +804,7 @@ export function loadProgram(entryPath, services, opts) {
|
|
|
712
804
|
};
|
|
713
805
|
const host = services.createProgramHost({ cwd: dirname(entryPath), fsShadow });
|
|
714
806
|
try {
|
|
715
|
-
const load = loadProgram7(host, entryPath, externalTypes);
|
|
807
|
+
const load = loadProgram7(host, entryPath, externalTypes, npmStaticPackages.length > 0);
|
|
716
808
|
let authoredHost = null;
|
|
717
809
|
let authoredLoad = null;
|
|
718
810
|
return {
|
|
@@ -757,9 +849,10 @@ export function loadProgram(entryPath, services, opts) {
|
|
|
757
849
|
* preflight diagnostics. Preserve the caller's complete load shape when
|
|
758
850
|
* mutating it, including its owned services and disposal callback. */
|
|
759
851
|
export function checkPreflight(load) {
|
|
760
|
-
const { diags, moduleOrder, startupCrash } = preflight7(load);
|
|
852
|
+
const { diags, moduleOrder, startupCrash, inlineRequireCycleCalls } = preflight7(load);
|
|
761
853
|
load.moduleOrder = moduleOrder;
|
|
762
854
|
load.startupCrash = startupCrash;
|
|
855
|
+
load.inlineRequireCycleCalls = inlineRequireCycleCalls;
|
|
763
856
|
return diags;
|
|
764
857
|
}
|
|
765
858
|
/* Finding 5: tsgo's strict CommonJS modeling fires checker codes on JS
|
|
@@ -779,6 +872,13 @@ export function checkPreflight(load) {
|
|
|
779
872
|
// retains only their call signature after a factory return. Heritage
|
|
780
873
|
// lowering separately verifies the actual constructor implementation.
|
|
781
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
|
+
]);
|
|
782
882
|
function suppressedJsStrictness7(d) {
|
|
783
883
|
const file = d.fileName;
|
|
784
884
|
if (!file || !isJsSourceFileName(file))
|
|
@@ -812,9 +912,9 @@ function requireSpecOf7(node) {
|
|
|
812
912
|
return null;
|
|
813
913
|
if (!ts.isIdentifier(value.expression) || value.expression.text !== "require")
|
|
814
914
|
return null;
|
|
815
|
-
if (value.arguments.length !== 1)
|
|
915
|
+
if (value.arguments.nodes.length !== 1)
|
|
816
916
|
return null;
|
|
817
|
-
const arg = value.arguments[0];
|
|
917
|
+
const arg = value.arguments.nodes[0];
|
|
818
918
|
return ts.isStringLiteral(arg) ? arg.text : null;
|
|
819
919
|
}
|
|
820
920
|
/** True for statements that are CommonJS require IMPORTS at a module's top
|
|
@@ -827,7 +927,7 @@ function isRequireStatement7(stmt) {
|
|
|
827
927
|
return requireSpecOf7(stmt.expression) !== null;
|
|
828
928
|
if (!ts.isVariableStatement(stmt))
|
|
829
929
|
return false;
|
|
830
|
-
const decls = stmt.declarationList.declarations;
|
|
930
|
+
const decls = stmt.declarationList.declarations.nodes;
|
|
831
931
|
return (decls.length > 0 &&
|
|
832
932
|
decls.every((d) => d.initializer !== undefined && requireSpecOf7(d.initializer) !== null));
|
|
833
933
|
}
|
|
@@ -841,7 +941,7 @@ function requiresOf7(stmt) {
|
|
|
841
941
|
if (!ts.isVariableStatement(stmt))
|
|
842
942
|
return [];
|
|
843
943
|
const out = [];
|
|
844
|
-
for (const decl of stmt.declarationList.declarations) {
|
|
944
|
+
for (const decl of stmt.declarationList.declarations.nodes) {
|
|
845
945
|
const spec = decl.initializer !== undefined ? requireSpecOf7(decl.initializer) : null;
|
|
846
946
|
if (spec !== null)
|
|
847
947
|
out.push({ spec, node: decl, decl });
|
|
@@ -861,9 +961,9 @@ export function isEsModuleStamp(expr) {
|
|
|
861
961
|
callee.name.text !== "defineProperty") {
|
|
862
962
|
return false;
|
|
863
963
|
}
|
|
864
|
-
if (expr.arguments.length !== 3)
|
|
964
|
+
if (expr.arguments.nodes.length !== 3)
|
|
865
965
|
return false;
|
|
866
|
-
const [recv, nameArg, desc] = expr.arguments;
|
|
966
|
+
const [recv, nameArg, desc] = expr.arguments.nodes;
|
|
867
967
|
const isExports = (ts.isIdentifier(recv) && recv.text === "exports") ||
|
|
868
968
|
(ts.isPropertyAccessExpression(recv) &&
|
|
869
969
|
ts.isIdentifier(recv.expression) &&
|
|
@@ -874,9 +974,9 @@ export function isEsModuleStamp(expr) {
|
|
|
874
974
|
return false;
|
|
875
975
|
if (!ts.isStringLiteral(nameArg) || nameArg.text !== "__esModule")
|
|
876
976
|
return false;
|
|
877
|
-
if (!ts.isObjectLiteralExpression(desc) || desc.properties.length !== 1)
|
|
977
|
+
if (!ts.isObjectLiteralExpression(desc) || desc.properties.nodes.length !== 1)
|
|
878
978
|
return false;
|
|
879
|
-
const p = desc.properties[0];
|
|
979
|
+
const p = desc.properties.nodes[0];
|
|
880
980
|
return (ts.isPropertyAssignment(p) &&
|
|
881
981
|
ts.isIdentifier(p.name) &&
|
|
882
982
|
p.name.text === "value" &&
|
|
@@ -890,13 +990,13 @@ function pureCjsExport7(program, stmt) {
|
|
|
890
990
|
const cjs = cjsExportAssignmentOf(stmt);
|
|
891
991
|
if (cjs === null)
|
|
892
992
|
return false;
|
|
893
|
-
const sf =
|
|
993
|
+
const sf = ts.getSourceFileOfNode(stmt);
|
|
894
994
|
const plainMember = (left) => {
|
|
895
995
|
if (!ts.isPropertyAccessExpression(left) || left.questionDotToken)
|
|
896
996
|
return false;
|
|
897
997
|
// A replacement export can have setters or non-writable function
|
|
898
998
|
// properties. Only the wrapper's original object gets this exception.
|
|
899
|
-
if (sf.statements.some((s) => cjsExportAssignmentOf(s)?.kind === "table"))
|
|
999
|
+
if (sf.statements.nodes.some((s) => cjsExportAssignmentOf(s)?.kind === "table"))
|
|
900
1000
|
return false;
|
|
901
1001
|
if (left.name.text === "__proto__" || left.name.text === "__esModule")
|
|
902
1002
|
return false;
|
|
@@ -938,17 +1038,13 @@ function pureCjsExport7(program, stmt) {
|
|
|
938
1038
|
const checker = program.getTypeChecker();
|
|
939
1039
|
const symbol = checker.getSymbolAtLocation(value);
|
|
940
1040
|
return (symbol !== undefined &&
|
|
941
|
-
|
|
942
|
-
.declarationsOf(symbol)
|
|
943
|
-
.some((decl) => ts.isFunctionDeclaration(decl) && decl.parent === stmt.parent));
|
|
1041
|
+
symbol.declarations.some((decl) => ts.isFunctionDeclaration(decl) && decl.parent === stmt.parent));
|
|
944
1042
|
}
|
|
945
1043
|
function sourceBinding7(program, ident) {
|
|
946
1044
|
const checker = program.getTypeChecker();
|
|
947
1045
|
const symbol = checker.getSymbolAtLocation(ident);
|
|
948
1046
|
return (symbol !== undefined &&
|
|
949
|
-
|
|
950
|
-
.declarationsOf(symbol)
|
|
951
|
-
.some((decl) => !decl.getSourceFile().isDeclarationFile && !ts.isSourceFile(decl)));
|
|
1047
|
+
symbol.declarations.some((decl) => !ts.getSourceFileOfNode(decl).isDeclarationFile && !ts.isSourceFile(decl)));
|
|
952
1048
|
}
|
|
953
1049
|
function purePrefixDecl7(decl) {
|
|
954
1050
|
const init = decl.initializer;
|
|
@@ -972,11 +1068,11 @@ function purePrefixStmt7(program, s) {
|
|
|
972
1068
|
return true; // directive
|
|
973
1069
|
if (isRequireStatement7(s))
|
|
974
1070
|
return true;
|
|
975
|
-
if (isCjsJsFile7(
|
|
1071
|
+
if (isCjsJsFile7(ts.getSourceFileOfNode(s), program)) {
|
|
976
1072
|
if (ts.isExpressionStatement(s) && isEsModuleStamp(s.expression)) {
|
|
977
1073
|
const call = s.expression;
|
|
978
1074
|
const object = call.expression.expression;
|
|
979
|
-
let receiver = call.arguments[0];
|
|
1075
|
+
let receiver = call.arguments.nodes[0];
|
|
980
1076
|
if (ts.isPropertyAccessExpression(receiver))
|
|
981
1077
|
receiver = receiver.expression;
|
|
982
1078
|
if (!sourceBinding7(program, object) &&
|
|
@@ -988,7 +1084,7 @@ function purePrefixStmt7(program, s) {
|
|
|
988
1084
|
return true;
|
|
989
1085
|
}
|
|
990
1086
|
if (ts.isVariableStatement(s)) {
|
|
991
|
-
return s.declarationList.declarations.every(purePrefixDecl7);
|
|
1087
|
+
return s.declarationList.declarations.nodes.every(purePrefixDecl7);
|
|
992
1088
|
}
|
|
993
1089
|
return false;
|
|
994
1090
|
}
|
|
@@ -1012,7 +1108,7 @@ export function bindingEarlyUse7(program, sf, k, decl, precedingDecls) {
|
|
|
1012
1108
|
if (ts.isIdentifier(decl.name))
|
|
1013
1109
|
bound.push(decl.name);
|
|
1014
1110
|
else if (ts.isObjectBindingPattern(decl.name)) {
|
|
1015
|
-
for (const el of decl.name.elements)
|
|
1111
|
+
for (const el of decl.name.elements.nodes)
|
|
1016
1112
|
if (el.name !== undefined && ts.isIdentifier(el.name))
|
|
1017
1113
|
bound.push(el.name);
|
|
1018
1114
|
}
|
|
@@ -1024,7 +1120,7 @@ export function bindingEarlyUse7(program, sf, k, decl, precedingDecls) {
|
|
|
1024
1120
|
}
|
|
1025
1121
|
if (bindings.size === 0)
|
|
1026
1122
|
return null;
|
|
1027
|
-
const stmts = sf.statements;
|
|
1123
|
+
const stmts = sf.statements.nodes;
|
|
1028
1124
|
const hoisted = new Map();
|
|
1029
1125
|
for (const s of stmts) {
|
|
1030
1126
|
if ((ts.isFunctionDeclaration(s) || ts.isClassDeclaration(s)) && s.name) {
|
|
@@ -1083,6 +1179,542 @@ export function bindingEarlyUse7(program, sf, k, decl, precedingDecls) {
|
|
|
1083
1179
|
}
|
|
1084
1180
|
return hit;
|
|
1085
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
|
+
}
|
|
1086
1718
|
/** Bare `require("...")` EXPRESSION STATEMENTS anywhere below the top
|
|
1087
1719
|
* level of a file — inside top-level ifs/blocks/loops and inside function
|
|
1088
1720
|
* bodies (the lazy-require idiom). No bindings, pure side-effect loads. */
|
|
@@ -1101,6 +1733,35 @@ function nestedBareRequiresOf7(sf) {
|
|
|
1101
1733
|
});
|
|
1102
1734
|
return out;
|
|
1103
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
|
+
}
|
|
1104
1765
|
function stripRequireCasts7(expr) {
|
|
1105
1766
|
let cur = expr;
|
|
1106
1767
|
while (ts.isParenthesizedExpression(cur) ||
|
|
@@ -1117,7 +1778,7 @@ function stripRequireCasts7(expr) {
|
|
|
1117
1778
|
function isCreateRequireImport7(program, ident) {
|
|
1118
1779
|
const checker = program.getTypeChecker();
|
|
1119
1780
|
const symbol = checker.getSymbolAtLocation(ident);
|
|
1120
|
-
const decl = symbol ?
|
|
1781
|
+
const decl = symbol ? symbol.declarations[0] : undefined;
|
|
1121
1782
|
if (decl === undefined || !ts.isImportSpecifier(decl))
|
|
1122
1783
|
return false;
|
|
1123
1784
|
const importDecl = decl.parent?.parent?.parent;
|
|
@@ -1129,11 +1790,12 @@ function isCreateRequireImport7(program, ident) {
|
|
|
1129
1790
|
}
|
|
1130
1791
|
if (symbol !== undefined && (symbol.flags & ts.SymbolFlags.Alias) !== 0) {
|
|
1131
1792
|
const target = checker.getAliasedSymbol(symbol);
|
|
1132
|
-
const targetDecl =
|
|
1133
|
-
if (targetDecl !== undefined &&
|
|
1793
|
+
const targetDecl = target.declarations[0];
|
|
1794
|
+
if (targetDecl !== undefined && ts.getSourceFileOfNode(targetDecl).isDeclarationFile) {
|
|
1134
1795
|
for (let p = targetDecl.parent; p !== undefined && !ts.isSourceFile(p); p = p.parent) {
|
|
1135
1796
|
if (ts.isModuleDeclaration(p) && ts.isStringLiteral(p.name)) {
|
|
1136
|
-
return (canonicalBuiltinModule(p.name.text) === "module" &&
|
|
1797
|
+
return (canonicalBuiltinModule(p.name.text) === "module" &&
|
|
1798
|
+
ts.symbolName(target) === "createRequire");
|
|
1137
1799
|
}
|
|
1138
1800
|
}
|
|
1139
1801
|
}
|
|
@@ -1147,9 +1809,7 @@ export function isCreateRequireBinding7(program, callee) {
|
|
|
1147
1809
|
const checker = program.getTypeChecker();
|
|
1148
1810
|
const symbol = checker.getSymbolAtLocation(callee);
|
|
1149
1811
|
const decl = symbol
|
|
1150
|
-
?
|
|
1151
|
-
.declarationsOf(symbol)
|
|
1152
|
-
.find((d) => ts.isVariableDeclaration(d))
|
|
1812
|
+
? symbol.declarations.find((d) => ts.isVariableDeclaration(d))
|
|
1153
1813
|
: undefined;
|
|
1154
1814
|
if (decl === undefined ||
|
|
1155
1815
|
decl.initializer === undefined ||
|
|
@@ -1182,8 +1842,8 @@ function staticCreateRequireUse7(expr) {
|
|
|
1182
1842
|
return (ts.isCallExpression(call) &&
|
|
1183
1843
|
call.expression === use &&
|
|
1184
1844
|
!call.questionDotToken &&
|
|
1185
|
-
call.arguments.length === 1 &&
|
|
1186
|
-
ts.isStringLiteralLike(call.arguments[0]));
|
|
1845
|
+
call.arguments.nodes.length === 1 &&
|
|
1846
|
+
ts.isStringLiteralLike(call.arguments.nodes[0]));
|
|
1187
1847
|
}
|
|
1188
1848
|
function stableCreateRequireBindingReason7(program, decl) {
|
|
1189
1849
|
const cache = program.analysis.createRequireReasons;
|
|
@@ -1198,11 +1858,11 @@ function stableCreateRequireBindingReason7(program, decl) {
|
|
|
1198
1858
|
}
|
|
1199
1859
|
const checker = program.getTypeChecker();
|
|
1200
1860
|
const symbol = checker.getSymbolAtLocation(decl.name);
|
|
1201
|
-
if (!symbol ||
|
|
1861
|
+
if (!symbol || symbol.declarations.length !== 1)
|
|
1202
1862
|
return "its createRequire binding is redeclared";
|
|
1203
1863
|
if ((ts.getCombinedModifierFlags(decl) & ts.ModifierFlags.Export) !== 0)
|
|
1204
1864
|
return "its createRequire result escapes through an exported binding";
|
|
1205
|
-
const sf =
|
|
1865
|
+
const sf = ts.getSourceFileOfNode(decl);
|
|
1206
1866
|
const refs = identifierOccurrences7(sf, decl.name.text);
|
|
1207
1867
|
checker.prefetchSymbolNodesExact(refs);
|
|
1208
1868
|
for (const ref of refs) {
|
|
@@ -1217,8 +1877,8 @@ function stableCreateRequireBindingReason7(program, decl) {
|
|
|
1217
1877
|
return "its createRequire binding is reassigned, escapes, or uses a computed specifier";
|
|
1218
1878
|
}
|
|
1219
1879
|
}
|
|
1220
|
-
const preceding = stmt.declarationList.declarations.slice(0, stmt.declarationList.declarations.indexOf(decl));
|
|
1221
|
-
if (bindingEarlyUse7(program, sf, sf.statements.indexOf(stmt), decl, preceding) !== null) {
|
|
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) {
|
|
1222
1882
|
return "its createRequire binding can be used before initialization";
|
|
1223
1883
|
}
|
|
1224
1884
|
return null;
|
|
@@ -1233,10 +1893,10 @@ function isCreateRequireBaseCall7(program, expr) {
|
|
|
1233
1893
|
init.questionDotToken !== undefined ||
|
|
1234
1894
|
!ts.isIdentifier(init.expression) ||
|
|
1235
1895
|
!isCreateRequireImport7(program, init.expression) ||
|
|
1236
|
-
init.arguments.length !== 1) {
|
|
1896
|
+
init.arguments.nodes.length !== 1) {
|
|
1237
1897
|
return false;
|
|
1238
1898
|
}
|
|
1239
|
-
const base = stripRequireCasts7(init.arguments[0]);
|
|
1899
|
+
const base = stripRequireCasts7(init.arguments.nodes[0]);
|
|
1240
1900
|
if (ts.isIdentifier(base) && base.text === "__filename")
|
|
1241
1901
|
return !sourceBinding7(program, base);
|
|
1242
1902
|
return (ts.isPropertyAccessExpression(base) &&
|
|
@@ -1259,8 +1919,8 @@ function npmStaticModuleImportReason7(program, stmt) {
|
|
|
1259
1919
|
if (!bindings || !ts.isNamedImports(bindings))
|
|
1260
1920
|
return null;
|
|
1261
1921
|
const checker = program.getTypeChecker();
|
|
1262
|
-
const sf =
|
|
1263
|
-
for (const specifier of bindings.elements) {
|
|
1922
|
+
const sf = ts.getSourceFileOfNode(stmt);
|
|
1923
|
+
for (const specifier of bindings.elements.nodes) {
|
|
1264
1924
|
if ((specifier.propertyName?.text ?? specifier.name.text) !== "createRequire")
|
|
1265
1925
|
continue;
|
|
1266
1926
|
const imported = checker.getSymbolAtLocation(specifier.name);
|
|
@@ -1335,8 +1995,8 @@ function requireCallBindingKind7(program, node) {
|
|
|
1335
1995
|
const symbol = checker.getSymbolAtLocation(call.expression);
|
|
1336
1996
|
if (symbol === undefined)
|
|
1337
1997
|
return "ambient";
|
|
1338
|
-
const decls =
|
|
1339
|
-
if (decls.every((d) =>
|
|
1998
|
+
const decls = symbol.declarations;
|
|
1999
|
+
if (decls.every((d) => ts.getSourceFileOfNode(d).isDeclarationFile))
|
|
1340
2000
|
return "ambient";
|
|
1341
2001
|
return isCreateRequireBinding7(program, call.expression) ? "createRequire" : "source";
|
|
1342
2002
|
}
|
|
@@ -1349,7 +2009,7 @@ const CJS_WRAPPER_NAMES = new Set(["require", "module", "exports", "__dirname",
|
|
|
1349
2009
|
function bindingDeclaresCjsWrapper7(name) {
|
|
1350
2010
|
if (ts.isIdentifier(name))
|
|
1351
2011
|
return CJS_WRAPPER_NAMES.has(name.text) ? name : null;
|
|
1352
|
-
for (const el of name.elements) {
|
|
2012
|
+
for (const el of name.elements.nodes) {
|
|
1353
2013
|
if (el.name === undefined)
|
|
1354
2014
|
continue;
|
|
1355
2015
|
const hit = bindingDeclaresCjsWrapper7(el.name);
|
|
@@ -1372,10 +2032,10 @@ function insideFunctionLike7(node) {
|
|
|
1372
2032
|
* import/export forms, import.meta, top-level await/for-await, or a top-level
|
|
1373
2033
|
* lexical declaration that would redeclare a CommonJS wrapper binding. */
|
|
1374
2034
|
function nodeEsmSyntaxMarker7(sf) {
|
|
1375
|
-
for (const stmt of sf.statements) {
|
|
2035
|
+
for (const stmt of sf.statements.nodes) {
|
|
1376
2036
|
if (ts.isImportDeclaration(stmt) && !erasedTypeOnlyImport(stmt))
|
|
1377
2037
|
return stmt;
|
|
1378
|
-
if (ts.isExportDeclaration(stmt) && !stmt.isTypeOnly
|
|
2038
|
+
if (ts.isExportDeclaration(stmt) && !stmt.isTypeOnly) {
|
|
1379
2039
|
return stmt;
|
|
1380
2040
|
}
|
|
1381
2041
|
if (ts.isExportAssignment(stmt))
|
|
@@ -1386,7 +2046,7 @@ function nodeEsmSyntaxMarker7(sf) {
|
|
|
1386
2046
|
}
|
|
1387
2047
|
if (ts.isVariableStatement(stmt) &&
|
|
1388
2048
|
(stmt.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) !== 0) {
|
|
1389
|
-
for (const decl of stmt.declarationList.declarations) {
|
|
2049
|
+
for (const decl of stmt.declarationList.declarations.nodes) {
|
|
1390
2050
|
const hit = bindingDeclaresCjsWrapper7(decl.name);
|
|
1391
2051
|
if (hit !== null)
|
|
1392
2052
|
return hit;
|
|
@@ -1479,15 +2139,15 @@ function selfImportTdzFences7(program, sf, clause, diags) {
|
|
|
1479
2139
|
// The aliased declaration's TDZ horizon: the position after which reads
|
|
1480
2140
|
// are initialized. Hoisted functions have none.
|
|
1481
2141
|
const tdzEndOf = (aliased) => {
|
|
1482
|
-
const d =
|
|
1483
|
-
if (d === undefined ||
|
|
2142
|
+
const d = aliased.valueDeclaration ?? aliased.declarations[0];
|
|
2143
|
+
if (d === undefined || ts.getSourceFileOfNode(d) !== sf)
|
|
1484
2144
|
return null;
|
|
1485
2145
|
if (ts.isFunctionDeclaration(d))
|
|
1486
2146
|
return null;
|
|
1487
|
-
return d.
|
|
2147
|
+
return d.end;
|
|
1488
2148
|
};
|
|
1489
2149
|
const fence = (ref, name) => {
|
|
1490
|
-
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)`));
|
|
1491
2151
|
};
|
|
1492
2152
|
const checkNamed = (bindingName) => {
|
|
1493
2153
|
const sym = checker.getSymbolAtLocation(bindingName);
|
|
@@ -1501,7 +2161,7 @@ function selfImportTdzFences7(program, sf, clause, diags) {
|
|
|
1501
2161
|
if (ts.isIdentifier(node) &&
|
|
1502
2162
|
node !== bindingName &&
|
|
1503
2163
|
node.text === bindingName.text &&
|
|
1504
|
-
|
|
2164
|
+
ts.tokenStartOfNode(node) < end &&
|
|
1505
2165
|
!insideFunction(node) &&
|
|
1506
2166
|
checker.getSymbolAtLocation(node) === sym) {
|
|
1507
2167
|
fence(node, bindingName.text);
|
|
@@ -1513,7 +2173,7 @@ function selfImportTdzFences7(program, sf, clause, diags) {
|
|
|
1513
2173
|
if (clause.name !== undefined)
|
|
1514
2174
|
checkNamed(clause.name);
|
|
1515
2175
|
if (clause.namedBindings !== undefined && ts.isNamedImports(clause.namedBindings)) {
|
|
1516
|
-
for (const el of clause.namedBindings.elements) {
|
|
2176
|
+
for (const el of clause.namedBindings.elements.nodes) {
|
|
1517
2177
|
if (!el.isTypeOnly)
|
|
1518
2178
|
checkNamed(el.name);
|
|
1519
2179
|
}
|
|
@@ -1534,7 +2194,7 @@ function selfImportTdzFences7(program, sf, clause, diags) {
|
|
|
1534
2194
|
const memberSym = checker.getSymbolAtLocation(node.name);
|
|
1535
2195
|
if (memberSym !== undefined) {
|
|
1536
2196
|
const end = tdzEndOf(memberSym);
|
|
1537
|
-
if (end !== null &&
|
|
2197
|
+
if (end !== null && ts.tokenStartOfNode(node) < end)
|
|
1538
2198
|
fence(node.expression, `${nsName.text}.${node.name.text}`);
|
|
1539
2199
|
}
|
|
1540
2200
|
}
|
|
@@ -1632,7 +2292,7 @@ function inTypePosition7(node) {
|
|
|
1632
2292
|
* coercion of a user object) disqualifies the module's cycles. */
|
|
1633
2293
|
function nonInertTopLevel7(program, sf) {
|
|
1634
2294
|
const nonInert = topLevelInertness7(program);
|
|
1635
|
-
for (const stmt of sf.statements) {
|
|
2295
|
+
for (const stmt of sf.statements.nodes) {
|
|
1636
2296
|
const offence = nonInert(stmt);
|
|
1637
2297
|
if (offence !== null)
|
|
1638
2298
|
return offence;
|
|
@@ -1677,10 +2337,10 @@ function topLevelInertness7(program) {
|
|
|
1677
2337
|
return false;
|
|
1678
2338
|
if (sym.flags & ts.SymbolFlags.Alias)
|
|
1679
2339
|
sym = checker.getAliasedSymbol(sym);
|
|
1680
|
-
const decls =
|
|
1681
|
-
return decls.length > 0 && decls.every((d) =>
|
|
2340
|
+
const decls = sym.declarations;
|
|
2341
|
+
return decls.length > 0 && decls.every((d) => ts.getSourceFileOfNode(d).isDeclarationFile);
|
|
1682
2342
|
};
|
|
1683
|
-
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);
|
|
1684
2344
|
/** No function-like node anywhere in the subtree — arguments to builtin
|
|
1685
2345
|
* calls must not smuggle a callback the builtin could invoke. */
|
|
1686
2346
|
const containsFunctionLike = (n) => {
|
|
@@ -1697,14 +2357,14 @@ function topLevelInertness7(program) {
|
|
|
1697
2357
|
const inertClass = (c) => {
|
|
1698
2358
|
if (hasDecorator(c))
|
|
1699
2359
|
return c;
|
|
1700
|
-
for (const h of c.heritageClauses ?? []) {
|
|
2360
|
+
for (const h of c.heritageClauses?.nodes ?? []) {
|
|
1701
2361
|
if (h.token !== ts.SyntaxKind.ExtendsKeyword)
|
|
1702
2362
|
continue;
|
|
1703
|
-
for (const t of h.types)
|
|
2363
|
+
for (const t of h.types.nodes)
|
|
1704
2364
|
if (!inert(t.expression))
|
|
1705
2365
|
return t.expression;
|
|
1706
2366
|
}
|
|
1707
|
-
for (const m of c.members) {
|
|
2367
|
+
for (const m of c.members.nodes) {
|
|
1708
2368
|
if (ts.isClassStaticBlockDeclaration(m))
|
|
1709
2369
|
return m;
|
|
1710
2370
|
if (hasDecorator(m))
|
|
@@ -1761,7 +2421,7 @@ function topLevelInertness7(program) {
|
|
|
1761
2421
|
return dtsRooted(e) && inert(e.argumentExpression) && primitiveTyped(e.argumentExpression);
|
|
1762
2422
|
}
|
|
1763
2423
|
if (ts.isTemplateExpression(e)) {
|
|
1764
|
-
return e.templateSpans.every((s) => inert(s.expression) && primitiveTyped(s.expression));
|
|
2424
|
+
return e.templateSpans.nodes.every((s) => inert(s.expression) && primitiveTyped(s.expression));
|
|
1765
2425
|
}
|
|
1766
2426
|
if (ts.isVoidExpression(e) || ts.isTypeOfExpression(e))
|
|
1767
2427
|
return inert(e.expression);
|
|
@@ -1785,9 +2445,9 @@ function topLevelInertness7(program) {
|
|
|
1785
2445
|
if (ts.isConditionalExpression(e))
|
|
1786
2446
|
return inert(e.condition) && inert(e.whenTrue) && inert(e.whenFalse);
|
|
1787
2447
|
if (ts.isArrayLiteralExpression(e))
|
|
1788
|
-
return e.elements.every((el) => !ts.isSpreadElement(el) && inert(el));
|
|
2448
|
+
return e.elements.nodes.every((el) => !ts.isSpreadElement(el) && inert(el));
|
|
1789
2449
|
if (ts.isObjectLiteralExpression(e)) {
|
|
1790
|
-
return e.properties.every((p) => {
|
|
2450
|
+
return e.properties.nodes.every((p) => {
|
|
1791
2451
|
if (ts.isShorthandPropertyAssignment(p))
|
|
1792
2452
|
return true;
|
|
1793
2453
|
if (!ts.isPropertyAssignment(p) || ts.isComputedPropertyName(p.name))
|
|
@@ -1798,7 +2458,7 @@ function topLevelInertness7(program) {
|
|
|
1798
2458
|
if (ts.isCallExpression(e) || ts.isNewExpression(e)) {
|
|
1799
2459
|
if (!dtsRooted(e.expression) || !ts.isIdentifier(chainRoot7(e.expression)))
|
|
1800
2460
|
return false;
|
|
1801
|
-
const args = e.arguments ?? [];
|
|
2461
|
+
const args = e.arguments?.nodes ?? [];
|
|
1802
2462
|
// A CALLABLE argument is admissible when it is itself dts-rooted:
|
|
1803
2463
|
// a builtin-owned function value (the `promisify(fs.readFile)`
|
|
1804
2464
|
// at every cycle member's top level) is runtime-implemented — even
|
|
@@ -1825,12 +2485,12 @@ function topLevelInertness7(program) {
|
|
|
1825
2485
|
return null;
|
|
1826
2486
|
}
|
|
1827
2487
|
if (ts.isEnumDeclaration(stmt)) {
|
|
1828
|
-
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);
|
|
1829
2489
|
}
|
|
1830
2490
|
if (ts.isClassDeclaration(stmt))
|
|
1831
2491
|
return inertClass(stmt);
|
|
1832
2492
|
if (ts.isVariableStatement(stmt)) {
|
|
1833
|
-
for (const d of stmt.declarationList.declarations) {
|
|
2493
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
1834
2494
|
if (!ts.isIdentifier(d.name))
|
|
1835
2495
|
return d.name; // patterns can invoke getters/iterators
|
|
1836
2496
|
if (d.initializer !== undefined && !inert(d.initializer))
|
|
@@ -1883,7 +2543,7 @@ function backEdgeUseOffence7(program, stmt, occurrences) {
|
|
|
1883
2543
|
if (ts.isNamespaceImport(clause.namedBindings))
|
|
1884
2544
|
bindingNames.push(clause.namedBindings.name);
|
|
1885
2545
|
else
|
|
1886
|
-
for (const el of clause.namedBindings.elements)
|
|
2546
|
+
for (const el of clause.namedBindings.elements.nodes)
|
|
1887
2547
|
if (!el.isTypeOnly)
|
|
1888
2548
|
bindingNames.push(el.name);
|
|
1889
2549
|
}
|
|
@@ -1948,8 +2608,8 @@ export function makeCycleAdmission(program, edgesOf) {
|
|
|
1948
2608
|
}
|
|
1949
2609
|
};
|
|
1950
2610
|
const lineOf = (node) => {
|
|
1951
|
-
const nsf =
|
|
1952
|
-
return `${nsf.fileName}:${ts.getLineAndCharacterOfPosition(nsf,
|
|
2611
|
+
const nsf = ts.getSourceFileOfNode(node);
|
|
2612
|
+
return `${nsf.fileName}:${ts.getLineAndCharacterOfPosition(nsf, ts.tokenStartOfNode(node)).line + 1}`;
|
|
1953
2613
|
};
|
|
1954
2614
|
// Cluster verdict memo (keyed by the component array identity): true
|
|
1955
2615
|
// when every member is an ES module passing the inert-top-level bar.
|
|
@@ -1980,13 +2640,26 @@ export function makeCycleAdmission(program, edgesOf) {
|
|
|
1980
2640
|
bindingUses.set(sf, uses);
|
|
1981
2641
|
return uses;
|
|
1982
2642
|
};
|
|
2643
|
+
// The CommonJS cluster verdict, same keying (cjsCycleRefusal7).
|
|
2644
|
+
const cjsVerdict = new Map();
|
|
1983
2645
|
return (importer, e) => {
|
|
1984
|
-
if (e.stmt === undefined)
|
|
1985
|
-
|
|
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
|
+
}
|
|
1986
2658
|
// Cheap per-edge admission: nothing readable binds through the edge.
|
|
1987
2659
|
if (ts.isImportDeclaration(e.stmt)) {
|
|
1988
2660
|
const clause = e.stmt.importClause;
|
|
1989
2661
|
if (clause === undefined ||
|
|
2662
|
+
typeOnlyNamedImport(e.stmt) ||
|
|
1990
2663
|
(clause.name === undefined &&
|
|
1991
2664
|
(clause.namedBindings === undefined ||
|
|
1992
2665
|
(ts.isNamespaceImport(clause.namedBindings) &&
|
|
@@ -2022,6 +2695,364 @@ export function makeCycleAdmission(program, edgesOf) {
|
|
|
2022
2695
|
return exactVerdict.get(comp) ?? null;
|
|
2023
2696
|
};
|
|
2024
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
|
+
}
|
|
2025
3056
|
/* ── exact cyclic initialization ─────────────────────────────────────────
|
|
2026
3057
|
* Cycles that fail the declaration-only rule still evaluate exactly like
|
|
2027
3058
|
* Node when their shape is representable: the guarded %init calls already
|
|
@@ -2065,7 +3096,7 @@ function exactCycleRefusal7(program, comp, lineOf) {
|
|
|
2065
3096
|
const spec = stmt.moduleSpecifier;
|
|
2066
3097
|
if (spec === undefined || !ts.isStringLiteral(spec))
|
|
2067
3098
|
return null;
|
|
2068
|
-
const sf =
|
|
3099
|
+
const sf = ts.getSourceFileOfNode(stmt);
|
|
2069
3100
|
return resolveImport7(program, sf, spec.text) ?? npmStaticDepSf7(program, sf, spec.text);
|
|
2070
3101
|
};
|
|
2071
3102
|
for (const m of comp) {
|
|
@@ -2075,7 +3106,7 @@ function exactCycleRefusal7(program, comp, lineOf) {
|
|
|
2075
3106
|
if (hasTopLevelAwait7(m)) {
|
|
2076
3107
|
return `${m.fileName} uses top-level await inside the cycle`;
|
|
2077
3108
|
}
|
|
2078
|
-
for (const stmt of m.statements) {
|
|
3109
|
+
for (const stmt of m.statements.nodes) {
|
|
2079
3110
|
if (ts.isExportAssignment(stmt) && !stmt.isExportEquals) {
|
|
2080
3111
|
return `the default export expression at ${lineOf(stmt)} has no initialization state inside the cycle`;
|
|
2081
3112
|
}
|
|
@@ -2223,7 +3254,7 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2223
3254
|
const names = new Set();
|
|
2224
3255
|
let dirty = !known;
|
|
2225
3256
|
evaluation.forEach((m, rank) => {
|
|
2226
|
-
for (const stmt of m.statements) {
|
|
3257
|
+
for (const stmt of m.statements.nodes) {
|
|
2227
3258
|
const offence = nonInert(stmt);
|
|
2228
3259
|
const exposed = dirty || offence !== null;
|
|
2229
3260
|
const declared = [];
|
|
@@ -2232,7 +3263,7 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2232
3263
|
ts.ModifierFlags.Ambient) ===
|
|
2233
3264
|
0) {
|
|
2234
3265
|
const lexical = (stmt.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) !== 0;
|
|
2235
|
-
for (const d of stmt.declarationList.declarations) {
|
|
3266
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
2236
3267
|
for (const name of boundNames7(d.name)) {
|
|
2237
3268
|
declared.push({ name, kind: lexical ? "lexical" : "var" });
|
|
2238
3269
|
}
|
|
@@ -2252,8 +3283,8 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2252
3283
|
module: m,
|
|
2253
3284
|
exposed,
|
|
2254
3285
|
rank,
|
|
2255
|
-
start:
|
|
2256
|
-
end: stmt.
|
|
3286
|
+
start: ts.tokenStartOfNode(stmt),
|
|
3287
|
+
end: stmt.end,
|
|
2257
3288
|
reference: null,
|
|
2258
3289
|
folded: null,
|
|
2259
3290
|
});
|
|
@@ -2305,14 +3336,14 @@ function computeCycleEarlyBindings7(program, entry, order, singleRoot, exact) {
|
|
|
2305
3336
|
// A class body names its own inner binding, initialized throughout.
|
|
2306
3337
|
if (c.kind === "class" &&
|
|
2307
3338
|
sf === c.module &&
|
|
2308
|
-
|
|
2309
|
-
ref.
|
|
3339
|
+
ts.tokenStartOfNode(ref) >= c.start &&
|
|
3340
|
+
ref.end <= c.end)
|
|
2310
3341
|
continue;
|
|
2311
3342
|
let early;
|
|
2312
3343
|
if (inDeferredPosition7(ref))
|
|
2313
3344
|
early = c.exposed;
|
|
2314
3345
|
else if (sf === c.module)
|
|
2315
|
-
early =
|
|
3346
|
+
early = ts.tokenStartOfNode(ref) < c.start;
|
|
2316
3347
|
else if (!memberSet.has(sf) || !rankOf.has(sf))
|
|
2317
3348
|
early = false;
|
|
2318
3349
|
else
|
|
@@ -2406,7 +3437,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2406
3437
|
immediate.set(e, classSyncParts7(e));
|
|
2407
3438
|
}
|
|
2408
3439
|
else if (ts.isObjectLiteralExpression(e)) {
|
|
2409
|
-
for (const p of e.properties) {
|
|
3440
|
+
for (const p of e.properties.nodes) {
|
|
2410
3441
|
if (ts.isMethodDeclaration(p) ||
|
|
2411
3442
|
ts.isGetAccessorDeclaration(p) ||
|
|
2412
3443
|
ts.isSetAccessorDeclaration(p)) {
|
|
@@ -2424,14 +3455,14 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2424
3455
|
}
|
|
2425
3456
|
}
|
|
2426
3457
|
else if (ts.isArrayLiteralExpression(e)) {
|
|
2427
|
-
for (const el of e.elements)
|
|
3458
|
+
for (const el of e.elements.nodes)
|
|
2428
3459
|
if (!ts.isSpreadElement(el))
|
|
2429
3460
|
storedIn(el, units);
|
|
2430
3461
|
}
|
|
2431
3462
|
else if (ts.isCallExpression(e)) {
|
|
2432
3463
|
// `const f = wrap(callback)` where wrap only returns closures over
|
|
2433
3464
|
// the callback: it runs when the stored result is called.
|
|
2434
|
-
e.arguments.forEach((arg, index) => {
|
|
3465
|
+
e.arguments.nodes.forEach((arg, index) => {
|
|
2435
3466
|
let fn = arg;
|
|
2436
3467
|
while (ts.isParenthesizedExpression(fn))
|
|
2437
3468
|
fn = fn.expression;
|
|
@@ -2441,7 +3472,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2441
3472
|
});
|
|
2442
3473
|
}
|
|
2443
3474
|
};
|
|
2444
|
-
sf.statements.forEach((stmt, index) => {
|
|
3475
|
+
sf.statements.nodes.forEach((stmt, index) => {
|
|
2445
3476
|
if (ambient(stmt))
|
|
2446
3477
|
return;
|
|
2447
3478
|
if (ts.isFunctionDeclaration(stmt) && stmt.name !== undefined && stmt.body !== undefined) {
|
|
@@ -2449,12 +3480,12 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2449
3480
|
}
|
|
2450
3481
|
else if (ts.isClassDeclaration(stmt) && stmt.name !== undefined) {
|
|
2451
3482
|
store(stmt.name, [stmt]);
|
|
2452
|
-
candidates.push({ name: stmt.name, index, start:
|
|
3483
|
+
candidates.push({ name: stmt.name, index, start: ts.tokenStartOfNode(stmt), cls: stmt });
|
|
2453
3484
|
candidateNames.add(stmt.name.text);
|
|
2454
3485
|
}
|
|
2455
3486
|
else if (ts.isVariableStatement(stmt)) {
|
|
2456
3487
|
const lexical = (stmt.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) !== 0;
|
|
2457
|
-
for (const d of stmt.declarationList.declarations) {
|
|
3488
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
2458
3489
|
if (ts.isIdentifier(d.name) && d.initializer !== undefined) {
|
|
2459
3490
|
const units = [];
|
|
2460
3491
|
storedIn(d.initializer, units);
|
|
@@ -2463,7 +3494,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2463
3494
|
if (!lexical)
|
|
2464
3495
|
continue;
|
|
2465
3496
|
for (const name of boundNames7(d.name)) {
|
|
2466
|
-
candidates.push({ name, index, start:
|
|
3497
|
+
candidates.push({ name, index, start: ts.tokenStartOfNode(stmt) });
|
|
2467
3498
|
candidateNames.add(name.text);
|
|
2468
3499
|
}
|
|
2469
3500
|
}
|
|
@@ -2506,7 +3537,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2506
3537
|
if (ts.isArrowFunction(e) || ts.isFunctionExpression(e))
|
|
2507
3538
|
stored.add(e);
|
|
2508
3539
|
else if (ts.isObjectLiteralExpression(e)) {
|
|
2509
|
-
for (const p of e.properties) {
|
|
3540
|
+
for (const p of e.properties.nodes) {
|
|
2510
3541
|
if (ts.isMethodDeclaration(p))
|
|
2511
3542
|
stored.add(p);
|
|
2512
3543
|
else if (ts.isPropertyAssignment(p))
|
|
@@ -2517,7 +3548,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2517
3548
|
ts.walkPreorder(sf, (node) => {
|
|
2518
3549
|
if ((ts.isCallExpression(node) || ts.isNewExpression(node)) &&
|
|
2519
3550
|
laterJobCallee7(checker, node.expression)) {
|
|
2520
|
-
for (const arg of node.arguments ?? [])
|
|
3551
|
+
for (const arg of node.arguments?.nodes ?? [])
|
|
2521
3552
|
callbacks(arg);
|
|
2522
3553
|
}
|
|
2523
3554
|
return undefined;
|
|
@@ -2569,8 +3600,8 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2569
3600
|
if (c !== undefined &&
|
|
2570
3601
|
node !== c.name &&
|
|
2571
3602
|
!reachedRefs.has(symbol) &&
|
|
2572
|
-
!(c.cls !== undefined &&
|
|
2573
|
-
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)
|
|
2574
3605
|
reachedRefs.set(symbol, node);
|
|
2575
3606
|
}
|
|
2576
3607
|
for (const unit of unitsBySymbol.get(symbol) ?? []) {
|
|
@@ -2591,8 +3622,8 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2591
3622
|
let next = 0;
|
|
2592
3623
|
const report = (declaration) => {
|
|
2593
3624
|
while (next < candidates.length &&
|
|
2594
|
-
candidates[next].name
|
|
2595
|
-
candidates[next].name.
|
|
3625
|
+
ts.tokenStartOfNode(candidates[next].name) >= ts.tokenStartOfNode(declaration) &&
|
|
3626
|
+
candidates[next].name.end <= declaration.end) {
|
|
2596
3627
|
const c = candidates[next++];
|
|
2597
3628
|
const symbol = checker.getSymbolAtLocation(c.name);
|
|
2598
3629
|
const reference = symbol === undefined ? undefined : reachedRefs.get(symbol);
|
|
@@ -2608,7 +3639,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2608
3639
|
});
|
|
2609
3640
|
}
|
|
2610
3641
|
};
|
|
2611
|
-
for (const stmt of sf.statements) {
|
|
3642
|
+
for (const stmt of sf.statements.nodes) {
|
|
2612
3643
|
if (ts.isClassDeclaration(stmt)) {
|
|
2613
3644
|
// The binding initializes once the class definition, static
|
|
2614
3645
|
// initializers included, has run.
|
|
@@ -2620,7 +3651,7 @@ function moduleEarlyBindingsOf7(program, sf, order) {
|
|
|
2620
3651
|
else if (ts.isVariableStatement(stmt)) {
|
|
2621
3652
|
// Declarators run in order: a later declarator's initializer cannot
|
|
2622
3653
|
// observe an earlier binding before it was initialized.
|
|
2623
|
-
for (const d of stmt.declarationList.declarations) {
|
|
3654
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
2624
3655
|
visit(d);
|
|
2625
3656
|
drain();
|
|
2626
3657
|
report(d);
|
|
@@ -2650,11 +3681,11 @@ function returnsOnlyClosuresOver7(checker, callee, index) {
|
|
|
2650
3681
|
if (symbol !== undefined && symbol.flags & ts.SymbolFlags.Alias) {
|
|
2651
3682
|
symbol = checker.getAliasedSymbol(symbol);
|
|
2652
3683
|
}
|
|
2653
|
-
const decls = symbol === undefined ? [] :
|
|
3684
|
+
const decls = symbol === undefined ? [] : symbol.declarations;
|
|
2654
3685
|
if (decls.length !== 1)
|
|
2655
3686
|
return false;
|
|
2656
3687
|
const decl = decls[0];
|
|
2657
|
-
if (
|
|
3688
|
+
if (ts.getSourceFileOfNode(decl).isDeclarationFile)
|
|
2658
3689
|
return false;
|
|
2659
3690
|
let fn;
|
|
2660
3691
|
if (ts.isFunctionDeclaration(decl))
|
|
@@ -2670,12 +3701,12 @@ function returnsOnlyClosuresOver7(checker, callee, index) {
|
|
|
2670
3701
|
return false;
|
|
2671
3702
|
const like = fn;
|
|
2672
3703
|
const body = like.body;
|
|
2673
|
-
const param = like.parameters[index];
|
|
3704
|
+
const param = like.parameters.nodes[index];
|
|
2674
3705
|
if (body === undefined || !ts.isBlock(body) || param === undefined)
|
|
2675
3706
|
return false;
|
|
2676
3707
|
if (!ts.isIdentifier(param.name) || param.dotDotDotToken !== undefined)
|
|
2677
3708
|
return false;
|
|
2678
|
-
if (like.parameters.slice(0, index).some((p) => p.dotDotDotToken !== undefined))
|
|
3709
|
+
if (like.parameters.nodes.slice(0, index).some((p) => p.dotDotDotToken !== undefined))
|
|
2679
3710
|
return false;
|
|
2680
3711
|
const paramName = param.name.text;
|
|
2681
3712
|
let deferred = true;
|
|
@@ -2723,9 +3754,9 @@ function returnsOnlyClosuresOver7(checker, callee, index) {
|
|
|
2723
3754
|
* initializers and static blocks. Methods and instance fields wait for a
|
|
2724
3755
|
* call or a construction. */
|
|
2725
3756
|
function classSyncParts7(c) {
|
|
2726
|
-
const decorators = (n) => (n.modifiers ?? []).filter((m) => m.kind === ts.SyntaxKind.Decorator);
|
|
2727
|
-
const parts = [...decorators(c), ...(c.heritageClauses ?? [])];
|
|
2728
|
-
for (const m of c.members) {
|
|
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) {
|
|
2729
3760
|
parts.push(...decorators(m));
|
|
2730
3761
|
const memberName = m.name;
|
|
2731
3762
|
if (memberName !== undefined && ts.isComputedPropertyName(memberName))
|
|
@@ -2784,15 +3815,15 @@ function laterJobCallee7(checker, callee) {
|
|
|
2784
3815
|
}
|
|
2785
3816
|
if (symbol === undefined)
|
|
2786
3817
|
return false;
|
|
2787
|
-
const decls =
|
|
2788
|
-
if (decls.length === 0 || !decls.every((d) =>
|
|
3818
|
+
const decls = symbol.declarations;
|
|
3819
|
+
if (decls.length === 0 || !decls.every((d) => ts.getSourceFileOfNode(d).isDeclarationFile))
|
|
2789
3820
|
return false;
|
|
2790
3821
|
if (LATER_JOB_BUILTINS7.has(name.text))
|
|
2791
3822
|
return true;
|
|
2792
3823
|
// The JavaScript standard library's callbacks mostly run synchronously;
|
|
2793
3824
|
// package declarations describe user code.
|
|
2794
3825
|
return decls.every((d) => {
|
|
2795
|
-
const file =
|
|
3826
|
+
const file = ts.getSourceFileOfNode(d).fileName;
|
|
2796
3827
|
return isNodeTypesPath(file) || file === fallbackDtsPath();
|
|
2797
3828
|
});
|
|
2798
3829
|
}
|
|
@@ -2855,7 +3886,7 @@ function boundNames7(name) {
|
|
|
2855
3886
|
if (ts.isIdentifier(name))
|
|
2856
3887
|
return [name];
|
|
2857
3888
|
const out = [];
|
|
2858
|
-
for (const el of name.elements) {
|
|
3889
|
+
for (const el of name.elements.nodes) {
|
|
2859
3890
|
if (ts.isOmittedExpression(el) || el.name === undefined)
|
|
2860
3891
|
continue;
|
|
2861
3892
|
out.push(...boundNames7(el.name));
|
|
@@ -2870,7 +3901,7 @@ function typeOnlyNamespace7(decl) {
|
|
|
2870
3901
|
body = body.body;
|
|
2871
3902
|
if (body === undefined || !ts.isModuleBlock(body))
|
|
2872
3903
|
return true;
|
|
2873
|
-
return body.statements.every((s) => ts.isInterfaceDeclaration(s) ||
|
|
3904
|
+
return body.statements.nodes.every((s) => ts.isInterfaceDeclaration(s) ||
|
|
2874
3905
|
ts.isTypeAliasDeclaration(s) ||
|
|
2875
3906
|
(ts.isModuleDeclaration(s) && typeOnlyNamespace7(s)));
|
|
2876
3907
|
}
|
|
@@ -2891,6 +3922,13 @@ function resolveNpmImport7(fromFileName, specifier, resolutionKind = "import") {
|
|
|
2891
3922
|
if (isRelativeSpecifier(specifier) || specifier.startsWith("node:")) {
|
|
2892
3923
|
return null;
|
|
2893
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;
|
|
2894
3932
|
// --provenance-sources: a registered specifier is NOT an npm import —
|
|
2895
3933
|
// its attested source compiles as program modules (resolveProjectModule
|
|
2896
3934
|
if (provenanceEntryFor(specifier) !== null)
|
|
@@ -2917,18 +3955,12 @@ function resolveNpmImport7(fromFileName, specifier, resolutionKind = "import") {
|
|
|
2917
3955
|
};
|
|
2918
3956
|
}
|
|
2919
3957
|
function locOf7(node) {
|
|
2920
|
-
const sf =
|
|
2921
|
-
return { file: sf.fileName, start:
|
|
3958
|
+
const sf = ts.getSourceFileOfNode(node);
|
|
3959
|
+
return { file: sf.fileName, start: ts.tokenStartOfNode(node), end: node.end };
|
|
2922
3960
|
}
|
|
2923
|
-
/** The
|
|
2924
|
-
*
|
|
2925
|
-
|
|
2926
|
-
* program — a path-identity mismatch between the two resolvers). */
|
|
2927
|
-
function npmStaticProgramDep(program, packageName, resolvedFile) {
|
|
2928
|
-
if (!isJsSourceFileName(resolvedFile)) {
|
|
2929
|
-
reportNpmStaticOffender(packageName, `its import resolves to '${resolvedFile}', not to runtime JavaScript`);
|
|
2930
|
-
return null;
|
|
2931
|
-
}
|
|
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) {
|
|
2932
3964
|
let dep = program.getSourceFile(resolvedFile) ?? null;
|
|
2933
3965
|
if (dep === null) {
|
|
2934
3966
|
// A workspace-linked package shipping its .ts SOURCE beside the
|
|
@@ -2942,6 +3974,18 @@ function npmStaticProgramDep(program, packageName, resolvedFile) {
|
|
|
2942
3974
|
break;
|
|
2943
3975
|
}
|
|
2944
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);
|
|
2945
3989
|
if (dep === null) {
|
|
2946
3990
|
reportNpmStaticOffender(packageName, `its entry '${resolvedFile}' did not join the type-checked program`);
|
|
2947
3991
|
return null;
|
|
@@ -3064,7 +4108,7 @@ function preflight7(load) {
|
|
|
3064
4108
|
names = new Set();
|
|
3065
4109
|
builtinNamespaceNames.set(d.fileName, names);
|
|
3066
4110
|
const sf = p.getSourceFile(d.fileName);
|
|
3067
|
-
for (const stmt of sf?.statements ?? []) {
|
|
4111
|
+
for (const stmt of sf?.statements?.nodes ?? []) {
|
|
3068
4112
|
if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
3069
4113
|
continue;
|
|
3070
4114
|
if (canonicalBuiltinModule(stmt.moduleSpecifier.text) === null)
|
|
@@ -3128,6 +4172,17 @@ function preflight7(load) {
|
|
|
3128
4172
|
: spec.split("/")[0];
|
|
3129
4173
|
return isWorkspacePackageName(prefix);
|
|
3130
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
|
+
};
|
|
3131
4186
|
const errorsOf = (p) => {
|
|
3132
4187
|
const all = ts.getPreEmitDiagnostics(p);
|
|
3133
4188
|
// First pass: every comment-side 2300's (file, name) — the partners
|
|
@@ -3143,7 +4198,7 @@ function preflight7(load) {
|
|
|
3143
4198
|
commentDup.add(`${d.fileName}:${sf.text.slice(d.pos, d.end)}`);
|
|
3144
4199
|
}
|
|
3145
4200
|
return all.filter((d) => d.category === ts.DiagnosticCategory.Error &&
|
|
3146
|
-
!suppressedJsStrictness7(d) &&
|
|
4201
|
+
(!suppressedJsStrictness7(d) || enforcedInCheckedJs(p, d)) &&
|
|
3147
4202
|
!npmStaticFileSuppressed(d) &&
|
|
3148
4203
|
!nodeModulesJsSuppressed(d) &&
|
|
3149
4204
|
!namespaceCalleeSuppressed(p, d) &&
|
|
@@ -3185,14 +4240,23 @@ function preflight7(load) {
|
|
|
3185
4240
|
entryPackageFile(sf.fileName) ||
|
|
3186
4241
|
npmStaticPackageOfPath(sf.fileName) !== null) &&
|
|
3187
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));
|
|
3188
4253
|
const userFiles = npmStaticActive()
|
|
3189
|
-
? planNpmStaticReexports(program, entry,
|
|
4254
|
+
? planNpmStaticReexports(program, entry, runtimeFiles, [
|
|
3190
4255
|
...createRequireProgramRoots7(program),
|
|
3191
4256
|
...forkTargetPaths(program, program.getImplementationSourceFiles()),
|
|
3192
4257
|
...workerTargetPaths(program, program.getImplementationSourceFiles()),
|
|
3193
|
-
],
|
|
3194
|
-
|
|
3195
|
-
: programFiles;
|
|
4258
|
+
], resolveRuntimeEdge)
|
|
4259
|
+
: runtimeFiles;
|
|
3196
4260
|
program.getTypeChecker().prefetchSourceFileStructures(userFiles);
|
|
3197
4261
|
// Unselected node_modules JS is not native program source even when
|
|
3198
4262
|
// maxNodeModuleJsDepth pulled it into the checker (nodeModulesJsSuppressed).
|
|
@@ -3229,7 +4293,7 @@ function preflight7(load) {
|
|
|
3229
4293
|
if (ambientModuleDecls === null) {
|
|
3230
4294
|
ambientModuleDecls = { names: new Set(), patterns: [] };
|
|
3231
4295
|
for (const f of program.getSourceFiles()) {
|
|
3232
|
-
for (const s of f.statements) {
|
|
4296
|
+
for (const s of f.statements.nodes) {
|
|
3233
4297
|
if (!ts.isModuleDeclaration(s) || !ts.isStringLiteral(s.name))
|
|
3234
4298
|
continue;
|
|
3235
4299
|
const name = s.name.text;
|
|
@@ -3270,7 +4334,7 @@ function preflight7(load) {
|
|
|
3270
4334
|
edges.set(sf, deps);
|
|
3271
4335
|
refusals.set(sf, []);
|
|
3272
4336
|
depPositions.set(sf, []);
|
|
3273
|
-
for (const stmt of sf.statements) {
|
|
4337
|
+
for (const stmt of sf.statements.nodes) {
|
|
3274
4338
|
if (ts.isImportEqualsDeclaration(stmt)) {
|
|
3275
4339
|
// The ENTITY form (`import a = A`, `import x = N.y`) is namespace
|
|
3276
4340
|
// alias plumbing — the lowerer resolves references through it and
|
|
@@ -3300,7 +4364,7 @@ function preflight7(load) {
|
|
|
3300
4364
|
continue;
|
|
3301
4365
|
}
|
|
3302
4366
|
if (ts.isExportDeclaration(stmt)) {
|
|
3303
|
-
if (stmt.isTypeOnly ||
|
|
4367
|
+
if (stmt.isTypeOnly || isPrunedNpmReexport(program, stmt))
|
|
3304
4368
|
continue;
|
|
3305
4369
|
if (!stmt.moduleSpecifier)
|
|
3306
4370
|
continue;
|
|
@@ -3353,7 +4417,7 @@ function preflight7(load) {
|
|
|
3353
4417
|
}
|
|
3354
4418
|
if (reDep && !reDep.fileName.endsWith(".json")) {
|
|
3355
4419
|
deps.push({ dep: reDep, stmt });
|
|
3356
|
-
depPositions.get(sf).push({ dep: reDep, pos:
|
|
4420
|
+
depPositions.get(sf).push({ dep: reDep, pos: ts.tokenStartOfNode(stmt) });
|
|
3357
4421
|
}
|
|
3358
4422
|
continue;
|
|
3359
4423
|
}
|
|
@@ -3400,7 +4464,7 @@ function preflight7(load) {
|
|
|
3400
4464
|
refusals.get(sf).push({
|
|
3401
4465
|
crash: { message, className, loc: locOf7(stmt) },
|
|
3402
4466
|
fallback: unsupportedDiag("SC1010", locOf7(stmt), fallbackFeature),
|
|
3403
|
-
pos:
|
|
4467
|
+
pos: ts.tokenStartOfNode(stmt),
|
|
3404
4468
|
});
|
|
3405
4469
|
};
|
|
3406
4470
|
// Project modules win before npm fallback: this is the source graph
|
|
@@ -3566,21 +4630,39 @@ function preflight7(load) {
|
|
|
3566
4630
|
}
|
|
3567
4631
|
if (dep && !isJson) {
|
|
3568
4632
|
deps.push({ dep, stmt });
|
|
3569
|
-
depPositions.get(sf).push({ dep, pos:
|
|
4633
|
+
depPositions.get(sf).push({ dep, pos: ts.tokenStartOfNode(stmt) });
|
|
3570
4634
|
}
|
|
3571
4635
|
}
|
|
3572
4636
|
{
|
|
3573
4637
|
const jsRequireFile = isJsSourceFileName(sf.fileName);
|
|
3574
|
-
const stmts = sf.statements;
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
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
|
+
};
|
|
3580
4658
|
for (let k = 0; k < stmts.length; k++) {
|
|
3581
4659
|
const stmt = stmts[k];
|
|
3582
4660
|
for (const req of requiresOf7(stmt)) {
|
|
3583
|
-
const loc = {
|
|
4661
|
+
const loc = {
|
|
4662
|
+
file: sf.fileName,
|
|
4663
|
+
start: ts.tokenStartOfNode(req.node),
|
|
4664
|
+
end: req.node.end,
|
|
4665
|
+
};
|
|
3584
4666
|
const bindingKind = requireCallBindingKind7(program, req.node);
|
|
3585
4667
|
// TypeScript source files join this scan only through the
|
|
3586
4668
|
// canonical createRequire bridge. Their ordinary require-shaped
|
|
@@ -3597,20 +4679,72 @@ function preflight7(load) {
|
|
|
3597
4679
|
if (load.externalTypes.has(req.spec)) {
|
|
3598
4680
|
continue;
|
|
3599
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
|
+
}
|
|
3600
4702
|
if (req.decl && ts.isArrayBindingPattern(req.decl.name)) {
|
|
3601
4703
|
diags.push(unsupportedDiag("SC1012", loc, "array-destructuring require() bindings"));
|
|
3602
4704
|
continue;
|
|
3603
4705
|
}
|
|
3604
4706
|
if (req.decl && ts.isObjectBindingPattern(req.decl.name)) {
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
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)"));
|
|
3611
4741
|
continue;
|
|
3612
4742
|
}
|
|
3613
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;
|
|
3614
4748
|
const isRelative = isRelativeSpecifier(req.spec);
|
|
3615
4749
|
let dep = resolveImport7(program, sf, req.spec, "require");
|
|
3616
4750
|
if (dep === null && !isRelative) {
|
|
@@ -3649,27 +4783,8 @@ function preflight7(load) {
|
|
|
3649
4783
|
continue;
|
|
3650
4784
|
}
|
|
3651
4785
|
}
|
|
3652
|
-
if (
|
|
3653
|
-
if (bindingKind === "createRequire")
|
|
3654
|
-
continue;
|
|
3655
|
-
diags.push(unsupportedDiag("SC1012", loc, "require() of JSON modules"));
|
|
3656
|
-
continue;
|
|
3657
|
-
}
|
|
3658
|
-
// Earlier declarators run too: `const x = read(), dep =
|
|
3659
|
-
// require('./dep')` must not lose the guard merely because both
|
|
3660
|
-
// initializers share one VariableStatement.
|
|
3661
|
-
const precedingDecls = req.decl && ts.isVariableStatement(stmt)
|
|
3662
|
-
? stmt.declarationList.declarations.slice(0, stmt.declarationList.declarations.indexOf(req.decl))
|
|
3663
|
-
: [];
|
|
3664
|
-
const prefixCanRun = (firstRunnable >= 0 && firstRunnable < k) ||
|
|
3665
|
-
precedingDecls.some((decl) => !purePrefixDecl7(decl));
|
|
3666
|
-
const tdzName = prefixCanRun && req.decl
|
|
3667
|
-
? bindingEarlyUse7(program, sf, k, req.decl, precedingDecls)
|
|
3668
|
-
: null;
|
|
3669
|
-
if (tdzName !== null) {
|
|
3670
|
-
diags.push(unsupportedDiag("SC1013", loc, `require() below code that can reach its binding '${tdzName}' (Node initializes the binding AT the require and throws ReferenceError on any earlier access, which is not modeled — move the require above the code that can run first)`));
|
|
4786
|
+
if (earlyRequireFence(req, bindingKind, loc))
|
|
3671
4787
|
continue;
|
|
3672
|
-
}
|
|
3673
4788
|
if (dep)
|
|
3674
4789
|
deps.push({ dep });
|
|
3675
4790
|
}
|
|
@@ -3680,7 +4795,7 @@ function preflight7(load) {
|
|
|
3680
4795
|
.prefetchSymbolNodesExact(nestedBareRequires.flatMap((call) => ts.isIdentifier(call.expression) ? [call.expression] : []));
|
|
3681
4796
|
for (const call of nestedBareRequires) {
|
|
3682
4797
|
const spec = requireSpecOf7(call);
|
|
3683
|
-
const loc = { file: sf.fileName, start:
|
|
4798
|
+
const loc = { file: sf.fileName, start: ts.tokenStartOfNode(call), end: call.end };
|
|
3684
4799
|
const bindingKind = requireCallBindingKind7(program, call);
|
|
3685
4800
|
if (!jsRequireFile && bindingKind !== "createRequire")
|
|
3686
4801
|
continue;
|
|
@@ -3693,14 +4808,14 @@ function preflight7(load) {
|
|
|
3693
4808
|
if (load.externalTypes.has(spec)) {
|
|
3694
4809
|
continue;
|
|
3695
4810
|
}
|
|
4811
|
+
if (npmBuiltinAliasOf(spec) !== null)
|
|
4812
|
+
continue;
|
|
3696
4813
|
const projectDep = resolveImport7(program, sf, spec, "require");
|
|
3697
4814
|
if (projectDep !== null) {
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
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"))
|
|
3702
4818
|
continue;
|
|
3703
|
-
}
|
|
3704
4819
|
deps.push({ dep: projectDep });
|
|
3705
4820
|
continue;
|
|
3706
4821
|
}
|
|
@@ -3728,6 +4843,36 @@ function preflight7(load) {
|
|
|
3728
4843
|
continue;
|
|
3729
4844
|
}
|
|
3730
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
|
+
}
|
|
3731
4876
|
}
|
|
3732
4877
|
}
|
|
3733
4878
|
// Node's evaluation order: depth-first postorder from the entry, each
|
|
@@ -3753,8 +4898,12 @@ function preflight7(load) {
|
|
|
3753
4898
|
// reads are all let/const bindings with module storage — the
|
|
3754
4899
|
// lowering checks each one (cycleEarlyBindings) and throws Node's
|
|
3755
4900
|
// ReferenceError on a read before the declaration ran.
|
|
3756
|
-
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
|
+
});
|
|
3757
4905
|
const order = [];
|
|
4906
|
+
const inlineRequireCycleCalls = new Set();
|
|
3758
4907
|
const state = new Map();
|
|
3759
4908
|
const stack = [];
|
|
3760
4909
|
const visit = (sf) => {
|
|
@@ -3763,10 +4912,16 @@ function preflight7(load) {
|
|
|
3763
4912
|
for (const e of edges.get(sf) ?? []) {
|
|
3764
4913
|
if (e.dep === sf)
|
|
3765
4914
|
continue; // self-import: a Node cache hit, not a cycle
|
|
4915
|
+
if (e.lazy === true)
|
|
4916
|
+
continue; // visited after this module completes
|
|
3766
4917
|
const s = state.get(e.dep);
|
|
3767
4918
|
if (s === "done")
|
|
3768
4919
|
continue;
|
|
3769
4920
|
if (s === "visiting") {
|
|
4921
|
+
if (e.call !== undefined) {
|
|
4922
|
+
inlineRequireCycleCalls.add(e.call);
|
|
4923
|
+
continue;
|
|
4924
|
+
}
|
|
3770
4925
|
// A back-edge: Node answers it from the cache (the module is
|
|
3771
4926
|
// already evaluating) — admitted by the cheap per-edge rule, the
|
|
3772
4927
|
// declaration-only init window rule, or the exact initialization
|
|
@@ -3784,6 +4939,12 @@ function preflight7(load) {
|
|
|
3784
4939
|
stack.pop();
|
|
3785
4940
|
state.set(sf, "done");
|
|
3786
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
|
+
}
|
|
3787
4948
|
};
|
|
3788
4949
|
visit(entry);
|
|
3789
4950
|
// The startup crash Node's RESOLUTION phase reports: modules resolve
|
|
@@ -3833,7 +4994,12 @@ function preflight7(load) {
|
|
|
3833
4994
|
const linkCrash = resolveCrash !== null
|
|
3834
4995
|
? null
|
|
3835
4996
|
: earlierLinkCrash(order, cjsNamedImportLinkCheck(program, entry, order, diags), esmNamedImportLinkCheck(program, entry, order, diags));
|
|
3836
|
-
return {
|
|
4997
|
+
return {
|
|
4998
|
+
diags,
|
|
4999
|
+
moduleOrder: order,
|
|
5000
|
+
startupCrash: resolveCrash ?? linkCrash,
|
|
5001
|
+
inlineRequireCycleCalls,
|
|
5002
|
+
};
|
|
3837
5003
|
}
|
|
3838
5004
|
/** Walks the entry's ESM instantiate graph exactly as V8 does — children
|
|
3839
5005
|
* in request order, each module's own imports checked AFTER its children
|
|
@@ -3867,12 +5033,19 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3867
5033
|
npmStaticDepSf7(program, from, spec, "require");
|
|
3868
5034
|
return dep !== null && isCjsJsFile7(dep, program) ? dep : null;
|
|
3869
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
|
+
};
|
|
3870
5043
|
const visible = (dep, name) =>
|
|
3871
5044
|
// `default` is the module.exports binding itself — always provided.
|
|
3872
5045
|
// The program already owns native source ASTs; reuse them without
|
|
3873
5046
|
// starting another syntax session or reparsing their source text.
|
|
3874
5047
|
name === "default" ||
|
|
3875
|
-
cjsVisibleNames(dep,
|
|
5048
|
+
cjsVisibleNames(dep, lexWithAccessorNames, resolveCjsDep, lexMemo).has(name);
|
|
3876
5049
|
/** The statement's resolved LOCAL CommonJS dependency, when it is an
|
|
3877
5050
|
* import/re-export from one. */
|
|
3878
5051
|
const cjsDepOf = (sf, spec) => {
|
|
@@ -3884,7 +5057,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3884
5057
|
* then `export { x } from` elements in source order. */
|
|
3885
5058
|
const firstInvisibleOf = (sf) => {
|
|
3886
5059
|
const entries = [];
|
|
3887
|
-
for (const stmt of sf.statements) {
|
|
5060
|
+
for (const stmt of sf.statements.nodes) {
|
|
3888
5061
|
if (!ts.isImportDeclaration(stmt) ||
|
|
3889
5062
|
stmt.moduleSpecifier === undefined ||
|
|
3890
5063
|
!ts.isStringLiteral(stmt.moduleSpecifier))
|
|
@@ -3898,7 +5071,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3898
5071
|
const dep = cjsDepOf(sf, spec);
|
|
3899
5072
|
if (dep === null)
|
|
3900
5073
|
continue;
|
|
3901
|
-
for (const e of clause.namedBindings.elements) {
|
|
5074
|
+
for (const e of clause.namedBindings.elements.nodes) {
|
|
3902
5075
|
if (e.isTypeOnly)
|
|
3903
5076
|
continue;
|
|
3904
5077
|
const nameNode = e.propertyName ?? e.name;
|
|
@@ -3910,7 +5083,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3910
5083
|
if (!visible(e.dep, e.exportName))
|
|
3911
5084
|
return { exportName: e.exportName, spec: e.spec, nameNode: e.nameNode, sf };
|
|
3912
5085
|
}
|
|
3913
|
-
for (const stmt of sf.statements) {
|
|
5086
|
+
for (const stmt of sf.statements.nodes) {
|
|
3914
5087
|
if (!ts.isExportDeclaration(stmt) || stmt.isTypeOnly)
|
|
3915
5088
|
continue;
|
|
3916
5089
|
if (stmt.moduleSpecifier === undefined || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
@@ -3921,7 +5094,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3921
5094
|
const dep = cjsDepOf(sf, spec);
|
|
3922
5095
|
if (dep === null)
|
|
3923
5096
|
continue;
|
|
3924
|
-
for (const e of stmt.exportClause.elements) {
|
|
5097
|
+
for (const e of stmt.exportClause.elements.nodes) {
|
|
3925
5098
|
if (e.isTypeOnly)
|
|
3926
5099
|
continue;
|
|
3927
5100
|
const nameNode = e.propertyName ?? e.name;
|
|
@@ -3940,7 +5113,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3940
5113
|
if (visited.has(sf))
|
|
3941
5114
|
return null;
|
|
3942
5115
|
visited.add(sf);
|
|
3943
|
-
for (const stmt of sf.statements) {
|
|
5116
|
+
for (const stmt of sf.statements.nodes) {
|
|
3944
5117
|
if (!ts.isImportDeclaration(stmt) && !(ts.isExportDeclaration(stmt) && !stmt.isTypeOnly))
|
|
3945
5118
|
continue;
|
|
3946
5119
|
if (ts.isExportDeclaration(stmt) && isPrunedNpmReexport(program, stmt))
|
|
@@ -3981,7 +5154,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
3981
5154
|
// it is CommonJS (module_job.js consults the ROOT job's moduleRequests/
|
|
3982
5155
|
// commonJsDeps — a deep module's failure keeps the generic wording).
|
|
3983
5156
|
let flavored = false;
|
|
3984
|
-
for (const stmt of entry.statements) {
|
|
5157
|
+
for (const stmt of entry.statements.nodes) {
|
|
3985
5158
|
if (!ts.isImportDeclaration(stmt) && !(ts.isExportDeclaration(stmt) && !stmt.isTypeOnly))
|
|
3986
5159
|
continue;
|
|
3987
5160
|
if (ts.isImportDeclaration(stmt) &&
|
|
@@ -4008,7 +5181,7 @@ function cjsNamedImportLinkCheck(program, entry, moduleOrder, diags) {
|
|
|
4008
5181
|
// swaps ` as ` for `: ` — reproduced exactly, quirks included
|
|
4009
5182
|
// (multi-line import statements simply lose the hint).
|
|
4010
5183
|
const text = bad.sf.text;
|
|
4011
|
-
const pos =
|
|
5184
|
+
const pos = ts.tokenStartOfNode(bad.nameNode);
|
|
4012
5185
|
const lineStart = text.lastIndexOf("\n", pos - 1) + 1;
|
|
4013
5186
|
const lineEnd = text.indexOf("\n", pos);
|
|
4014
5187
|
let line = text.slice(lineStart, lineEnd < 0 ? text.length : lineEnd);
|
|
@@ -4066,9 +5239,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4066
5239
|
// type-only, but the native ESM linker sees the runtime placeholder.
|
|
4067
5240
|
if (name === "default" &&
|
|
4068
5241
|
hasNodeTsDefaultInterfacePlaceholder7(dep) &&
|
|
4069
|
-
|
|
4070
|
-
.declarationsOf(resolved)
|
|
4071
|
-
.some((declaration) => ts.isInterfaceDeclaration(declaration) &&
|
|
5242
|
+
resolved.declarations.some((declaration) => ts.isInterfaceDeclaration(declaration) &&
|
|
4072
5243
|
ts
|
|
4073
5244
|
.getModifiers(declaration)
|
|
4074
5245
|
?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) === true &&
|
|
@@ -4087,7 +5258,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4087
5258
|
if (name === "default")
|
|
4088
5259
|
return undefined;
|
|
4089
5260
|
let starExport;
|
|
4090
|
-
for (const stmt of dep.statements) {
|
|
5261
|
+
for (const stmt of dep.statements.nodes) {
|
|
4091
5262
|
if (!ts.isExportDeclaration(stmt) || stmt.isTypeOnly || stmt.exportClause !== undefined)
|
|
4092
5263
|
continue;
|
|
4093
5264
|
if (stmt.moduleSpecifier === undefined || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
@@ -4106,7 +5277,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4106
5277
|
};
|
|
4107
5278
|
const firstMissingOf = (sf) => {
|
|
4108
5279
|
const imports = [];
|
|
4109
|
-
for (const stmt of sf.statements) {
|
|
5280
|
+
for (const stmt of sf.statements.nodes) {
|
|
4110
5281
|
if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
4111
5282
|
continue;
|
|
4112
5283
|
const clause = stmt.importClause;
|
|
@@ -4127,7 +5298,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4127
5298
|
}
|
|
4128
5299
|
if (clause.namedBindings === undefined || !ts.isNamedImports(clause.namedBindings))
|
|
4129
5300
|
continue;
|
|
4130
|
-
for (const element of clause.namedBindings.elements) {
|
|
5301
|
+
for (const element of clause.namedBindings.elements.nodes) {
|
|
4131
5302
|
if (element.isTypeOnly)
|
|
4132
5303
|
continue;
|
|
4133
5304
|
const nameNode = element.propertyName ?? element.name;
|
|
@@ -4154,7 +5325,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4154
5325
|
};
|
|
4155
5326
|
}
|
|
4156
5327
|
}
|
|
4157
|
-
for (const stmt of sf.statements) {
|
|
5328
|
+
for (const stmt of sf.statements.nodes) {
|
|
4158
5329
|
if (!ts.isExportDeclaration(stmt) || stmt.isTypeOnly)
|
|
4159
5330
|
continue;
|
|
4160
5331
|
const moduleSpecifier = stmt.moduleSpecifier;
|
|
@@ -4167,7 +5338,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4167
5338
|
const dep = resolveEdge(sf, spec);
|
|
4168
5339
|
if (dep === null || dep.fileName.endsWith(".json") || !isNodeEsmFile7(dep, program))
|
|
4169
5340
|
continue;
|
|
4170
|
-
for (const element of exportClause.elements) {
|
|
5341
|
+
for (const element of exportClause.elements.nodes) {
|
|
4171
5342
|
if (element.isTypeOnly)
|
|
4172
5343
|
continue;
|
|
4173
5344
|
const nameNode = element.propertyName ?? element.name;
|
|
@@ -4186,7 +5357,7 @@ function analyzeEsmNamedImportLinks(program, entry) {
|
|
|
4186
5357
|
if (visited.has(sf))
|
|
4187
5358
|
return null;
|
|
4188
5359
|
visited.add(sf);
|
|
4189
|
-
for (const stmt of sf.statements) {
|
|
5360
|
+
for (const stmt of sf.statements.nodes) {
|
|
4190
5361
|
if (!ts.isImportDeclaration(stmt) && !(ts.isExportDeclaration(stmt) && !stmt.isTypeOnly))
|
|
4191
5362
|
continue;
|
|
4192
5363
|
if (ts.isExportDeclaration(stmt) && isPrunedNpmReexport(program, stmt))
|
|
@@ -4268,17 +5439,17 @@ function earlierLinkCrash(moduleOrder, first, second) {
|
|
|
4268
5439
|
return first.loc.start < second.loc.start ? first : second;
|
|
4269
5440
|
const rank = (crash) => {
|
|
4270
5441
|
const entries = [];
|
|
4271
|
-
for (const stmt of sf.statements) {
|
|
5442
|
+
for (const stmt of sf.statements.nodes) {
|
|
4272
5443
|
if (ts.isImportDeclaration(stmt) && ts.isStringLiteral(stmt.moduleSpecifier)) {
|
|
4273
5444
|
const clause = stmt.importClause;
|
|
4274
5445
|
if (clause?.phaseModifier === ts.SyntaxKind.TypeKeyword)
|
|
4275
5446
|
continue;
|
|
4276
5447
|
if (clause?.namedBindings && ts.isNamedImports(clause.namedBindings)) {
|
|
4277
|
-
for (const element of clause.namedBindings.elements) {
|
|
5448
|
+
for (const element of clause.namedBindings.elements.nodes) {
|
|
4278
5449
|
if (!element.isTypeOnly) {
|
|
4279
5450
|
entries.push({
|
|
4280
5451
|
local: element.name.text,
|
|
4281
|
-
start: (element.propertyName ?? element.name)
|
|
5452
|
+
start: ts.tokenStartOfNode(element.propertyName ?? element.name),
|
|
4282
5453
|
kind: 0,
|
|
4283
5454
|
});
|
|
4284
5455
|
}
|
|
@@ -4291,16 +5462,16 @@ function earlierLinkCrash(moduleOrder, first, second) {
|
|
|
4291
5462
|
if (direct >= 0)
|
|
4292
5463
|
return [0, direct];
|
|
4293
5464
|
let reexport = 0;
|
|
4294
|
-
for (const stmt of sf.statements) {
|
|
5465
|
+
for (const stmt of sf.statements.nodes) {
|
|
4295
5466
|
const exportClause = ts.isExportDeclaration(stmt) ? stmt.exportClause : undefined;
|
|
4296
5467
|
if (!ts.isExportDeclaration(stmt) ||
|
|
4297
5468
|
stmt.isTypeOnly ||
|
|
4298
5469
|
exportClause === undefined ||
|
|
4299
5470
|
!ts.isNamedExports(exportClause))
|
|
4300
5471
|
continue;
|
|
4301
|
-
for (const element of exportClause.elements) {
|
|
5472
|
+
for (const element of exportClause.elements.nodes) {
|
|
4302
5473
|
if (!element.isTypeOnly &&
|
|
4303
|
-
(element.propertyName ?? element.name)
|
|
5474
|
+
ts.tokenStartOfNode(element.propertyName ?? element.name) === crash.loc.start) {
|
|
4304
5475
|
return [1, reexport];
|
|
4305
5476
|
}
|
|
4306
5477
|
if (!element.isTypeOnly)
|
|
@@ -4328,54 +5499,38 @@ const nodeBuiltinNames = new Set(builtinModules);
|
|
|
4328
5499
|
* established (the phase-2 port kept every spelling); the world-neutral
|
|
4329
5500
|
* helpers re-export from their focused modules. */
|
|
4330
5501
|
export { ambientDtsPath, fallbackDtsPath, isNodeTypesPath, overridesDtsPath } from "./dts-paths.js";
|
|
4331
|
-
export { builtinDefaultImportModule, canonicalBuiltinModule, SUPPORTED_BUILTIN_MODULES, } from "./builtin-modules.js";
|
|
5502
|
+
export { builtinDefaultImportModule, canonicalBuiltinModule, npmBuiltinAliasOf, SUPPORTED_BUILTIN_MODULES, } from "./builtin-modules.js";
|
|
4332
5503
|
export { npmPackageNameOf, workspacePackageOfPath } from "./workspace-registry.js";
|
|
4333
|
-
export { requireSpecOf7 as requireSpecOf, isRequireStatement7 as isRequireStatement, requiresOf7 as requiresOf, isNodeEsmFile7 as isNodeEsmFile, resolveImport7 as resolveImport, resolveNpmImport7 as resolveNpmImport, locOf7 as locOf, };
|
|
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, };
|
|
4334
5505
|
/** True for JavaScript source files (.js/.mjs/.cjs) — the files whose
|
|
4335
5506
|
* types come entirely from inference (checkJs + JSDoc) and whose classes
|
|
4336
5507
|
* declare fields by constructor assignment. */
|
|
4337
5508
|
export function isJsSourceFile(sf) {
|
|
4338
5509
|
return isJsSourceFileName(sf.fileName);
|
|
4339
5510
|
}
|
|
4340
|
-
/**
|
|
4341
|
-
*
|
|
4342
|
-
*
|
|
4343
|
-
*
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
return true;
|
|
4357
|
-
return (clause.name === undefined &&
|
|
4358
|
-
clause.namedBindings !== undefined &&
|
|
4359
|
-
ts.isNamedImports(clause.namedBindings) &&
|
|
4360
|
-
clause.namedBindings.elements.length > 0 &&
|
|
4361
|
-
clause.namedBindings.elements.every((e) => e.isTypeOnly));
|
|
4362
|
-
}
|
|
4363
|
-
/** The re-export twin: `export { type X } from "./m"` with every element
|
|
4364
|
-
* `type`-qualified erases at emit exactly like `export type { X } from`
|
|
4365
|
-
* (which stmt.isTypeOnly already covers) — no module edge. */
|
|
4366
|
-
function erasedTypeOnlyReexport(stmt) {
|
|
4367
|
-
return (stmt.exportClause !== undefined &&
|
|
4368
|
-
ts.isNamedExports(stmt.exportClause) &&
|
|
4369
|
-
stmt.exportClause.elements.length > 0 &&
|
|
4370
|
-
stmt.exportClause.elements.every((e) => e.isTypeOnly));
|
|
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;
|
|
4371
5527
|
}
|
|
4372
5528
|
export function orderedImportsOf(program, sf) {
|
|
4373
5529
|
const out = [];
|
|
4374
|
-
for (const stmt of sf.statements) {
|
|
5530
|
+
for (const stmt of sf.statements.nodes) {
|
|
4375
5531
|
if (ts.isExportDeclaration(stmt) && isPrunedNpmReexport(program, stmt))
|
|
4376
5532
|
continue;
|
|
4377
|
-
if (ts.isExportDeclaration(stmt) &&
|
|
4378
|
-
(stmt.isTypeOnly || erasedTypeOnlyReexport(stmt) || !stmt.moduleSpecifier))
|
|
5533
|
+
if (ts.isExportDeclaration(stmt) && (stmt.isTypeOnly || !stmt.moduleSpecifier))
|
|
4379
5534
|
continue;
|
|
4380
5535
|
if (!ts.isImportDeclaration(stmt) && !ts.isExportDeclaration(stmt))
|
|
4381
5536
|
continue;
|
|
@@ -4394,6 +5549,58 @@ export function orderedImportsOf(program, sf) {
|
|
|
4394
5549
|
}
|
|
4395
5550
|
return out;
|
|
4396
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
|
+
}
|
|
4397
5604
|
/** The program source file a bare specifier reaches when it names an
|
|
4398
5605
|
* opted-in --npm-static package (the shipped-JS entry preflight admitted
|
|
4399
5606
|
* as a module edge), else null. No offender reporting here — preflight
|
|
@@ -4435,6 +5642,19 @@ export function cjsExportAssignmentOf(stmt) {
|
|
|
4435
5642
|
if (isModuleExportsAccess(e.left)) {
|
|
4436
5643
|
return { kind: "table", obj: ts.isObjectLiteralExpression(e.right) ? e.right : null, expr: e };
|
|
4437
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
|
+
}
|
|
4438
5658
|
if (ts.isPropertyAccessExpression(e.left) && !e.left.questionDotToken) {
|
|
4439
5659
|
const recv = e.left.expression;
|
|
4440
5660
|
const isExports = ts.isIdentifier(recv) && recv.text === "exports";
|
|
@@ -4444,6 +5664,85 @@ export function cjsExportAssignmentOf(stmt) {
|
|
|
4444
5664
|
}
|
|
4445
5665
|
return null;
|
|
4446
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
|
+
}
|
|
4447
5746
|
/** Why Node would DISCARD this CommonJS export statement, or null when it
|
|
4448
5747
|
* survives (Node's export-object identity rules — checker-free, pure
|
|
4449
5748
|
* AST): `module.exports = {...}` REPLACES the export object, so members
|
|
@@ -4459,7 +5758,7 @@ export function cjsExportDiscardReason(stmt) {
|
|
|
4459
5758
|
const mine = cjsExportAssignmentOf(stmt);
|
|
4460
5759
|
if (!mine)
|
|
4461
5760
|
return null;
|
|
4462
|
-
const stmts = sf.statements;
|
|
5761
|
+
const stmts = sf.statements.nodes;
|
|
4463
5762
|
let lastTable = -1;
|
|
4464
5763
|
for (let i = 0; i < stmts.length; i++) {
|
|
4465
5764
|
if (cjsExportAssignmentOf(stmts[i])?.kind === "table")
|
|
@@ -4477,6 +5776,9 @@ export function cjsExportDiscardReason(stmt) {
|
|
|
4477
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)";
|
|
4478
5777
|
}
|
|
4479
5778
|
const left = mine.expr.left;
|
|
5779
|
+
const last = cjsExportAssignmentOf(stmts[lastTable]);
|
|
5780
|
+
if (last?.kind === "table" && last.rebindsExports === true)
|
|
5781
|
+
return null;
|
|
4480
5782
|
return ts.isIdentifier(left.expression) && left.expression.text === "exports"
|
|
4481
5783
|
? "'exports.f =' after a 'module.exports =' assignment ('exports' still references the replaced object — Node discards this member; write module.exports.f instead)"
|
|
4482
5784
|
: null;
|
|
@@ -4496,16 +5798,16 @@ export function cjsExportTargetLiteral(e, sf) {
|
|
|
4496
5798
|
if (ts.isNewExpression(e) &&
|
|
4497
5799
|
ts.isIdentifier(e.expression) &&
|
|
4498
5800
|
e.expression.text === "Proxy" &&
|
|
4499
|
-
(e.arguments?.length ?? 0) >= 1) {
|
|
4500
|
-
return cjsExportTargetLiteral(e.arguments[0], sf);
|
|
5801
|
+
(e.arguments?.nodes.length ?? 0) >= 1) {
|
|
5802
|
+
return cjsExportTargetLiteral(e.arguments.nodes[0], sf);
|
|
4501
5803
|
}
|
|
4502
5804
|
if (ts.isIdentifier(e)) {
|
|
4503
|
-
for (const stmt of sf.statements) {
|
|
5805
|
+
for (const stmt of sf.statements.nodes) {
|
|
4504
5806
|
if (!ts.isVariableStatement(stmt))
|
|
4505
5807
|
continue;
|
|
4506
5808
|
if ((stmt.declarationList.flags & ts.NodeFlags.Const) === 0)
|
|
4507
5809
|
continue;
|
|
4508
|
-
for (const d of stmt.declarationList.declarations) {
|
|
5810
|
+
for (const d of stmt.declarationList.declarations.nodes) {
|
|
4509
5811
|
if (d.name !== undefined &&
|
|
4510
5812
|
ts.isIdentifier(d.name) &&
|
|
4511
5813
|
d.name.text === e.text &&
|
|
@@ -4527,7 +5829,7 @@ export function cjsExportTargetLiteral(e, sf) {
|
|
|
4527
5829
|
* order against it). Null when the kept export is anything else. */
|
|
4528
5830
|
export function cjsClassExprWholeExportOf(sf) {
|
|
4529
5831
|
let last = null;
|
|
4530
|
-
for (const stmt of sf.statements) {
|
|
5832
|
+
for (const stmt of sf.statements.nodes) {
|
|
4531
5833
|
const cjs = cjsExportAssignmentOf(stmt);
|
|
4532
5834
|
if (!cjs || cjs.kind !== "table")
|
|
4533
5835
|
continue;
|
|
@@ -4558,10 +5860,10 @@ export function isCjsExportTableLiteral(obj) {
|
|
|
4558
5860
|
const decl = obj.parent;
|
|
4559
5861
|
if (!ts.isVariableDeclaration(decl) || decl.initializer !== obj)
|
|
4560
5862
|
return false;
|
|
4561
|
-
const sf =
|
|
5863
|
+
const sf = ts.getSourceFileOfNode(obj);
|
|
4562
5864
|
if (!isJsSourceFile(sf))
|
|
4563
5865
|
return false;
|
|
4564
|
-
for (const stmt of sf.statements) {
|
|
5866
|
+
for (const stmt of sf.statements.nodes) {
|
|
4565
5867
|
const cjs = cjsExportAssignmentOf(stmt);
|
|
4566
5868
|
if (cjs?.kind === "table" && cjsExportDiscardReason(stmt) === null) {
|
|
4567
5869
|
return cjsExportTargetLiteral(cjs.expr.right, sf) === obj;
|
|
@@ -4668,7 +5970,7 @@ function receiverRoot(text, pos) {
|
|
|
4668
5970
|
/** Whether `name` is bound in `fileName` by an import of a Node builtin. */
|
|
4669
5971
|
function importsNodeBuiltin(load, fileName, name) {
|
|
4670
5972
|
const sf = load.program.getSourceFile(fileName);
|
|
4671
|
-
for (const stmt of sf?.statements ?? []) {
|
|
5973
|
+
for (const stmt of sf?.statements?.nodes ?? []) {
|
|
4672
5974
|
if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
4673
5975
|
continue;
|
|
4674
5976
|
if (canonicalBuiltinModule(stmt.moduleSpecifier.text) === null)
|
|
@@ -4681,7 +5983,7 @@ function importsNodeBuiltin(load, fileName, name) {
|
|
|
4681
5983
|
return true;
|
|
4682
5984
|
if (bindings &&
|
|
4683
5985
|
ts.isNamedImports(bindings) &&
|
|
4684
|
-
bindings.elements.some((e) => e.name.text === name))
|
|
5986
|
+
bindings.elements.nodes.some((e) => e.name.text === name))
|
|
4685
5987
|
return true;
|
|
4686
5988
|
}
|
|
4687
5989
|
return false;
|