@scriptc/compiler 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ambient/scriptc-node-fallback.d.ts +35 -5
- package/dist/backend/executable-features.js +7 -0
- package/dist/backend/executable-features.js.map +1 -1
- package/dist/backend/library-pack.js +3 -0
- package/dist/backend/library-pack.js.map +1 -1
- package/dist/backend/link-plan-core.d.ts +2 -0
- package/dist/backend/link-plan-core.js +2 -0
- package/dist/backend/link-plan-core.js.map +1 -1
- package/dist/backend/link-plan.d.ts +1 -0
- package/dist/backend/link-plan.js +1 -0
- package/dist/backend/link-plan.js.map +1 -1
- package/dist/backend/llvm/array-search.js +3 -1
- package/dist/backend/llvm/array-search.js.map +1 -1
- package/dist/backend/llvm/classes.d.ts +27 -1
- package/dist/backend/llvm/classes.js +115 -22
- package/dist/backend/llvm/classes.js.map +1 -1
- package/dist/backend/llvm/classes.test.js +21 -9
- package/dist/backend/llvm/classes.test.js.map +1 -1
- package/dist/backend/llvm/common.d.ts +21 -3
- package/dist/backend/llvm/common.js +50 -3
- package/dist/backend/llvm/common.js.map +1 -1
- package/dist/backend/llvm/dense-array-access.d.ts +3 -1
- package/dist/backend/llvm/dense-array-access.js +61 -38
- package/dist/backend/llvm/dense-array-access.js.map +1 -1
- package/dist/backend/llvm/dense-array-access.test.js +4 -0
- package/dist/backend/llvm/dense-array-access.test.js.map +1 -1
- package/dist/backend/llvm/dense-array-loops.js +3 -3
- package/dist/backend/llvm/dense-array-loops.js.map +1 -1
- package/dist/backend/llvm/dyn.d.ts +9 -0
- package/dist/backend/llvm/dyn.js +62 -6
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emit-function.js +5 -2
- package/dist/backend/llvm/emit-function.js.map +1 -1
- package/dist/backend/llvm/emit-module.js +54 -32
- package/dist/backend/llvm/emit-module.js.map +1 -1
- package/dist/backend/llvm/emit-statements.d.ts +3 -2
- package/dist/backend/llvm/emit-statements.js +90 -13
- package/dist/backend/llvm/emit-statements.js.map +1 -1
- package/dist/backend/llvm/emitter.d.ts +20 -9
- package/dist/backend/llvm/emitter.js +42 -31
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/expr-calls.js +17 -4
- package/dist/backend/llvm/expr-calls.js.map +1 -1
- package/dist/backend/llvm/expr-containers.js +6 -9
- package/dist/backend/llvm/expr-containers.js.map +1 -1
- package/dist/backend/llvm/expr-dynamic.js +46 -4
- package/dist/backend/llvm/expr-dynamic.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.js +3 -3
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.test.js +55 -0
- package/dist/backend/llvm/expr-primitives.test.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.js +11 -15
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
- package/dist/backend/llvm/integer-clones.js +3 -3
- package/dist/backend/llvm/integer-clones.js.map +1 -1
- package/dist/backend/llvm/js-ic.d.ts +18 -0
- package/dist/backend/llvm/js-ic.js +712 -0
- package/dist/backend/llvm/js-ic.js.map +1 -0
- package/dist/backend/llvm/jsval.js +139 -11
- package/dist/backend/llvm/jsval.js.map +1 -1
- package/dist/backend/llvm/lib-process.js +4 -3
- package/dist/backend/llvm/lib-process.js.map +1 -1
- package/dist/backend/llvm/lib-shared.js +22 -0
- package/dist/backend/llvm/lib-shared.js.map +1 -1
- package/dist/backend/llvm/local-array-reads.js +40 -31
- package/dist/backend/llvm/local-array-reads.js.map +1 -1
- package/dist/backend/llvm/map-number-lookup.d.ts +20 -4
- package/dist/backend/llvm/map-number-lookup.js +43 -7
- package/dist/backend/llvm/map-number-lookup.js.map +1 -1
- package/dist/backend/llvm/narrow-guards.js +64 -0
- package/dist/backend/llvm/narrow-guards.js.map +1 -1
- package/dist/backend/llvm/publish.d.ts +3 -0
- package/dist/backend/llvm/publish.js +36 -17
- package/dist/backend/llvm/publish.js.map +1 -1
- package/dist/backend/llvm/regions.js +2 -2
- package/dist/backend/llvm/regions.js.map +1 -1
- package/dist/backend/llvm/regions.test.js +7 -1
- package/dist/backend/llvm/regions.test.js.map +1 -1
- package/dist/backend/llvm/shapes.d.ts +8 -2
- package/dist/backend/llvm/shapes.js +9 -7
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/backend/llvm/speculative-integers.d.ts +20 -1
- package/dist/backend/llvm/speculative-integers.js +94 -6
- package/dist/backend/llvm/speculative-integers.js.map +1 -1
- package/dist/backend/llvm/speculative-integers.test.js +55 -1
- package/dist/backend/llvm/speculative-integers.test.js.map +1 -1
- package/dist/backend/llvm/string-reads.d.ts +1 -1
- package/dist/backend/llvm/string-reads.js +4 -4
- package/dist/backend/llvm/string-reads.js.map +1 -1
- package/dist/backend/llvm/thread-slots.test.js +5 -4
- package/dist/backend/llvm/thread-slots.test.js.map +1 -1
- package/dist/backend/mangle.d.ts +5 -0
- package/dist/backend/mangle.js +7 -0
- package/dist/backend/mangle.js.map +1 -1
- package/dist/backend/native/contracts.d.ts +20 -0
- package/dist/backend/native/executable.js +20 -3
- package/dist/backend/native/executable.js.map +1 -1
- package/dist/backend/native/library.js +2 -1
- package/dist/backend/native/library.js.map +1 -1
- package/dist/backend/native-codegen.d.ts +6 -0
- package/dist/backend/native-codegen.js +19 -0
- package/dist/backend/native-codegen.js.map +1 -1
- package/dist/backend/native-codegen.test.js +27 -0
- package/dist/backend/native-codegen.test.js.map +1 -1
- package/dist/backend/native-link-info-core.d.ts +18 -0
- package/dist/backend/native-link-info-core.js.map +1 -1
- package/dist/backend/native-profile.d.ts +32 -0
- package/dist/backend/native-profile.js +39 -0
- package/dist/backend/native-profile.js.map +1 -0
- package/dist/backend/native-profile.test.d.ts +1 -0
- package/dist/backend/native-profile.test.js +58 -0
- package/dist/backend/native-profile.test.js.map +1 -0
- package/dist/backend/native-tools.d.ts +14 -0
- package/dist/backend/native-tools.js +13 -0
- package/dist/backend/native-tools.js.map +1 -1
- package/dist/backend/runtime-abi.d.ts +2 -2
- package/dist/backend/runtime-abi.js +2 -2
- package/dist/backend/runtime-pack-core.d.ts +4 -0
- package/dist/backend/runtime-pack-core.js +4 -0
- package/dist/backend/runtime-pack-core.js.map +1 -1
- package/dist/backend/runtime-pack-targets.test.js +4 -1
- package/dist/backend/runtime-pack-targets.test.js.map +1 -1
- package/dist/backend/runtime-pack.test.js +4 -1
- package/dist/backend/runtime-pack.test.js.map +1 -1
- package/dist/backend/target-diagnostics.js +7 -0
- package/dist/backend/target-diagnostics.js.map +1 -1
- package/dist/backend/warm-cache.js +3 -0
- package/dist/backend/warm-cache.js.map +1 -1
- package/dist/cli/command.js +63 -1
- package/dist/cli/command.js.map +1 -1
- package/dist/cli/host.d.ts +3 -0
- package/dist/cli/output-options.d.ts +2 -0
- package/dist/cli/output-options.js +9 -0
- package/dist/cli/output-options.js.map +1 -1
- package/dist/cli/usage.d.ts +11 -1
- package/dist/cli/usage.js +23 -0
- package/dist/cli/usage.js.map +1 -1
- package/dist/compile-types.d.ts +9 -0
- package/dist/contracts/check.js +1 -2
- package/dist/contracts/check.js.map +1 -1
- package/dist/executable/executable-cache.d.ts +10 -0
- package/dist/executable/executable-cache.js +6 -0
- package/dist/executable/executable-cache.js.map +1 -1
- package/dist/executable/executable-cache.test.js +5 -0
- package/dist/executable/executable-cache.test.js.map +1 -1
- package/dist/frontend/arguments-usage.d.ts +8 -0
- package/dist/frontend/arguments-usage.js +98 -0
- package/dist/frontend/arguments-usage.js.map +1 -1
- package/dist/frontend/arguments-usage.test.d.ts +1 -0
- package/dist/frontend/arguments-usage.test.js +32 -0
- package/dist/frontend/arguments-usage.test.js.map +1 -0
- package/dist/frontend/builtin-package-aliases.d.ts +24 -0
- package/dist/frontend/builtin-package-aliases.js +133 -0
- package/dist/frontend/builtin-package-aliases.js.map +1 -0
- package/dist/frontend/builtin-package-aliases.test.d.ts +1 -0
- package/dist/frontend/builtin-package-aliases.test.js +48 -0
- package/dist/frontend/builtin-package-aliases.test.js.map +1 -0
- package/dist/frontend/dts-paths.d.ts +4 -0
- package/dist/frontend/dts-paths.js +9 -1
- package/dist/frontend/dts-paths.js.map +1 -1
- package/dist/frontend/lowering/builtins/builtin-class-dyn.d.ts +8 -0
- package/dist/frontend/lowering/builtins/builtin-class-dyn.js +50 -1
- package/dist/frontend/lowering/builtins/builtin-class-dyn.js.map +1 -1
- package/dist/frontend/lowering/builtins/callable-aliases.js +3 -2
- package/dist/frontend/lowering/builtins/callable-aliases.js.map +1 -1
- package/dist/frontend/lowering/builtins/crypto.d.ts +3 -0
- package/dist/frontend/lowering/builtins/crypto.js +4 -1
- package/dist/frontend/lowering/builtins/crypto.js.map +1 -1
- package/dist/frontend/lowering/builtins/ecdh.d.ts +10 -0
- package/dist/frontend/lowering/builtins/ecdh.js +208 -0
- package/dist/frontend/lowering/builtins/ecdh.js.map +1 -0
- package/dist/frontend/lowering/builtins/json.js +52 -0
- package/dist/frontend/lowering/builtins/json.js.map +1 -1
- package/dist/frontend/lowering/builtins/process.d.ts +9 -0
- package/dist/frontend/lowering/builtins/process.js +44 -0
- package/dist/frontend/lowering/builtins/process.js.map +1 -1
- package/dist/frontend/lowering/builtins/promisify-callback.d.ts +3 -0
- package/dist/frontend/lowering/builtins/promisify-callback.js +21 -3
- package/dist/frontend/lowering/builtins/promisify-callback.js.map +1 -1
- package/dist/frontend/lowering/builtins/reflection.js +26 -0
- package/dist/frontend/lowering/builtins/reflection.js.map +1 -1
- package/dist/frontend/lowering/builtins/timers.js +5 -1
- package/dist/frontend/lowering/builtins/timers.js.map +1 -1
- package/dist/frontend/lowering/builtins/typed-array-members.d.ts +7 -0
- package/dist/frontend/lowering/builtins/typed-array-members.js +160 -0
- package/dist/frontend/lowering/builtins/typed-array-members.js.map +1 -0
- package/dist/frontend/lowering/call-signatures.d.ts +4 -0
- package/dist/frontend/lowering/call-signatures.js +126 -9
- package/dist/frontend/lowering/call-signatures.js.map +1 -1
- package/dist/frontend/lowering/cjs-exports-object.js +34 -1
- package/dist/frontend/lowering/cjs-exports-object.js.map +1 -1
- package/dist/frontend/lowering/class-dynamic-dispatch.js +9 -1
- package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
- package/dist/frontend/lowering/class-protocols.d.ts +10 -0
- package/dist/frontend/lowering/class-protocols.js +53 -3
- package/dist/frontend/lowering/class-protocols.js.map +1 -1
- package/dist/frontend/lowering/class-prototypes.js +6 -1
- package/dist/frontend/lowering/class-prototypes.js.map +1 -1
- package/dist/frontend/lowering/class-to-primitive.d.ts +2 -2
- package/dist/frontend/lowering/class-to-primitive.js +6 -3
- package/dist/frontend/lowering/class-to-primitive.js.map +1 -1
- package/dist/frontend/lowering/coercions/fresh-spread.d.ts +13 -0
- package/dist/frontend/lowering/coercions/fresh-spread.js +95 -0
- package/dist/frontend/lowering/coercions/fresh-spread.js.map +1 -0
- package/dist/frontend/lowering/coercions/function-adapters.js +99 -70
- package/dist/frontend/lowering/coercions/function-adapters.js.map +1 -1
- package/dist/frontend/lowering/containers/array-callbacks.d.ts +8 -0
- package/dist/frontend/lowering/containers/array-callbacks.js +22 -19
- package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
- package/dist/frontend/lowering/containers/array-construction.js +7 -0
- package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
- package/dist/frontend/lowering/containers/array-methods.js +5 -0
- package/dist/frontend/lowering/containers/array-methods.js.map +1 -1
- package/dist/frontend/lowering/containers/bytes.d.ts +9 -0
- package/dist/frontend/lowering/containers/bytes.js +493 -17
- package/dist/frontend/lowering/containers/bytes.js.map +1 -1
- package/dist/frontend/lowering/containers/collection-methods.js +72 -3
- package/dist/frontend/lowering/containers/collection-methods.js.map +1 -1
- package/dist/frontend/lowering/containers/string-and-regexp.js +49 -13
- package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
- package/dist/frontend/lowering/cycle-initialization.d.ts +26 -10
- package/dist/frontend/lowering/cycle-initialization.js +152 -35
- package/dist/frontend/lowering/cycle-initialization.js.map +1 -1
- package/dist/frontend/lowering/expressions/array-literals.js +33 -13
- package/dist/frontend/lowering/expressions/array-literals.js.map +1 -1
- package/dist/frontend/lowering/expressions/binary.js +79 -5
- package/dist/frontend/lowering/expressions/binary.js.map +1 -1
- package/dist/frontend/lowering/expressions/element-access.js +13 -6
- package/dist/frontend/lowering/expressions/element-access.js.map +1 -1
- package/dist/frontend/lowering/expressions/keyed-field-targets.d.ts +14 -2
- package/dist/frontend/lowering/expressions/keyed-field-targets.js +91 -10
- package/dist/frontend/lowering/expressions/keyed-field-targets.js.map +1 -1
- package/dist/frontend/lowering/expressions/narrowing.js +17 -2
- package/dist/frontend/lowering/expressions/narrowing.js.map +1 -1
- package/dist/frontend/lowering/expressions/object-literals.js +48 -1
- package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
- package/dist/frontend/lowering/expressions/optional-chains.d.ts +1 -1
- package/dist/frontend/lowering/expressions/optional-chains.js +12 -3
- package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
- package/dist/frontend/lowering/expressions/property-access.d.ts +5 -0
- package/dist/frontend/lowering/expressions/property-access.js +252 -9
- package/dist/frontend/lowering/expressions/property-access.js.map +1 -1
- package/dist/frontend/lowering/expressions/relational.js +49 -4
- package/dist/frontend/lowering/expressions/relational.js.map +1 -1
- package/dist/frontend/lowering/expressions/typeof.js +13 -0
- package/dist/frontend/lowering/expressions/typeof.js.map +1 -1
- package/dist/frontend/lowering/expressions/updates.js +1 -1
- package/dist/frontend/lowering/expressions/updates.js.map +1 -1
- package/dist/frontend/lowering/generator-delegation.d.ts +8 -0
- package/dist/frontend/lowering/generator-delegation.js +191 -1
- package/dist/frontend/lowering/generator-delegation.js.map +1 -1
- package/dist/frontend/lowering/generic-functions.d.ts +4 -0
- package/dist/frontend/lowering/generic-functions.js +213 -56
- package/dist/frontend/lowering/generic-functions.js.map +1 -1
- package/dist/frontend/lowering/handle-properties.d.ts +24 -0
- package/dist/frontend/lowering/handle-properties.js +281 -0
- package/dist/frontend/lowering/handle-properties.js.map +1 -0
- package/dist/frontend/lowering/iterable-spelling.d.ts +7 -0
- package/dist/frontend/lowering/iterable-spelling.js +38 -0
- package/dist/frontend/lowering/iterable-spelling.js.map +1 -0
- package/dist/frontend/lowering/lower-array-sort.d.ts +33 -15
- package/dist/frontend/lowering/lower-array-sort.js +117 -21
- package/dist/frontend/lowering/lower-array-sort.js.map +1 -1
- package/dist/frontend/lowering/lower-array-sort.test.js +93 -14
- package/dist/frontend/lowering/lower-array-sort.test.js.map +1 -1
- package/dist/frontend/lowering/lower-builtin-values.js +1 -0
- package/dist/frontend/lowering/lower-builtin-values.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +166 -7
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.d.ts +4 -0
- package/dist/frontend/lowering/lower-classes.js +59 -7
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-dgram.js +62 -13
- package/dist/frontend/lowering/lower-dgram.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.js +32 -1
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-functions.js +4 -0
- package/dist/frontend/lowering/lower-functions.js.map +1 -1
- package/dist/frontend/lowering/lower-generators.js +10 -4
- package/dist/frontend/lowering/lower-generators.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.js +569 -11
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.d.ts +11 -3
- package/dist/frontend/lowering/lower-modules.js +212 -67
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-namespaces.js +20 -0
- package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
- package/dist/frontend/lowering/lower-server.js +26 -1
- package/dist/frontend/lowering/lower-server.js.map +1 -1
- package/dist/frontend/lowering/lower-stdlib.js +28 -9
- package/dist/frontend/lowering/lower-stdlib.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.d.ts +7 -10
- package/dist/frontend/lowering/lower-stmts.js +418 -51
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lower-timers.js +17 -1
- package/dist/frontend/lowering/lower-timers.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +29 -5
- package/dist/frontend/lowering/lowerer.js +172 -25
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/rebindable-functions.d.ts +8 -0
- package/dist/frontend/lowering/rebindable-functions.js +54 -0
- package/dist/frontend/lowering/rebindable-functions.js.map +1 -0
- package/dist/frontend/lowering/static-typeof.d.ts +26 -0
- package/dist/frontend/lowering/static-typeof.js +133 -0
- package/dist/frontend/lowering/static-typeof.js.map +1 -0
- package/dist/frontend/lowering/string-index-bounds.js +3 -2
- package/dist/frontend/lowering/string-index-bounds.js.map +1 -1
- package/dist/frontend/lowering/surfaces.js +30 -4
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/lowering/thenables.d.ts +16 -0
- package/dist/frontend/lowering/thenables.js +124 -0
- package/dist/frontend/lowering/thenables.js.map +1 -0
- package/dist/frontend/npm-static-builtin-aliases.d.ts +8 -0
- package/dist/frontend/npm-static-builtin-aliases.js +65 -0
- package/dist/frontend/npm-static-builtin-aliases.js.map +1 -0
- package/dist/frontend/npm-static-bundled-chunks.d.ts +8 -1
- package/dist/frontend/npm-static-bundled-chunks.js +173 -2
- package/dist/frontend/npm-static-bundled-chunks.js.map +1 -1
- package/dist/frontend/npm-static-bundled-chunks.test.js +112 -0
- package/dist/frontend/npm-static-bundled-chunks.test.js.map +1 -1
- package/dist/frontend/npm-static-bundled-esm.js +224 -4
- package/dist/frontend/npm-static-bundled-esm.js.map +1 -1
- package/dist/frontend/npm-static-bundled-esm.test.js +129 -0
- package/dist/frontend/npm-static-bundled-esm.test.js.map +1 -1
- package/dist/frontend/npm-static-enum-iife.d.ts +6 -0
- package/dist/frontend/npm-static-enum-iife.js +280 -0
- package/dist/frontend/npm-static-enum-iife.js.map +1 -0
- package/dist/frontend/npm-static-enum-iife.test.d.ts +1 -0
- package/dist/frontend/npm-static-enum-iife.test.js +116 -0
- package/dist/frontend/npm-static-enum-iife.test.js.map +1 -0
- package/dist/frontend/npm-static.d.ts +8 -0
- package/dist/frontend/npm-static.js +46 -1
- package/dist/frontend/npm-static.js.map +1 -1
- package/dist/frontend/npm.js +13 -0
- package/dist/frontend/npm.js.map +1 -1
- package/dist/frontend/package-shims.d.ts +47 -0
- package/dist/frontend/package-shims.js +300 -0
- package/dist/frontend/package-shims.js.map +1 -0
- package/dist/frontend/pipeline.js +67 -1
- package/dist/frontend/pipeline.js.map +1 -1
- package/dist/frontend/program.d.ts +8 -0
- package/dist/frontend/program.js +72 -9
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/resolve.js +13 -0
- package/dist/frontend/resolve.js.map +1 -1
- package/dist/frontend/services.d.ts +6 -0
- package/dist/frontend/services.js +19 -0
- package/dist/frontend/services.js.map +1 -1
- package/dist/frontend/ts7/program-host.d.ts +6 -5
- package/dist/frontend/ts7/program-host.js +7 -0
- package/dist/frontend/ts7/program-host.js.map +1 -1
- package/dist/frontend/ts7/semantic-model.d.ts +3 -0
- package/dist/frontend/ts7/semantic-model.js +26 -0
- package/dist/frontend/ts7/semantic-model.js.map +1 -1
- package/dist/frontend/ts7/session.d.ts +19 -4
- package/dist/frontend/ts7/session.js.map +1 -1
- package/dist/frontend/type-mapper.js +201 -15
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +58 -6
- package/dist/index.js.map +1 -1
- package/dist/ir/array-length-stability.d.ts +3 -2
- package/dist/ir/array-length-stability.js +15 -2
- package/dist/ir/array-length-stability.js.map +1 -1
- package/dist/ir/array-length-stability.test.js +22 -1
- package/dist/ir/array-length-stability.test.js.map +1 -1
- package/dist/ir/builtin-effects.js +13 -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 +46 -4
- package/dist/ir/builtin-signatures.js.map +1 -1
- package/dist/ir/integer-loop-facts.d.ts +5 -0
- package/dist/ir/integer-loop-facts.js +79 -14
- package/dist/ir/integer-loop-facts.js.map +1 -1
- package/dist/ir/integer-ranges.d.ts +10 -1
- package/dist/ir/integer-ranges.js +122 -25
- package/dist/ir/integer-ranges.js.map +1 -1
- package/dist/ir/integer-ranges.test.js +191 -1
- package/dist/ir/integer-ranges.test.js.map +1 -1
- package/dist/ir/ir.js +8 -0
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/js-ic.d.ts +52 -0
- package/dist/ir/js-ic.js +199 -0
- package/dist/ir/js-ic.js.map +1 -0
- package/dist/ir/js-ic.test.d.ts +1 -0
- package/dist/ir/js-ic.test.js +148 -0
- package/dist/ir/js-ic.test.js.map +1 -0
- package/dist/ir/jsval.js +38 -4
- package/dist/ir/jsval.js.map +1 -1
- package/dist/ir/runtime-features.d.ts +39 -4
- package/dist/ir/runtime-features.js +229 -99
- package/dist/ir/runtime-features.js.map +1 -1
- package/dist/ir/traverse.js +110 -68
- package/dist/ir/traverse.js.map +1 -1
- package/dist/ir/validate.js +21 -8
- package/dist/ir/validate.js.map +1 -1
- package/dist/ir/validate.test.js +15 -2
- package/dist/ir/validate.test.js.map +1 -1
- package/dist/library/ir-policy.js +1 -0
- package/dist/library/ir-policy.js.map +1 -1
- package/dist/native/cli.js +17 -0
- package/dist/native/cli.js.map +1 -1
- package/dist/native/compiler.js +33 -4
- package/dist/native/compiler.js.map +1 -1
- package/dist/native/executable-cache.js +3 -0
- package/dist/native/executable-cache.js.map +1 -1
- package/dist/native/prepare.js +3 -0
- package/dist/native/prepare.js.map +1 -1
- package/dist/native/sanitizer.test.js +7 -0
- package/dist/native/sanitizer.test.js.map +1 -1
- package/package.json +21 -20
- package/shims/fs-extra/core/api.ts +1192 -0
- package/shims/fs-extra/index.ts +9 -0
- package/shims/undici/core/agent.ts +163 -0
- package/shims/undici/core/api.ts +93 -0
- package/shims/undici/core/client.ts +1304 -0
- package/shims/undici/core/connector.ts +157 -0
- package/shims/undici/core/diagnostics-types.ts +68 -0
- package/shims/undici/core/diagnostics.ts +16 -0
- package/shims/undici/core/dispatcher.ts +574 -0
- package/shims/undici/core/errors-v5.ts +22 -0
- package/shims/undici/core/errors-v7.ts +25 -0
- package/shims/undici/core/errors.ts +255 -0
- package/shims/undici/core/fetch.ts +635 -0
- package/shims/undici/core/pool.ts +280 -0
- package/shims/undici/core/readable.ts +268 -0
- package/shims/undici/core/request.ts +313 -0
- package/shims/undici/core/timers.ts +80 -0
- package/shims/undici/core/types.ts +167 -0
- package/shims/undici/core/util.ts +67 -0
- package/shims/undici/v5.ts +119 -0
- package/shims/undici/v7.ts +119 -0
- package/surface-manifest.json +2 -4
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
// undici's fetch(). Without a dispatcher (no init.dispatcher and no
|
|
2
|
+
// program-installed global dispatcher) it is the runtime's own fetch, which
|
|
3
|
+
// implements the same WHATWG algorithm. With one, the request goes through
|
|
4
|
+
// that dispatcher (its connector, lookup and pool), following undici's
|
|
5
|
+
// fetch for request headers, redirects and errors. The promise resolves
|
|
6
|
+
// when the response headers arrive, and the Response body streams from the
|
|
7
|
+
// connection with undici's back-pressure (see dispatchOnce).
|
|
8
|
+
//
|
|
9
|
+
// Known gaps: a Response built here reports `url` as "" and `redirected` as
|
|
10
|
+
// false (the runtime's Response has no settable URL yet), and https requests
|
|
11
|
+
// offer `gzip, deflate` rather than undici's `br, gzip, deflate` (the runtime
|
|
12
|
+
// has no Brotli decoder).
|
|
13
|
+
import type { Transform } from "node:stream";
|
|
14
|
+
import * as zlib from "node:zlib";
|
|
15
|
+
import type { Dispatcher } from "./dispatcher.ts";
|
|
16
|
+
import { getGlobalDispatcher, hasCustomGlobalDispatcher } from "./api.ts";
|
|
17
|
+
import type { DispatchHandlers, Profile } from "./types.ts";
|
|
18
|
+
|
|
19
|
+
/** undici's RequestInit, restricted to the implemented members: string and
|
|
20
|
+
* byte bodies, and the init members the dispatcher path honors. */
|
|
21
|
+
export interface UndiciRequestInit {
|
|
22
|
+
method?: string;
|
|
23
|
+
headers?: Headers | [string, string][] | Record<string, string>;
|
|
24
|
+
body?: string | Uint8Array | null;
|
|
25
|
+
signal?: AbortSignal | null;
|
|
26
|
+
redirect?: "follow" | "manual" | "error";
|
|
27
|
+
dispatcher?: Dispatcher;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The fetch standard's blocked ports (undici lib/web/fetch/constants.js). */
|
|
31
|
+
const badPorts = new Set([
|
|
32
|
+
"1",
|
|
33
|
+
"7",
|
|
34
|
+
"9",
|
|
35
|
+
"11",
|
|
36
|
+
"13",
|
|
37
|
+
"15",
|
|
38
|
+
"17",
|
|
39
|
+
"19",
|
|
40
|
+
"20",
|
|
41
|
+
"21",
|
|
42
|
+
"22",
|
|
43
|
+
"23",
|
|
44
|
+
"25",
|
|
45
|
+
"37",
|
|
46
|
+
"42",
|
|
47
|
+
"43",
|
|
48
|
+
"53",
|
|
49
|
+
"69",
|
|
50
|
+
"77",
|
|
51
|
+
"79",
|
|
52
|
+
"87",
|
|
53
|
+
"95",
|
|
54
|
+
"101",
|
|
55
|
+
"102",
|
|
56
|
+
"103",
|
|
57
|
+
"104",
|
|
58
|
+
"109",
|
|
59
|
+
"110",
|
|
60
|
+
"111",
|
|
61
|
+
"113",
|
|
62
|
+
"115",
|
|
63
|
+
"117",
|
|
64
|
+
"119",
|
|
65
|
+
"123",
|
|
66
|
+
"135",
|
|
67
|
+
"137",
|
|
68
|
+
"139",
|
|
69
|
+
"143",
|
|
70
|
+
"161",
|
|
71
|
+
"179",
|
|
72
|
+
"389",
|
|
73
|
+
"427",
|
|
74
|
+
"465",
|
|
75
|
+
"512",
|
|
76
|
+
"513",
|
|
77
|
+
"514",
|
|
78
|
+
"515",
|
|
79
|
+
"526",
|
|
80
|
+
"530",
|
|
81
|
+
"531",
|
|
82
|
+
"532",
|
|
83
|
+
"540",
|
|
84
|
+
"548",
|
|
85
|
+
"554",
|
|
86
|
+
"556",
|
|
87
|
+
"563",
|
|
88
|
+
"587",
|
|
89
|
+
"601",
|
|
90
|
+
"636",
|
|
91
|
+
"989",
|
|
92
|
+
"990",
|
|
93
|
+
"993",
|
|
94
|
+
"995",
|
|
95
|
+
"1719",
|
|
96
|
+
"1720",
|
|
97
|
+
"1723",
|
|
98
|
+
"2049",
|
|
99
|
+
"3659",
|
|
100
|
+
"4045",
|
|
101
|
+
"4190",
|
|
102
|
+
"5060",
|
|
103
|
+
"5061",
|
|
104
|
+
"6000",
|
|
105
|
+
"6566",
|
|
106
|
+
"6665",
|
|
107
|
+
"6666",
|
|
108
|
+
"6667",
|
|
109
|
+
"6668",
|
|
110
|
+
"6669",
|
|
111
|
+
"6679",
|
|
112
|
+
"6697",
|
|
113
|
+
"10080",
|
|
114
|
+
]);
|
|
115
|
+
|
|
116
|
+
interface RawResponse {
|
|
117
|
+
status: number;
|
|
118
|
+
statusText: string;
|
|
119
|
+
headers: string[];
|
|
120
|
+
/** null when the response has no body to expose: a null-body status or
|
|
121
|
+
* HEAD (its bytes, if any, are read and dropped), or a redirect fetch
|
|
122
|
+
* follows or rejects (the request is aborted, closing its connection). */
|
|
123
|
+
body: ReadableStream<Uint8Array> | null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const redirectStatuses = [301, 302, 303, 307, 308];
|
|
127
|
+
const nullBodyStatuses = [101, 204, 205, 304];
|
|
128
|
+
|
|
129
|
+
export function undiciFetch(
|
|
130
|
+
input: string | URL,
|
|
131
|
+
init: UndiciRequestInit | undefined,
|
|
132
|
+
createGlobal: () => Dispatcher,
|
|
133
|
+
profile: Profile,
|
|
134
|
+
): Promise<Response> {
|
|
135
|
+
const explicit = init !== undefined ? init.dispatcher : undefined;
|
|
136
|
+
if (explicit === undefined && !hasCustomGlobalDispatcher()) {
|
|
137
|
+
if (init === undefined) return fetch(input);
|
|
138
|
+
return fetch(input, {
|
|
139
|
+
method: init.method,
|
|
140
|
+
headers: init.headers,
|
|
141
|
+
body: init.body,
|
|
142
|
+
signal: init.signal ?? undefined,
|
|
143
|
+
redirect: init.redirect,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
const dispatcher = explicit ?? getGlobalDispatcher(createGlobal);
|
|
147
|
+
return fetchThrough(dispatcher, input, init ?? {}, profile);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function normalizeMethod(method: string): string {
|
|
151
|
+
const upper = method.toUpperCase();
|
|
152
|
+
return ["DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH"].includes(upper)
|
|
153
|
+
? upper
|
|
154
|
+
: method;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function fetchThrough(
|
|
158
|
+
dispatcher: Dispatcher,
|
|
159
|
+
input: string | URL,
|
|
160
|
+
init: UndiciRequestInit,
|
|
161
|
+
profile: Profile,
|
|
162
|
+
): Promise<Response> {
|
|
163
|
+
let url = typeof input === "string" ? new URL(input) : new URL(input.href);
|
|
164
|
+
let method = normalizeMethod(init.method ?? "GET");
|
|
165
|
+
const signal = init.signal ?? null;
|
|
166
|
+
const redirectMode = init.redirect ?? "follow";
|
|
167
|
+
|
|
168
|
+
// Request headers: the caller's (as a Headers list: lower-cased, sorted,
|
|
169
|
+
// combined), then undici fetch's defaults.
|
|
170
|
+
const headers = headerListOf(init.headers);
|
|
171
|
+
let body: Buffer | null = null;
|
|
172
|
+
const rawBody = init.body ?? null;
|
|
173
|
+
if (rawBody !== null) {
|
|
174
|
+
if (typeof rawBody === "string") {
|
|
175
|
+
body = Buffer.from(rawBody);
|
|
176
|
+
if (!headers.has("content-type")) headers.set("content-type", "text/plain;charset=UTF-8");
|
|
177
|
+
} else {
|
|
178
|
+
body = Buffer.from(rawBody.buffer, rawBody.byteOffset, rawBody.byteLength);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (!headers.has("accept")) headers.set("accept", "*/*");
|
|
182
|
+
if (!headers.has("accept-language")) headers.set("accept-language", "*");
|
|
183
|
+
|
|
184
|
+
for (let redirects = 0; ; redirects++) {
|
|
185
|
+
if (signal !== null && signal.aborted) throw abortReason(signal);
|
|
186
|
+
if (badPorts.has(url.port)) {
|
|
187
|
+
throw new TypeError("fetch failed", { cause: new Error("bad port") });
|
|
188
|
+
}
|
|
189
|
+
const requestHeaders = new HeaderList(headers);
|
|
190
|
+
if (body !== null) {
|
|
191
|
+
if (!requestHeaders.has("content-length"))
|
|
192
|
+
requestHeaders.set("content-length", String(body.length));
|
|
193
|
+
} else if ((method === "POST" || method === "PUT") && !requestHeaders.has("content-length")) {
|
|
194
|
+
requestHeaders.set("content-length", "0");
|
|
195
|
+
}
|
|
196
|
+
requestHeaders.set("sec-fetch-mode", "cors");
|
|
197
|
+
if (!requestHeaders.has("user-agent")) requestHeaders.set("user-agent", "undici");
|
|
198
|
+
// undici also offers br over https; the native runtime has no Brotli
|
|
199
|
+
// decoder, so only the codings it can decode are offered.
|
|
200
|
+
if (!requestHeaders.has("accept-encoding"))
|
|
201
|
+
requestHeaders.set("accept-encoding", "gzip, deflate");
|
|
202
|
+
const pairs = requestHeaders.pairs();
|
|
203
|
+
|
|
204
|
+
let raw: RawResponse;
|
|
205
|
+
try {
|
|
206
|
+
raw = await dispatchOnce(dispatcher, url, method, pairs, body, signal, redirectMode, profile);
|
|
207
|
+
} catch (err) {
|
|
208
|
+
if (signal !== null && signal.aborted) throw abortReason(signal);
|
|
209
|
+
throw new TypeError("fetch failed", { cause: err });
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const responseHeaders = new Headers();
|
|
213
|
+
for (let i = 0; i + 1 < raw.headers.length; i += 2) {
|
|
214
|
+
responseHeaders.append(raw.headers[i]!, raw.headers[i + 1]!);
|
|
215
|
+
}
|
|
216
|
+
const location = responseHeaders.get("location");
|
|
217
|
+
if (redirectStatuses.includes(raw.status) && location !== null && redirectMode !== "manual") {
|
|
218
|
+
if (redirectMode === "error") {
|
|
219
|
+
throw new TypeError("fetch failed", { cause: new Error("unexpected redirect") });
|
|
220
|
+
}
|
|
221
|
+
if (redirects >= 20) {
|
|
222
|
+
throw new TypeError("fetch failed", { cause: new Error("redirect count exceeded") });
|
|
223
|
+
}
|
|
224
|
+
const next = new URL(location, url);
|
|
225
|
+
if (
|
|
226
|
+
raw.status === 303 && method !== "GET" && method !== "HEAD"
|
|
227
|
+
? true
|
|
228
|
+
: (raw.status === 301 || raw.status === 302) && method === "POST"
|
|
229
|
+
) {
|
|
230
|
+
method = "GET";
|
|
231
|
+
body = null;
|
|
232
|
+
for (const name of [
|
|
233
|
+
"content-encoding",
|
|
234
|
+
"content-language",
|
|
235
|
+
"content-location",
|
|
236
|
+
"content-type",
|
|
237
|
+
"content-length",
|
|
238
|
+
]) {
|
|
239
|
+
headers.delete(name);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (next.origin !== url.origin) {
|
|
243
|
+
headers.delete("authorization");
|
|
244
|
+
headers.delete("proxy-authorization");
|
|
245
|
+
headers.delete("cookie");
|
|
246
|
+
headers.delete("host");
|
|
247
|
+
}
|
|
248
|
+
url = next;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return new Response(raw.body, {
|
|
253
|
+
status: raw.status,
|
|
254
|
+
statusText: raw.statusText,
|
|
255
|
+
headers: responseHeaders,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** A Fetch header list: lower-cased names, values combined with ", " in
|
|
261
|
+
* insertion order, serialized sorted by name (set-cookie values stay
|
|
262
|
+
* separate) — what a Headers object yields when iterated. */
|
|
263
|
+
class HeaderList {
|
|
264
|
+
names: string[];
|
|
265
|
+
values: Map<string, string[]>;
|
|
266
|
+
|
|
267
|
+
constructor(from: HeaderList | null) {
|
|
268
|
+
this.names = from !== null ? from.names.slice() : [];
|
|
269
|
+
this.values = new Map<string, string[]>();
|
|
270
|
+
if (from !== null)
|
|
271
|
+
for (const name of from.names) this.values.set(name, from.values.get(name)!.slice());
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
has(name: string): boolean {
|
|
275
|
+
return this.values.has(name.toLowerCase());
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
append(name: string, value: string): void {
|
|
279
|
+
const key = name.toLowerCase();
|
|
280
|
+
const normalized = value.replace(/^[\t\n\r ]+|[\t\n\r ]+$/g, "");
|
|
281
|
+
const existing = this.values.get(key);
|
|
282
|
+
if (existing !== undefined) existing.push(normalized);
|
|
283
|
+
else {
|
|
284
|
+
this.names.push(key);
|
|
285
|
+
this.values.set(key, [normalized]);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
set(name: string, value: string): void {
|
|
290
|
+
this.delete(name);
|
|
291
|
+
this.append(name, value);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
delete(name: string): void {
|
|
295
|
+
const key = name.toLowerCase();
|
|
296
|
+
if (!this.values.has(key)) return;
|
|
297
|
+
this.values.delete(key);
|
|
298
|
+
this.names = this.names.filter((n) => n !== key);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
pairs(): string[] {
|
|
302
|
+
const out: string[] = [];
|
|
303
|
+
for (const name of this.names.slice().sort()) {
|
|
304
|
+
const list = this.values.get(name)!;
|
|
305
|
+
if (name === "set-cookie") for (const value of list) out.push(name, value);
|
|
306
|
+
else out.push(name, list.join(", "));
|
|
307
|
+
}
|
|
308
|
+
return out;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** The caller's headers init as a header list. Records and pair arrays read
|
|
313
|
+
* directly; a Headers object is read through forEach. */
|
|
314
|
+
function headerListOf(
|
|
315
|
+
init: Headers | [string, string][] | Record<string, string> | undefined,
|
|
316
|
+
): HeaderList {
|
|
317
|
+
const list = new HeaderList(null);
|
|
318
|
+
if (init === undefined) return list;
|
|
319
|
+
if (init instanceof Headers) {
|
|
320
|
+
init.forEach((value: string, name: string) => list.append(name, value));
|
|
321
|
+
} else if (Array.isArray(init)) {
|
|
322
|
+
for (const pair of init) list.append(pair[0], pair[1]);
|
|
323
|
+
} else {
|
|
324
|
+
for (const name of Object.keys(init)) list.append(name, init[name]!);
|
|
325
|
+
}
|
|
326
|
+
return list;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** undici 7's limit on a response's content codings, applied in both
|
|
330
|
+
* profiles: undici 5 has none, and builds one decoder per listed coding. */
|
|
331
|
+
const maxContentEncodings = 5;
|
|
332
|
+
|
|
333
|
+
/** Whether every coding has a decoder; otherwise the body passes through
|
|
334
|
+
* as sent. */
|
|
335
|
+
function decodable(codings: string[]): boolean {
|
|
336
|
+
if (codings.length === 0) return false;
|
|
337
|
+
for (const coding of codings) {
|
|
338
|
+
if (coding !== "gzip" && coding !== "x-gzip" && coding !== "deflate") return false;
|
|
339
|
+
}
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** A decoder for one coding. undici 7 decodes with Z_SYNC_FLUSH, which
|
|
344
|
+
* accepts a truncated stream; undici 5 uses zlib's defaults. */
|
|
345
|
+
function decoderFor(coding: string, profile: Profile): Transform {
|
|
346
|
+
const options =
|
|
347
|
+
profile.major >= 7
|
|
348
|
+
? { flush: zlib.constants.Z_SYNC_FLUSH, finishFlush: zlib.constants.Z_SYNC_FLUSH }
|
|
349
|
+
: {};
|
|
350
|
+
return coding === "deflate" ? zlib.createInflate(options) : zlib.createGunzip(options);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function abortReason(signal: AbortSignal): Error {
|
|
354
|
+
const reason: unknown = signal.reason;
|
|
355
|
+
return reason instanceof Error
|
|
356
|
+
? reason
|
|
357
|
+
: new DOMException("This operation was aborted", "AbortError");
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** Unread bytes held beside the response stream before the connection
|
|
361
|
+
* pauses: Node's Readable highWaterMark, which undici's fetch body uses. */
|
|
362
|
+
const bodyHighWaterMark = 64 * 1024;
|
|
363
|
+
|
|
364
|
+
/** Dispatches one request and resolves when its response headers arrive.
|
|
365
|
+
* The body streams as undici's fetch reads one: up to bodyHighWaterMark
|
|
366
|
+
* unread bytes wait beside the stream, past that the connection (or the
|
|
367
|
+
* last decoder) pauses until the reader pulls again; cancelling the stream
|
|
368
|
+
* aborts the request, and an error after the headers errors the stream
|
|
369
|
+
* with TypeError('terminated'). */
|
|
370
|
+
function dispatchOnce(
|
|
371
|
+
dispatcher: Dispatcher,
|
|
372
|
+
url: URL,
|
|
373
|
+
method: string,
|
|
374
|
+
headers: string[],
|
|
375
|
+
body: Buffer | null,
|
|
376
|
+
signal: AbortSignal | null,
|
|
377
|
+
redirectMode: "follow" | "manual" | "error",
|
|
378
|
+
profile: Profile,
|
|
379
|
+
): Promise<RawResponse> {
|
|
380
|
+
return new Promise<RawResponse>((resolve, reject) => {
|
|
381
|
+
let resolved = false;
|
|
382
|
+
let done = false;
|
|
383
|
+
let dump = false;
|
|
384
|
+
let abortFn: ((err?: Error) => void) | null = null;
|
|
385
|
+
|
|
386
|
+
// The response body: its stream controller, the unread bytes beside it,
|
|
387
|
+
// and how to restart the paused producer.
|
|
388
|
+
let controller: ReadableStreamDefaultController<Uint8Array> | null = null;
|
|
389
|
+
let hasBody = false;
|
|
390
|
+
const queue: Buffer[] = [];
|
|
391
|
+
let queued = 0;
|
|
392
|
+
let ended = false;
|
|
393
|
+
let closed = false;
|
|
394
|
+
let onDrain: (() => void) | null = null;
|
|
395
|
+
// The decoders, first-applied last; their listeners hold this scope, so
|
|
396
|
+
// releaseDecoders drops them once the body ends, fails or is cancelled.
|
|
397
|
+
let decoding = false;
|
|
398
|
+
let decoders: Transform[] = [];
|
|
399
|
+
let first: Transform | null = null;
|
|
400
|
+
let encodedBytes = 0;
|
|
401
|
+
let resumeConnection: (() => void) | null = null;
|
|
402
|
+
|
|
403
|
+
const abortRequest = (err: Error): void => {
|
|
404
|
+
const abort = abortFn;
|
|
405
|
+
if (abort !== null && !done) abort(err);
|
|
406
|
+
};
|
|
407
|
+
const onAbort = (): void => {
|
|
408
|
+
if (signal === null) return;
|
|
409
|
+
const reason = abortReason(signal);
|
|
410
|
+
// After the headers undici 7 errors the body with the signal's
|
|
411
|
+
// reason; undici 5 aborts its fetch controller without one, so the
|
|
412
|
+
// body gets the controller's default AbortError.
|
|
413
|
+
errorBody(
|
|
414
|
+
profile.major >= 7 ? reason : new DOMException("The operation was aborted.", "AbortError"),
|
|
415
|
+
);
|
|
416
|
+
abortRequest(reason);
|
|
417
|
+
};
|
|
418
|
+
const stopListening = (): void => {
|
|
419
|
+
if (signal !== null) signal.removeEventListener("abort", onAbort);
|
|
420
|
+
};
|
|
421
|
+
if (signal !== null) signal.addEventListener("abort", onAbort);
|
|
422
|
+
|
|
423
|
+
const releaseDecoders = (): void => {
|
|
424
|
+
const chain = decoders;
|
|
425
|
+
decoders = [];
|
|
426
|
+
first = null;
|
|
427
|
+
for (const decoder of chain) {
|
|
428
|
+
decoder.removeAllListeners();
|
|
429
|
+
decoder.destroy();
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
const closeBody = (): void => {
|
|
433
|
+
closed = true;
|
|
434
|
+
controller!.close();
|
|
435
|
+
stopListening();
|
|
436
|
+
};
|
|
437
|
+
const errorBody = (err: unknown): void => {
|
|
438
|
+
if (!hasBody || closed) return;
|
|
439
|
+
closed = true;
|
|
440
|
+
queue.length = 0;
|
|
441
|
+
queued = 0;
|
|
442
|
+
controller!.error(err);
|
|
443
|
+
stopListening();
|
|
444
|
+
releaseDecoders();
|
|
445
|
+
};
|
|
446
|
+
const endBody = (): void => {
|
|
447
|
+
if (closed) return;
|
|
448
|
+
ended = true;
|
|
449
|
+
if (queue.length === 0) closeBody();
|
|
450
|
+
};
|
|
451
|
+
/** Takes a chunk; false when the producer should pause until onDrain. */
|
|
452
|
+
const pushBody = (chunk: Buffer): boolean => {
|
|
453
|
+
if (closed) return true;
|
|
454
|
+
if (queue.length === 0 && (controller!.desiredSize ?? 0) > 0) {
|
|
455
|
+
controller!.enqueue(new Uint8Array(chunk));
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
queue.push(chunk);
|
|
459
|
+
queued += chunk.length;
|
|
460
|
+
return queued < bodyHighWaterMark;
|
|
461
|
+
};
|
|
462
|
+
const pullBody = (): void => {
|
|
463
|
+
if (closed) return;
|
|
464
|
+
const next = queue.shift();
|
|
465
|
+
if (next !== undefined) {
|
|
466
|
+
queued -= next.length;
|
|
467
|
+
controller!.enqueue(new Uint8Array(next));
|
|
468
|
+
}
|
|
469
|
+
if (queue.length === 0 && ended) {
|
|
470
|
+
closeBody();
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const drain = onDrain;
|
|
474
|
+
if (drain !== null && queued < bodyHighWaterMark) {
|
|
475
|
+
onDrain = null;
|
|
476
|
+
drain();
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
const cancelBody = (reason: unknown): void => {
|
|
480
|
+
if (closed) return;
|
|
481
|
+
closed = true;
|
|
482
|
+
queue.length = 0;
|
|
483
|
+
queued = 0;
|
|
484
|
+
stopListening();
|
|
485
|
+
releaseDecoders();
|
|
486
|
+
abortRequest(
|
|
487
|
+
reason instanceof Error
|
|
488
|
+
? reason
|
|
489
|
+
: new DOMException("The operation was aborted.", "AbortError"),
|
|
490
|
+
);
|
|
491
|
+
};
|
|
492
|
+
const failBody = (err: Error): void => {
|
|
493
|
+
errorBody(new TypeError("terminated", { cause: err }));
|
|
494
|
+
abortRequest(err);
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
const handler: DispatchHandlers = {
|
|
498
|
+
onConnect: (abort: (err?: Error) => void): void => {
|
|
499
|
+
abortFn = abort;
|
|
500
|
+
if (signal !== null && signal.aborted) abort(abortReason(signal));
|
|
501
|
+
},
|
|
502
|
+
onHeaders: (statusCode: number, raw: Buffer[], resume: () => void, text: string): boolean => {
|
|
503
|
+
if (statusCode < 200) return true;
|
|
504
|
+
resolved = true;
|
|
505
|
+
resumeConnection = resume;
|
|
506
|
+
const rawHeaders: string[] = [];
|
|
507
|
+
let location = false;
|
|
508
|
+
let encoding: string | null = null;
|
|
509
|
+
for (let i = 0; i + 1 < raw.length; i += 2) {
|
|
510
|
+
const name = raw[i]!.toString("latin1");
|
|
511
|
+
const value = raw[i + 1]!.toString("latin1");
|
|
512
|
+
rawHeaders.push(name, value);
|
|
513
|
+
const lower = name.toLowerCase();
|
|
514
|
+
if (lower === "location") location = true;
|
|
515
|
+
else if (lower === "content-encoding")
|
|
516
|
+
encoding = encoding === null ? value : `${encoding}, ${value}`;
|
|
517
|
+
}
|
|
518
|
+
const follows =
|
|
519
|
+
redirectStatuses.includes(statusCode) && location && redirectMode !== "manual";
|
|
520
|
+
if (follows || nullBodyStatuses.includes(statusCode) || method === "HEAD") {
|
|
521
|
+
dump = true;
|
|
522
|
+
stopListening();
|
|
523
|
+
resolve({ status: statusCode, statusText: text, headers: rawHeaders, body: null });
|
|
524
|
+
// A redirect that is followed or rejected never reads its body:
|
|
525
|
+
// abort the request so the connection is released instead of
|
|
526
|
+
// draining a body that may never end.
|
|
527
|
+
if (follows) abortRequest(new DOMException("The operation was aborted.", "AbortError"));
|
|
528
|
+
return true;
|
|
529
|
+
}
|
|
530
|
+
const codings =
|
|
531
|
+
encoding === null
|
|
532
|
+
? []
|
|
533
|
+
: encoding
|
|
534
|
+
.toLowerCase()
|
|
535
|
+
.split(",")
|
|
536
|
+
.map((c) => c.trim());
|
|
537
|
+
if (codings.length > maxContentEncodings) {
|
|
538
|
+
dump = true;
|
|
539
|
+
stopListening();
|
|
540
|
+
reject(
|
|
541
|
+
new Error(
|
|
542
|
+
`too many content-encodings in response: ${codings.length}, maximum allowed is ${maxContentEncodings}`,
|
|
543
|
+
),
|
|
544
|
+
);
|
|
545
|
+
abortRequest(new DOMException("The operation was aborted.", "AbortError"));
|
|
546
|
+
return true;
|
|
547
|
+
}
|
|
548
|
+
hasBody = true;
|
|
549
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
550
|
+
start: (c: ReadableStreamDefaultController<Uint8Array>): void => {
|
|
551
|
+
controller = c;
|
|
552
|
+
},
|
|
553
|
+
pull: (): void => pullBody(),
|
|
554
|
+
cancel: (reason: unknown): void => cancelBody(reason),
|
|
555
|
+
});
|
|
556
|
+
if (decodable(codings)) {
|
|
557
|
+
// Decoders run last-applied coding first, piped into each other;
|
|
558
|
+
// the last one feeds the body.
|
|
559
|
+
decoding = true;
|
|
560
|
+
let last: Transform | null = null;
|
|
561
|
+
for (let i = codings.length - 1; i >= 0; i--) {
|
|
562
|
+
const decoder = decoderFor(codings[i]!, profile);
|
|
563
|
+
decoder.on("error", (err: Error) => failBody(err));
|
|
564
|
+
if (last === null) first = decoder;
|
|
565
|
+
else last.pipe(decoder);
|
|
566
|
+
decoders.push(decoder);
|
|
567
|
+
last = decoder;
|
|
568
|
+
}
|
|
569
|
+
const output = last!;
|
|
570
|
+
output.on("data", (chunk: Buffer) => {
|
|
571
|
+
if (!pushBody(chunk)) {
|
|
572
|
+
output.pause();
|
|
573
|
+
onDrain = (): void => {
|
|
574
|
+
output.resume();
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
output.on("end", () => {
|
|
579
|
+
releaseDecoders();
|
|
580
|
+
endBody();
|
|
581
|
+
});
|
|
582
|
+
first!.on("drain", () => resume());
|
|
583
|
+
}
|
|
584
|
+
resolve({ status: statusCode, statusText: text, headers: rawHeaders, body: stream });
|
|
585
|
+
return true;
|
|
586
|
+
},
|
|
587
|
+
onData: (chunk: Buffer): boolean => {
|
|
588
|
+
if (dump || !hasBody || closed) return true;
|
|
589
|
+
if (decoding) {
|
|
590
|
+
const decoder = first;
|
|
591
|
+
if (decoder === null) return true;
|
|
592
|
+
encodedBytes += chunk.length;
|
|
593
|
+
return decoder.write(chunk);
|
|
594
|
+
}
|
|
595
|
+
if (pushBody(chunk)) return true;
|
|
596
|
+
onDrain = resumeConnection;
|
|
597
|
+
return false;
|
|
598
|
+
},
|
|
599
|
+
onComplete: (_trailers: string[] | null): void => {
|
|
600
|
+
done = true;
|
|
601
|
+
if (!hasBody) {
|
|
602
|
+
stopListening();
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
// zlib rejects an empty stream; undici ends such a body unread.
|
|
606
|
+
const decoder = first;
|
|
607
|
+
if (decoder !== null && encodedBytes > 0) {
|
|
608
|
+
decoder.end();
|
|
609
|
+
} else {
|
|
610
|
+
releaseDecoders();
|
|
611
|
+
endBody();
|
|
612
|
+
}
|
|
613
|
+
},
|
|
614
|
+
onError: (err: Error): void => {
|
|
615
|
+
done = true;
|
|
616
|
+
if (!resolved) {
|
|
617
|
+
stopListening();
|
|
618
|
+
reject(err);
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
errorBody(new TypeError("terminated", { cause: err }));
|
|
622
|
+
},
|
|
623
|
+
};
|
|
624
|
+
dispatcher.dispatch(
|
|
625
|
+
{
|
|
626
|
+
origin: url.origin,
|
|
627
|
+
path: url.pathname + url.search,
|
|
628
|
+
method,
|
|
629
|
+
headers,
|
|
630
|
+
body,
|
|
631
|
+
},
|
|
632
|
+
handler,
|
|
633
|
+
);
|
|
634
|
+
});
|
|
635
|
+
}
|