webpack 5.112.0 → 5.112.2
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/bin/webpack.js +13 -7
- package/lib/Compilation.js +198 -61
- package/lib/Compiler.js +12 -25
- package/lib/asset/AssetBytesGenerator.js +14 -6
- package/lib/asset/AssetBytesParser.js +10 -8
- package/lib/asset/AssetGenerator.js +36 -48
- package/lib/asset/AssetModule.js +11 -0
- package/lib/asset/AssetModulesPlugin.js +5 -4
- package/lib/asset/AssetParser.js +8 -8
- package/lib/asset/AssetSourceGenerator.js +16 -8
- package/lib/asset/AssetSourceParser.js +10 -8
- package/lib/asset/WebManifestGenerator.js +11 -6
- package/lib/asset/WebManifestParser.js +3 -3
- package/lib/async-modules/AsyncModuleHelpers.js +8 -2
- package/lib/async-modules/InferAsyncModulesPlugin.js +7 -2
- package/lib/cache/CacheFacade.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +6 -10
- package/lib/cache/ResolverCachePlugin.js +58 -8
- package/lib/config/WebpackOptionsApply.js +8 -28
- package/lib/config/cli.js +9 -6
- package/lib/config/defaults.js +24 -13
- package/lib/config/getClaimedAssetTypes.js +2 -2
- package/lib/config/target.js +1 -1
- package/lib/context/ContextModule.js +1 -1
- package/lib/context/ContextModuleFactory.js +1 -1
- package/lib/context/ContextReplacementPlugin.js +3 -9
- package/lib/css/CssGenerator.js +40 -47
- package/lib/css/CssModule.js +10 -0
- package/lib/css/CssModulesPlugin.js +13 -6
- package/lib/css/CssParser.js +33 -32
- package/lib/css/conventions.js +1 -1
- package/lib/css/data.js +224 -219
- package/lib/css/syntax-parser.js +1312 -312
- package/lib/css/syntax-printer.js +1142 -1025
- package/lib/debug/ProfilingPlugin.js +65 -43
- package/lib/define/DefinePlugin.js +10 -15
- package/lib/define/DotenvPlugin.js +10 -6
- package/lib/define/EnvironmentPlugin.js +4 -2
- package/lib/dependencies/amd/AMDDefineDependencyParserPlugin.js +1 -2
- package/lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/commonjs/CommonJsExportRequireDependency.js +1 -4
- package/lib/dependencies/commonjs/CommonJsExportsParserPlugin.js +18 -33
- package/lib/dependencies/commonjs/CommonJsImportsParserPlugin.js +1 -3
- package/lib/dependencies/commonjs/CommonJsObjectExportDependency.js +4 -4
- package/lib/dependencies/commonjs/CommonJsPlugin.js +2 -5
- package/lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js +1 -2
- package/lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js +4 -7
- package/lib/dependencies/context/ImportMetaGlobHelpers.js +8 -10
- package/lib/dependencies/core/CachedConstDependency.js +9 -6
- package/lib/dependencies/css/CssIcssExportDependency.js +6 -7
- package/lib/dependencies/css/CssIcssImportDependency.js +1 -3
- package/lib/dependencies/css/CssUrlDependency.js +2 -6
- package/lib/dependencies/esm/ESMDetectionParserPlugin.js +2 -4
- package/lib/dependencies/esm/ESMExportExpressionDependency.js +2 -2
- package/lib/dependencies/esm/ESMExportImportedSpecifierDependency.js +16 -18
- package/lib/dependencies/esm/ESMExportSpecifierDependency.js +20 -3
- package/lib/dependencies/esm/ESMExports.js +2 -10
- package/lib/dependencies/esm/ESMImportDependency.js +17 -2
- package/lib/dependencies/esm/ESMImportDependencyParserPlugin.js +6 -17
- package/lib/dependencies/esm/ESMImportGuard.js +11 -23
- package/lib/dependencies/esm/ESMImportSideEffectDependency.js +1 -1
- package/lib/dependencies/esm/ESMImportSpecifierDependency.js +4 -1
- package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
- package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
- package/lib/dependencies/esm/ESMModulesPlugin.js +1 -3
- package/lib/dependencies/esm/TopLevelAwaitDependency.js +1 -8
- package/lib/dependencies/helpers/DynamicExports.js +4 -6
- package/lib/dependencies/html/HtmlEntryDependency.js +5 -14
- package/lib/dependencies/html/HtmlInlineHtmlDependency.js +1 -4
- package/lib/dependencies/html/HtmlInlineScriptDependency.js +2 -6
- package/lib/dependencies/html/HtmlInlineStyleDependency.js +1 -4
- package/lib/dependencies/import/ImportParserPlugin.js +3 -6
- package/lib/dependencies/import-meta/ImportMetaPlugin.js +4 -6
- package/lib/dependencies/url/URLParserPlugin.js +1 -1
- package/lib/dependencies/worker/WorkerAndWorkletPlugin.js +51 -20
- package/lib/devtool/ModuleFilenameHelpers.js +1 -1
- package/lib/devtool/SourceMapDevToolPlugin.js +1 -1
- package/lib/dll/DelegatedModule.js +3 -3
- package/lib/dll/DllModule.js +3 -1
- package/lib/dll/DllReferencePlugin.js +1 -4
- package/lib/errors/AbstractMethodError.js +1 -1
- package/lib/errors/ErrorHelpers.js +2 -1
- package/lib/errors/HookWebpackError.js +2 -1
- package/lib/errors/JSONParseError.js +4 -4
- package/lib/errors/WebpackError.js +3 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +36 -1
- package/lib/externals/ExternalModule.js +12 -9
- package/lib/externals/ExternalModuleFactoryPlugin.js +1 -2
- package/lib/externals/ExternalsPlugin.js +1 -1
- package/lib/fs/FileSystemInfo.js +4 -4
- package/lib/graph/AsyncDependenciesBlock.js +1 -1
- package/lib/graph/ChunkGraph.js +5 -0
- package/lib/graph/Dependency.js +8 -2
- package/lib/graph/ExportsInfo.js +1 -1
- package/lib/graph/ModuleGraph.js +14 -3
- package/lib/graph/buildChunkGraph.js +17 -19
- package/lib/graph/findGraphRoots.js +1 -1
- package/lib/hmr/HotModuleReplacement.runtime.js +10 -9
- package/lib/hmr/HotModuleReplacementPlugin.js +5 -11
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +16 -19
- package/lib/hmr/LazyCompilationPlugin.js +1 -7
- package/lib/html/HtmlGenerator.js +25 -17
- package/lib/html/HtmlModule.js +11 -1
- package/lib/html/HtmlModulesPlugin.js +12 -11
- package/lib/html/HtmlParser.js +10 -9
- package/lib/html/builtinEmbeddedRenderer.js +31 -33
- package/lib/html/data.js +42 -21
- package/lib/html/htmlMinify.js +4 -1
- package/lib/html/syntax-parser.js +34 -35
- package/lib/html/syntax-printer.js +2 -3
- package/lib/html/xmlMinify.js +4 -1
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -12
- package/lib/javascript/APIPlugin.js +7 -13
- package/lib/javascript/BasicEvaluatedExpression.js +5 -5
- package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -7
- package/lib/javascript/ConstPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +16 -11
- package/lib/javascript/JavascriptMetaInfoPlugin.js +3 -15
- package/lib/javascript/JavascriptModule.js +10 -0
- package/lib/javascript/JavascriptModulesPlugin.js +2 -4
- package/lib/javascript/JavascriptParser.js +99 -11
- package/lib/javascript/ScopeAnalyzer.js +183 -107
- package/lib/javascript/UseStrictPlugin.js +2 -5
- package/lib/javascript/jsMinify.js +1 -1
- package/lib/javascript/regexp.js +2 -2
- package/lib/javascript/syntax-parser.js +2114 -1506
- package/lib/javascript/syntax-printer-data.js +167 -1
- package/lib/javascript/syntax-printer.js +9554 -2782
- package/lib/json/JsonGenerator.js +15 -7
- package/lib/json/JsonModule.js +11 -0
- package/lib/json/JsonParser.js +7 -6
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +399 -23
- package/lib/loaders/LoaderRunner.js +76 -38
- package/lib/loaders/loadLoader.js +16 -10
- package/lib/module/Generator.js +17 -9
- package/lib/module/Module.js +2 -2
- package/lib/module/NormalModule.js +7 -5
- package/lib/module/NormalModuleFactory.js +11 -17
- package/lib/module/Parser.js +9 -2
- package/lib/module/extractSourceMap.js +69 -18
- package/lib/module/findCaseMismatch.js +2 -2
- package/lib/node/ExternalModuleInitFragment.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -12
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -6
- package/lib/node/nodeConsole.js +4 -3
- package/lib/optimize/CircularModulesPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +4 -8
- package/lib/optimize/FlagDependencyExportsPlugin.js +6 -11
- package/lib/optimize/FlagDependencyUsagePlugin.js +28 -3
- package/lib/optimize/InlineExports.js +4 -7
- package/lib/optimize/LazyBarrels.js +41 -5
- package/lib/optimize/ModuleConcatenationPlugin.js +8 -10
- package/lib/optimize/RealContentHashPlugin.js +2 -6
- package/lib/optimize/SideEffectsFlagPlugin.js +7 -21
- package/lib/optimize/SplitChunksPlugin.js +11 -24
- package/lib/optimize/TupleQueue.js +1 -1
- package/lib/output/CleanPlugin.js +3 -1
- package/lib/output/CopyPlugin.js +3 -4
- package/lib/performance/EvalUsagePlugin.js +1 -3
- package/lib/performance/HotspotsPlugin.js +33 -9
- package/lib/performance/PureAnnotationsPlugin.js +16 -10
- package/lib/performance/TopLevelThisPlugin.js +17 -9
- package/lib/prefetch/ResourceHintPlugin.js +1 -1
- package/lib/provide/ProvidedDependency.js +36 -4
- package/lib/rules/BasicEffectRulePlugin.js +1 -1
- package/lib/rules/RuleSetCompiler.js +15 -5
- package/lib/rules/UseEffectRulePlugin.js +1 -3
- package/lib/runtime/AsyncModuleRuntimeModule.js +7 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -5
- package/lib/runtime/RuntimeGlobals.js +6 -0
- package/lib/runtime/RuntimePlugin.js +2 -0
- package/lib/schemes/HttpUriPlugin.js +1 -2
- package/lib/schemes/VirtualUrlPlugin.js +3 -1
- package/lib/serialization/AggregateErrorSerializer.js +3 -3
- package/lib/serialization/BinaryMiddleware.js +4 -1
- package/lib/serialization/ErrorObjectSerializer.js +2 -5
- package/lib/serialization/ObjectMiddleware.js +17 -15
- package/lib/serialization/PlainObjectSerializer.js +3 -7
- package/lib/serialization/Serializer.js +21 -11
- package/lib/serialization/SerializerMiddleware.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +35 -35
- package/lib/stats/DefaultStatsPresetPlugin.js +2 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +12 -11
- package/lib/stats/StatsFactory.js +194 -24
- package/lib/stats/StatsPrinter.js +126 -13
- package/lib/template/DependencyTemplate.js +1 -1
- package/lib/template/RuntimeTemplate.js +13 -32
- package/lib/template/Template.js +1 -1
- package/lib/util/SourceProcessor.js +146 -29
- package/lib/util/WeakTupleMap.js +10 -4
- package/lib/util/cleverMerge.js +61 -33
- package/lib/util/comparators.js +9 -5
- package/lib/util/dataURL.js +2 -0
- package/lib/util/deprecation.js +4 -3
- package/lib/util/globUtils.js +1 -4
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/makeSerializable.js +6 -4
- package/lib/util/memoize.js +1 -1
- package/lib/util/parseJson.js +2 -2
- package/lib/util/serialization.js +31 -27
- package/lib/wasm/AsyncWasmModule.js +12 -2
- package/lib/wasm/AsyncWebAssemblyGenerator.js +12 -4
- package/lib/wasm/AsyncWebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm/AsyncWebAssemblyParser.js +7 -5
- package/lib/wasm/UniversalCompileAsyncWasmPlugin.js +2 -6
- package/lib/wasm-sync/SyncWasmModule.js +16 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +15 -10
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm-sync/WebAssemblyParser.js +10 -12
- package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -12
- package/lib/web/FetchCompileWasmPlugin.js +2 -6
- package/package.json +18 -19
- package/schemas/WebpackOptions.check.js +3 -3
- package/schemas/WebpackOptions.json +2 -2
- package/schemas/plugins/BannerPlugin.check.js +3 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +3 -3
- package/schemas/plugins/HtmlParserOptions.check.js +3 -3
- package/schemas/plugins/IgnorePlugin.check.js +3 -3
- package/schemas/plugins/LoaderOptionsPlugin.check.js +3 -3
- package/schemas/plugins/ManifestPlugin.check.js +3 -3
- package/schemas/plugins/ProgressPlugin.check.js +3 -3
- package/schemas/plugins/SSRManifestPlugin.check.js +3 -3
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +3 -3
- package/schemas/plugins/WatchIgnorePlugin.check.js +3 -3
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetParserOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +3 -3
- package/schemas/plugins/container/ContainerPlugin.check.js +3 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +3 -3
- package/schemas/plugins/container/ExternalsType.check.js +3 -3
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +3 -3
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssParserOptions.check.js +3 -3
- package/schemas/plugins/debug/ProfilingPlugin.check.js +3 -3
- package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
- package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
- package/schemas/plugins/dll/DllPlugin.check.js +3 -3
- package/schemas/plugins/dll/DllReferencePlugin.check.js +3 -3
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +3 -3
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +3 -3
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +3 -3
- package/schemas/plugins/output/CleanOptions.check.js +7 -0
- package/schemas/plugins/output/CleanOptions.json +3 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +3 -3
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/SharePlugin.check.js +3 -3
- package/types.d.ts +1482 -358
package/lib/util/cleverMerge.js
CHANGED
|
@@ -88,19 +88,27 @@ const cachedSetProperty = (obj, property, value) => {
|
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* Defines the by values type used by this module.
|
|
91
|
-
* @
|
|
91
|
+
* @template V
|
|
92
|
+
* @typedef {Map<string, V>} ByValues
|
|
92
93
|
*/
|
|
93
94
|
|
|
94
95
|
/**
|
|
95
96
|
* Defines the object parsed property entry type used by this module.
|
|
96
97
|
* @template T
|
|
98
|
+
* @template [V=T[keyof T]]
|
|
97
99
|
* @typedef {object} ObjectParsedPropertyEntry
|
|
98
|
-
* @property {
|
|
100
|
+
* @property {V | undefined} base base value
|
|
99
101
|
* @property {`by${string}` | undefined} byProperty the name of the selector property
|
|
100
|
-
* @property {ByValues | undefined} byValues value depending on selector property, merged with base
|
|
102
|
+
* @property {ByValues<V | undefined> | undefined} byValues value depending on selector property, merged with base
|
|
101
103
|
*/
|
|
102
104
|
|
|
103
|
-
/**
|
|
105
|
+
/**
|
|
106
|
+
* Result of merging a value of type `A` with a value of type `B`.
|
|
107
|
+
* @template A, B
|
|
108
|
+
* @typedef {A & B | (A | B)[] | A | A[] | B | B[]} MergedValue
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/** @typedef {((...values: never[]) => object) & { [DYNAMIC_INFO]: [DynamicFunction, object] }} DynamicFunction */
|
|
104
112
|
|
|
105
113
|
/**
|
|
106
114
|
* Defines the parsed object static type used by this module.
|
|
@@ -139,7 +147,11 @@ const cachedParseObject = (obj) => {
|
|
|
139
147
|
return result;
|
|
140
148
|
};
|
|
141
149
|
|
|
142
|
-
/**
|
|
150
|
+
/**
|
|
151
|
+
* Defines the by object type used by this module.
|
|
152
|
+
* @template T
|
|
153
|
+
* @typedef {{ [p: string]: Partial<T> } | DynamicFunction} ByObject
|
|
154
|
+
*/
|
|
143
155
|
|
|
144
156
|
/**
|
|
145
157
|
* Returns parsed object.
|
|
@@ -172,7 +184,7 @@ const parseObject = (obj) => {
|
|
|
172
184
|
const key = /** @type {keyof T} */ (key_);
|
|
173
185
|
if (typeof key === "string" && key.startsWith("by")) {
|
|
174
186
|
const byProperty = key;
|
|
175
|
-
const byObj = /** @type {ByObject} */ (obj[byProperty]);
|
|
187
|
+
const byObj = /** @type {ByObject<T>} */ (obj[byProperty]);
|
|
176
188
|
if (typeof byObj === "object") {
|
|
177
189
|
for (const byValue of Object.keys(byObj)) {
|
|
178
190
|
const obj = byObj[/** @type {keyof (keyof T)} */ (byValue)];
|
|
@@ -183,20 +195,20 @@ const parseObject = (obj) => {
|
|
|
183
195
|
entry.byValues = new Map();
|
|
184
196
|
} else if (entry.byProperty !== byProperty) {
|
|
185
197
|
throw new Error(
|
|
186
|
-
`${
|
|
198
|
+
`${byProperty} and ${entry.byProperty} for a single property is not supported`
|
|
187
199
|
);
|
|
188
200
|
}
|
|
189
|
-
/** @type {ByValues} */
|
|
190
|
-
(entry.byValues).set(byValue, obj[key]);
|
|
201
|
+
/** @type {ByValues<T[keyof T] | undefined>} */
|
|
202
|
+
(entry.byValues).set(byValue, obj[/** @type {keyof T} */ (key)]);
|
|
191
203
|
if (byValue === "default") {
|
|
192
204
|
for (const otherByValue of Object.keys(byObj)) {
|
|
193
205
|
if (
|
|
194
206
|
!(
|
|
195
|
-
/** @type {ByValues} */
|
|
207
|
+
/** @type {ByValues<T[keyof T] | undefined>} */
|
|
196
208
|
(entry.byValues).has(otherByValue)
|
|
197
209
|
)
|
|
198
210
|
) {
|
|
199
|
-
/** @type {ByValues} */
|
|
211
|
+
/** @type {ByValues<T[keyof T] | undefined>} */
|
|
200
212
|
(entry.byValues).set(otherByValue, undefined);
|
|
201
213
|
}
|
|
202
214
|
}
|
|
@@ -237,13 +249,19 @@ const parseObject = (obj) => {
|
|
|
237
249
|
* @returns {T} the object
|
|
238
250
|
*/
|
|
239
251
|
const serializeObject = (info, dynamicInfo) => {
|
|
240
|
-
const obj =
|
|
252
|
+
const obj =
|
|
253
|
+
/** @type {Record<PropertyKey, T[keyof T] | Record<string, Record<PropertyKey, T[keyof T]>> | DynamicFunction>} */
|
|
254
|
+
({});
|
|
241
255
|
// Setup byProperty structure
|
|
242
256
|
for (const entry of info.values()) {
|
|
243
257
|
if (entry.byProperty !== undefined) {
|
|
244
258
|
const byProperty = entry.byProperty;
|
|
245
|
-
const byObj =
|
|
246
|
-
|
|
259
|
+
const byObj =
|
|
260
|
+
/** @type {Record<string, Record<PropertyKey, T[keyof T]>>} */
|
|
261
|
+
(obj[byProperty] = obj[byProperty] || {});
|
|
262
|
+
for (const byValue of /** @type {ByValues<T[keyof T] | undefined>} */ (
|
|
263
|
+
entry.byValues
|
|
264
|
+
).keys()) {
|
|
247
265
|
byObj[byValue] = byObj[byValue] || {};
|
|
248
266
|
}
|
|
249
267
|
}
|
|
@@ -255,10 +273,12 @@ const serializeObject = (info, dynamicInfo) => {
|
|
|
255
273
|
// Fill byProperty structure
|
|
256
274
|
if (entry.byProperty !== undefined) {
|
|
257
275
|
const byProperty = entry.byProperty;
|
|
258
|
-
const byObj =
|
|
276
|
+
const byObj =
|
|
277
|
+
/** @type {Record<string, Record<PropertyKey, T[keyof T]>>} */
|
|
278
|
+
(obj[byProperty] = obj[byProperty] || {});
|
|
259
279
|
for (const byValue of Object.keys(byObj)) {
|
|
260
280
|
const value = getFromByValues(
|
|
261
|
-
/** @type {ByValues} */
|
|
281
|
+
/** @type {ByValues<T[keyof T] | undefined>} */
|
|
262
282
|
(entry.byValues),
|
|
263
283
|
byValue
|
|
264
284
|
);
|
|
@@ -269,7 +289,7 @@ const serializeObject = (info, dynamicInfo) => {
|
|
|
269
289
|
if (dynamicInfo !== undefined) {
|
|
270
290
|
obj[dynamicInfo.byProperty] = dynamicInfo.fn;
|
|
271
291
|
}
|
|
272
|
-
return obj;
|
|
292
|
+
return /** @type {T} */ (obj);
|
|
273
293
|
};
|
|
274
294
|
|
|
275
295
|
const VALUE_TYPE_UNDEFINED = 0;
|
|
@@ -395,7 +415,7 @@ const _cleverMerge = (first, second, internalCaching = false) => {
|
|
|
395
415
|
* @param {ObjectParsedPropertyEntry<T>} firstEntry a
|
|
396
416
|
* @param {ObjectParsedPropertyEntry<O>} secondEntry b
|
|
397
417
|
* @param {boolean} internalCaching should parsing of objects and nested merges be cached
|
|
398
|
-
* @returns {ObjectParsedPropertyEntry<T> | ObjectParsedPropertyEntry<O> | ObjectParsedPropertyEntry<T & O
|
|
418
|
+
* @returns {ObjectParsedPropertyEntry<T> | ObjectParsedPropertyEntry<O> | ObjectParsedPropertyEntry<T & O, MergedValue<T[keyof T] | undefined, O[keyof O] | undefined>>} new entry
|
|
399
419
|
*/
|
|
400
420
|
const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
401
421
|
switch (getValueType(secondEntry.base)) {
|
|
@@ -420,13 +440,16 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
420
440
|
} else {
|
|
421
441
|
// = first.base + (first.byProperty + second.byProperty)
|
|
422
442
|
// need to merge first and second byValues
|
|
423
|
-
/** @type {
|
|
443
|
+
/** @type {ByValues<MergedValue<T[keyof T] | undefined, O[keyof O] | undefined>>} */
|
|
424
444
|
const newByValues = new Map(firstEntry.byValues);
|
|
425
|
-
for (const [
|
|
445
|
+
for (const [
|
|
446
|
+
key,
|
|
447
|
+
value
|
|
448
|
+
] of /** @type {ByValues<O[keyof O] | undefined>} */ (
|
|
426
449
|
secondEntry.byValues
|
|
427
450
|
)) {
|
|
428
451
|
const firstValue = getFromByValues(
|
|
429
|
-
/** @type {ByValues} */
|
|
452
|
+
/** @type {ByValues<T[keyof T] | undefined>} */
|
|
430
453
|
(firstEntry.byValues),
|
|
431
454
|
key
|
|
432
455
|
);
|
|
@@ -461,7 +484,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
461
484
|
}
|
|
462
485
|
/** @type {O[keyof O] | T[keyof T] | (T[keyof T] & O[keyof O]) | (T[keyof T] | undefined)[] | (O[keyof O] | undefined)[] | (O[keyof O] | T[keyof T] | undefined)[] | undefined} */
|
|
463
486
|
let newBase;
|
|
464
|
-
/** @type {
|
|
487
|
+
/** @type {ByValues<MergedValue<T[keyof T] | undefined, O[keyof O] | undefined>>} */
|
|
465
488
|
const intermediateByValues = new Map(firstEntry.byValues);
|
|
466
489
|
for (const [key, value] of intermediateByValues) {
|
|
467
490
|
intermediateByValues.set(
|
|
@@ -470,12 +493,14 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
470
493
|
);
|
|
471
494
|
}
|
|
472
495
|
if (
|
|
473
|
-
[
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
496
|
+
[
|
|
497
|
+
.../** @type {ByValues<T[keyof T] | undefined>} */ (
|
|
498
|
+
firstEntry.byValues
|
|
499
|
+
).values()
|
|
500
|
+
].every((value) => {
|
|
501
|
+
const type = getValueType(value);
|
|
502
|
+
return type === VALUE_TYPE_ATOM || type === VALUE_TYPE_DELETE;
|
|
503
|
+
})
|
|
479
504
|
) {
|
|
480
505
|
// = (first.base + second.base) + ((first.byProperty + second.base) + second.byProperty)
|
|
481
506
|
newBase = mergeSingleValue(
|
|
@@ -502,9 +527,12 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
502
527
|
`${firstEntry.byProperty} and ${secondEntry.byProperty} for a single property is not supported`
|
|
503
528
|
);
|
|
504
529
|
}
|
|
505
|
-
/** @type {
|
|
530
|
+
/** @type {ByValues<MergedValue<T[keyof T] | undefined, O[keyof O] | undefined>>} */
|
|
506
531
|
const newByValues = new Map(intermediateByValues);
|
|
507
|
-
for (const [
|
|
532
|
+
for (const [
|
|
533
|
+
key,
|
|
534
|
+
value
|
|
535
|
+
] of /** @type {ByValues<O[keyof O] | undefined>} */ (
|
|
508
536
|
secondEntry.byValues
|
|
509
537
|
)) {
|
|
510
538
|
const firstValue = getFromByValues(intermediateByValues, key);
|
|
@@ -525,7 +553,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
525
553
|
/**
|
|
526
554
|
* Gets from by values.
|
|
527
555
|
* @template V
|
|
528
|
-
* @param {ByValues} byValues all values
|
|
556
|
+
* @param {ByValues<V>} byValues all values
|
|
529
557
|
* @param {string} key value of the selector
|
|
530
558
|
* @returns {V | undefined} value
|
|
531
559
|
*/
|
|
@@ -543,7 +571,7 @@ const getFromByValues = (byValues, key) => {
|
|
|
543
571
|
* @param {A | A[]} a value
|
|
544
572
|
* @param {B | B[]} b value
|
|
545
573
|
* @param {boolean} internalCaching should parsing of objects and nested merges be cached
|
|
546
|
-
* @returns {A
|
|
574
|
+
* @returns {MergedValue<A, B>} value
|
|
547
575
|
*/
|
|
548
576
|
const mergeSingleValue = (a, b, internalCaching) => {
|
|
549
577
|
const bType = getValueType(b);
|
|
@@ -635,7 +663,7 @@ const removeOperations = (obj, keysToKeepOriginalValue = []) => {
|
|
|
635
663
|
newObj[key] =
|
|
636
664
|
/** @type {T[keyof T]} */
|
|
637
665
|
(
|
|
638
|
-
/** @type {
|
|
666
|
+
/** @type {T[keyof T] extends readonly (infer E)[] ? E[] : never} */
|
|
639
667
|
(value).filter((i) => i !== "...")
|
|
640
668
|
);
|
|
641
669
|
break;
|
package/lib/util/comparators.js
CHANGED
|
@@ -93,7 +93,9 @@ const compareIds = (a, b) => {
|
|
|
93
93
|
*/
|
|
94
94
|
const compareIterables = (elementComparator) => {
|
|
95
95
|
const cacheEntry = compareIteratorsCache.get(elementComparator);
|
|
96
|
-
if (cacheEntry !== undefined)
|
|
96
|
+
if (cacheEntry !== undefined) {
|
|
97
|
+
return /** @type {Comparator<Iterable<T>>} */ (cacheEntry);
|
|
98
|
+
}
|
|
97
99
|
/**
|
|
98
100
|
* Returns compare result.
|
|
99
101
|
* @param {Iterable<T>} a first value
|
|
@@ -419,7 +421,7 @@ class TwoKeyWeakMap {
|
|
|
419
421
|
}
|
|
420
422
|
}
|
|
421
423
|
|
|
422
|
-
/** @type {TwoKeyWeakMap<Comparator<
|
|
424
|
+
/** @type {TwoKeyWeakMap<Comparator<never>, Comparator<never>, Comparator<never>>} */
|
|
423
425
|
const concatComparatorsCache = new TwoKeyWeakMap();
|
|
424
426
|
|
|
425
427
|
/**
|
|
@@ -460,7 +462,7 @@ const concatComparators = (c1, c2, ...cRest) => {
|
|
|
460
462
|
* @typedef {(input: A) => B | undefined | null} Selector
|
|
461
463
|
*/
|
|
462
464
|
|
|
463
|
-
/** @type {TwoKeyWeakMap<
|
|
465
|
+
/** @type {TwoKeyWeakMap<(input: never) => void, Comparator<never>, Comparator<never>>} */
|
|
464
466
|
const compareSelectCache = new TwoKeyWeakMap();
|
|
465
467
|
|
|
466
468
|
/**
|
|
@@ -473,7 +475,9 @@ const compareSelectCache = new TwoKeyWeakMap();
|
|
|
473
475
|
*/
|
|
474
476
|
const compareSelect = (getter, comparator) => {
|
|
475
477
|
const cacheEntry = compareSelectCache.get(getter, comparator);
|
|
476
|
-
if (cacheEntry !== undefined)
|
|
478
|
+
if (cacheEntry !== undefined) {
|
|
479
|
+
return /** @type {Comparator<T>} */ (cacheEntry);
|
|
480
|
+
}
|
|
477
481
|
/**
|
|
478
482
|
* Returns compare result.
|
|
479
483
|
* @param {T} a first value
|
|
@@ -530,7 +534,7 @@ const compareErrors = concatComparators(
|
|
|
530
534
|
)
|
|
531
535
|
);
|
|
532
536
|
|
|
533
|
-
/** @type {WeakMap<Comparator<
|
|
537
|
+
/** @type {WeakMap<Comparator<never>, Comparator<Iterable<never>>>} */
|
|
534
538
|
const compareIteratorsCache = new WeakMap();
|
|
535
539
|
|
|
536
540
|
// TODO this is no longer needed when minimum node.js version is >= 12
|
package/lib/util/dataURL.js
CHANGED
package/lib/util/deprecation.js
CHANGED
|
@@ -96,7 +96,7 @@ module.exports.arrayToSetDeprecation = (set, name) => {
|
|
|
96
96
|
`${name} was changed from Array to Set (using Array method '${method}' is deprecated)`,
|
|
97
97
|
"ARRAY_TO_SET"
|
|
98
98
|
);
|
|
99
|
-
/** @type {
|
|
99
|
+
/** @type {Set<T> & Record<COPY_METHODS_NAMES, (this: Set<T>) => void>} */
|
|
100
100
|
(set)[method] =
|
|
101
101
|
// eslint-disable-next-line func-names
|
|
102
102
|
function () {
|
|
@@ -318,10 +318,11 @@ module.exports.soonFrozenObjectDeprecation = (obj, name, code, note = "") => {
|
|
|
318
318
|
set: util.deprecate(
|
|
319
319
|
/**
|
|
320
320
|
* Handles the callback logic for this hook.
|
|
321
|
+
* @template V
|
|
321
322
|
* @param {object} target target
|
|
322
323
|
* @param {string | symbol} property property
|
|
323
|
-
* @param {
|
|
324
|
-
* @param {
|
|
324
|
+
* @param {V} value value
|
|
325
|
+
* @param {T} receiver receiver
|
|
325
326
|
* @returns {boolean} result
|
|
326
327
|
*/
|
|
327
328
|
(target, property, value, receiver) =>
|
package/lib/util/globUtils.js
CHANGED
|
@@ -15,10 +15,7 @@ const memoize = require("./memoize");
|
|
|
15
15
|
|
|
16
16
|
// watchpack's glob-to-regexp core, loaded only when a glob is translated
|
|
17
17
|
const getGlobToRegExpSource = memoize(
|
|
18
|
-
() =>
|
|
19
|
-
/** @type {{ util: { globToRegExp: (glob: string) => string } }} */ (
|
|
20
|
-
/** @type {unknown} */ (require("watchpack"))
|
|
21
|
-
).util.globToRegExp
|
|
18
|
+
() => require("watchpack").util.globToRegExp
|
|
22
19
|
);
|
|
23
20
|
|
|
24
21
|
/** @typedef {{ caseSensitive?: boolean, requireLiteralLeadingDot?: boolean }} GlobMatchOptions */
|
|
@@ -315,6 +315,8 @@ module.exports = {
|
|
|
315
315
|
require("../dependencies/esm/ESMImportSideEffectDependency"),
|
|
316
316
|
"dependencies/esm/ESMImportSpecifierDependency": () =>
|
|
317
317
|
require("../dependencies/esm/ESMImportSpecifierDependency"),
|
|
318
|
+
"dependencies/esm/ESMLiveExportDependency": () =>
|
|
319
|
+
require("../dependencies/esm/ESMLiveExportDependency"),
|
|
318
320
|
"dependencies/esm/TopLevelAwaitDependency": () =>
|
|
319
321
|
require("../dependencies/esm/TopLevelAwaitDependency"),
|
|
320
322
|
"dependencies/hmr/ImportMetaHotAcceptDependency": () =>
|
|
@@ -8,7 +8,6 @@ const { register, registerLegacyRequest } = require("./serialization");
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @import {
|
|
11
|
-
* Constructor,
|
|
12
11
|
* ObjectDeserializerContext,
|
|
13
12
|
* ObjectSerializerContext
|
|
14
13
|
* } from "../serialization/ObjectMiddleware"
|
|
@@ -18,7 +17,7 @@ const { register, registerLegacyRequest } = require("./serialization");
|
|
|
18
17
|
/**
|
|
19
18
|
* Defines the serializable class constructor type used by this module.
|
|
20
19
|
* @template {SerializableClass} T
|
|
21
|
-
* @typedef {(new (...params:
|
|
20
|
+
* @typedef {(new (...params: never[]) => T) & { deserialize?: (context: ObjectDeserializerContext) => T }} SerializableClassConstructor
|
|
22
21
|
*/
|
|
23
22
|
|
|
24
23
|
/**
|
|
@@ -64,7 +63,7 @@ class ClassSerializer {
|
|
|
64
63
|
* keep requests the class was written under before a move readable: the first
|
|
65
64
|
* is the one it is written under now, the rest restore older cache packs; a
|
|
66
65
|
* historical entry written under another name pairs its request with it.
|
|
67
|
-
* @template {
|
|
66
|
+
* @template {new (...params: never[]) => EXPECTED_OBJECT} T
|
|
68
67
|
* @param {T} Constructor the constructor
|
|
69
68
|
* @param {string | (string | [string, string | null])[]} request the request which will be required when deserializing, current one first
|
|
70
69
|
* @param {string | null=} name the name to make multiple serializer unique when sharing a request
|
|
@@ -75,7 +74,10 @@ module.exports = (Constructor, request, name = null) => {
|
|
|
75
74
|
Constructor,
|
|
76
75
|
/** @type {string} */ (requests[0]),
|
|
77
76
|
name,
|
|
78
|
-
new ClassSerializer(
|
|
77
|
+
new ClassSerializer(
|
|
78
|
+
/** @type {SerializableClassConstructor<SerializableClass>} */
|
|
79
|
+
(Constructor)
|
|
80
|
+
)
|
|
79
81
|
);
|
|
80
82
|
// TODO in the next major release: remove, dropping every request but the
|
|
81
83
|
// first from each caller, which stops pre-move cache packs loading
|
package/lib/util/memoize.js
CHANGED
package/lib/util/parseJson.js
CHANGED
|
@@ -8,7 +8,7 @@ const memoize = require("./memoize");
|
|
|
8
8
|
|
|
9
9
|
const getJSONParseError = memoize(() => require("../errors/JSONParseError"));
|
|
10
10
|
|
|
11
|
-
/** @import { JsonValue } from "../fs/fs" */
|
|
11
|
+
/** @import { JsonArray, JsonObject, JsonValue } from "../fs/fs" */
|
|
12
12
|
|
|
13
13
|
// Inspired by https://github.com/npm/json-parse-even-better-errors
|
|
14
14
|
|
|
@@ -25,7 +25,7 @@ const stripBOM = (txt) => String(txt).replace(/^\uFEFF/, "");
|
|
|
25
25
|
* @template [R=JsonValue]
|
|
26
26
|
* @callback ParseJsonFn
|
|
27
27
|
* @param {string} raw text
|
|
28
|
-
* @param {(this:
|
|
28
|
+
* @param {(this: JsonObject | JsonArray, key: string, value: JsonValue) => JsonValue=} reviver reviver
|
|
29
29
|
* @returns {R} parsed JSON
|
|
30
30
|
*/
|
|
31
31
|
|
|
@@ -54,6 +54,12 @@ const registerSerializers = memoize(() => {
|
|
|
54
54
|
*/
|
|
55
55
|
/** @import { HashFunction } from "../util/Hash" */
|
|
56
56
|
/** @import { IntermediateFileSystem } from "../fs/fs" */
|
|
57
|
+
/**
|
|
58
|
+
* @import {
|
|
59
|
+
* BufferSerializableType,
|
|
60
|
+
* ComplexSerializableType
|
|
61
|
+
* } from "../serialization/types"
|
|
62
|
+
*/
|
|
57
63
|
|
|
58
64
|
/**
|
|
59
65
|
* Defines the serializer type used by this module.
|
|
@@ -62,7 +68,7 @@ const registerSerializers = memoize(() => {
|
|
|
62
68
|
*/
|
|
63
69
|
|
|
64
70
|
/**
|
|
65
|
-
* @type {Serializer<
|
|
71
|
+
* @type {Serializer<ComplexSerializableType, BufferSerializableType[], EXPECTED_OBJECT>}
|
|
66
72
|
*/
|
|
67
73
|
let buffersSerializer;
|
|
68
74
|
|
|
@@ -97,7 +103,7 @@ module.exports = {
|
|
|
97
103
|
const Serializer = getSerializer();
|
|
98
104
|
const binaryMiddleware = getBinaryMiddlewareInstance();
|
|
99
105
|
const SingleItemMiddleware = getSingleItemMiddleware();
|
|
100
|
-
return /** @type {Serializer<
|
|
106
|
+
return /** @type {Serializer<ComplexSerializableType, BufferSerializableType[], EXPECTED_OBJECT>} */ (
|
|
101
107
|
buffersSerializer = new Serializer([
|
|
102
108
|
new SingleItemMiddleware(),
|
|
103
109
|
new ObjectMiddleware((context) => {
|
|
@@ -129,30 +135,28 @@ module.exports = {
|
|
|
129
135
|
const fileMiddleware = new FileMiddleware(fs, hashFunction);
|
|
130
136
|
const binaryMiddleware = getBinaryMiddlewareInstance();
|
|
131
137
|
const SingleItemMiddleware = getSingleItemMiddleware();
|
|
132
|
-
return
|
|
133
|
-
new
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
context.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
])
|
|
156
|
-
);
|
|
138
|
+
return new Serializer([
|
|
139
|
+
new SingleItemMiddleware(),
|
|
140
|
+
new ObjectMiddleware((context) => {
|
|
141
|
+
if ("write" in context) {
|
|
142
|
+
context.writeLazy = (value) => {
|
|
143
|
+
context.write(
|
|
144
|
+
SerializerMiddleware.createLazy(value, binaryMiddleware)
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
context.writeSeparate = (value, options) => {
|
|
148
|
+
const lazy = SerializerMiddleware.createLazy(
|
|
149
|
+
value,
|
|
150
|
+
fileMiddleware,
|
|
151
|
+
options
|
|
152
|
+
);
|
|
153
|
+
context.write(lazy);
|
|
154
|
+
return lazy;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}, hashFunction),
|
|
158
|
+
binaryMiddleware,
|
|
159
|
+
fileMiddleware
|
|
160
|
+
]);
|
|
157
161
|
}
|
|
158
162
|
};
|
|
@@ -7,12 +7,22 @@
|
|
|
7
7
|
const NormalModule = require("../module/NormalModule");
|
|
8
8
|
const makeSerializable = require("../util/makeSerializable");
|
|
9
9
|
|
|
10
|
-
/** @import Module from "../module/Module" */
|
|
11
|
-
/**
|
|
10
|
+
/** @import Module, { BuildMeta } from "../module/Module" */
|
|
11
|
+
/**
|
|
12
|
+
* @import {
|
|
13
|
+
* NormalModuleBuildInfo,
|
|
14
|
+
* NormalModuleCreateData
|
|
15
|
+
* } from "../module/NormalModule"
|
|
16
|
+
*/
|
|
12
17
|
/** @import { ImportPhaseName } from "../dependencies/core/ImportPhase" */
|
|
13
18
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[ImportPhaseName | undefined]>} ObjectDeserializerContext */
|
|
14
19
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[ImportPhaseName | undefined]>} ObjectSerializerContext */
|
|
15
20
|
|
|
21
|
+
/**
|
|
22
|
+
* A built async wasm module, typed with its build info and build meta.
|
|
23
|
+
* @typedef {NormalModule & { buildInfo: NormalModuleBuildInfo, buildMeta: BuildMeta }} BuiltAsyncWasmModule
|
|
24
|
+
*/
|
|
25
|
+
|
|
16
26
|
/**
|
|
17
27
|
* Module class for `webassembly/async` modules. Wasm-specific properties should live here instead of `NormalModule`.
|
|
18
28
|
*/
|
|
@@ -20,6 +20,14 @@ const { WEBASSEMBLY_TYPES } = require("../module/ModuleSourceTypeConstants");
|
|
|
20
20
|
* @property {boolean=} mangleImports mangle imports
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* The module type the JSDoc inherited from `Generator` names.
|
|
25
|
+
* @typedef {NormalModule} TModule
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @extends {Generator<TModule>}
|
|
30
|
+
*/
|
|
23
31
|
class AsyncWebAssemblyGenerator extends Generator {
|
|
24
32
|
/**
|
|
25
33
|
* Creates an instance of AsyncWebAssemblyGenerator.
|
|
@@ -33,7 +41,7 @@ class AsyncWebAssemblyGenerator extends Generator {
|
|
|
33
41
|
|
|
34
42
|
/**
|
|
35
43
|
* Returns the source types available for this module.
|
|
36
|
-
* @param {
|
|
44
|
+
* @param {TModule} module fresh module
|
|
37
45
|
* @returns {SourceTypes} available types (do not mutate)
|
|
38
46
|
*/
|
|
39
47
|
getTypes(module) {
|
|
@@ -42,7 +50,7 @@ class AsyncWebAssemblyGenerator extends Generator {
|
|
|
42
50
|
|
|
43
51
|
/**
|
|
44
52
|
* Returns the estimated size for the requested source type.
|
|
45
|
-
* @param {
|
|
53
|
+
* @param {TModule} module the module
|
|
46
54
|
* @param {SourceType=} type source type
|
|
47
55
|
* @returns {number} estimate size of the module
|
|
48
56
|
*/
|
|
@@ -56,7 +64,7 @@ class AsyncWebAssemblyGenerator extends Generator {
|
|
|
56
64
|
|
|
57
65
|
/**
|
|
58
66
|
* Generates generated code for this runtime module.
|
|
59
|
-
* @param {
|
|
67
|
+
* @param {TModule} module module for which the code should be generated
|
|
60
68
|
* @param {GenerateContext} generateContext context for generate
|
|
61
69
|
* @returns {Source | null} generated code
|
|
62
70
|
*/
|
|
@@ -67,7 +75,7 @@ class AsyncWebAssemblyGenerator extends Generator {
|
|
|
67
75
|
/**
|
|
68
76
|
* Generates fallback output for the provided error condition.
|
|
69
77
|
* @param {Error} error the error
|
|
70
|
-
* @param {
|
|
78
|
+
* @param {TModule} module module for which the code should be generated
|
|
71
79
|
* @param {GenerateContext} generateContext context for generate
|
|
72
80
|
* @returns {Source | null} generated code
|
|
73
81
|
*/
|
|
@@ -25,10 +25,18 @@ const Template = require("../template/Template");
|
|
|
25
25
|
* @typedef {{ request: string, importVar: string, dependency: WebAssemblyImportDependency }} ImportObjRequestItem
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* The module type the JSDoc inherited from `Generator` names.
|
|
30
|
+
* @typedef {NormalModule} TModule
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @extends {Generator<TModule>}
|
|
35
|
+
*/
|
|
28
36
|
class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
29
37
|
/**
|
|
30
38
|
* Returns the source types available for this module.
|
|
31
|
-
* @param {
|
|
39
|
+
* @param {TModule} module fresh module
|
|
32
40
|
* @returns {SourceTypes} available types (do not mutate)
|
|
33
41
|
*/
|
|
34
42
|
getTypes(module) {
|
|
@@ -37,7 +45,7 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
|
37
45
|
|
|
38
46
|
/**
|
|
39
47
|
* Returns the estimated size for the requested source type.
|
|
40
|
-
* @param {
|
|
48
|
+
* @param {TModule} module the module
|
|
41
49
|
* @param {SourceType=} type source type
|
|
42
50
|
* @returns {number} estimate size of the module
|
|
43
51
|
*/
|
|
@@ -53,7 +61,7 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
|
53
61
|
|
|
54
62
|
/**
|
|
55
63
|
* Generates generated code for this runtime module.
|
|
56
|
-
* @param {
|
|
64
|
+
* @param {TModule} module module for which the code should be generated
|
|
57
65
|
* @param {GenerateContext} generateContext context for generate
|
|
58
66
|
* @returns {Source | null} generated code
|
|
59
67
|
*/
|
|
@@ -236,7 +244,7 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
|
236
244
|
|
|
237
245
|
/**
|
|
238
246
|
* Generate code for source phase import (returns WebAssembly.Module)
|
|
239
|
-
* @param {
|
|
247
|
+
* @param {TModule} module module for which the code should be generated
|
|
240
248
|
* @param {GenerateContext} generateContext context for generate
|
|
241
249
|
* @returns {Source} generated code
|
|
242
250
|
*/
|
|
@@ -298,7 +306,7 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
|
298
306
|
/**
|
|
299
307
|
* Generates fallback output for the provided error condition.
|
|
300
308
|
* @param {Error} error the error
|
|
301
|
-
* @param {
|
|
309
|
+
* @param {TModule} module module for which the code should be generated
|
|
302
310
|
* @param {GenerateContext} generateContext context for generate
|
|
303
311
|
* @returns {Source | null} generated code
|
|
304
312
|
*/
|
|
@@ -16,8 +16,7 @@ const getEnvironmentNotSupportAsyncWarning = memoize(() =>
|
|
|
16
16
|
require("../errors/EnvironmentNotSupportAsyncWarning")
|
|
17
17
|
);
|
|
18
18
|
|
|
19
|
-
/** @import AsyncWasmModule from "./AsyncWasmModule" */
|
|
20
|
-
/** @import { BuildInfo, BuildMeta } from "../module/Module" */
|
|
19
|
+
/** @import AsyncWasmModule, { BuiltAsyncWasmModule } from "./AsyncWasmModule" */
|
|
21
20
|
/** @import { ParserState, PreparsedAst } from "../module/Parser" */
|
|
22
21
|
|
|
23
22
|
const WASM_HEADER = Buffer.from([0x00, 0x61, 0x73, 0x6d]);
|
|
@@ -30,6 +29,9 @@ const decoderOpts = {
|
|
|
30
29
|
ignoreCustomNameSection: true
|
|
31
30
|
};
|
|
32
31
|
|
|
32
|
+
/**
|
|
33
|
+
* @extends {Parser<BuiltAsyncWasmModule>}
|
|
34
|
+
*/
|
|
33
35
|
class AsyncWebAssemblyParser extends Parser {
|
|
34
36
|
/**
|
|
35
37
|
* Parses the provided source and updates the parser state.
|
|
@@ -42,7 +44,9 @@ class AsyncWebAssemblyParser extends Parser {
|
|
|
42
44
|
throw new Error("AsyncWebAssemblyParser input must be a Buffer");
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
const buildMeta = /** @type {
|
|
47
|
+
const { buildInfo, buildMeta } = /** @type {BuiltAsyncWasmModule} */ (
|
|
48
|
+
state.module
|
|
49
|
+
);
|
|
46
50
|
buildMeta.exportsType = "namespace";
|
|
47
51
|
buildMeta.async = true;
|
|
48
52
|
|
|
@@ -53,8 +57,6 @@ class AsyncWebAssemblyParser extends Parser {
|
|
|
53
57
|
);
|
|
54
58
|
|
|
55
59
|
// flag it as async module
|
|
56
|
-
const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
|
|
57
|
-
|
|
58
60
|
buildInfo.strict = true;
|
|
59
61
|
|
|
60
62
|
if (/** @type {AsyncWasmModule} */ (state.module).phase === "source") {
|