@depup/webpack 5.106.0-depup.0 → 5.109.0-depup.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/README.md +9 -11
- package/changes.json +16 -24
- package/hot/dev-server.js +2 -0
- package/lib/APIPlugin.js +60 -35
- package/lib/AsyncDependenciesBlock.js +3 -0
- package/lib/AutomaticPrefetchPlugin.js +6 -1
- package/lib/BannerPlugin.js +13 -5
- package/lib/Cache.js +27 -5
- package/lib/CacheFacade.js +41 -0
- package/lib/Chunk.js +71 -25
- package/lib/ChunkGraph.js +141 -9
- package/lib/ChunkGroup.js +115 -28
- package/lib/ChunkTemplate.js +9 -0
- package/lib/CircularModulesPlugin.js +190 -0
- package/lib/CleanPlugin.js +23 -26
- package/lib/CodeGenerationResults.js +19 -0
- package/lib/CompatibilityPlugin.js +54 -37
- package/lib/Compilation.js +635 -107
- package/lib/Compiler.js +93 -31
- package/lib/ConcatenationScope.js +34 -4
- package/lib/ConditionalInitFragment.js +6 -0
- package/lib/ConstPlugin.js +15 -12
- package/lib/ContextExclusionPlugin.js +3 -1
- package/lib/ContextModule.js +345 -55
- package/lib/ContextModuleFactory.js +193 -51
- package/lib/ContextReplacementPlugin.js +8 -1
- package/lib/DefinePlugin.js +498 -127
- package/lib/DependenciesBlock.js +6 -1
- package/lib/Dependency.js +159 -11
- package/lib/DependencyTemplate.js +7 -1
- package/lib/DependencyTemplates.js +4 -0
- package/lib/DotenvPlugin.js +3 -0
- package/lib/DynamicEntryPlugin.js +3 -1
- package/lib/EntryOptionPlugin.js +42 -2
- package/lib/EntryPlugin.js +4 -1
- package/lib/Entrypoint.js +5 -1
- package/lib/EnvironmentPlugin.js +3 -2
- package/lib/ErrorHelpers.js +7 -0
- package/lib/EvalDevToolModulePlugin.js +3 -1
- package/lib/EvalSourceMapDevToolPlugin.js +11 -11
- package/lib/ExportsInfo.js +399 -108
- package/lib/ExportsInfoApiPlugin.js +4 -3
- package/lib/ExternalModule.js +376 -78
- package/lib/ExternalModuleFactoryPlugin.js +75 -3
- package/lib/ExternalsPlugin.js +3 -1
- package/lib/FileSystemInfo.js +575 -149
- package/lib/FlagAllModulesAsUsedPlugin.js +3 -6
- package/lib/FlagDependencyExportsPlugin.js +82 -9
- package/lib/FlagDependencyUsagePlugin.js +92 -6
- package/lib/FlagEntryExportAsUsedPlugin.js +4 -1
- package/lib/Generator.js +24 -3
- package/lib/HotModuleReplacementPlugin.js +110 -44
- package/lib/IgnorePlugin.js +5 -2
- package/lib/IgnoreWarningsPlugin.js +2 -1
- package/lib/InitFragment.js +15 -0
- package/lib/JavascriptMetaInfoPlugin.js +9 -6
- package/lib/LazyBarrel.js +389 -0
- package/lib/LibraryTemplatePlugin.js +2 -1
- package/lib/LoaderOptionsPlugin.js +3 -1
- package/lib/LoaderTargetPlugin.js +3 -1
- package/lib/MainTemplate.js +15 -0
- package/lib/ManifestPlugin.js +9 -2
- package/lib/Module.js +121 -60
- package/lib/ModuleFactory.js +6 -1
- package/lib/ModuleFilenameHelpers.js +5 -2
- package/lib/ModuleGraph.js +69 -2
- package/lib/ModuleGraphConnection.js +9 -0
- package/lib/ModuleInfoHeaderPlugin.js +5 -0
- package/lib/ModuleNotFoundError.js +3 -83
- package/lib/ModuleProfile.js +27 -1
- package/lib/ModuleSourceTypeConstants.js +52 -19
- package/lib/ModuleTemplate.js +10 -0
- package/lib/ModuleTypeConstants.js +20 -4
- package/lib/MultiCompiler.js +59 -4
- package/lib/MultiStats.js +9 -0
- package/lib/MultiWatching.js +6 -0
- package/lib/NoEmitOnErrorsPlugin.js +1 -1
- package/lib/NodeStuffPlugin.js +78 -46
- package/lib/NormalModule.js +485 -181
- package/lib/NormalModuleFactory.js +148 -29
- package/lib/NormalModuleReplacementPlugin.js +3 -1
- package/lib/NullFactory.js +1 -0
- package/lib/OptionsApply.js +1 -0
- package/lib/Parser.js +3 -1
- package/lib/PlatformPlugin.js +2 -1
- package/lib/PrefetchPlugin.js +4 -1
- package/lib/ProgressPlugin.js +351 -161
- package/lib/ProvidePlugin.js +6 -3
- package/lib/RawModule.js +32 -16
- package/lib/RecordIdsPlugin.js +9 -0
- package/lib/RequestShortener.js +8 -0
- package/lib/ResolverFactory.js +5 -0
- package/lib/RuntimeGlobals.js +58 -5
- package/lib/RuntimeModule.js +22 -7
- package/lib/RuntimePlugin.js +104 -26
- package/lib/RuntimeTemplate.js +616 -37
- package/lib/SelfModuleFactory.js +3 -0
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -0
- package/lib/SourceMapDevToolPlugin.js +341 -63
- package/lib/Stats.js +6 -0
- package/lib/Template.js +29 -3
- package/lib/TemplatedPathPlugin.js +505 -138
- package/lib/UseStrictPlugin.js +3 -2
- package/lib/WarnCaseSensitiveModulesPlugin.js +72 -3
- package/lib/WarnDeprecatedOptionPlugin.js +6 -2
- package/lib/WarnNoModeSetPlugin.js +18 -2
- package/lib/WatchIgnorePlugin.js +5 -1
- package/lib/Watching.js +25 -3
- package/lib/WebpackError.js +3 -74
- package/lib/WebpackIsIncludedPlugin.js +4 -2
- package/lib/WebpackOptionsApply.js +88 -25
- package/lib/WebpackOptionsDefaulter.js +1 -0
- package/lib/asset/AssetBytesGenerator.js +28 -10
- package/lib/asset/AssetBytesParser.js +1 -0
- package/lib/asset/AssetGenerator.js +199 -60
- package/lib/asset/AssetModule.js +47 -0
- package/lib/asset/AssetModulesPlugin.js +115 -24
- package/lib/asset/AssetParser.js +4 -2
- package/lib/asset/AssetSourceGenerator.js +26 -8
- package/lib/asset/AssetSourceParser.js +1 -0
- package/lib/asset/RawDataUrlModule.js +23 -13
- package/lib/asset/WebManifestGenerator.js +164 -0
- package/lib/asset/WebManifestParser.js +130 -0
- package/lib/async-modules/AsyncModuleHelpers.js +1 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +18 -4
- package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
- package/lib/async-modules/isGeneratorLowered.js +26 -0
- package/lib/buildChunkGraph.js +107 -15
- package/lib/bun/BunTargetPlugin.js +42 -0
- package/lib/cache/AddBuildDependenciesPlugin.js +3 -1
- package/lib/cache/AddManagedPathsPlugin.js +5 -1
- package/lib/cache/IdleFileCachePlugin.js +6 -1
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +4 -1
- package/lib/cache/PackFileCacheStrategy.js +43 -7
- package/lib/cache/ResolverCachePlugin.js +12 -1
- package/lib/cache/getLazyHashedEtag.js +13 -2
- package/lib/cache/mergeEtags.js +4 -0
- package/lib/cli.js +142 -20
- package/lib/config/browserslistTargetHandler.js +141 -0
- package/lib/config/defaults.js +591 -41
- package/lib/config/defineConfig.js +31 -0
- package/lib/config/normalization.js +46 -1
- package/lib/config/target.js +200 -2
- package/lib/container/ContainerEntryDependency.js +2 -0
- package/lib/container/ContainerEntryModule.js +27 -14
- package/lib/container/ContainerEntryModuleFactory.js +1 -0
- package/lib/container/ContainerExposedDependency.js +6 -2
- package/lib/container/ContainerPlugin.js +2 -1
- package/lib/container/ContainerReferencePlugin.js +3 -2
- package/lib/container/FallbackDependency.js +9 -7
- package/lib/container/FallbackItemDependency.js +1 -0
- package/lib/container/FallbackModule.js +22 -9
- package/lib/container/FallbackModuleFactory.js +1 -0
- package/lib/container/ModuleFederationPlugin.js +12 -26
- package/lib/container/RemoteModule.js +33 -10
- package/lib/container/RemoteRuntimeModule.js +15 -12
- package/lib/container/RemoteToExternalDependency.js +1 -0
- package/lib/container/options.js +7 -0
- package/lib/css/CssGenerator.js +534 -272
- package/lib/css/CssInjectStyleRuntimeModule.js +86 -70
- package/lib/css/CssLoadingRuntimeModule.js +156 -77
- package/lib/{CssModule.js → css/CssModule.js} +72 -37
- package/lib/css/CssModulesPlugin.js +356 -204
- package/lib/css/CssParser.js +3452 -1950
- package/lib/css/syntax.js +4058 -0
- package/lib/debug/ProfilingPlugin.js +33 -2
- package/lib/deno/DenoTargetPlugin.js +41 -0
- package/lib/dependencies/AMDDefineDependency.js +29 -17
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +19 -6
- package/lib/dependencies/AMDPlugin.js +6 -3
- package/lib/dependencies/AMDRequireArrayDependency.js +13 -11
- package/lib/dependencies/AMDRequireContextDependency.js +10 -11
- package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -14
- package/lib/dependencies/AMDRequireDependency.js +28 -20
- package/lib/dependencies/AMDRequireItemDependency.js +1 -0
- package/lib/dependencies/AMDRuntimeModules.js +3 -0
- package/lib/dependencies/CachedConstDependency.js +9 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +104 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +138 -38
- package/lib/dependencies/CommonJsExportsDependency.js +74 -20
- package/lib/dependencies/CommonJsExportsParserPlugin.js +246 -15
- package/lib/dependencies/CommonJsFullRequireDependency.js +62 -27
- package/lib/dependencies/CommonJsImportsParserPlugin.js +187 -24
- package/lib/dependencies/CommonJsPlugin.js +7 -4
- package/lib/dependencies/CommonJsRequireContextDependency.js +13 -13
- package/lib/dependencies/CommonJsRequireDependency.js +135 -13
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +60 -16
- package/lib/dependencies/ConstDependency.js +22 -12
- package/lib/dependencies/ContextDependency.js +13 -2
- package/lib/dependencies/ContextDependencyHelpers.js +7 -4
- package/lib/dependencies/ContextDependencyTemplateAsId.js +2 -1
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
- package/lib/dependencies/ContextElementDependency.js +27 -14
- package/lib/dependencies/CreateRequireParserPlugin.js +14 -7
- package/lib/dependencies/CreateScriptUrlDependency.js +9 -7
- package/lib/dependencies/CriticalDependencyWarning.js +3 -1
- package/lib/dependencies/CssIcssExportDependency.js +682 -368
- package/lib/dependencies/CssIcssImportDependency.js +62 -17
- package/lib/dependencies/CssIcssSymbolDependency.js +36 -17
- package/lib/dependencies/CssImportDependency.js +37 -1
- package/lib/dependencies/CssUrlDependency.js +87 -14
- package/lib/dependencies/DelegatedSourceDependency.js +1 -0
- package/lib/dependencies/DllEntryDependency.js +12 -13
- package/lib/dependencies/DynamicExports.js +5 -0
- package/lib/dependencies/EntryDependency.js +1 -0
- package/lib/dependencies/ExportBindingInitFragment.js +164 -0
- package/lib/dependencies/ExportsInfoDependency.js +18 -12
- package/lib/dependencies/ExternalModuleDependency.js +13 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +10 -5
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +19 -12
- package/lib/dependencies/HarmonyAcceptDependency.js +24 -26
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -0
- package/lib/dependencies/HarmonyCompatibilityDependency.js +33 -14
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +108 -30
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +32 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +70 -33
- package/lib/dependencies/HarmonyExportExpressionDependency.js +140 -46
- package/lib/dependencies/HarmonyExportHeaderDependency.js +11 -9
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +253 -37
- package/lib/dependencies/HarmonyExportInitFragment.js +28 -20
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +88 -18
- package/lib/dependencies/HarmonyExports.js +6 -1
- package/lib/dependencies/HarmonyImportDependency.js +59 -3
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +139 -146
- package/lib/dependencies/HarmonyImportGuard.js +426 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +22 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +136 -17
- package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +6 -3
- package/lib/dependencies/HarmonyModulesPlugin.js +11 -1
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +2 -1
- package/lib/dependencies/HtmlEntryDependency.js +1295 -0
- package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
- package/lib/dependencies/HtmlInlineScriptDependency.js +126 -0
- package/lib/dependencies/HtmlInlineStyleDependency.js +152 -0
- package/lib/dependencies/HtmlSourceDependency.js +172 -0
- package/lib/dependencies/ImportContextDependency.js +9 -9
- package/lib/dependencies/ImportDependency.js +92 -3
- package/lib/dependencies/ImportEagerDependency.js +2 -0
- package/lib/dependencies/ImportMetaContextDependency.js +1 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +35 -19
- package/lib/dependencies/ImportMetaContextPlugin.js +40 -8
- package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
- package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
- package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +2 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +2 -0
- package/lib/dependencies/ImportMetaPlugin.js +595 -209
- package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
- package/lib/dependencies/ImportParserPlugin.js +114 -27
- package/lib/dependencies/ImportPhase.js +17 -11
- package/lib/dependencies/ImportPlugin.js +2 -1
- package/lib/dependencies/ImportWeakDependency.js +3 -0
- package/lib/dependencies/JsonExportsDependency.js +15 -10
- package/lib/dependencies/LoaderDependency.js +2 -0
- package/lib/dependencies/LoaderImportDependency.js +3 -0
- package/lib/dependencies/LoaderPlugin.js +9 -2
- package/lib/dependencies/LocalModule.js +15 -12
- package/lib/dependencies/LocalModuleDependency.js +15 -13
- package/lib/dependencies/LocalModulesHelpers.js +3 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +16 -10
- package/lib/dependencies/ModuleDependency.js +14 -0
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +1 -0
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +2 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +2 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +19 -11
- package/lib/dependencies/NullDependency.js +2 -0
- package/lib/dependencies/PrefetchDependency.js +1 -0
- package/lib/dependencies/ProvidedDependency.js +36 -27
- package/lib/dependencies/PureExpressionDependency.js +14 -10
- package/lib/dependencies/RequireContextDependency.js +1 -0
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +2 -1
- package/lib/dependencies/RequireContextPlugin.js +2 -1
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +4 -6
- package/lib/dependencies/RequireEnsureDependency.js +16 -13
- package/lib/dependencies/RequireEnsureItemDependency.js +1 -0
- package/lib/dependencies/RequireEnsurePlugin.js +2 -1
- package/lib/dependencies/RequireHeaderDependency.js +7 -4
- package/lib/dependencies/RequireIncludeDependency.js +2 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +11 -12
- package/lib/dependencies/RequireIncludePlugin.js +2 -1
- package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +9 -8
- package/lib/dependencies/RequireResolveContextDependency.js +10 -11
- package/lib/dependencies/RequireResolveDependency.js +2 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +8 -5
- package/lib/dependencies/RuntimeRequirementsDependency.js +11 -8
- package/lib/dependencies/StaticExportsDependency.js +13 -10
- package/lib/dependencies/SystemPlugin.js +9 -6
- package/lib/dependencies/SystemRuntimeModule.js +1 -0
- package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
- package/lib/dependencies/URLContextDependency.js +8 -7
- package/lib/dependencies/URLDependency.js +157 -33
- package/lib/dependencies/URLPlugin.js +2 -0
- package/lib/dependencies/UnsupportedDependency.js +12 -13
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +15 -16
- package/lib/dependencies/WebAssemblyImportDependency.js +19 -18
- package/lib/dependencies/WebpackIsIncludedDependency.js +3 -0
- package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +364 -114
- package/lib/dependencies/WorkerDependency.js +111 -27
- package/lib/dependencies/WorkletDependency.js +278 -0
- package/lib/dependencies/getFunctionExpression.js +1 -0
- package/lib/dependencies/processExportInfo.js +14 -11
- package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +71 -44
- package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +27 -4
- package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +5 -3
- package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +9 -5
- package/lib/{DllModule.js → dll/DllModule.js} +36 -24
- package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +5 -4
- package/lib/{DllPlugin.js → dll/DllPlugin.js} +24 -6
- package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +26 -18
- package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +14 -10
- package/lib/electron/ElectronTargetPlugin.js +24 -5
- package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +10 -1
- package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +8 -3
- package/lib/errors/BuildCycleError.js +1 -1
- package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
- package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
- package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +9 -3
- package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +5 -2
- package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +5 -5
- package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +20 -16
- package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +7 -4
- package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +6 -3
- package/lib/errors/JSONParseError.js +115 -0
- package/lib/errors/LoaderLoadingError.js +20 -0
- package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +22 -16
- package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +10 -3
- package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +13 -5
- package/lib/{ModuleError.js → errors/ModuleError.js} +10 -14
- package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +5 -1
- package/lib/errors/ModuleNotFoundError.js +94 -0
- package/lib/errors/ModuleParseError.js +141 -0
- package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +4 -1
- package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +5 -1
- package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +13 -14
- package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +7 -5
- package/lib/errors/NonErrorEmittedError.js +30 -0
- package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +9 -2
- package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +4 -3
- package/lib/errors/WebpackError.js +84 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +52 -15
- package/lib/esm/ModuleChunkLoadingPlugin.js +11 -3
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +71 -49
- package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +8 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +154 -7
- package/lib/hmr/lazyCompilationBackend.js +34 -8
- package/lib/html/HtmlGenerator.js +1470 -0
- package/lib/html/HtmlModule.js +41 -0
- package/lib/html/HtmlModulesPlugin.js +1111 -0
- package/lib/html/HtmlParser.js +1970 -0
- package/lib/html/favicon.svg +1 -0
- package/lib/html/syntax.js +9020 -0
- package/lib/ids/ChunkModuleIdRangePlugin.js +3 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +3 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +3 -1
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/ids/IdHelpers.js +25 -2
- package/lib/ids/NamedChunkIdsPlugin.js +3 -1
- package/lib/ids/NamedModuleIdsPlugin.js +3 -1
- package/lib/ids/NaturalChunkIdsPlugin.js +1 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -1
- package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -1
- package/lib/ids/SyncModuleIdsPlugin.js +3 -1
- package/lib/index.js +66 -15
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -6
- package/lib/javascript/BasicEvaluatedExpression.js +370 -49
- package/lib/javascript/ChunkFormatHelpers.js +2 -1
- package/lib/javascript/ChunkHelpers.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/EnableChunkLoadingPlugin.js +6 -1
- package/lib/javascript/JavascriptGenerator.js +213 -51
- package/lib/javascript/JavascriptModule.js +54 -0
- package/lib/javascript/JavascriptModulesPlugin.js +579 -183
- package/lib/javascript/JavascriptParser.js +1289 -462
- package/lib/javascript/JavascriptParserHelpers.js +10 -7
- package/lib/javascript/StartupHelpers.js +5 -0
- package/lib/javascript/syntax.js +4380 -0
- package/lib/json/JsonData.js +5 -0
- package/lib/json/JsonGenerator.js +21 -0
- package/lib/json/JsonModule.js +40 -0
- package/lib/json/JsonModulesPlugin.js +8 -1
- package/lib/json/JsonParser.js +18 -27
- package/lib/library/AbstractLibraryPlugin.js +17 -2
- package/lib/library/AmdLibraryPlugin.js +8 -0
- package/lib/library/AssignLibraryPlugin.js +21 -3
- package/lib/library/EnableLibraryPlugin.js +8 -2
- package/lib/library/ExportPropertyLibraryPlugin.js +10 -0
- package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +2 -1
- package/lib/library/JsonpLibraryPlugin.js +8 -0
- package/lib/library/ModuleLibraryPlugin.js +154 -7
- package/lib/library/SystemLibraryPlugin.js +11 -3
- package/lib/library/UmdLibraryPlugin.js +16 -0
- package/lib/loaders/LoaderRunner.js +714 -0
- package/lib/loaders/loadLoader.js +100 -0
- package/lib/logging/Logger.js +17 -0
- package/lib/logging/createConsoleLogger.js +7 -0
- package/lib/logging/runtime.js +2 -0
- package/lib/logging/truncateArgs.js +2 -0
- package/lib/node/CommonJsChunkLoadingPlugin.js +5 -1
- package/lib/node/NodeEnvironmentPlugin.js +7 -3
- package/lib/node/NodeSourcePlugin.js +1 -1
- package/lib/node/NodeTargetPlugin.js +4 -63
- package/lib/node/NodeTemplatePlugin.js +3 -1
- package/lib/node/NodeWatchFileSystem.js +40 -22
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +13 -9
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +23 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +18 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +21 -16
- package/lib/node/nodeBuiltins.js +80 -0
- package/lib/node/nodeConsole.js +116 -64
- package/lib/optimize/AggressiveMergingPlugin.js +3 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +6 -1
- package/lib/optimize/ConcatenatedModule.js +585 -116
- package/lib/optimize/ConstExportsPlugin.js +211 -0
- package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -1
- package/lib/optimize/FlagIncludedChunksPlugin.js +15 -4
- package/lib/optimize/InlineExports.js +178 -0
- package/lib/optimize/InnerGraph.js +374 -262
- package/lib/optimize/InnerGraphPlugin.js +246 -117
- package/lib/optimize/LimitChunkCountPlugin.js +9 -0
- package/lib/optimize/MangleExportsPlugin.js +5 -1
- package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -0
- package/lib/optimize/MinChunkSizePlugin.js +2 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +159 -34
- package/lib/optimize/RealContentHashPlugin.js +125 -50
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
- package/lib/optimize/RemoveParentModulesPlugin.js +3 -1
- package/lib/optimize/RuntimeChunkPlugin.js +2 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +381 -55
- package/lib/optimize/SplitChunksPlugin.js +54 -6
- package/lib/performance/AssetsOverSizeLimitWarning.js +3 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +3 -2
- package/lib/performance/NoAsyncChunksWarning.js +5 -3
- package/lib/performance/SizeLimitsPlugin.js +8 -2
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +1 -0
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +21 -0
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +1 -0
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -1
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +25 -13
- package/lib/prefetch/ResourceHintPlugin.js +663 -0
- package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
- package/lib/prefetch/parseResourceHintOptions.js +103 -0
- package/lib/rules/BasicEffectRulePlugin.js +3 -0
- package/lib/rules/BasicMatcherRulePlugin.js +3 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +3 -0
- package/lib/rules/RuleSetCompiler.js +132 -0
- package/lib/rules/UseEffectRulePlugin.js +10 -3
- package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +52 -33
- package/lib/runtime/AutoPublicPathRuntimeModule.js +22 -9
- package/lib/runtime/BaseUriRuntimeModule.js +1 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
- package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +2 -1
- package/lib/runtime/CompatRuntimeModule.js +2 -0
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +7 -4
- package/lib/runtime/CreateScriptRuntimeModule.js +1 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +1 -0
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +34 -4
- package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +88 -8
- package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -0
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
- package/lib/runtime/GlobalRuntimeModule.js +1 -0
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +2 -1
- package/lib/runtime/HelperRuntimeModule.js +5 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +28 -37
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +354 -37
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +2 -1
- package/lib/runtime/NonceRuntimeModule.js +1 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +5 -4
- package/lib/runtime/PublicPathRuntimeModule.js +1 -0
- package/lib/runtime/RelativeUrlRuntimeModule.js +4 -2
- package/lib/runtime/RuntimeIdRuntimeModule.js +1 -0
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +38 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +13 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +2 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +5 -3
- package/lib/runtime/SystemContextRuntimeModule.js +1 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +1 -0
- package/lib/runtime/WorkerRuntimeModule.js +33 -0
- package/lib/schemes/DataUriPlugin.js +14 -2
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +86 -4
- package/lib/schemes/VirtualUrlPlugin.js +8 -4
- package/lib/serialization/AggregateErrorSerializer.js +9 -6
- package/lib/serialization/ArraySerializer.js +6 -8
- package/lib/serialization/BinaryMiddleware.js +552 -463
- package/lib/serialization/DateObjectSerializer.js +4 -2
- package/lib/serialization/ErrorObjectSerializer.js +10 -6
- package/lib/serialization/FileMiddleware.js +50 -3
- package/lib/serialization/MapObjectSerializer.js +7 -9
- package/lib/serialization/NullPrototypeObjectSerializer.js +9 -9
- package/lib/serialization/ObjectMiddleware.js +73 -13
- package/lib/serialization/PlainObjectSerializer.js +16 -8
- package/lib/serialization/RegExpObjectSerializer.js +4 -2
- package/lib/serialization/Serializer.js +6 -0
- package/lib/serialization/SerializerMiddleware.js +14 -2
- package/lib/serialization/SetObjectSerializer.js +6 -8
- package/lib/serialization/SingleItemMiddleware.js +3 -0
- package/lib/sharing/ConsumeSharedFallbackDependency.js +1 -0
- package/lib/sharing/ConsumeSharedModule.js +21 -7
- package/lib/sharing/ConsumeSharedPlugin.js +11 -11
- package/lib/sharing/ConsumeSharedRuntimeModule.js +55 -45
- package/lib/sharing/ProvideForSharedDependency.js +1 -0
- package/lib/sharing/ProvideSharedDependency.js +34 -15
- package/lib/sharing/ProvideSharedModule.js +42 -12
- package/lib/sharing/ProvideSharedModuleFactory.js +1 -0
- package/lib/sharing/ProvideSharedPlugin.js +13 -8
- package/lib/sharing/SharePlugin.js +5 -1
- package/lib/sharing/ShareRuntimeModule.js +19 -16
- package/lib/sharing/resolveMatchedConfigs.js +6 -2
- package/lib/sharing/utils.js +9 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +94 -12
- package/lib/stats/DefaultStatsPresetPlugin.js +14 -2
- package/lib/stats/DefaultStatsPrinterPlugin.js +64 -18
- package/lib/stats/StatsFactory.js +39 -18
- package/lib/stats/StatsPrinter.js +16 -2
- package/lib/typescript/TypeScriptPlugin.js +210 -0
- package/lib/url/URLParserPlugin.js +111 -23
- package/lib/util/ArrayHelpers.js +1 -0
- package/lib/util/ArrayQueue.js +10 -5
- package/lib/util/AsyncQueue.js +154 -74
- package/lib/util/Hash.js +2 -2
- package/lib/util/IterableHelpers.js +3 -0
- package/lib/util/LazyBucketSortedSet.js +26 -0
- package/lib/util/LazySet.js +45 -4
- package/lib/util/LocConverter.js +64 -0
- package/lib/util/ParallelismFactorCalculator.js +1 -0
- package/lib/util/Queue.js +6 -3
- package/lib/util/Semaphore.js +15 -1
- package/lib/util/SetHelpers.js +4 -1
- package/lib/util/SortableSet.js +7 -1
- package/lib/util/SourceProcessor.js +119 -0
- package/lib/util/StackedCacheMap.js +20 -3
- package/lib/util/StackedMap.js +162 -43
- package/lib/util/StringXor.js +1 -1
- package/lib/util/TupleQueue.js +7 -3
- package/lib/util/TupleSet.js +14 -0
- package/lib/util/URLAbsoluteSpecifier.js +1 -0
- package/lib/util/WeakTupleMap.js +60 -1
- package/lib/util/binarySearchBounds.js +3 -2
- package/lib/util/chainedImports.js +3 -3
- package/lib/util/cleverMerge.js +19 -2
- package/lib/util/comparators.js +35 -4
- package/lib/util/compileBooleanMatcher.js +9 -0
- package/lib/util/concatenate.js +80 -24
- package/lib/util/conventions.js +46 -1
- package/lib/util/createHash.js +0 -1
- package/lib/util/createHooksRegistry.js +43 -0
- package/lib/util/createMappings.js +118 -0
- package/lib/util/dataURL.js +3 -2
- package/lib/util/deprecation.js +19 -0
- package/lib/util/deterministicGrouping.js +46 -17
- package/lib/util/extractSourceMap.js +2 -1
- package/lib/util/extractUrlAndGlobal.js +1 -0
- package/lib/util/findGraphRoots.js +7 -0
- package/lib/{formatLocation.js → util/formatLocation.js} +4 -2
- package/lib/{SizeFormatHelpers.js → util/formatSize.js} +10 -3
- package/lib/util/fs.js +87 -14
- package/lib/util/generateDebugId.js +1 -0
- package/lib/util/globUtils.js +710 -0
- package/lib/util/hash/BatchedHash.js +1 -0
- package/lib/util/hash/BulkUpdateHash.js +1 -0
- package/lib/util/hash/DebugHash.js +1 -0
- package/lib/util/hash/hash-digest.js +32 -15
- package/lib/util/hash/md4.js +1 -1
- package/lib/util/hash/wasm-hash.js +5 -0
- package/lib/util/hash/xxhash64.js +1 -1
- package/lib/util/identifier.js +97 -6
- package/lib/util/implicitTypeLoaderFallback.js +62 -0
- package/lib/util/internalSerializables.js +102 -60
- package/lib/util/magicComment.js +149 -7
- package/lib/util/makeSerializable.js +7 -0
- package/lib/util/memoize.js +2 -0
- package/lib/util/mimeTypes.js +176 -0
- package/lib/util/nonNumericOnlyHash.js +31 -1
- package/lib/util/numberHash.js +2 -2
- package/lib/util/parseJson.js +41 -0
- package/lib/util/processAsyncTree.js +8 -0
- package/lib/util/property.js +9 -2
- package/lib/util/publicPathPlaceholder.js +64 -0
- package/lib/util/registerExternalSerializer.js +24 -4
- package/lib/util/removeBOM.js +1 -0
- package/lib/util/runtime.js +32 -0
- package/lib/util/semver.js +15 -0
- package/lib/util/serialization.js +2 -0
- package/lib/util/smartGrouping.js +8 -0
- package/lib/util/source.js +23 -0
- package/lib/util/topologicalSort.js +69 -0
- package/lib/validateSchema.js +1 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +15 -1
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +25 -18
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +34 -22
- package/lib/wasm-async/AsyncWasmModule.js +77 -0
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +6 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +22 -126
- package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -2
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +13 -2
- package/lib/wasm-sync/SyncWasmModule.js +39 -0
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +7 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +86 -19
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +4 -3
- package/lib/wasm-sync/WebAssemblyGenerator.js +27 -1
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +9 -3
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +4 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +20 -1
- package/lib/wasm-sync/WebAssemblyParser.js +9 -3
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -0
- package/lib/web/FetchCompileAsyncWasmPlugin.js +29 -1
- package/lib/web/FetchCompileWasmPlugin.js +27 -1
- package/lib/web/JsonpChunkLoadingPlugin.js +11 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +58 -64
- package/lib/web/JsonpTemplatePlugin.js +2 -1
- package/lib/webpack.js +78 -1
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +10 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -10
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -1
- package/module.d.ts +21 -0
- package/package.json +79 -77
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +1117 -79
- package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
- package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
- package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
- package/schemas/plugins/{DllReferencePlugin.check.d.ts → HtmlParserOptions.check.d.ts} +1 -1
- package/schemas/plugins/HtmlParserOptions.check.js +6 -0
- package/schemas/plugins/HtmlParserOptions.json +3 -0
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.json +38 -0
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +2 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +2 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
- package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
- package/types.d.ts +8608 -1159
- package/lib/CaseSensitiveModulesWarning.js +0 -72
- package/lib/GraphHelpers.js +0 -46
- package/lib/ModuleParseError.js +0 -125
- package/lib/NoModeWarning.js +0 -23
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -56
- package/lib/css/walkCssTokens.js +0 -1843
- package/lib/util/AppendOnlyStackedSet.js +0 -78
- /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
- /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
|
@@ -84,6 +84,7 @@ const NULL3_HEADER = 0x12;
|
|
|
84
84
|
const NULLS8_HEADER = 0x13;
|
|
85
85
|
const NULLS32_HEADER = 0x14;
|
|
86
86
|
const NULL_AND_I8_HEADER = 0x15;
|
|
87
|
+
const NULL_AND_I16_HEADER = 0x19;
|
|
87
88
|
const NULL_AND_I32_HEADER = 0x16;
|
|
88
89
|
const NULL_AND_TRUE_HEADER = 0x17;
|
|
89
90
|
const NULL_AND_FALSE_HEADER = 0x18;
|
|
@@ -104,6 +105,7 @@ const SHORT_STRING_LENGTH_MASK = 0x7f; // 0b0111_1111
|
|
|
104
105
|
|
|
105
106
|
const HEADER_SIZE = 1;
|
|
106
107
|
const I8_SIZE = 1;
|
|
108
|
+
const I16_SIZE = 2;
|
|
107
109
|
const I32_SIZE = 4;
|
|
108
110
|
const F64_SIZE = 8;
|
|
109
111
|
|
|
@@ -114,6 +116,7 @@ const MEASURE_END_OPERATION = Symbol("MEASURE_END_OPERATION");
|
|
|
114
116
|
/** @typedef {typeof MEASURE_END_OPERATION} MEASURE_END_OPERATION_TYPE */
|
|
115
117
|
|
|
116
118
|
/**
|
|
119
|
+
* Returns type of number for serialization.
|
|
117
120
|
* @param {number} n number
|
|
118
121
|
* @returns {0 | 1 | 2} type of number for serialization
|
|
119
122
|
*/
|
|
@@ -126,6 +129,7 @@ const identifyNumber = (n) => {
|
|
|
126
129
|
};
|
|
127
130
|
|
|
128
131
|
/**
|
|
132
|
+
* Returns type of bigint for serialization.
|
|
129
133
|
* @param {bigint} n bigint
|
|
130
134
|
* @returns {0 | 1 | 2} type of bigint for serialization
|
|
131
135
|
*/
|
|
@@ -140,16 +144,534 @@ const identifyBigInt = (n) => {
|
|
|
140
144
|
/** @typedef {{ retainedBuffer?: (x: Buffer) => Buffer }} Context} */
|
|
141
145
|
|
|
142
146
|
/**
|
|
147
|
+
* Defines the lazy function type used by this module.
|
|
143
148
|
* @template LazyInputValue
|
|
144
149
|
* @template LazyOutputValue
|
|
145
150
|
* @typedef {import("./SerializerMiddleware").LazyFunction<LazyInputValue, LazyOutputValue, BinaryMiddleware, undefined>} LazyFunction
|
|
146
151
|
*/
|
|
147
152
|
|
|
148
153
|
/**
|
|
154
|
+
* Mutable read state of one `_deserialize` run; the module-level dispatch
|
|
155
|
+
* table operates on this instead of per-call closures.
|
|
156
|
+
*/
|
|
157
|
+
class ReadState {
|
|
158
|
+
/**
|
|
159
|
+
* @param {SerializedType} data data
|
|
160
|
+
* @param {Context} context context object
|
|
161
|
+
* @param {BinaryMiddleware} middleware binary middleware
|
|
162
|
+
*/
|
|
163
|
+
constructor(data, context, middleware) {
|
|
164
|
+
/** @type {SerializedType} */
|
|
165
|
+
this.data = data;
|
|
166
|
+
/** @type {Context} */
|
|
167
|
+
this.context = context;
|
|
168
|
+
/** @type {BinaryMiddleware} */
|
|
169
|
+
this.middleware = middleware;
|
|
170
|
+
this.retainedBuffer = context.retainedBuffer || ((x) => x);
|
|
171
|
+
/** @type {number} */
|
|
172
|
+
this.currentDataItem = 0;
|
|
173
|
+
/** @type {BufferSerializableType | null} */
|
|
174
|
+
this.currentBuffer = data[0];
|
|
175
|
+
/** @type {boolean} */
|
|
176
|
+
this.currentIsBuffer = Buffer.isBuffer(this.currentBuffer);
|
|
177
|
+
/** @type {number} */
|
|
178
|
+
this.currentPosition = 0;
|
|
179
|
+
/** @type {DeserializedType} */
|
|
180
|
+
this.result = [];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Advances to the next data item (does not reset the position). */
|
|
184
|
+
nextDataItem() {
|
|
185
|
+
this.currentDataItem++;
|
|
186
|
+
this.currentBuffer =
|
|
187
|
+
this.currentDataItem < this.data.length
|
|
188
|
+
? this.data[this.currentDataItem]
|
|
189
|
+
: null;
|
|
190
|
+
this.currentIsBuffer = Buffer.isBuffer(this.currentBuffer);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
checkOverflow() {
|
|
194
|
+
if (
|
|
195
|
+
this.currentPosition >= /** @type {Buffer} */ (this.currentBuffer).length
|
|
196
|
+
) {
|
|
197
|
+
this.currentPosition = 0;
|
|
198
|
+
this.nextDataItem();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Checks whether n bytes are available in the current buffer.
|
|
204
|
+
* @param {number} n n
|
|
205
|
+
* @returns {boolean} true when in current buffer, otherwise false
|
|
206
|
+
*/
|
|
207
|
+
isInCurrentBuffer(n) {
|
|
208
|
+
return (
|
|
209
|
+
this.currentIsBuffer &&
|
|
210
|
+
n + this.currentPosition <=
|
|
211
|
+
/** @type {Buffer} */ (this.currentBuffer).length
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
ensureBuffer() {
|
|
216
|
+
if (!this.currentIsBuffer) {
|
|
217
|
+
throw new Error(
|
|
218
|
+
this.currentBuffer === null
|
|
219
|
+
? "Unexpected end of stream"
|
|
220
|
+
: "Unexpected lazy element in stream"
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Returns buffer with bytes.
|
|
227
|
+
* @param {number} n amount of bytes to read
|
|
228
|
+
* @returns {Buffer} buffer with bytes
|
|
229
|
+
*/
|
|
230
|
+
read(n) {
|
|
231
|
+
this.ensureBuffer();
|
|
232
|
+
const rem =
|
|
233
|
+
/** @type {Buffer} */ (this.currentBuffer).length - this.currentPosition;
|
|
234
|
+
if (rem < n) {
|
|
235
|
+
const buffers = [this.read(rem)];
|
|
236
|
+
n -= rem;
|
|
237
|
+
this.ensureBuffer();
|
|
238
|
+
while (/** @type {Buffer} */ (this.currentBuffer).length < n) {
|
|
239
|
+
const b = /** @type {Buffer} */ (this.currentBuffer);
|
|
240
|
+
buffers.push(b);
|
|
241
|
+
n -= b.length;
|
|
242
|
+
this.nextDataItem();
|
|
243
|
+
this.ensureBuffer();
|
|
244
|
+
}
|
|
245
|
+
buffers.push(this.read(n));
|
|
246
|
+
return Buffer.concat(buffers);
|
|
247
|
+
}
|
|
248
|
+
const b = /** @type {Buffer} */ (this.currentBuffer);
|
|
249
|
+
const res = Buffer.from(b.buffer, b.byteOffset + this.currentPosition, n);
|
|
250
|
+
this.currentPosition += n;
|
|
251
|
+
this.checkOverflow();
|
|
252
|
+
return res;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Reads up to n bytes.
|
|
257
|
+
* @param {number} n amount of bytes to read
|
|
258
|
+
* @returns {Buffer} buffer with bytes
|
|
259
|
+
*/
|
|
260
|
+
readUpTo(n) {
|
|
261
|
+
this.ensureBuffer();
|
|
262
|
+
const rem =
|
|
263
|
+
/** @type {Buffer} */ (this.currentBuffer).length - this.currentPosition;
|
|
264
|
+
if (rem < n) {
|
|
265
|
+
n = rem;
|
|
266
|
+
}
|
|
267
|
+
const b = /** @type {Buffer} */ (this.currentBuffer);
|
|
268
|
+
const res = Buffer.from(b.buffer, b.byteOffset + this.currentPosition, n);
|
|
269
|
+
this.currentPosition += n;
|
|
270
|
+
this.checkOverflow();
|
|
271
|
+
return res;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Returns u8.
|
|
276
|
+
* @returns {number} U8
|
|
277
|
+
*/
|
|
278
|
+
readU8() {
|
|
279
|
+
this.ensureBuffer();
|
|
280
|
+
/**
|
|
281
|
+
* There is no need to check remaining buffer size here
|
|
282
|
+
* since {@link ReadState#checkOverflow} guarantees at least one byte remaining
|
|
283
|
+
*/
|
|
284
|
+
const byte =
|
|
285
|
+
/** @type {Buffer} */
|
|
286
|
+
(this.currentBuffer).readUInt8(this.currentPosition);
|
|
287
|
+
this.currentPosition += I8_SIZE;
|
|
288
|
+
this.checkOverflow();
|
|
289
|
+
return byte;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Returns u32.
|
|
294
|
+
* @returns {number} U32
|
|
295
|
+
*/
|
|
296
|
+
readU32() {
|
|
297
|
+
// fast path avoids allocating a 4-byte view per length read
|
|
298
|
+
if (this.isInCurrentBuffer(I32_SIZE)) {
|
|
299
|
+
const value =
|
|
300
|
+
/** @type {Buffer} */
|
|
301
|
+
(this.currentBuffer).readUInt32LE(this.currentPosition);
|
|
302
|
+
this.currentPosition += I32_SIZE;
|
|
303
|
+
this.checkOverflow();
|
|
304
|
+
return value;
|
|
305
|
+
}
|
|
306
|
+
return this.read(I32_SIZE).readUInt32LE(0);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Pushes the lowest n bits of data as booleans.
|
|
311
|
+
* @param {number} data data
|
|
312
|
+
* @param {number} n n
|
|
313
|
+
*/
|
|
314
|
+
readBits(data, n) {
|
|
315
|
+
let mask = 1;
|
|
316
|
+
while (n !== 0) {
|
|
317
|
+
this.result.push((data & mask) !== 0);
|
|
318
|
+
mask <<= 1;
|
|
319
|
+
n--;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Deserialize handlers indexed by header byte; built once so each
|
|
326
|
+
* `_deserialize` call doesn't rebuild 256 closures (hot on cache restore).
|
|
327
|
+
* @type {((s: ReadState) => void)[]}
|
|
328
|
+
*/
|
|
329
|
+
const dispatchTable = Array.from({ length: 256 }, (_, header) => {
|
|
330
|
+
switch (header) {
|
|
331
|
+
case LAZY_HEADER:
|
|
332
|
+
return (s) => {
|
|
333
|
+
const count = s.readU32();
|
|
334
|
+
/** @type {number[]} */
|
|
335
|
+
const lengths = [];
|
|
336
|
+
for (let i = 0; i < count; i++) lengths.push(s.readU32());
|
|
337
|
+
/** @type {(Buffer | LazyFunction<SerializedType, DeserializedType>)[]} */
|
|
338
|
+
const content = [];
|
|
339
|
+
for (let l of lengths) {
|
|
340
|
+
if (l === 0) {
|
|
341
|
+
if (typeof s.currentBuffer !== "function") {
|
|
342
|
+
throw new Error("Unexpected non-lazy element in stream");
|
|
343
|
+
}
|
|
344
|
+
content.push(s.currentBuffer);
|
|
345
|
+
s.nextDataItem();
|
|
346
|
+
} else {
|
|
347
|
+
do {
|
|
348
|
+
const buf = s.readUpTo(l);
|
|
349
|
+
l -= buf.length;
|
|
350
|
+
content.push(s.retainedBuffer(buf));
|
|
351
|
+
} while (l > 0);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
s.result.push(s.middleware._createLazyDeserialized(content, s.context));
|
|
355
|
+
};
|
|
356
|
+
case BUFFER_HEADER:
|
|
357
|
+
return (s) => {
|
|
358
|
+
const len = s.readU32();
|
|
359
|
+
s.result.push(s.retainedBuffer(s.read(len)));
|
|
360
|
+
};
|
|
361
|
+
case TRUE_HEADER:
|
|
362
|
+
return (s) => s.result.push(true);
|
|
363
|
+
case FALSE_HEADER:
|
|
364
|
+
return (s) => s.result.push(false);
|
|
365
|
+
case NULL3_HEADER:
|
|
366
|
+
return (s) => s.result.push(null, null, null);
|
|
367
|
+
case NULL2_HEADER:
|
|
368
|
+
return (s) => s.result.push(null, null);
|
|
369
|
+
case NULL_HEADER:
|
|
370
|
+
return (s) => s.result.push(null);
|
|
371
|
+
case NULL_AND_TRUE_HEADER:
|
|
372
|
+
return (s) => s.result.push(null, true);
|
|
373
|
+
case NULL_AND_FALSE_HEADER:
|
|
374
|
+
return (s) => s.result.push(null, false);
|
|
375
|
+
case NULL_AND_I8_HEADER:
|
|
376
|
+
return (s) => {
|
|
377
|
+
if (s.currentIsBuffer) {
|
|
378
|
+
s.result.push(
|
|
379
|
+
null,
|
|
380
|
+
/** @type {Buffer} */ (s.currentBuffer).readInt8(s.currentPosition)
|
|
381
|
+
);
|
|
382
|
+
s.currentPosition += I8_SIZE;
|
|
383
|
+
s.checkOverflow();
|
|
384
|
+
} else {
|
|
385
|
+
s.result.push(null, s.read(I8_SIZE).readInt8(0));
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
case NULL_AND_I16_HEADER:
|
|
389
|
+
return (s) => {
|
|
390
|
+
s.result.push(null);
|
|
391
|
+
if (s.isInCurrentBuffer(I16_SIZE)) {
|
|
392
|
+
s.result.push(
|
|
393
|
+
/** @type {Buffer} */ (s.currentBuffer).readInt16LE(
|
|
394
|
+
s.currentPosition
|
|
395
|
+
)
|
|
396
|
+
);
|
|
397
|
+
s.currentPosition += I16_SIZE;
|
|
398
|
+
s.checkOverflow();
|
|
399
|
+
} else {
|
|
400
|
+
s.result.push(s.read(I16_SIZE).readInt16LE(0));
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
case NULL_AND_I32_HEADER:
|
|
404
|
+
return (s) => {
|
|
405
|
+
s.result.push(null);
|
|
406
|
+
if (s.isInCurrentBuffer(I32_SIZE)) {
|
|
407
|
+
s.result.push(
|
|
408
|
+
/** @type {Buffer} */ (s.currentBuffer).readInt32LE(
|
|
409
|
+
s.currentPosition
|
|
410
|
+
)
|
|
411
|
+
);
|
|
412
|
+
s.currentPosition += I32_SIZE;
|
|
413
|
+
s.checkOverflow();
|
|
414
|
+
} else {
|
|
415
|
+
s.result.push(s.read(I32_SIZE).readInt32LE(0));
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
case NULLS8_HEADER:
|
|
419
|
+
return (s) => {
|
|
420
|
+
const len = s.readU8() + 4;
|
|
421
|
+
for (let i = 0; i < len; i++) {
|
|
422
|
+
s.result.push(null);
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
case NULLS32_HEADER:
|
|
426
|
+
return (s) => {
|
|
427
|
+
const len = s.readU32() + 260;
|
|
428
|
+
for (let i = 0; i < len; i++) {
|
|
429
|
+
s.result.push(null);
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
case BOOLEANS_HEADER:
|
|
433
|
+
return (s) => {
|
|
434
|
+
const innerHeader = s.readU8();
|
|
435
|
+
if ((innerHeader & 0xf0) === 0) {
|
|
436
|
+
s.readBits(innerHeader, 3);
|
|
437
|
+
} else if ((innerHeader & 0xe0) === 0) {
|
|
438
|
+
s.readBits(innerHeader, 4);
|
|
439
|
+
} else if ((innerHeader & 0xc0) === 0) {
|
|
440
|
+
s.readBits(innerHeader, 5);
|
|
441
|
+
} else if ((innerHeader & 0x80) === 0) {
|
|
442
|
+
s.readBits(innerHeader, 6);
|
|
443
|
+
} else if (innerHeader !== 0xff) {
|
|
444
|
+
let count = (innerHeader & 0x7f) + 7;
|
|
445
|
+
while (count > 8) {
|
|
446
|
+
s.readBits(s.readU8(), 8);
|
|
447
|
+
count -= 8;
|
|
448
|
+
}
|
|
449
|
+
s.readBits(s.readU8(), count);
|
|
450
|
+
} else {
|
|
451
|
+
let count = s.readU32();
|
|
452
|
+
while (count > 8) {
|
|
453
|
+
s.readBits(s.readU8(), 8);
|
|
454
|
+
count -= 8;
|
|
455
|
+
}
|
|
456
|
+
s.readBits(s.readU8(), count);
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
case STRING_HEADER:
|
|
460
|
+
return (s) => {
|
|
461
|
+
const len = s.readU32();
|
|
462
|
+
if (s.isInCurrentBuffer(len) && s.currentPosition + len < 0x7fffffff) {
|
|
463
|
+
s.result.push(
|
|
464
|
+
/** @type {Buffer} */
|
|
465
|
+
(s.currentBuffer).toString(
|
|
466
|
+
undefined,
|
|
467
|
+
s.currentPosition,
|
|
468
|
+
s.currentPosition + len
|
|
469
|
+
)
|
|
470
|
+
);
|
|
471
|
+
s.currentPosition += len;
|
|
472
|
+
s.checkOverflow();
|
|
473
|
+
} else {
|
|
474
|
+
s.result.push(s.read(len).toString());
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
case SHORT_STRING_HEADER:
|
|
478
|
+
return (s) => s.result.push("");
|
|
479
|
+
case SHORT_STRING_HEADER | 1:
|
|
480
|
+
return (s) => {
|
|
481
|
+
if (s.currentIsBuffer && s.currentPosition < 0x7ffffffe) {
|
|
482
|
+
s.result.push(
|
|
483
|
+
/** @type {Buffer} */
|
|
484
|
+
(s.currentBuffer).toString(
|
|
485
|
+
"latin1",
|
|
486
|
+
s.currentPosition,
|
|
487
|
+
s.currentPosition + 1
|
|
488
|
+
)
|
|
489
|
+
);
|
|
490
|
+
s.currentPosition++;
|
|
491
|
+
s.checkOverflow();
|
|
492
|
+
} else {
|
|
493
|
+
s.result.push(s.read(1).toString("latin1"));
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
case I8_HEADER:
|
|
497
|
+
return (s) => {
|
|
498
|
+
if (s.currentIsBuffer) {
|
|
499
|
+
s.result.push(
|
|
500
|
+
/** @type {Buffer} */ (s.currentBuffer).readInt8(s.currentPosition)
|
|
501
|
+
);
|
|
502
|
+
s.currentPosition++;
|
|
503
|
+
s.checkOverflow();
|
|
504
|
+
} else {
|
|
505
|
+
s.result.push(s.read(1).readInt8(0));
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
case BIGINT_I8_HEADER: {
|
|
509
|
+
const len = 1;
|
|
510
|
+
return (s) => {
|
|
511
|
+
const need = I8_SIZE * len;
|
|
512
|
+
|
|
513
|
+
if (s.isInCurrentBuffer(need)) {
|
|
514
|
+
for (let i = 0; i < len; i++) {
|
|
515
|
+
const value =
|
|
516
|
+
/** @type {Buffer} */
|
|
517
|
+
(s.currentBuffer).readInt8(s.currentPosition);
|
|
518
|
+
s.result.push(BigInt(value));
|
|
519
|
+
s.currentPosition += I8_SIZE;
|
|
520
|
+
}
|
|
521
|
+
s.checkOverflow();
|
|
522
|
+
} else {
|
|
523
|
+
const buf = s.read(need);
|
|
524
|
+
for (let i = 0; i < len; i++) {
|
|
525
|
+
const value = buf.readInt8(i * I8_SIZE);
|
|
526
|
+
s.result.push(BigInt(value));
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
case BIGINT_I32_HEADER: {
|
|
532
|
+
const len = 1;
|
|
533
|
+
return (s) => {
|
|
534
|
+
const need = I32_SIZE * len;
|
|
535
|
+
if (s.isInCurrentBuffer(need)) {
|
|
536
|
+
for (let i = 0; i < len; i++) {
|
|
537
|
+
const value = /** @type {Buffer} */ (s.currentBuffer).readInt32LE(
|
|
538
|
+
s.currentPosition
|
|
539
|
+
);
|
|
540
|
+
s.result.push(BigInt(value));
|
|
541
|
+
s.currentPosition += I32_SIZE;
|
|
542
|
+
}
|
|
543
|
+
s.checkOverflow();
|
|
544
|
+
} else {
|
|
545
|
+
const buf = s.read(need);
|
|
546
|
+
for (let i = 0; i < len; i++) {
|
|
547
|
+
const value = buf.readInt32LE(i * I32_SIZE);
|
|
548
|
+
s.result.push(BigInt(value));
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
case BIGINT_HEADER: {
|
|
554
|
+
return (s) => {
|
|
555
|
+
const len = s.readU32();
|
|
556
|
+
if (s.isInCurrentBuffer(len) && s.currentPosition + len < 0x7fffffff) {
|
|
557
|
+
const value =
|
|
558
|
+
/** @type {Buffer} */
|
|
559
|
+
(s.currentBuffer).toString(
|
|
560
|
+
undefined,
|
|
561
|
+
s.currentPosition,
|
|
562
|
+
s.currentPosition + len
|
|
563
|
+
);
|
|
564
|
+
|
|
565
|
+
s.result.push(BigInt(value));
|
|
566
|
+
s.currentPosition += len;
|
|
567
|
+
s.checkOverflow();
|
|
568
|
+
} else {
|
|
569
|
+
const value = s.read(len).toString();
|
|
570
|
+
s.result.push(BigInt(value));
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
default:
|
|
575
|
+
if (header <= 10) {
|
|
576
|
+
return (s) => s.result.push(header);
|
|
577
|
+
} else if ((header & SHORT_STRING_HEADER) === SHORT_STRING_HEADER) {
|
|
578
|
+
const len = header & SHORT_STRING_LENGTH_MASK;
|
|
579
|
+
return (s) => {
|
|
580
|
+
if (
|
|
581
|
+
s.isInCurrentBuffer(len) &&
|
|
582
|
+
s.currentPosition + len < 0x7fffffff
|
|
583
|
+
) {
|
|
584
|
+
s.result.push(
|
|
585
|
+
/** @type {Buffer} */
|
|
586
|
+
(s.currentBuffer).toString(
|
|
587
|
+
"latin1",
|
|
588
|
+
s.currentPosition,
|
|
589
|
+
s.currentPosition + len
|
|
590
|
+
)
|
|
591
|
+
);
|
|
592
|
+
s.currentPosition += len;
|
|
593
|
+
s.checkOverflow();
|
|
594
|
+
} else {
|
|
595
|
+
s.result.push(s.read(len).toString("latin1"));
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
} else if ((header & NUMBERS_HEADER_MASK) === F64_HEADER) {
|
|
599
|
+
const len = (header & NUMBERS_COUNT_MASK) + 1;
|
|
600
|
+
return (s) => {
|
|
601
|
+
const need = F64_SIZE * len;
|
|
602
|
+
if (s.isInCurrentBuffer(need)) {
|
|
603
|
+
for (let i = 0; i < len; i++) {
|
|
604
|
+
s.result.push(
|
|
605
|
+
/** @type {Buffer} */ (s.currentBuffer).readDoubleLE(
|
|
606
|
+
s.currentPosition
|
|
607
|
+
)
|
|
608
|
+
);
|
|
609
|
+
s.currentPosition += F64_SIZE;
|
|
610
|
+
}
|
|
611
|
+
s.checkOverflow();
|
|
612
|
+
} else {
|
|
613
|
+
const buf = s.read(need);
|
|
614
|
+
for (let i = 0; i < len; i++) {
|
|
615
|
+
s.result.push(buf.readDoubleLE(i * F64_SIZE));
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
} else if ((header & NUMBERS_HEADER_MASK) === I32_HEADER) {
|
|
620
|
+
const len = (header & NUMBERS_COUNT_MASK) + 1;
|
|
621
|
+
return (s) => {
|
|
622
|
+
const need = I32_SIZE * len;
|
|
623
|
+
if (s.isInCurrentBuffer(need)) {
|
|
624
|
+
for (let i = 0; i < len; i++) {
|
|
625
|
+
s.result.push(
|
|
626
|
+
/** @type {Buffer} */ (s.currentBuffer).readInt32LE(
|
|
627
|
+
s.currentPosition
|
|
628
|
+
)
|
|
629
|
+
);
|
|
630
|
+
s.currentPosition += I32_SIZE;
|
|
631
|
+
}
|
|
632
|
+
s.checkOverflow();
|
|
633
|
+
} else {
|
|
634
|
+
const buf = s.read(need);
|
|
635
|
+
for (let i = 0; i < len; i++) {
|
|
636
|
+
s.result.push(buf.readInt32LE(i * I32_SIZE));
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
} else if ((header & NUMBERS_HEADER_MASK) === I8_HEADER) {
|
|
641
|
+
const len = (header & NUMBERS_COUNT_MASK) + 1;
|
|
642
|
+
return (s) => {
|
|
643
|
+
const need = I8_SIZE * len;
|
|
644
|
+
if (s.isInCurrentBuffer(need)) {
|
|
645
|
+
for (let i = 0; i < len; i++) {
|
|
646
|
+
s.result.push(
|
|
647
|
+
/** @type {Buffer} */ (s.currentBuffer).readInt8(
|
|
648
|
+
s.currentPosition
|
|
649
|
+
)
|
|
650
|
+
);
|
|
651
|
+
s.currentPosition += I8_SIZE;
|
|
652
|
+
}
|
|
653
|
+
s.checkOverflow();
|
|
654
|
+
} else {
|
|
655
|
+
const buf = s.read(need);
|
|
656
|
+
for (let i = 0; i < len; i++) {
|
|
657
|
+
s.result.push(buf.readInt8(i * I8_SIZE));
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
return (s) => {
|
|
663
|
+
throw new Error(`Unexpected header byte 0x${header.toString(16)}`);
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Represents BinaryMiddleware.
|
|
149
670
|
* @extends {SerializerMiddleware<DeserializedType, SerializedType, Context>}
|
|
150
671
|
*/
|
|
151
672
|
class BinaryMiddleware extends SerializerMiddleware {
|
|
152
673
|
/**
|
|
674
|
+
* Serializes this instance into the provided serializer context.
|
|
153
675
|
* @param {DeserializedType} data data
|
|
154
676
|
* @param {Context} context context object
|
|
155
677
|
* @returns {SerializedType | Promise<SerializedType> | null} serialized data
|
|
@@ -159,6 +681,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
159
681
|
}
|
|
160
682
|
|
|
161
683
|
/**
|
|
684
|
+
* Returns new lazy.
|
|
162
685
|
* @param {LazyFunction<DeserializedType, SerializedType>} fn lazy function
|
|
163
686
|
* @param {Context} context serialize function
|
|
164
687
|
* @returns {LazyFunction<SerializedType, DeserializedType>} new lazy
|
|
@@ -170,6 +693,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
170
693
|
}
|
|
171
694
|
|
|
172
695
|
/**
|
|
696
|
+
* Returns serialized data.
|
|
173
697
|
* @param {DeserializedType} data data
|
|
174
698
|
* @param {Context} context context object
|
|
175
699
|
* @param {{ leftOverBuffer: Buffer | null, allocationSize: number, increaseCounter: number }} allocationScope allocation scope
|
|
@@ -196,6 +720,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
196
720
|
currentBuffer = Buffer.allocUnsafe(allocationScope.allocationSize);
|
|
197
721
|
}
|
|
198
722
|
/**
|
|
723
|
+
* Processes the provided bytes needed.
|
|
199
724
|
* @param {number} bytesNeeded bytes needed
|
|
200
725
|
*/
|
|
201
726
|
const allocate = (bytesNeeded) => {
|
|
@@ -246,6 +771,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
246
771
|
}
|
|
247
772
|
};
|
|
248
773
|
/**
|
|
774
|
+
* Processes the provided byte.
|
|
249
775
|
* @param {number} byte byte
|
|
250
776
|
*/
|
|
251
777
|
const writeU8 = (byte) => {
|
|
@@ -253,6 +779,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
253
779
|
(currentBuffer).writeUInt8(byte, currentPosition++);
|
|
254
780
|
};
|
|
255
781
|
/**
|
|
782
|
+
* Processes the provided ui32.
|
|
256
783
|
* @param {number} ui32 ui32
|
|
257
784
|
*/
|
|
258
785
|
const writeU32 = (ui32) => {
|
|
@@ -266,6 +793,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
266
793
|
measureStack.push(buffers.length, currentPosition);
|
|
267
794
|
};
|
|
268
795
|
/**
|
|
796
|
+
* Returns size.
|
|
269
797
|
* @returns {number} size
|
|
270
798
|
*/
|
|
271
799
|
const measureEnd = () => {
|
|
@@ -571,10 +1099,19 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
571
1099
|
currentPosition += I8_SIZE;
|
|
572
1100
|
i++;
|
|
573
1101
|
} else if (type === 1) {
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
1102
|
+
// `null` + i32 is 5 bytes; if the value also fits an
|
|
1103
|
+
// i16, fuse it as 3 bytes instead (helps back-references)
|
|
1104
|
+
if (next >= -32768 && next <= 32767) {
|
|
1105
|
+
allocate(HEADER_SIZE + I16_SIZE);
|
|
1106
|
+
writeU8(NULL_AND_I16_HEADER);
|
|
1107
|
+
currentBuffer.writeInt16LE(next, currentPosition);
|
|
1108
|
+
currentPosition += I16_SIZE;
|
|
1109
|
+
} else {
|
|
1110
|
+
allocate(HEADER_SIZE + I32_SIZE);
|
|
1111
|
+
writeU8(NULL_AND_I32_HEADER);
|
|
1112
|
+
currentBuffer.writeInt32LE(next, currentPosition);
|
|
1113
|
+
currentPosition += I32_SIZE;
|
|
1114
|
+
}
|
|
578
1115
|
i++;
|
|
579
1116
|
} else {
|
|
580
1117
|
allocate(HEADER_SIZE);
|
|
@@ -653,6 +1190,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
653
1190
|
}
|
|
654
1191
|
|
|
655
1192
|
/**
|
|
1193
|
+
* Restores this instance from the provided deserializer context.
|
|
656
1194
|
* @param {SerializedType} data data
|
|
657
1195
|
* @param {Context} context context object
|
|
658
1196
|
* @returns {DeserializedType | Promise<DeserializedType>} deserialized data
|
|
@@ -662,7 +1200,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
662
1200
|
}
|
|
663
1201
|
|
|
664
1202
|
/**
|
|
665
|
-
*
|
|
1203
|
+
* Create lazy deserialized. Internal, but called from the dispatch table.
|
|
666
1204
|
* @param {SerializedType} content content
|
|
667
1205
|
* @param {Context} context context object
|
|
668
1206
|
* @returns {LazyFunction<DeserializedType, SerializedType>} lazy function
|
|
@@ -677,6 +1215,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
677
1215
|
}
|
|
678
1216
|
|
|
679
1217
|
/**
|
|
1218
|
+
* Returns new lazy.
|
|
680
1219
|
* @private
|
|
681
1220
|
* @param {LazyFunction<SerializedType, DeserializedType>} fn lazy function
|
|
682
1221
|
* @param {Context} context context object
|
|
@@ -689,472 +1228,22 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
689
1228
|
}
|
|
690
1229
|
|
|
691
1230
|
/**
|
|
1231
|
+
* Returns deserialized data.
|
|
692
1232
|
* @param {SerializedType} data data
|
|
693
1233
|
* @param {Context} context context object
|
|
694
1234
|
* @returns {DeserializedType} deserialized data
|
|
695
1235
|
*/
|
|
696
1236
|
_deserialize(data, context) {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
const retainedBuffer = context.retainedBuffer || ((x) => x);
|
|
704
|
-
|
|
705
|
-
const checkOverflow = () => {
|
|
706
|
-
if (currentPosition >= /** @type {Buffer} */ (currentBuffer).length) {
|
|
707
|
-
currentPosition = 0;
|
|
708
|
-
currentDataItem++;
|
|
709
|
-
currentBuffer =
|
|
710
|
-
currentDataItem < data.length ? data[currentDataItem] : null;
|
|
711
|
-
currentIsBuffer = Buffer.isBuffer(currentBuffer);
|
|
712
|
-
}
|
|
713
|
-
};
|
|
714
|
-
/**
|
|
715
|
-
* @param {number} n n
|
|
716
|
-
* @returns {boolean} true when in current buffer, otherwise false
|
|
717
|
-
*/
|
|
718
|
-
const isInCurrentBuffer = (n) =>
|
|
719
|
-
currentIsBuffer &&
|
|
720
|
-
n + currentPosition <= /** @type {Buffer} */ (currentBuffer).length;
|
|
721
|
-
const ensureBuffer = () => {
|
|
722
|
-
if (!currentIsBuffer) {
|
|
723
|
-
throw new Error(
|
|
724
|
-
currentBuffer === null
|
|
725
|
-
? "Unexpected end of stream"
|
|
726
|
-
: "Unexpected lazy element in stream"
|
|
727
|
-
);
|
|
728
|
-
}
|
|
729
|
-
};
|
|
730
|
-
/**
|
|
731
|
-
* Reads n bytes
|
|
732
|
-
* @param {number} n amount of bytes to read
|
|
733
|
-
* @returns {Buffer} buffer with bytes
|
|
734
|
-
*/
|
|
735
|
-
const read = (n) => {
|
|
736
|
-
ensureBuffer();
|
|
737
|
-
const rem =
|
|
738
|
-
/** @type {Buffer} */ (currentBuffer).length - currentPosition;
|
|
739
|
-
if (rem < n) {
|
|
740
|
-
const buffers = [read(rem)];
|
|
741
|
-
n -= rem;
|
|
742
|
-
ensureBuffer();
|
|
743
|
-
while (/** @type {Buffer} */ (currentBuffer).length < n) {
|
|
744
|
-
const b = /** @type {Buffer} */ (currentBuffer);
|
|
745
|
-
buffers.push(b);
|
|
746
|
-
n -= b.length;
|
|
747
|
-
currentDataItem++;
|
|
748
|
-
currentBuffer =
|
|
749
|
-
currentDataItem < data.length ? data[currentDataItem] : null;
|
|
750
|
-
currentIsBuffer = Buffer.isBuffer(currentBuffer);
|
|
751
|
-
ensureBuffer();
|
|
752
|
-
}
|
|
753
|
-
buffers.push(read(n));
|
|
754
|
-
return Buffer.concat(buffers);
|
|
755
|
-
}
|
|
756
|
-
const b = /** @type {Buffer} */ (currentBuffer);
|
|
757
|
-
const res = Buffer.from(b.buffer, b.byteOffset + currentPosition, n);
|
|
758
|
-
currentPosition += n;
|
|
759
|
-
checkOverflow();
|
|
760
|
-
return res;
|
|
761
|
-
};
|
|
762
|
-
/**
|
|
763
|
-
* Reads up to n bytes
|
|
764
|
-
* @param {number} n amount of bytes to read
|
|
765
|
-
* @returns {Buffer} buffer with bytes
|
|
766
|
-
*/
|
|
767
|
-
const readUpTo = (n) => {
|
|
768
|
-
ensureBuffer();
|
|
769
|
-
const rem =
|
|
770
|
-
/** @type {Buffer} */
|
|
771
|
-
(currentBuffer).length - currentPosition;
|
|
772
|
-
if (rem < n) {
|
|
773
|
-
n = rem;
|
|
774
|
-
}
|
|
775
|
-
const b = /** @type {Buffer} */ (currentBuffer);
|
|
776
|
-
const res = Buffer.from(b.buffer, b.byteOffset + currentPosition, n);
|
|
777
|
-
currentPosition += n;
|
|
778
|
-
checkOverflow();
|
|
779
|
-
return res;
|
|
780
|
-
};
|
|
781
|
-
/**
|
|
782
|
-
* @returns {number} U8
|
|
783
|
-
*/
|
|
784
|
-
const readU8 = () => {
|
|
785
|
-
ensureBuffer();
|
|
786
|
-
/**
|
|
787
|
-
* There is no need to check remaining buffer size here
|
|
788
|
-
* since {@link checkOverflow} guarantees at least one byte remaining
|
|
789
|
-
*/
|
|
790
|
-
const byte =
|
|
791
|
-
/** @type {Buffer} */
|
|
792
|
-
(currentBuffer).readUInt8(currentPosition);
|
|
793
|
-
currentPosition += I8_SIZE;
|
|
794
|
-
checkOverflow();
|
|
795
|
-
return byte;
|
|
796
|
-
};
|
|
797
|
-
/**
|
|
798
|
-
* @returns {number} U32
|
|
799
|
-
*/
|
|
800
|
-
const readU32 = () => read(I32_SIZE).readUInt32LE(0);
|
|
801
|
-
/**
|
|
802
|
-
* @param {number} data data
|
|
803
|
-
* @param {number} n n
|
|
804
|
-
*/
|
|
805
|
-
const readBits = (data, n) => {
|
|
806
|
-
let mask = 1;
|
|
807
|
-
while (n !== 0) {
|
|
808
|
-
result.push((data & mask) !== 0);
|
|
809
|
-
mask <<= 1;
|
|
810
|
-
n--;
|
|
811
|
-
}
|
|
812
|
-
};
|
|
813
|
-
const dispatchTable = Array.from({ length: 256 }).map((_, header) => {
|
|
814
|
-
switch (header) {
|
|
815
|
-
case LAZY_HEADER:
|
|
816
|
-
return () => {
|
|
817
|
-
const count = readU32();
|
|
818
|
-
const lengths = Array.from({ length: count }).map(() => readU32());
|
|
819
|
-
/** @type {(Buffer | LazyFunction<SerializedType, DeserializedType>)[]} */
|
|
820
|
-
const content = [];
|
|
821
|
-
for (let l of lengths) {
|
|
822
|
-
if (l === 0) {
|
|
823
|
-
if (typeof currentBuffer !== "function") {
|
|
824
|
-
throw new Error("Unexpected non-lazy element in stream");
|
|
825
|
-
}
|
|
826
|
-
content.push(currentBuffer);
|
|
827
|
-
currentDataItem++;
|
|
828
|
-
currentBuffer =
|
|
829
|
-
currentDataItem < data.length ? data[currentDataItem] : null;
|
|
830
|
-
currentIsBuffer = Buffer.isBuffer(currentBuffer);
|
|
831
|
-
} else {
|
|
832
|
-
do {
|
|
833
|
-
const buf = readUpTo(l);
|
|
834
|
-
l -= buf.length;
|
|
835
|
-
content.push(retainedBuffer(buf));
|
|
836
|
-
} while (l > 0);
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
result.push(this._createLazyDeserialized(content, context));
|
|
840
|
-
};
|
|
841
|
-
case BUFFER_HEADER:
|
|
842
|
-
return () => {
|
|
843
|
-
const len = readU32();
|
|
844
|
-
result.push(retainedBuffer(read(len)));
|
|
845
|
-
};
|
|
846
|
-
case TRUE_HEADER:
|
|
847
|
-
return () => result.push(true);
|
|
848
|
-
case FALSE_HEADER:
|
|
849
|
-
return () => result.push(false);
|
|
850
|
-
case NULL3_HEADER:
|
|
851
|
-
return () => result.push(null, null, null);
|
|
852
|
-
case NULL2_HEADER:
|
|
853
|
-
return () => result.push(null, null);
|
|
854
|
-
case NULL_HEADER:
|
|
855
|
-
return () => result.push(null);
|
|
856
|
-
case NULL_AND_TRUE_HEADER:
|
|
857
|
-
return () => result.push(null, true);
|
|
858
|
-
case NULL_AND_FALSE_HEADER:
|
|
859
|
-
return () => result.push(null, false);
|
|
860
|
-
case NULL_AND_I8_HEADER:
|
|
861
|
-
return () => {
|
|
862
|
-
if (currentIsBuffer) {
|
|
863
|
-
result.push(
|
|
864
|
-
null,
|
|
865
|
-
/** @type {Buffer} */ (currentBuffer).readInt8(currentPosition)
|
|
866
|
-
);
|
|
867
|
-
currentPosition += I8_SIZE;
|
|
868
|
-
checkOverflow();
|
|
869
|
-
} else {
|
|
870
|
-
result.push(null, read(I8_SIZE).readInt8(0));
|
|
871
|
-
}
|
|
872
|
-
};
|
|
873
|
-
case NULL_AND_I32_HEADER:
|
|
874
|
-
return () => {
|
|
875
|
-
result.push(null);
|
|
876
|
-
if (isInCurrentBuffer(I32_SIZE)) {
|
|
877
|
-
result.push(
|
|
878
|
-
/** @type {Buffer} */ (currentBuffer).readInt32LE(
|
|
879
|
-
currentPosition
|
|
880
|
-
)
|
|
881
|
-
);
|
|
882
|
-
currentPosition += I32_SIZE;
|
|
883
|
-
checkOverflow();
|
|
884
|
-
} else {
|
|
885
|
-
result.push(read(I32_SIZE).readInt32LE(0));
|
|
886
|
-
}
|
|
887
|
-
};
|
|
888
|
-
case NULLS8_HEADER:
|
|
889
|
-
return () => {
|
|
890
|
-
const len = readU8() + 4;
|
|
891
|
-
for (let i = 0; i < len; i++) {
|
|
892
|
-
result.push(null);
|
|
893
|
-
}
|
|
894
|
-
};
|
|
895
|
-
case NULLS32_HEADER:
|
|
896
|
-
return () => {
|
|
897
|
-
const len = readU32() + 260;
|
|
898
|
-
for (let i = 0; i < len; i++) {
|
|
899
|
-
result.push(null);
|
|
900
|
-
}
|
|
901
|
-
};
|
|
902
|
-
case BOOLEANS_HEADER:
|
|
903
|
-
return () => {
|
|
904
|
-
const innerHeader = readU8();
|
|
905
|
-
if ((innerHeader & 0xf0) === 0) {
|
|
906
|
-
readBits(innerHeader, 3);
|
|
907
|
-
} else if ((innerHeader & 0xe0) === 0) {
|
|
908
|
-
readBits(innerHeader, 4);
|
|
909
|
-
} else if ((innerHeader & 0xc0) === 0) {
|
|
910
|
-
readBits(innerHeader, 5);
|
|
911
|
-
} else if ((innerHeader & 0x80) === 0) {
|
|
912
|
-
readBits(innerHeader, 6);
|
|
913
|
-
} else if (innerHeader !== 0xff) {
|
|
914
|
-
let count = (innerHeader & 0x7f) + 7;
|
|
915
|
-
while (count > 8) {
|
|
916
|
-
readBits(readU8(), 8);
|
|
917
|
-
count -= 8;
|
|
918
|
-
}
|
|
919
|
-
readBits(readU8(), count);
|
|
920
|
-
} else {
|
|
921
|
-
let count = readU32();
|
|
922
|
-
while (count > 8) {
|
|
923
|
-
readBits(readU8(), 8);
|
|
924
|
-
count -= 8;
|
|
925
|
-
}
|
|
926
|
-
readBits(readU8(), count);
|
|
927
|
-
}
|
|
928
|
-
};
|
|
929
|
-
case STRING_HEADER:
|
|
930
|
-
return () => {
|
|
931
|
-
const len = readU32();
|
|
932
|
-
if (isInCurrentBuffer(len) && currentPosition + len < 0x7fffffff) {
|
|
933
|
-
result.push(
|
|
934
|
-
/** @type {Buffer} */
|
|
935
|
-
(currentBuffer).toString(
|
|
936
|
-
undefined,
|
|
937
|
-
currentPosition,
|
|
938
|
-
currentPosition + len
|
|
939
|
-
)
|
|
940
|
-
);
|
|
941
|
-
currentPosition += len;
|
|
942
|
-
checkOverflow();
|
|
943
|
-
} else {
|
|
944
|
-
result.push(read(len).toString());
|
|
945
|
-
}
|
|
946
|
-
};
|
|
947
|
-
case SHORT_STRING_HEADER:
|
|
948
|
-
return () => result.push("");
|
|
949
|
-
case SHORT_STRING_HEADER | 1:
|
|
950
|
-
return () => {
|
|
951
|
-
if (currentIsBuffer && currentPosition < 0x7ffffffe) {
|
|
952
|
-
result.push(
|
|
953
|
-
/** @type {Buffer} */
|
|
954
|
-
(currentBuffer).toString(
|
|
955
|
-
"latin1",
|
|
956
|
-
currentPosition,
|
|
957
|
-
currentPosition + 1
|
|
958
|
-
)
|
|
959
|
-
);
|
|
960
|
-
currentPosition++;
|
|
961
|
-
checkOverflow();
|
|
962
|
-
} else {
|
|
963
|
-
result.push(read(1).toString("latin1"));
|
|
964
|
-
}
|
|
965
|
-
};
|
|
966
|
-
case I8_HEADER:
|
|
967
|
-
return () => {
|
|
968
|
-
if (currentIsBuffer) {
|
|
969
|
-
result.push(
|
|
970
|
-
/** @type {Buffer} */ (currentBuffer).readInt8(currentPosition)
|
|
971
|
-
);
|
|
972
|
-
currentPosition++;
|
|
973
|
-
checkOverflow();
|
|
974
|
-
} else {
|
|
975
|
-
result.push(read(1).readInt8(0));
|
|
976
|
-
}
|
|
977
|
-
};
|
|
978
|
-
case BIGINT_I8_HEADER: {
|
|
979
|
-
const len = 1;
|
|
980
|
-
return () => {
|
|
981
|
-
const need = I8_SIZE * len;
|
|
982
|
-
|
|
983
|
-
if (isInCurrentBuffer(need)) {
|
|
984
|
-
for (let i = 0; i < len; i++) {
|
|
985
|
-
const value =
|
|
986
|
-
/** @type {Buffer} */
|
|
987
|
-
(currentBuffer).readInt8(currentPosition);
|
|
988
|
-
result.push(BigInt(value));
|
|
989
|
-
currentPosition += I8_SIZE;
|
|
990
|
-
}
|
|
991
|
-
checkOverflow();
|
|
992
|
-
} else {
|
|
993
|
-
const buf = read(need);
|
|
994
|
-
for (let i = 0; i < len; i++) {
|
|
995
|
-
const value = buf.readInt8(i * I8_SIZE);
|
|
996
|
-
result.push(BigInt(value));
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
};
|
|
1000
|
-
}
|
|
1001
|
-
case BIGINT_I32_HEADER: {
|
|
1002
|
-
const len = 1;
|
|
1003
|
-
return () => {
|
|
1004
|
-
const need = I32_SIZE * len;
|
|
1005
|
-
if (isInCurrentBuffer(need)) {
|
|
1006
|
-
for (let i = 0; i < len; i++) {
|
|
1007
|
-
const value = /** @type {Buffer} */ (currentBuffer).readInt32LE(
|
|
1008
|
-
currentPosition
|
|
1009
|
-
);
|
|
1010
|
-
result.push(BigInt(value));
|
|
1011
|
-
currentPosition += I32_SIZE;
|
|
1012
|
-
}
|
|
1013
|
-
checkOverflow();
|
|
1014
|
-
} else {
|
|
1015
|
-
const buf = read(need);
|
|
1016
|
-
for (let i = 0; i < len; i++) {
|
|
1017
|
-
const value = buf.readInt32LE(i * I32_SIZE);
|
|
1018
|
-
result.push(BigInt(value));
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
};
|
|
1022
|
-
}
|
|
1023
|
-
case BIGINT_HEADER: {
|
|
1024
|
-
return () => {
|
|
1025
|
-
const len = readU32();
|
|
1026
|
-
if (isInCurrentBuffer(len) && currentPosition + len < 0x7fffffff) {
|
|
1027
|
-
const value =
|
|
1028
|
-
/** @type {Buffer} */
|
|
1029
|
-
(currentBuffer).toString(
|
|
1030
|
-
undefined,
|
|
1031
|
-
currentPosition,
|
|
1032
|
-
currentPosition + len
|
|
1033
|
-
);
|
|
1034
|
-
|
|
1035
|
-
result.push(BigInt(value));
|
|
1036
|
-
currentPosition += len;
|
|
1037
|
-
checkOverflow();
|
|
1038
|
-
} else {
|
|
1039
|
-
const value = read(len).toString();
|
|
1040
|
-
result.push(BigInt(value));
|
|
1041
|
-
}
|
|
1042
|
-
};
|
|
1043
|
-
}
|
|
1044
|
-
default:
|
|
1045
|
-
if (header <= 10) {
|
|
1046
|
-
return () => result.push(header);
|
|
1047
|
-
} else if ((header & SHORT_STRING_HEADER) === SHORT_STRING_HEADER) {
|
|
1048
|
-
const len = header & SHORT_STRING_LENGTH_MASK;
|
|
1049
|
-
return () => {
|
|
1050
|
-
if (
|
|
1051
|
-
isInCurrentBuffer(len) &&
|
|
1052
|
-
currentPosition + len < 0x7fffffff
|
|
1053
|
-
) {
|
|
1054
|
-
result.push(
|
|
1055
|
-
/** @type {Buffer} */
|
|
1056
|
-
(currentBuffer).toString(
|
|
1057
|
-
"latin1",
|
|
1058
|
-
currentPosition,
|
|
1059
|
-
currentPosition + len
|
|
1060
|
-
)
|
|
1061
|
-
);
|
|
1062
|
-
currentPosition += len;
|
|
1063
|
-
checkOverflow();
|
|
1064
|
-
} else {
|
|
1065
|
-
result.push(read(len).toString("latin1"));
|
|
1066
|
-
}
|
|
1067
|
-
};
|
|
1068
|
-
} else if ((header & NUMBERS_HEADER_MASK) === F64_HEADER) {
|
|
1069
|
-
const len = (header & NUMBERS_COUNT_MASK) + 1;
|
|
1070
|
-
return () => {
|
|
1071
|
-
const need = F64_SIZE * len;
|
|
1072
|
-
if (isInCurrentBuffer(need)) {
|
|
1073
|
-
for (let i = 0; i < len; i++) {
|
|
1074
|
-
result.push(
|
|
1075
|
-
/** @type {Buffer} */ (currentBuffer).readDoubleLE(
|
|
1076
|
-
currentPosition
|
|
1077
|
-
)
|
|
1078
|
-
);
|
|
1079
|
-
currentPosition += F64_SIZE;
|
|
1080
|
-
}
|
|
1081
|
-
checkOverflow();
|
|
1082
|
-
} else {
|
|
1083
|
-
const buf = read(need);
|
|
1084
|
-
for (let i = 0; i < len; i++) {
|
|
1085
|
-
result.push(buf.readDoubleLE(i * F64_SIZE));
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
};
|
|
1089
|
-
} else if ((header & NUMBERS_HEADER_MASK) === I32_HEADER) {
|
|
1090
|
-
const len = (header & NUMBERS_COUNT_MASK) + 1;
|
|
1091
|
-
return () => {
|
|
1092
|
-
const need = I32_SIZE * len;
|
|
1093
|
-
if (isInCurrentBuffer(need)) {
|
|
1094
|
-
for (let i = 0; i < len; i++) {
|
|
1095
|
-
result.push(
|
|
1096
|
-
/** @type {Buffer} */ (currentBuffer).readInt32LE(
|
|
1097
|
-
currentPosition
|
|
1098
|
-
)
|
|
1099
|
-
);
|
|
1100
|
-
currentPosition += I32_SIZE;
|
|
1101
|
-
}
|
|
1102
|
-
checkOverflow();
|
|
1103
|
-
} else {
|
|
1104
|
-
const buf = read(need);
|
|
1105
|
-
for (let i = 0; i < len; i++) {
|
|
1106
|
-
result.push(buf.readInt32LE(i * I32_SIZE));
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
};
|
|
1110
|
-
} else if ((header & NUMBERS_HEADER_MASK) === I8_HEADER) {
|
|
1111
|
-
const len = (header & NUMBERS_COUNT_MASK) + 1;
|
|
1112
|
-
return () => {
|
|
1113
|
-
const need = I8_SIZE * len;
|
|
1114
|
-
if (isInCurrentBuffer(need)) {
|
|
1115
|
-
for (let i = 0; i < len; i++) {
|
|
1116
|
-
result.push(
|
|
1117
|
-
/** @type {Buffer} */ (currentBuffer).readInt8(
|
|
1118
|
-
currentPosition
|
|
1119
|
-
)
|
|
1120
|
-
);
|
|
1121
|
-
currentPosition += I8_SIZE;
|
|
1122
|
-
}
|
|
1123
|
-
checkOverflow();
|
|
1124
|
-
} else {
|
|
1125
|
-
const buf = read(need);
|
|
1126
|
-
for (let i = 0; i < len; i++) {
|
|
1127
|
-
result.push(buf.readInt8(i * I8_SIZE));
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
};
|
|
1131
|
-
}
|
|
1132
|
-
return () => {
|
|
1133
|
-
throw new Error(`Unexpected header byte 0x${header.toString(16)}`);
|
|
1134
|
-
};
|
|
1135
|
-
}
|
|
1136
|
-
});
|
|
1137
|
-
|
|
1138
|
-
/** @type {DeserializedType} */
|
|
1139
|
-
let result = [];
|
|
1140
|
-
while (currentBuffer !== null) {
|
|
1141
|
-
if (typeof currentBuffer === "function") {
|
|
1142
|
-
result.push(this._deserializeLazy(currentBuffer, context));
|
|
1143
|
-
currentDataItem++;
|
|
1144
|
-
currentBuffer =
|
|
1145
|
-
currentDataItem < data.length ? data[currentDataItem] : null;
|
|
1146
|
-
currentIsBuffer = Buffer.isBuffer(currentBuffer);
|
|
1237
|
+
const state = new ReadState(data, context, this);
|
|
1238
|
+
while (state.currentBuffer !== null) {
|
|
1239
|
+
if (typeof state.currentBuffer === "function") {
|
|
1240
|
+
state.result.push(this._deserializeLazy(state.currentBuffer, context));
|
|
1241
|
+
state.nextDataItem();
|
|
1147
1242
|
} else {
|
|
1148
|
-
|
|
1149
|
-
dispatchTable[header]();
|
|
1243
|
+
dispatchTable[state.readU8()](state);
|
|
1150
1244
|
}
|
|
1151
1245
|
}
|
|
1152
|
-
|
|
1153
|
-
// avoid leaking memory in context
|
|
1154
|
-
// eslint-disable-next-line prefer-const
|
|
1155
|
-
let _result = result;
|
|
1156
|
-
result = /** @type {EXPECTED_ANY} */ (undefined);
|
|
1157
|
-
return _result;
|
|
1246
|
+
return state.result;
|
|
1158
1247
|
}
|
|
1159
1248
|
}
|
|
1160
1249
|
|