webpack 5.104.1 → 5.105.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +85 -15
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AsyncDependenciesBlock.js +17 -2
- package/lib/AsyncDependencyToInitialChunkError.js +3 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +5 -1
- package/lib/CacheFacade.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +1 -0
- package/lib/Chunk.js +9 -5
- package/lib/ChunkGraph.js +30 -9
- package/lib/ChunkGroup.js +6 -3
- package/lib/ChunkRenderError.js +9 -2
- package/lib/CleanPlugin.js +4 -1
- package/lib/CodeGenerationError.js +7 -1
- package/lib/CodeGenerationResults.js +10 -3
- package/lib/CommentCompilationWarning.js +2 -1
- package/lib/Compilation.js +284 -236
- package/lib/Compiler.js +4 -3
- package/lib/ConcatenationScope.js +2 -1
- package/lib/ConcurrentCompilationError.js +3 -3
- package/lib/ContextModule.js +248 -111
- package/lib/ContextModuleFactory.js +14 -2
- package/lib/DefinePlugin.js +15 -8
- package/lib/DelegatedModule.js +6 -0
- package/lib/DelegatedModuleFactoryPlugin.js +2 -0
- package/lib/Dependency.js +6 -1
- package/lib/DependencyTemplates.js +3 -2
- package/lib/DllModule.js +2 -0
- package/lib/DllReferencePlugin.js +1 -0
- package/lib/DotenvPlugin.js +11 -5
- package/lib/DynamicEntryPlugin.js +8 -1
- package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +17 -13
- package/lib/ExportsInfo.js +8 -4
- package/lib/ExternalModule.js +16 -0
- package/lib/ExternalModuleFactoryPlugin.js +9 -2
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FalseIIFEUmdWarning.js +1 -0
- package/lib/FileSystemInfo.js +49 -25
- package/lib/FlagDependencyExportsPlugin.js +8 -1
- package/lib/FlagDependencyUsagePlugin.js +9 -7
- package/lib/HarmonyLinkingError.js +1 -0
- package/lib/HookWebpackError.js +2 -0
- package/lib/HotModuleReplacementPlugin.js +16 -2
- package/lib/IgnoreWarningsPlugin.js +5 -2
- package/lib/InitFragment.js +1 -0
- package/lib/InvalidDependenciesModuleWarning.js +1 -0
- package/lib/LibManifestPlugin.js +1 -0
- package/lib/ManifestPlugin.js +8 -1
- package/lib/Module.js +7 -4
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +1 -0
- package/lib/ModuleDependencyWarning.js +1 -0
- package/lib/ModuleError.js +4 -1
- package/lib/ModuleFilenameHelpers.js +4 -2
- package/lib/ModuleGraph.js +3 -0
- package/lib/ModuleGraphConnection.js +10 -1
- package/lib/ModuleHashingError.js +2 -0
- package/lib/ModuleInfoHeaderPlugin.js +6 -1
- package/lib/ModuleNotFoundError.js +1 -0
- package/lib/ModuleParseError.js +5 -1
- package/lib/ModuleProfile.js +1 -1
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleSourceTypeConstants.js +1 -11
- package/lib/ModuleStoreError.js +2 -0
- package/lib/ModuleWarning.js +3 -1
- package/lib/MultiCompiler.js +11 -7
- package/lib/MultiWatching.js +2 -2
- package/lib/NoModeWarning.js +1 -0
- package/lib/NodeStuffInWebError.js +1 -0
- package/lib/NormalModule.js +28 -5
- package/lib/NormalModuleFactory.js +20 -4
- package/lib/OptionsApply.js +3 -1
- package/lib/ProgressPlugin.js +4 -0
- package/lib/RawModule.js +2 -0
- package/lib/RuntimeModule.js +10 -0
- package/lib/RuntimePlugin.js +7 -9
- package/lib/RuntimeTemplate.js +14 -7
- package/lib/SourceMapDevToolPlugin.js +30 -23
- package/lib/Template.js +10 -5
- package/lib/TemplatedPathPlugin.js +4 -2
- package/lib/UnhandledSchemeError.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +3 -0
- package/lib/WarnDeprecatedOptionPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -1
- package/lib/Watching.js +5 -0
- package/lib/WebpackError.js +4 -0
- package/lib/WebpackOptionsApply.js +61 -41
- package/lib/asset/AssetBytesGenerator.js +1 -0
- package/lib/asset/AssetGenerator.js +18 -3
- package/lib/asset/AssetModulesPlugin.js +33 -2
- package/lib/asset/AssetParser.js +4 -0
- package/lib/asset/AssetSourceGenerator.js +1 -0
- package/lib/asset/RawDataUrlModule.js +4 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
- package/lib/buildChunkGraph.js +31 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +41 -8
- package/lib/cache/getLazyHashedEtag.js +13 -4
- package/lib/cache/mergeEtags.js +3 -1
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +65 -44
- package/lib/config/normalization.js +96 -0
- package/lib/container/ContainerEntryDependency.js +3 -0
- package/lib/container/ContainerEntryModule.js +7 -0
- package/lib/container/ContainerExposedDependency.js +1 -0
- package/lib/container/FallbackDependency.js +1 -0
- package/lib/container/FallbackItemDependency.js +1 -0
- package/lib/container/FallbackModule.js +4 -0
- package/lib/container/HoistContainerReferencesPlugin.js +6 -0
- package/lib/container/ModuleFederationPlugin.js +1 -1
- package/lib/container/RemoteModule.js +24 -0
- package/lib/css/CssGenerator.js +31 -4
- package/lib/css/CssModulesPlugin.js +26 -30
- package/lib/css/CssParser.js +12 -9
- package/lib/debug/ProfilingPlugin.js +1 -0
- package/lib/dependencies/AMDDefineDependency.js +3 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
- package/lib/dependencies/AMDPlugin.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
- package/lib/dependencies/CachedConstDependency.js +1 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
- package/lib/dependencies/ConstDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +11 -4
- package/lib/dependencies/ContextElementDependency.js +1 -0
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +7 -4
- package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
- package/lib/dependencies/CssUrlDependency.js +2 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
- package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -1
- package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
- package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyImportDependency.js +1 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +269 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
- package/lib/dependencies/ImportDependency.js +1 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +53 -11
- package/lib/dependencies/ImportParserPlugin.js +7 -12
- package/lib/dependencies/LoaderPlugin.js +3 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
- package/lib/dependencies/ModuleDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
- package/lib/dependencies/ProvidedDependency.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +1 -0
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +9 -3
- package/lib/dependencies/WorkerPlugin.js +1 -0
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/electron/ElectronTargetPlugin.js +3 -1
- package/lib/errors/BuildCycleError.js +4 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
- package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +5 -0
- package/lib/hmr/lazyCompilationBackend.js +3 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +9 -7
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -0
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -0
- package/lib/ids/HashedModuleIdsPlugin.js +3 -8
- package/lib/ids/IdHelpers.js +10 -8
- package/lib/ids/NamedChunkIdsPlugin.js +7 -5
- package/lib/ids/NamedModuleIdsPlugin.js +1 -0
- package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +18 -10
- package/lib/ids/SyncModuleIdsPlugin.js +30 -20
- package/lib/index.js +2 -2
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
- package/lib/javascript/JavascriptModulesPlugin.js +29 -8
- package/lib/javascript/JavascriptParser.js +47 -14
- package/lib/json/JsonGenerator.js +1 -0
- package/lib/json/JsonParser.js +9 -2
- package/lib/library/AbstractLibraryPlugin.js +4 -1
- package/lib/library/AmdLibraryPlugin.js +2 -1
- package/lib/library/AssignLibraryPlugin.js +6 -2
- package/lib/library/EnableLibraryPlugin.js +1 -0
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +130 -13
- package/lib/library/SystemLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +4 -3
- package/lib/logging/Logger.js +9 -5
- package/lib/logging/createConsoleLogger.js +4 -0
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +6 -4
- package/lib/node/NodeEnvironmentPlugin.js +1 -0
- package/lib/node/NodeTargetPlugin.js +10 -1
- package/lib/node/NodeTemplatePlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +6 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -0
- package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -0
- package/lib/node/nodeConsole.js +18 -1
- package/lib/optimize/AggressiveMergingPlugin.js +2 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +15 -6
- package/lib/optimize/ConcatenatedModule.js +33 -19
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
- package/lib/optimize/InnerGraph.js +5 -3
- package/lib/optimize/InnerGraphPlugin.js +25 -25
- package/lib/optimize/LimitChunkCountPlugin.js +3 -2
- package/lib/optimize/MangleExportsPlugin.js +14 -2
- package/lib/optimize/MergeDuplicateChunksPlugin.js +5 -1
- package/lib/optimize/MinChunkSizePlugin.js +5 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
- package/lib/optimize/RealContentHashPlugin.js +37 -27
- package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
- package/lib/optimize/RuntimeChunkPlugin.js +3 -5
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
- package/lib/optimize/SplitChunksPlugin.js +23 -5
- package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
- package/lib/performance/NoAsyncChunksWarning.js +1 -0
- package/lib/performance/SizeLimitsPlugin.js +6 -6
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +2 -0
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -0
- package/lib/rules/BasicEffectRulePlugin.js +2 -0
- package/lib/rules/BasicMatcherRulePlugin.js +3 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
- package/lib/rules/RuleSetCompiler.js +6 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
- package/lib/runtime/CompatRuntimeModule.js +1 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -0
- package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +16 -32
- package/lib/runtime/PublicPathRuntimeModule.js +1 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
- package/lib/schemes/HttpUriPlugin.js +39 -20
- package/lib/schemes/VirtualUrlPlugin.js +28 -2
- package/lib/serialization/BinaryMiddleware.js +4 -0
- package/lib/serialization/FileMiddleware.js +9 -4
- package/lib/serialization/ObjectMiddleware.js +34 -11
- package/lib/serialization/PlainObjectSerializer.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +60 -0
- package/lib/sharing/ConsumeSharedPlugin.js +5 -4
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +24 -25
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -12
- package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/url/URLParserPlugin.js +5 -3
- package/lib/util/AppendOnlyStackedSet.js +57 -0
- package/lib/util/Hash.js +1 -0
- package/lib/util/IterableHelpers.js +1 -0
- package/lib/util/LazyBucketSortedSet.js +1 -0
- package/lib/util/LazySet.js +1 -0
- package/lib/util/ParallelismFactorCalculator.js +1 -0
- package/lib/util/SortableSet.js +1 -0
- package/lib/util/StringXor.js +1 -0
- package/lib/util/binarySearchBounds.js +15 -8
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +6 -1
- package/lib/util/comparators.js +21 -1
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +3 -2
- package/lib/util/conventions.js +3 -2
- package/lib/util/deterministicGrouping.js +13 -1
- package/lib/util/extractSourceMap.js +12 -13
- package/lib/util/fs.js +15 -19
- package/lib/util/hash/BatchedHash.js +4 -0
- package/lib/util/hash/BulkUpdateHash.js +8 -1
- package/lib/util/hash/hash-digest.js +1 -0
- package/lib/util/hash/wasm-hash.js +18 -2
- package/lib/util/identifier.js +7 -2
- package/lib/util/magicComment.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -0
- package/lib/util/runtime.js +15 -1
- package/lib/util/semver.js +1 -0
- package/lib/util/serialization.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +2 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyParser.js +3 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
- package/lib/webpack.js +16 -4
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -0
- package/package.json +33 -36
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +121 -55
- package/schemas/plugins/BannerPlugin.json +2 -2
- package/schemas/plugins/IgnorePlugin.json +1 -1
- package/schemas/plugins/ManifestPlugin.json +3 -3
- package/schemas/plugins/ProgressPlugin.json +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/schemas/plugins/schemes/HttpUriPlugin.json +1 -1
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
- package/types.d.ts +440 -137
|
@@ -318,7 +318,7 @@ class VariableInfo {
|
|
|
318
318
|
/** @typedef {Literal | string | null | undefined} ImportSource */
|
|
319
319
|
|
|
320
320
|
/**
|
|
321
|
-
* @typedef {Omit<ParseOptions, "sourceType"> & {sourceType: "module" | "script" | "auto"}} InternalParseOptions
|
|
321
|
+
* @typedef {Omit<ParseOptions, "sourceType"> & { sourceType: "module" | "script" | "auto" }} InternalParseOptions
|
|
322
322
|
*/
|
|
323
323
|
|
|
324
324
|
/**
|
|
@@ -347,12 +347,13 @@ class VariableInfo {
|
|
|
347
347
|
/** @typedef {symbol} Tag */
|
|
348
348
|
|
|
349
349
|
/** @typedef {import("../dependencies/HarmonyImportDependencyParserPlugin").HarmonySettings} HarmonySettings */
|
|
350
|
+
/** @typedef {import("../dependencies/HarmonyImportDependencyParserPlugin").HarmonySpecifierGuards} HarmonySpecifierGuards */
|
|
350
351
|
/** @typedef {import("../dependencies/ImportParserPlugin").ImportSettings} ImportSettings */
|
|
351
352
|
/** @typedef {import("../dependencies/CommonJsImportsParserPlugin").CommonJsImportSettings} CommonJsImportSettings */
|
|
352
353
|
/** @typedef {import("../CompatibilityPlugin").CompatibilitySettings} CompatibilitySettings */
|
|
353
354
|
/** @typedef {import("../optimize/InnerGraph").TopLevelSymbol} TopLevelSymbol */
|
|
354
355
|
|
|
355
|
-
/** @typedef {HarmonySettings | ImportSettings | CommonJsImportSettings | TopLevelSymbol | CompatibilitySettings} KnownTagData */
|
|
356
|
+
/** @typedef {HarmonySettings | ImportSettings | CommonJsImportSettings | TopLevelSymbol | CompatibilitySettings | HarmonySpecifierGuards} KnownTagData */
|
|
356
357
|
/** @typedef {KnownTagData | Record<string, EXPECTED_ANY>} TagData */
|
|
357
358
|
|
|
358
359
|
/**
|
|
@@ -519,6 +520,8 @@ class JavascriptParser extends Parser {
|
|
|
519
520
|
statement: new SyncBailHook(["statement"]),
|
|
520
521
|
/** @type {SyncBailHook<[IfStatement], boolean | void>} */
|
|
521
522
|
statementIf: new SyncBailHook(["statement"]),
|
|
523
|
+
/** @type {SyncBailHook<[Expression], ((walk: () => void) => void) | void>} */
|
|
524
|
+
collectGuards: new SyncBailHook(["expression"]),
|
|
522
525
|
/** @type {SyncBailHook<[Expression, ClassExpression | ClassDeclaration | MaybeNamedClassDeclaration], boolean | void>} */
|
|
523
526
|
classExtendsExpression: new SyncBailHook([
|
|
524
527
|
"expression",
|
|
@@ -747,6 +750,7 @@ class JavascriptParser extends Parser {
|
|
|
747
750
|
return;
|
|
748
751
|
}
|
|
749
752
|
|
|
753
|
+
/** @type {undefined | string} */
|
|
750
754
|
let regExp;
|
|
751
755
|
const arg1 = expr.arguments[0];
|
|
752
756
|
|
|
@@ -769,6 +773,7 @@ class JavascriptParser extends Parser {
|
|
|
769
773
|
);
|
|
770
774
|
}
|
|
771
775
|
|
|
776
|
+
/** @type {undefined | string} */
|
|
772
777
|
let flags;
|
|
773
778
|
const arg2 = expr.arguments[1];
|
|
774
779
|
|
|
@@ -1597,7 +1602,7 @@ class JavascriptParser extends Parser {
|
|
|
1597
1602
|
const arg1Eval = this.evaluateExpression(arg1);
|
|
1598
1603
|
if (!arg1Eval.isString()) return;
|
|
1599
1604
|
const arg1Value = /** @type {string} */ (arg1Eval.string);
|
|
1600
|
-
|
|
1605
|
+
/** @type {number} */
|
|
1601
1606
|
let result;
|
|
1602
1607
|
if (arg2) {
|
|
1603
1608
|
if (arg2.type === "SpreadElement") return;
|
|
@@ -1642,7 +1647,9 @@ class JavascriptParser extends Parser {
|
|
|
1642
1647
|
.for(fn)
|
|
1643
1648
|
.tap(CLASS_NAME, (expr, param) => {
|
|
1644
1649
|
if (!param.isString()) return;
|
|
1650
|
+
/** @type {BasicEvaluatedExpression} */
|
|
1645
1651
|
let arg1;
|
|
1652
|
+
/** @type {string} */
|
|
1646
1653
|
let result;
|
|
1647
1654
|
const str = /** @type {string} */ (param.string);
|
|
1648
1655
|
switch (expr.arguments.length) {
|
|
@@ -1682,7 +1689,7 @@ class JavascriptParser extends Parser {
|
|
|
1682
1689
|
/**
|
|
1683
1690
|
* @param {"cooked" | "raw"} kind kind of values to get
|
|
1684
1691
|
* @param {TemplateLiteral} templateLiteralExpr TemplateLiteral expr
|
|
1685
|
-
* @returns {{quasis: BasicEvaluatedExpression[], parts: BasicEvaluatedExpression[]}} Simplified template
|
|
1692
|
+
* @returns {{ quasis: BasicEvaluatedExpression[], parts: BasicEvaluatedExpression[] }} Simplified template
|
|
1686
1693
|
*/
|
|
1687
1694
|
const getSimplifiedTemplateResult = (kind, templateLiteralExpr) => {
|
|
1688
1695
|
/** @type {BasicEvaluatedExpression[]} */
|
|
@@ -1764,7 +1771,8 @@ class JavascriptParser extends Parser {
|
|
|
1764
1771
|
.for("concat")
|
|
1765
1772
|
.tap(CLASS_NAME, (expr, param) => {
|
|
1766
1773
|
if (!param.isString() && !param.isWrapped()) return;
|
|
1767
|
-
|
|
1774
|
+
/** @type {undefined | BasicEvaluatedExpression} */
|
|
1775
|
+
let stringSuffix;
|
|
1768
1776
|
let hasUnknownParams = false;
|
|
1769
1777
|
/** @type {BasicEvaluatedExpression[]} */
|
|
1770
1778
|
const innerExpressions = [];
|
|
@@ -1840,6 +1848,7 @@ class JavascriptParser extends Parser {
|
|
|
1840
1848
|
if (!param.isString()) return;
|
|
1841
1849
|
if (expr.arguments.length !== 1) return;
|
|
1842
1850
|
if (expr.arguments[0].type === "SpreadElement") return;
|
|
1851
|
+
/** @type {string[]} */
|
|
1843
1852
|
let result;
|
|
1844
1853
|
const arg = this.evaluateExpression(expr.arguments[0]);
|
|
1845
1854
|
if (arg.isString()) {
|
|
@@ -1865,6 +1874,7 @@ class JavascriptParser extends Parser {
|
|
|
1865
1874
|
|
|
1866
1875
|
const condition = this.evaluateExpression(expr.test);
|
|
1867
1876
|
const conditionValue = condition.asBool();
|
|
1877
|
+
/** @type {BasicEvaluatedExpression} */
|
|
1868
1878
|
let res;
|
|
1869
1879
|
if (conditionValue === undefined) {
|
|
1870
1880
|
const consequent = this.evaluateExpression(expr.consequent);
|
|
@@ -1983,6 +1993,7 @@ class JavascriptParser extends Parser {
|
|
|
1983
1993
|
this.walkExpression(classy.superClass);
|
|
1984
1994
|
}
|
|
1985
1995
|
if (classy.body && classy.body.type === "ClassBody") {
|
|
1996
|
+
/** @type {Identifier[]} */
|
|
1986
1997
|
const scopeParams = [];
|
|
1987
1998
|
// Add class name in scope for recursive calls
|
|
1988
1999
|
if (classy.id) {
|
|
@@ -2318,8 +2329,16 @@ class JavascriptParser extends Parser {
|
|
|
2318
2329
|
walkIfStatement(statement) {
|
|
2319
2330
|
const result = this.hooks.statementIf.call(statement);
|
|
2320
2331
|
if (result === undefined) {
|
|
2321
|
-
this.
|
|
2322
|
-
|
|
2332
|
+
const inGuard = this.hooks.collectGuards.call(statement.test);
|
|
2333
|
+
if (inGuard) {
|
|
2334
|
+
inGuard(() => {
|
|
2335
|
+
this.walkExpression(statement.test);
|
|
2336
|
+
this.walkNestedStatement(statement.consequent);
|
|
2337
|
+
});
|
|
2338
|
+
} else {
|
|
2339
|
+
this.walkExpression(statement.test);
|
|
2340
|
+
this.walkNestedStatement(statement.consequent);
|
|
2341
|
+
}
|
|
2323
2342
|
|
|
2324
2343
|
const consequentTerminated = this.scope.terminated;
|
|
2325
2344
|
this.scope.terminated = undefined;
|
|
@@ -3704,8 +3723,16 @@ class JavascriptParser extends Parser {
|
|
|
3704
3723
|
walkConditionalExpression(expression) {
|
|
3705
3724
|
const result = this.hooks.expressionConditionalOperator.call(expression);
|
|
3706
3725
|
if (result === undefined) {
|
|
3707
|
-
this.
|
|
3708
|
-
|
|
3726
|
+
const inGuard = this.hooks.collectGuards.call(expression.test);
|
|
3727
|
+
if (inGuard) {
|
|
3728
|
+
inGuard(() => {
|
|
3729
|
+
this.walkExpression(expression.test);
|
|
3730
|
+
this.walkExpression(expression.consequent);
|
|
3731
|
+
});
|
|
3732
|
+
} else {
|
|
3733
|
+
this.walkExpression(expression.test);
|
|
3734
|
+
this.walkExpression(expression.consequent);
|
|
3735
|
+
}
|
|
3709
3736
|
|
|
3710
3737
|
if (expression.alternate) {
|
|
3711
3738
|
this.walkExpression(expression.alternate);
|
|
@@ -4220,6 +4247,7 @@ class JavascriptParser extends Parser {
|
|
|
4220
4247
|
* @returns {R | undefined} result of hook
|
|
4221
4248
|
*/
|
|
4222
4249
|
callHooksForInfoWithFallback(hookMap, info, fallback, defined, ...args) {
|
|
4250
|
+
/** @type {string} */
|
|
4223
4251
|
let name;
|
|
4224
4252
|
if (typeof info === "string") {
|
|
4225
4253
|
name = info;
|
|
@@ -4247,7 +4275,7 @@ class JavascriptParser extends Parser {
|
|
|
4247
4275
|
}
|
|
4248
4276
|
return;
|
|
4249
4277
|
}
|
|
4250
|
-
name = info.name;
|
|
4278
|
+
name = /** @type {string} */ (info.name);
|
|
4251
4279
|
}
|
|
4252
4280
|
const hook = hookMap.get(name);
|
|
4253
4281
|
if (hook !== undefined) {
|
|
@@ -4255,7 +4283,7 @@ class JavascriptParser extends Parser {
|
|
|
4255
4283
|
if (result !== undefined) return result;
|
|
4256
4284
|
}
|
|
4257
4285
|
if (fallback !== undefined) {
|
|
4258
|
-
return fallback(
|
|
4286
|
+
return fallback(name);
|
|
4259
4287
|
}
|
|
4260
4288
|
}
|
|
4261
4289
|
|
|
@@ -4891,7 +4919,7 @@ class JavascriptParser extends Parser {
|
|
|
4891
4919
|
]).some(
|
|
4892
4920
|
(comment) =>
|
|
4893
4921
|
comment.type === "Block" &&
|
|
4894
|
-
/^\s*(
|
|
4922
|
+
/^\s*(?:#|@)__PURE__\s*$/.test(comment.value)
|
|
4895
4923
|
);
|
|
4896
4924
|
if (!pureFlag) return false;
|
|
4897
4925
|
commentsStartPos = /** @type {Range} */ (expr.callee.range)[1];
|
|
@@ -5187,8 +5215,11 @@ class JavascriptParser extends Parser {
|
|
|
5187
5215
|
extractMemberExpressionChain(expression) {
|
|
5188
5216
|
/** @type {Node} */
|
|
5189
5217
|
let expr = expression;
|
|
5218
|
+
/** @type {Members} */
|
|
5190
5219
|
const members = [];
|
|
5220
|
+
/** @type {MembersOptionals} */
|
|
5191
5221
|
const membersOptionals = [];
|
|
5222
|
+
/** @type {MemberRanges} */
|
|
5192
5223
|
const memberRanges = [];
|
|
5193
5224
|
while (expr.type === "MemberExpression") {
|
|
5194
5225
|
if (expr.computed) {
|
|
@@ -5214,10 +5245,11 @@ class JavascriptParser extends Parser {
|
|
|
5214
5245
|
|
|
5215
5246
|
/**
|
|
5216
5247
|
* @param {string} varName variable name
|
|
5217
|
-
* @returns {{name: string, info: VariableInfo | string} | undefined} name of the free variable and variable info for that
|
|
5248
|
+
* @returns {{ name: string, info: VariableInfo | string } | undefined} name of the free variable and variable info for that
|
|
5218
5249
|
*/
|
|
5219
5250
|
getFreeInfoFromVariable(varName) {
|
|
5220
5251
|
const info = this.getVariableInfo(varName);
|
|
5252
|
+
/** @type {string} */
|
|
5221
5253
|
let name;
|
|
5222
5254
|
if (info instanceof VariableInfo && info.name) {
|
|
5223
5255
|
if (!info.isFree()) return;
|
|
@@ -5232,10 +5264,11 @@ class JavascriptParser extends Parser {
|
|
|
5232
5264
|
|
|
5233
5265
|
/**
|
|
5234
5266
|
* @param {string} varName variable name
|
|
5235
|
-
* @returns {{name: string, info: VariableInfo | string} | undefined} name of the free variable and variable info for that
|
|
5267
|
+
* @returns {{ name: string, info: VariableInfo | string } | undefined} name of the free variable and variable info for that
|
|
5236
5268
|
*/
|
|
5237
5269
|
getNameInfoFromVariable(varName) {
|
|
5238
5270
|
const info = this.getVariableInfo(varName);
|
|
5271
|
+
/** @type {string} */
|
|
5239
5272
|
let name;
|
|
5240
5273
|
if (info instanceof VariableInfo && info.name) {
|
|
5241
5274
|
if (!info.isFree() && !info.isTagged()) return;
|
package/lib/json/JsonParser.js
CHANGED
|
@@ -17,17 +17,24 @@ const JsonData = require("./JsonData");
|
|
|
17
17
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
|
18
18
|
/** @typedef {import("../util/fs").JsonValue} JsonValue */
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @template T
|
|
22
|
+
* @typedef {import("../util/memoize").FunctionReturning<T>} FunctionReturning
|
|
23
|
+
*/
|
|
24
|
+
|
|
20
25
|
/** @typedef {(input: string) => Buffer | JsonValue} ParseFn */
|
|
21
26
|
|
|
27
|
+
/** @type {FunctionReturning<ParseFn>} */
|
|
22
28
|
const getParseJson = memoize(() => require("json-parse-even-better-errors"));
|
|
23
29
|
|
|
24
30
|
class JsonParser extends Parser {
|
|
25
31
|
/**
|
|
26
32
|
* @param {JsonModulesPluginParserOptions} options parser options
|
|
27
33
|
*/
|
|
28
|
-
constructor(options) {
|
|
34
|
+
constructor(options = {}) {
|
|
29
35
|
super();
|
|
30
|
-
|
|
36
|
+
/** @type {JsonModulesPluginParserOptions} */
|
|
37
|
+
this.options = options;
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
/**
|
|
@@ -48,8 +48,11 @@ class AbstractLibraryPlugin {
|
|
|
48
48
|
* @param {AbstractLibraryPluginOptions} options options
|
|
49
49
|
*/
|
|
50
50
|
constructor({ pluginName, type }) {
|
|
51
|
+
/** @type {AbstractLibraryPluginOptions["pluginName"]} */
|
|
51
52
|
this._pluginName = pluginName;
|
|
53
|
+
/** @type {AbstractLibraryPluginOptions["type"]} */
|
|
52
54
|
this._type = type;
|
|
55
|
+
/** @type {WeakMap<LibraryOptions, T>} */
|
|
53
56
|
this._parseCache = new WeakMap();
|
|
54
57
|
}
|
|
55
58
|
|
|
@@ -236,7 +239,7 @@ class AbstractLibraryPlugin {
|
|
|
236
239
|
/**
|
|
237
240
|
* @abstract
|
|
238
241
|
* @param {LibraryOptions} library normalized library option
|
|
239
|
-
* @returns {T
|
|
242
|
+
* @returns {T} preprocess as needed by overriding
|
|
240
243
|
*/
|
|
241
244
|
parseOptions(library) {
|
|
242
245
|
const AbstractMethodError = require("../AbstractMethodError");
|
|
@@ -47,12 +47,13 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
47
47
|
pluginName: "AmdLibraryPlugin",
|
|
48
48
|
type: options.type
|
|
49
49
|
});
|
|
50
|
+
/** @type {AmdLibraryPluginOptions["requireAsWrapper"]} */
|
|
50
51
|
this.requireAsWrapper = options.requireAsWrapper;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
55
|
* @param {LibraryOptions} library normalized library option
|
|
55
|
-
* @returns {T
|
|
56
|
+
* @returns {T} preprocess as needed by overriding
|
|
56
57
|
*/
|
|
57
58
|
parseOptions(library) {
|
|
58
59
|
const { name, amdContainer } = library;
|
|
@@ -33,7 +33,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
const KEYWORD_REGEX =
|
|
36
|
-
/^(await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|super|switch|static|this|throw|try|true|typeof|var|void|while|with|yield)$/;
|
|
36
|
+
/^(?:await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|super|switch|static|this|throw|try|true|typeof|var|void|while|with|yield)$/;
|
|
37
37
|
const IDENTIFIER_REGEX =
|
|
38
38
|
/^[\p{L}\p{Nl}$_][\p{L}\p{Nl}$\p{Mn}\p{Mc}\p{Nd}\p{Pc}]*$/iu;
|
|
39
39
|
|
|
@@ -128,15 +128,19 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
128
128
|
pluginName: "AssignLibraryPlugin",
|
|
129
129
|
type: options.type
|
|
130
130
|
});
|
|
131
|
+
/** @type {AssignLibraryPluginOptions["prefix"]} */
|
|
131
132
|
this.prefix = options.prefix;
|
|
133
|
+
/** @type {AssignLibraryPluginOptions["declare"]} */
|
|
132
134
|
this.declare = options.declare;
|
|
135
|
+
/** @type {AssignLibraryPluginOptions["unnamed"]} */
|
|
133
136
|
this.unnamed = options.unnamed;
|
|
137
|
+
/** @type {AssignLibraryPluginOptions["named"]} */
|
|
134
138
|
this.named = options.named || "assign";
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
/**
|
|
138
142
|
* @param {LibraryOptions} library normalized library option
|
|
139
|
-
* @returns {T
|
|
143
|
+
* @returns {T} preprocess as needed by overriding
|
|
140
144
|
*/
|
|
141
145
|
parseOptions(library) {
|
|
142
146
|
const { name } = library;
|
|
@@ -51,7 +51,7 @@ class ExportPropertyLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* @param {LibraryOptions} library normalized library option
|
|
54
|
-
* @returns {T
|
|
54
|
+
* @returns {T} preprocess as needed by overriding
|
|
55
55
|
*/
|
|
56
56
|
parseOptions(library) {
|
|
57
57
|
return {
|
|
@@ -48,7 +48,7 @@ class JsonpLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* @param {LibraryOptions} library normalized library option
|
|
51
|
-
* @returns {T
|
|
51
|
+
* @returns {T} preprocess as needed by overriding
|
|
52
52
|
*/
|
|
53
53
|
parseOptions(library) {
|
|
54
54
|
const { name } = library;
|
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
const { ConcatSource } = require("webpack-sources");
|
|
9
9
|
const { UsageState } = require("../ExportsInfo");
|
|
10
|
+
const ExternalModule = require("../ExternalModule");
|
|
10
11
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
11
12
|
const Template = require("../Template");
|
|
13
|
+
const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency");
|
|
12
14
|
const ConcatenatedModule = require("../optimize/ConcatenatedModule");
|
|
13
15
|
const propertyAccess = require("../util/propertyAccess");
|
|
14
|
-
const { getEntryRuntime } = require("../util/runtime");
|
|
16
|
+
const { getEntryRuntime, getRuntimeKey } = require("../util/runtime");
|
|
15
17
|
const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
16
18
|
|
|
17
19
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
@@ -20,11 +22,14 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
20
22
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryExport} LibraryExport */
|
|
21
23
|
/** @typedef {import("../Chunk")} Chunk */
|
|
22
24
|
/** @typedef {import("../Compiler")} Compiler */
|
|
25
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
23
26
|
/** @typedef {import("../Module")} Module */
|
|
24
27
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
25
28
|
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
26
29
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
|
|
27
30
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").ModuleRenderContext} ModuleRenderContext */
|
|
31
|
+
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
32
|
+
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|
28
33
|
|
|
29
34
|
/**
|
|
30
35
|
* @template T
|
|
@@ -76,17 +81,20 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
76
81
|
/** @type {BuildMeta} */
|
|
77
82
|
const buildMeta = module.buildMeta || (module.buildMeta = {});
|
|
78
83
|
|
|
84
|
+
/** @type {BuildMeta["exportsSourceByRuntime"]} */
|
|
79
85
|
const exportsSourceByRuntime =
|
|
80
86
|
buildMeta.exportsSourceByRuntime ||
|
|
81
87
|
(buildMeta.exportsSourceByRuntime = new Map());
|
|
82
88
|
|
|
89
|
+
/** @type {BuildMeta["exportsFinalNameByRuntime"]} */
|
|
83
90
|
const exportsFinalNameByRuntime =
|
|
84
91
|
buildMeta.exportsFinalNameByRuntime ||
|
|
85
92
|
(buildMeta.exportsFinalNameByRuntime = new Map());
|
|
86
93
|
|
|
87
94
|
for (const runtime of runtimes) {
|
|
88
|
-
|
|
89
|
-
|
|
95
|
+
const key = getRuntimeKey(runtime);
|
|
96
|
+
exportsSourceByRuntime.set(key, source);
|
|
97
|
+
exportsFinalNameByRuntime.set(key, finalName);
|
|
90
98
|
}
|
|
91
99
|
|
|
92
100
|
return true;
|
|
@@ -116,8 +124,13 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
116
124
|
exportsInfo.canMangleUse = false;
|
|
117
125
|
} else {
|
|
118
126
|
const exportsInfo = moduleGraph.getExportsInfo(module);
|
|
119
|
-
|
|
120
|
-
if (
|
|
127
|
+
|
|
128
|
+
if (
|
|
129
|
+
// If the entry module is commonjs, its exports cannot be mangled
|
|
130
|
+
(module.buildMeta && module.buildMeta.treatAsCommonJs) ||
|
|
131
|
+
// The entry module provides unknown exports
|
|
132
|
+
exportsInfo._otherExportsInfo.provided === null
|
|
133
|
+
) {
|
|
121
134
|
exportsInfo.setUsedInUnknownWay(runtime);
|
|
122
135
|
} else {
|
|
123
136
|
exportsInfo.setAllKnownExportsUsed(runtime);
|
|
@@ -128,7 +141,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
128
141
|
|
|
129
142
|
/**
|
|
130
143
|
* @param {LibraryOptions} library normalized library option
|
|
131
|
-
* @returns {T
|
|
144
|
+
* @returns {T} preprocess as needed by overriding
|
|
132
145
|
*/
|
|
133
146
|
parseOptions(library) {
|
|
134
147
|
const { name } = library;
|
|
@@ -144,6 +157,94 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
144
157
|
};
|
|
145
158
|
}
|
|
146
159
|
|
|
160
|
+
/**
|
|
161
|
+
* @param {Source} source source
|
|
162
|
+
* @param {Module} module module
|
|
163
|
+
* @param {ModuleGraph} moduleGraph moduleGraph
|
|
164
|
+
* @param {RuntimeSpec} runtime chunk runtime
|
|
165
|
+
* @param {[string, string][]} exports exports
|
|
166
|
+
* @param {Set<string>} alreadyRenderedExports already rendered exports
|
|
167
|
+
* @returns {ConcatSource} source with null provided exports
|
|
168
|
+
*/
|
|
169
|
+
_analyzeUnknownProvidedExports(
|
|
170
|
+
source,
|
|
171
|
+
module,
|
|
172
|
+
moduleGraph,
|
|
173
|
+
runtime,
|
|
174
|
+
exports,
|
|
175
|
+
alreadyRenderedExports
|
|
176
|
+
) {
|
|
177
|
+
const result = new ConcatSource(source);
|
|
178
|
+
/** @type {Set<string>} */
|
|
179
|
+
const moduleRequests = new Set();
|
|
180
|
+
/** @type {Map<string, string>} */
|
|
181
|
+
const unknownProvidedExports = new Map();
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @param {Module} module the module
|
|
185
|
+
* @param {boolean} isDynamicReexport if module is dynamic reexported
|
|
186
|
+
*/
|
|
187
|
+
const resolveDynamicStarReexport = (module, isDynamicReexport) => {
|
|
188
|
+
for (const connection of moduleGraph.getOutgoingConnections(module)) {
|
|
189
|
+
const dep = connection.dependency;
|
|
190
|
+
|
|
191
|
+
// Only handle star-reexport statement
|
|
192
|
+
if (
|
|
193
|
+
dep instanceof HarmonyExportImportedSpecifierDependency &&
|
|
194
|
+
dep.name === null
|
|
195
|
+
) {
|
|
196
|
+
const importedModule = connection.resolvedModule;
|
|
197
|
+
const importedModuleExportsInfo =
|
|
198
|
+
moduleGraph.getExportsInfo(importedModule);
|
|
199
|
+
|
|
200
|
+
// The imported module provides unknown exports
|
|
201
|
+
// So keep the reexports rendered in the bundle
|
|
202
|
+
if (
|
|
203
|
+
dep.getMode(moduleGraph, runtime).type === "dynamic-reexport" &&
|
|
204
|
+
importedModuleExportsInfo._otherExportsInfo.provided === null
|
|
205
|
+
) {
|
|
206
|
+
// Handle export * from 'external'
|
|
207
|
+
if (importedModule instanceof ExternalModule) {
|
|
208
|
+
moduleRequests.add(importedModule.userRequest);
|
|
209
|
+
} else {
|
|
210
|
+
resolveDynamicStarReexport(importedModule, true);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// If importer modules existing `dynamic-reexport` dependency
|
|
214
|
+
// We should keep export statement rendered in the bundle
|
|
215
|
+
else if (isDynamicReexport) {
|
|
216
|
+
for (const exportInfo of importedModuleExportsInfo.orderedExports) {
|
|
217
|
+
if (!exportInfo.provided || exportInfo.name === "default") {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
const originalName = exportInfo.name;
|
|
221
|
+
const usedName = exportInfo.getUsedName(originalName, runtime);
|
|
222
|
+
|
|
223
|
+
if (!alreadyRenderedExports.has(originalName) && usedName) {
|
|
224
|
+
unknownProvidedExports.set(originalName, usedName);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
resolveDynamicStarReexport(module, false);
|
|
233
|
+
|
|
234
|
+
for (const request of moduleRequests) {
|
|
235
|
+
result.add(`export * from "${request}";\n`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
for (const [origin, used] of unknownProvidedExports) {
|
|
239
|
+
exports.push([
|
|
240
|
+
origin,
|
|
241
|
+
`${RuntimeGlobals.exports}${propertyAccess([used])}`
|
|
242
|
+
]);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
|
|
147
248
|
/**
|
|
148
249
|
* @param {Source} source source
|
|
149
250
|
* @param {Module} module module
|
|
@@ -164,9 +265,8 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
164
265
|
},
|
|
165
266
|
{ options, compilation }
|
|
166
267
|
) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const exportsInfo = options.export
|
|
268
|
+
let result = new ConcatSource(source);
|
|
269
|
+
const exportInfos = options.export
|
|
170
270
|
? [
|
|
171
271
|
moduleGraph.getExportInfo(
|
|
172
272
|
module,
|
|
@@ -178,7 +278,9 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
178
278
|
const exportsFinalNameByRuntime =
|
|
179
279
|
(module.buildMeta &&
|
|
180
280
|
module.buildMeta.exportsFinalNameByRuntime &&
|
|
181
|
-
module.buildMeta.exportsFinalNameByRuntime.get(
|
|
281
|
+
module.buildMeta.exportsFinalNameByRuntime.get(
|
|
282
|
+
getRuntimeKey(chunk.runtime)
|
|
283
|
+
)) ||
|
|
182
284
|
{};
|
|
183
285
|
|
|
184
286
|
const definitions =
|
|
@@ -188,6 +290,9 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
188
290
|
const shortHandedExports = [];
|
|
189
291
|
/** @type {[string, string][]} */
|
|
190
292
|
const exports = [];
|
|
293
|
+
/** @type {Set<string>} */
|
|
294
|
+
const alreadyRenderedExports = new Set();
|
|
295
|
+
|
|
191
296
|
const isAsync = moduleGraph.isAsync(module);
|
|
192
297
|
|
|
193
298
|
const treatAsCommonJs =
|
|
@@ -200,7 +305,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
200
305
|
);
|
|
201
306
|
}
|
|
202
307
|
|
|
203
|
-
outer: for (const exportInfo of
|
|
308
|
+
outer: for (const exportInfo of exportInfos) {
|
|
204
309
|
if (!exportInfo.provided) continue;
|
|
205
310
|
|
|
206
311
|
const originalName = exportInfo.name;
|
|
@@ -273,6 +378,8 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
273
378
|
: `${finalName} as ${originalName}`
|
|
274
379
|
);
|
|
275
380
|
}
|
|
381
|
+
|
|
382
|
+
alreadyRenderedExports.add(originalName);
|
|
276
383
|
}
|
|
277
384
|
|
|
278
385
|
if (treatAsCommonJs) {
|
|
@@ -283,6 +390,15 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
283
390
|
result.add(`export { ${shortHandedExports.join(", ")} };\n`);
|
|
284
391
|
}
|
|
285
392
|
|
|
393
|
+
result = this._analyzeUnknownProvidedExports(
|
|
394
|
+
result,
|
|
395
|
+
module,
|
|
396
|
+
moduleGraph,
|
|
397
|
+
chunk.runtime,
|
|
398
|
+
exports,
|
|
399
|
+
alreadyRenderedExports
|
|
400
|
+
);
|
|
401
|
+
|
|
286
402
|
for (const [exportName, final] of exports) {
|
|
287
403
|
result.add(
|
|
288
404
|
`export ${runtimeTemplate.renderConst()} ${exportName} = ${final};\n`
|
|
@@ -308,9 +424,10 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
308
424
|
const exportsSource =
|
|
309
425
|
module.buildMeta &&
|
|
310
426
|
module.buildMeta.exportsSourceByRuntime &&
|
|
311
|
-
module.buildMeta.exportsSourceByRuntime.get(chunk.runtime);
|
|
427
|
+
module.buildMeta.exportsSourceByRuntime.get(getRuntimeKey(chunk.runtime));
|
|
312
428
|
|
|
313
|
-
// Re-add the module's exports source when rendered in factory
|
|
429
|
+
// Re-add the module's exports source when rendered in factory
|
|
430
|
+
// or as an inlined startup module wrapped in an IIFE
|
|
314
431
|
if ((inlinedInIIFE || factory) && exportsSource) {
|
|
315
432
|
return new ConcatSource(exportsSource, source);
|
|
316
433
|
}
|
|
@@ -17,6 +17,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
17
17
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
|
18
18
|
/** @typedef {import("../Chunk")} Chunk */
|
|
19
19
|
/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
|
|
20
|
+
/** @typedef {import("../ExportsInfo").ExportInfoName} ExportInfoName */
|
|
20
21
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
|
21
22
|
/** @typedef {import("../util/Hash")} Hash */
|
|
22
23
|
/**
|
|
@@ -51,7 +52,7 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
51
52
|
|
|
52
53
|
/**
|
|
53
54
|
* @param {LibraryOptions} library normalized library option
|
|
54
|
-
* @returns {T
|
|
55
|
+
* @returns {T} preprocess as needed by overriding
|
|
55
56
|
*/
|
|
56
57
|
parseOptions(library) {
|
|
57
58
|
const { name } = library;
|
|
@@ -128,7 +129,9 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
128
129
|
const otherUnused =
|
|
129
130
|
exportsInfo.otherExportsInfo.getUsed(chunk.runtime) ===
|
|
130
131
|
UsageState.Unused;
|
|
132
|
+
/** @type {string[]} */
|
|
131
133
|
const instructions = [];
|
|
134
|
+
/** @type {ExportInfoName[]} */
|
|
132
135
|
const handledNames = [];
|
|
133
136
|
for (const exportInfo of exportsInfo.orderedExports) {
|
|
134
137
|
const used = exportInfo.getUsedName(
|
|
@@ -83,12 +83,13 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
83
83
|
type: options.type
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
+
/** @type {UmdLibraryPluginOptions["optionalAmdExternalAsGlobal"]} */
|
|
86
87
|
this.optionalAmdExternalAsGlobal = options.optionalAmdExternalAsGlobal;
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
/**
|
|
90
91
|
* @param {LibraryOptions} library normalized library option
|
|
91
|
-
* @returns {T
|
|
92
|
+
* @returns {T} preprocess as needed by overriding
|
|
92
93
|
*/
|
|
93
94
|
parseOptions(library) {
|
|
94
95
|
/** @type {LibraryName | undefined} */
|
|
@@ -207,7 +208,6 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
207
208
|
replaceKeys(
|
|
208
209
|
externals
|
|
209
210
|
.map((m) => {
|
|
210
|
-
let expr;
|
|
211
211
|
let request = m.request;
|
|
212
212
|
if (typeof request === "object") {
|
|
213
213
|
request =
|
|
@@ -219,7 +219,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
219
219
|
`Missing external configuration for type:${type}`
|
|
220
220
|
);
|
|
221
221
|
}
|
|
222
|
-
expr = Array.isArray(request)
|
|
222
|
+
let expr = Array.isArray(request)
|
|
223
223
|
? `require(${JSON.stringify(
|
|
224
224
|
request[0]
|
|
225
225
|
)})${accessorToObjectAccess(request.slice(1))}`
|
|
@@ -258,6 +258,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
258
258
|
)
|
|
259
259
|
);
|
|
260
260
|
|
|
261
|
+
/** @type {string} */
|
|
261
262
|
let amdFactory;
|
|
262
263
|
if (optionalExternals.length > 0) {
|
|
263
264
|
const wrapperArguments = externalsArguments(requiredExternals);
|