webpack 5.93.0 → 5.95.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 +8 -5
- package/bin/webpack.js +6 -7
- package/hot/log.js +1 -2
- package/hot/only-dev-server.js +1 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/APIPlugin.js +4 -3
- package/lib/AbstractMethodError.js +10 -5
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +12 -6
- package/lib/Cache.js +8 -10
- package/lib/CacheFacade.js +3 -3
- package/lib/CaseSensitiveModulesWarning.js +5 -7
- package/lib/Chunk.js +14 -11
- package/lib/ChunkGraph.js +58 -36
- package/lib/ChunkGroup.js +2 -3
- package/lib/ChunkTemplate.js +43 -0
- package/lib/CleanPlugin.js +10 -11
- package/lib/CodeGenerationResults.js +6 -5
- package/lib/CommentCompilationWarning.js +0 -1
- package/lib/Compilation.js +223 -191
- package/lib/Compiler.js +81 -82
- package/lib/ConcatenationScope.js +3 -6
- package/lib/ConditionalInitFragment.js +6 -7
- package/lib/ConstPlugin.js +7 -15
- package/lib/ContextExclusionPlugin.js +3 -3
- package/lib/ContextModule.js +33 -20
- package/lib/ContextModuleFactory.js +89 -44
- package/lib/ContextReplacementPlugin.js +10 -9
- package/lib/DefinePlugin.js +75 -68
- package/lib/DelegatedModule.js +7 -3
- package/lib/DelegatedModuleFactoryPlugin.js +36 -22
- package/lib/DelegatedPlugin.js +4 -0
- package/lib/DependenciesBlock.js +0 -1
- package/lib/Dependency.js +10 -14
- package/lib/DllEntryPlugin.js +4 -2
- package/lib/DllModuleFactory.js +1 -0
- package/lib/DllPlugin.js +9 -7
- package/lib/DllReferencePlugin.js +30 -15
- package/lib/EntryPlugin.js +1 -3
- package/lib/EnvironmentPlugin.js +6 -2
- package/lib/ErrorHelpers.js +11 -12
- package/lib/EvalDevToolModulePlugin.js +10 -12
- package/lib/EvalSourceMapDevToolPlugin.js +15 -13
- package/lib/ExportsInfo.js +185 -120
- package/lib/ExternalModule.js +41 -15
- package/lib/ExternalModuleFactoryPlugin.js +23 -10
- package/lib/FileSystemInfo.js +791 -422
- package/lib/FlagAllModulesAsUsedPlugin.js +1 -1
- package/lib/FlagDependencyExportsPlugin.js +12 -11
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +2 -5
- package/lib/GraphHelpers.js +3 -2
- package/lib/HookWebpackError.js +8 -10
- package/lib/HotModuleReplacementPlugin.js +78 -64
- package/lib/IgnoreErrorModuleFactory.js +3 -3
- package/lib/IgnorePlugin.js +1 -3
- package/lib/IgnoreWarningsPlugin.js +6 -9
- package/lib/InitFragment.js +2 -3
- package/lib/LibManifestPlugin.js +4 -3
- package/lib/MainTemplate.js +72 -19
- package/lib/Module.js +25 -9
- package/lib/ModuleBuildError.js +4 -11
- package/lib/ModuleDependencyError.js +5 -5
- package/lib/ModuleDependencyWarning.js +5 -5
- package/lib/ModuleError.js +1 -5
- package/lib/ModuleFilenameHelpers.js +29 -46
- package/lib/ModuleGraph.js +7 -6
- package/lib/ModuleGraphConnection.js +6 -6
- package/lib/ModuleInfoHeaderPlugin.js +82 -30
- package/lib/ModuleParseError.js +8 -9
- package/lib/ModuleRestoreError.js +1 -1
- package/lib/ModuleStoreError.js +1 -1
- package/lib/ModuleTemplate.js +33 -1
- package/lib/ModuleTypeConstants.js +21 -22
- package/lib/ModuleWarning.js +1 -5
- package/lib/MultiCompiler.js +24 -26
- package/lib/MultiStats.js +73 -31
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +130 -69
- package/lib/NormalModuleFactory.js +53 -49
- package/lib/OptimizationStages.js +3 -3
- package/lib/ProgressPlugin.js +9 -9
- package/lib/ProvidePlugin.js +4 -4
- package/lib/RuntimeGlobals.js +71 -70
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +24 -12
- package/lib/RuntimeTemplate.js +40 -44
- package/lib/SizeFormatHelpers.js +2 -4
- package/lib/SourceMapDevToolPlugin.js +42 -34
- package/lib/Stats.js +5 -11
- package/lib/Template.js +18 -24
- package/lib/TemplatedPathPlugin.js +21 -13
- package/lib/WarnDeprecatedOptionPlugin.js +0 -1
- package/lib/WatchIgnorePlugin.js +26 -9
- package/lib/Watching.js +10 -5
- package/lib/WebpackOptionsApply.js +84 -62
- package/lib/asset/AssetGenerator.js +107 -42
- package/lib/asset/AssetModulesPlugin.js +29 -23
- package/lib/asset/AssetSourceGenerator.js +2 -7
- package/lib/async-modules/AwaitDependenciesInitFragment.js +6 -7
- package/lib/buildChunkGraph.js +93 -81
- package/lib/cache/IdleFileCachePlugin.js +4 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +5 -5
- package/lib/cache/PackFileCacheStrategy.js +51 -50
- package/lib/cache/ResolverCachePlugin.js +6 -6
- package/lib/cache/mergeEtags.js +16 -21
- package/lib/cli.js +148 -104
- package/lib/config/browserslistTargetHandler.js +16 -13
- package/lib/config/defaults.js +32 -28
- package/lib/config/normalization.js +335 -344
- package/lib/config/target.js +42 -52
- package/lib/container/ContainerEntryModule.js +2 -2
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +11 -8
- package/lib/container/options.js +18 -4
- package/lib/css/CssExportsGenerator.js +26 -24
- package/lib/css/CssGenerator.js +9 -4
- package/lib/css/CssLoadingRuntimeModule.js +10 -10
- package/lib/css/CssModulesPlugin.js +127 -47
- package/lib/css/CssParser.js +20 -18
- package/lib/css/walkCssTokens.js +80 -95
- package/lib/debug/ProfilingPlugin.js +19 -20
- package/lib/dependencies/AMDDefineDependency.js +1 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +83 -47
- package/lib/dependencies/AMDRequireArrayDependency.js +9 -10
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +22 -16
- package/lib/dependencies/AMDRuntimeModules.js +2 -2
- package/lib/dependencies/CommonJsDependencyHelpers.js +6 -2
- package/lib/dependencies/CommonJsExportRequireDependency.js +37 -41
- package/lib/dependencies/CommonJsExportsDependency.js +0 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +19 -23
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +52 -61
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +6 -8
- package/lib/dependencies/ConstDependency.js +1 -1
- package/lib/dependencies/ContextDependency.js +7 -2
- package/lib/dependencies/ContextDependencyHelpers.js +31 -34
- package/lib/dependencies/ContextElementDependency.js +35 -8
- package/lib/dependencies/CriticalDependencyWarning.js +1 -1
- package/lib/dependencies/CssExportDependency.js +7 -7
- package/lib/dependencies/CssImportDependency.js +0 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +3 -3
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +4 -5
- package/lib/dependencies/DynamicExports.js +5 -5
- package/lib/dependencies/ExportsInfoDependency.js +1 -2
- package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +27 -16
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +107 -64
- package/lib/dependencies/HarmonyExports.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +2 -4
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -15
- package/lib/dependencies/ImportDependency.js +1 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +5 -5
- package/lib/dependencies/ImportMetaPlugin.js +11 -13
- package/lib/dependencies/ImportParserPlugin.js +39 -44
- package/lib/dependencies/JsonExportsDependency.js +22 -18
- package/lib/dependencies/LoaderPlugin.js +47 -36
- package/lib/dependencies/LocalModule.js +1 -1
- package/lib/dependencies/LocalModulesHelpers.js +4 -4
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -1
- package/lib/dependencies/ProvidedDependency.js +1 -1
- package/lib/dependencies/PureExpressionDependency.js +6 -6
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLDependency.js +3 -3
- package/lib/dependencies/URLPlugin.js +66 -12
- package/lib/dependencies/WorkerPlugin.js +25 -24
- package/lib/dependencies/processExportInfo.js +3 -1
- package/lib/electron/ElectronTargetPlugin.js +1 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +3 -3
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -3
- package/lib/formatLocation.js +1 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +4 -5
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +9 -12
- package/lib/hmr/LazyCompilationPlugin.js +27 -12
- package/lib/hmr/lazyCompilationBackend.js +64 -40
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +2 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +5 -1
- package/lib/ids/IdHelpers.js +29 -39
- package/lib/ids/SyncModuleIdsPlugin.js +7 -2
- package/lib/index.js +1 -5
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -4
- package/lib/javascript/BasicEvaluatedExpression.js +4 -19
- package/lib/javascript/ChunkHelpers.js +1 -1
- package/lib/javascript/CommonJsChunkFormatPlugin.js +3 -2
- package/lib/javascript/EnableChunkLoadingPlugin.js +7 -6
- package/lib/javascript/JavascriptGenerator.js +23 -7
- package/lib/javascript/JavascriptModulesPlugin.js +133 -86
- package/lib/javascript/JavascriptParser.js +179 -200
- package/lib/javascript/JavascriptParserHelpers.js +20 -21
- package/lib/javascript/StartupHelpers.js +41 -13
- package/lib/json/JsonGenerator.js +7 -13
- package/lib/json/JsonModulesPlugin.js +1 -4
- package/lib/json/JsonParser.js +5 -3
- package/lib/library/AmdLibraryPlugin.js +12 -16
- package/lib/library/AssignLibraryPlugin.js +8 -10
- package/lib/library/EnableLibraryPlugin.js +15 -14
- package/lib/library/JsonpLibraryPlugin.js +2 -1
- package/lib/library/ModernModuleLibraryPlugin.js +8 -6
- package/lib/library/ModuleLibraryPlugin.js +2 -1
- package/lib/library/SystemLibraryPlugin.js +2 -1
- package/lib/library/UmdLibraryPlugin.js +66 -92
- package/lib/logging/Logger.js +32 -4
- package/lib/logging/createConsoleLogger.js +12 -13
- package/lib/logging/runtime.js +7 -8
- package/lib/logging/truncateArgs.js +5 -8
- package/lib/node/NodeWatchFileSystem.js +3 -18
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/nodeConsole.js +22 -22
- package/lib/optimize/AggressiveMergingPlugin.js +2 -4
- package/lib/optimize/AggressiveSplittingPlugin.js +16 -19
- package/lib/optimize/ConcatenatedModule.js +81 -51
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -3
- package/lib/optimize/InnerGraph.js +17 -17
- package/lib/optimize/InnerGraphPlugin.js +8 -7
- package/lib/optimize/LimitChunkCountPlugin.js +2 -3
- package/lib/optimize/MangleExportsPlugin.js +1 -0
- package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
- package/lib/optimize/MinMaxSizeWarning.js +1 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +54 -78
- package/lib/optimize/RealContentHashPlugin.js +7 -10
- package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -2
- package/lib/optimize/SplitChunksPlugin.js +34 -30
- package/lib/performance/SizeLimitsPlugin.js +2 -2
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
- package/lib/rules/BasicEffectRulePlugin.js +3 -1
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -1
- package/lib/rules/RuleSetCompiler.js +41 -22
- package/lib/rules/UseEffectRulePlugin.js +36 -32
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +10 -11
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +11 -17
- package/lib/runtime/LoadScriptRuntimeModule.js +17 -18
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -3
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +241 -126
- package/lib/serialization/BinaryMiddleware.js +44 -28
- package/lib/serialization/DateObjectSerializer.js +1 -0
- package/lib/serialization/ErrorObjectSerializer.js +2 -0
- package/lib/serialization/FileMiddleware.js +154 -106
- package/lib/serialization/MapObjectSerializer.js +2 -1
- package/lib/serialization/NullPrototypeObjectSerializer.js +3 -2
- package/lib/serialization/ObjectMiddleware.js +52 -56
- package/lib/serialization/PlainObjectSerializer.js +32 -6
- package/lib/serialization/RegExpObjectSerializer.js +1 -0
- package/lib/serialization/Serializer.js +4 -5
- package/lib/serialization/SerializerMiddleware.js +6 -6
- package/lib/serialization/SetObjectSerializer.js +2 -1
- package/lib/sharing/ConsumeSharedPlugin.js +116 -97
- package/lib/sharing/ConsumeSharedRuntimeModule.js +4 -4
- package/lib/sharing/ProvideForSharedDependency.js +0 -1
- package/lib/sharing/ProvideSharedPlugin.js +2 -2
- package/lib/sharing/resolveMatchedConfigs.js +2 -1
- package/lib/sharing/utils.js +15 -27
- package/lib/stats/DefaultStatsFactoryPlugin.js +424 -281
- package/lib/stats/DefaultStatsPresetPlugin.js +73 -18
- package/lib/stats/DefaultStatsPrinterPlugin.js +370 -101
- package/lib/stats/StatsFactory.js +127 -56
- package/lib/stats/StatsPrinter.js +75 -44
- package/lib/util/ArrayHelpers.js +8 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +31 -12
- package/lib/util/IterableHelpers.js +3 -4
- package/lib/util/LazyBucketSortedSet.js +60 -44
- package/lib/util/LazySet.js +13 -0
- package/lib/util/MapHelpers.js +1 -3
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Queue.js +1 -1
- package/lib/util/Semaphore.js +4 -7
- package/lib/util/SetHelpers.js +5 -5
- package/lib/util/SortableSet.js +4 -3
- package/lib/util/StackedCacheMap.js +4 -6
- package/lib/util/StackedMap.js +1 -3
- package/lib/util/StringXor.js +0 -5
- package/lib/util/TupleQueue.js +1 -1
- package/lib/util/TupleSet.js +15 -5
- package/lib/util/URLAbsoluteSpecifier.js +7 -7
- package/lib/util/WeakTupleMap.js +19 -21
- package/lib/util/binarySearchBounds.js +5 -12
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +21 -19
- package/lib/util/comparators.js +57 -52
- package/lib/util/compileBooleanMatcher.js +3 -6
- package/lib/util/conventions.js +8 -11
- package/lib/util/createHash.js +9 -6
- package/lib/util/deprecation.js +22 -12
- package/lib/util/deterministicGrouping.js +19 -26
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +32 -32
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +7 -7
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +81 -59
- package/lib/util/memoize.js +8 -10
- package/lib/util/mergeScope.js +6 -9
- package/lib/util/nonNumericOnlyHash.js +2 -2
- package/lib/util/numberHash.js +1 -6
- package/lib/util/objectToMap.js +0 -1
- package/lib/util/propertyAccess.js +2 -5
- package/lib/util/propertyName.js +1 -3
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +109 -113
- package/lib/util/semver.js +29 -27
- package/lib/util/serialization.js +16 -1
- package/lib/util/smartGrouping.js +5 -5
- package/lib/util/source.js +1 -1
- package/lib/wasm/EnableWasmLoadingPlugin.js +5 -4
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -6
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +20 -19
- package/lib/wasm-sync/WebAssemblyGenerator.js +14 -29
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +18 -17
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +5 -0
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -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 +1 -0
- package/types.d.ts +681 -355
@@ -43,7 +43,6 @@ const ModuleDecoratorDependency = require("./ModuleDecoratorDependency");
|
|
43
43
|
* exports.foo = void 0;
|
44
44
|
* exports.foo = "bar";
|
45
45
|
* ```
|
46
|
-
*
|
47
46
|
* @param {TODO} expr expression
|
48
47
|
* @returns {Expression | undefined} returns the value of property descriptor
|
49
48
|
*/
|
@@ -61,15 +60,13 @@ const getValueOfPropertyDescription = expr => {
|
|
61
60
|
* The purpose of this function is to check whether an expression is a truthy literal or not. This is
|
62
61
|
* useful when parsing CommonJS exports, because CommonJS modules can export any value, including falsy
|
63
62
|
* values like `null` and `false`. However, exports should only be created if the exported value is truthy.
|
64
|
-
*
|
65
63
|
* @param {Expression} expr expression being checked
|
66
64
|
* @returns {boolean} true, when the expression is a truthy literal
|
67
|
-
*
|
68
65
|
*/
|
69
66
|
const isTruthyLiteral = expr => {
|
70
67
|
switch (expr.type) {
|
71
68
|
case "Literal":
|
72
|
-
return
|
69
|
+
return Boolean(expr.value);
|
73
70
|
case "UnaryExpression":
|
74
71
|
if (expr.operator === "!") return isFalsyLiteral(expr.argument);
|
75
72
|
}
|
@@ -80,7 +77,6 @@ const isTruthyLiteral = expr => {
|
|
80
77
|
* The purpose of this function is to check whether an expression is a falsy literal or not. This is
|
81
78
|
* useful when parsing CommonJS exports, because CommonJS modules can export any value, including falsy
|
82
79
|
* values like `null` and `false`. However, exports should only be created if the exported value is truthy.
|
83
|
-
*
|
84
80
|
* @param {Expression} expr expression being checked
|
85
81
|
* @returns {boolean} true, when the expression is a falsy literal
|
86
82
|
*/
|
@@ -215,7 +211,7 @@ class CommonJsExportsParserPlugin {
|
|
215
211
|
!parser.isStatementLevelExpression(expr)
|
216
212
|
);
|
217
213
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
218
|
-
dep.optional =
|
214
|
+
dep.optional = Boolean(parser.scope.inTry);
|
219
215
|
parser.state.module.addDependency(dep);
|
220
216
|
return true;
|
221
217
|
}
|
@@ -241,9 +237,9 @@ class CommonJsExportsParserPlugin {
|
|
241
237
|
};
|
242
238
|
parser.hooks.assignMemberChain
|
243
239
|
.for("exports")
|
244
|
-
.tap("CommonJsExportsParserPlugin", (expr, members) =>
|
245
|
-
|
246
|
-
|
240
|
+
.tap("CommonJsExportsParserPlugin", (expr, members) =>
|
241
|
+
handleAssignExport(expr, "exports", members)
|
242
|
+
);
|
247
243
|
parser.hooks.assignMemberChain
|
248
244
|
.for("this")
|
249
245
|
.tap("CommonJsExportsParserPlugin", (expr, members) => {
|
@@ -306,7 +302,7 @@ class CommonJsExportsParserPlugin {
|
|
306
302
|
* @param {CallExpression=} call call expression
|
307
303
|
* @returns {boolean | void} true, when the expression was handled
|
308
304
|
*/
|
309
|
-
const handleAccessExport = (expr, base, members, call
|
305
|
+
const handleAccessExport = (expr, base, members, call) => {
|
310
306
|
if (HarmonyExports.isEnabled(parser.state)) return;
|
311
307
|
if (members.length === 0) {
|
312
308
|
bailout(
|
@@ -328,7 +324,7 @@ class CommonJsExportsParserPlugin {
|
|
328
324
|
/** @type {Range} */ (expr.range),
|
329
325
|
base,
|
330
326
|
members,
|
331
|
-
|
327
|
+
Boolean(call)
|
332
328
|
);
|
333
329
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
334
330
|
parser.state.module.addDependency(dep);
|
@@ -339,19 +335,19 @@ class CommonJsExportsParserPlugin {
|
|
339
335
|
};
|
340
336
|
parser.hooks.callMemberChain
|
341
337
|
.for("exports")
|
342
|
-
.tap("CommonJsExportsParserPlugin", (expr, members) =>
|
343
|
-
|
344
|
-
|
338
|
+
.tap("CommonJsExportsParserPlugin", (expr, members) =>
|
339
|
+
handleAccessExport(expr.callee, "exports", members, expr)
|
340
|
+
);
|
345
341
|
parser.hooks.expressionMemberChain
|
346
342
|
.for("exports")
|
347
|
-
.tap("CommonJsExportsParserPlugin", (expr, members) =>
|
348
|
-
|
349
|
-
|
343
|
+
.tap("CommonJsExportsParserPlugin", (expr, members) =>
|
344
|
+
handleAccessExport(expr, "exports", members)
|
345
|
+
);
|
350
346
|
parser.hooks.expression
|
351
347
|
.for("exports")
|
352
|
-
.tap("CommonJsExportsParserPlugin", expr =>
|
353
|
-
|
354
|
-
|
348
|
+
.tap("CommonJsExportsParserPlugin", expr =>
|
349
|
+
handleAccessExport(expr, "exports", [])
|
350
|
+
);
|
355
351
|
parser.hooks.callMemberChain
|
356
352
|
.for("module")
|
357
353
|
.tap("CommonJsExportsParserPlugin", (expr, members) => {
|
@@ -371,9 +367,9 @@ class CommonJsExportsParserPlugin {
|
|
371
367
|
});
|
372
368
|
parser.hooks.expression
|
373
369
|
.for("module.exports")
|
374
|
-
.tap("CommonJsExportsParserPlugin", expr =>
|
375
|
-
|
376
|
-
|
370
|
+
.tap("CommonJsExportsParserPlugin", expr =>
|
371
|
+
handleAccessExport(expr, "module.exports", [])
|
372
|
+
);
|
377
373
|
parser.hooks.callMemberChain
|
378
374
|
.for("this")
|
379
375
|
.tap("CommonJsExportsParserPlugin", (expr, members) => {
|
@@ -146,7 +146,7 @@ CommonJsFullRequireDependency.Template = class CommonJsFullRequireDependencyTemp
|
|
146
146
|
if (usedImported) {
|
147
147
|
const comment = equals(usedImported, trimmedIds)
|
148
148
|
? ""
|
149
|
-
: Template.toNormalComment(propertyAccess(trimmedIds))
|
149
|
+
: `${Template.toNormalComment(propertyAccess(trimmedIds))} `;
|
150
150
|
const access = `${comment}${propertyAccess(usedImported)}`;
|
151
151
|
requireExpr =
|
152
152
|
dep.asiSafe === true
|
@@ -63,7 +63,7 @@ class CommonJsImportsParserPlugin {
|
|
63
63
|
}
|
64
64
|
};
|
65
65
|
|
66
|
-
|
66
|
+
// #region metadata
|
67
67
|
/**
|
68
68
|
* @param {string} expression expression
|
69
69
|
* @param {() => string[]} getMembers get members
|
@@ -102,7 +102,7 @@ class CommonJsImportsParserPlugin {
|
|
102
102
|
tapRequireExpression("require", () => []);
|
103
103
|
tapRequireExpression("require.resolve", () => ["resolve"]);
|
104
104
|
tapRequireExpression("require.resolveWeak", () => ["resolveWeak"]);
|
105
|
-
|
105
|
+
// #endregion
|
106
106
|
|
107
107
|
// Weird stuff //
|
108
108
|
parser.hooks.assign
|
@@ -115,7 +115,7 @@ class CommonJsImportsParserPlugin {
|
|
115
115
|
return true;
|
116
116
|
});
|
117
117
|
|
118
|
-
|
118
|
+
// #region Unsupported
|
119
119
|
parser.hooks.expression
|
120
120
|
.for("require.main")
|
121
121
|
.tap(
|
@@ -152,9 +152,9 @@ class CommonJsImportsParserPlugin {
|
|
152
152
|
"module.parent.require is not supported by webpack."
|
153
153
|
)
|
154
154
|
);
|
155
|
-
|
155
|
+
// #endregion
|
156
156
|
|
157
|
-
|
157
|
+
// #region Renaming
|
158
158
|
/**
|
159
159
|
* @param {Expression} expr expression
|
160
160
|
* @returns {boolean} true when set undefined
|
@@ -175,9 +175,9 @@ class CommonJsImportsParserPlugin {
|
|
175
175
|
parser.hooks.rename
|
176
176
|
.for("require")
|
177
177
|
.tap("CommonJsImportsParserPlugin", defineUndefined);
|
178
|
-
|
178
|
+
// #endregion
|
179
179
|
|
180
|
-
|
180
|
+
// #region Inspection
|
181
181
|
const requireCache = toConstantDependency(
|
182
182
|
parser,
|
183
183
|
RuntimeGlobals.moduleCache,
|
@@ -191,9 +191,9 @@ class CommonJsImportsParserPlugin {
|
|
191
191
|
parser.hooks.expression
|
192
192
|
.for("require.cache")
|
193
193
|
.tap("CommonJsImportsParserPlugin", requireCache);
|
194
|
-
|
194
|
+
// #endregion
|
195
195
|
|
196
|
-
|
196
|
+
// #region Require as expression
|
197
197
|
/**
|
198
198
|
* @param {Expression} expr expression
|
199
199
|
* @returns {boolean} true when handled
|
@@ -215,16 +215,16 @@ class CommonJsImportsParserPlugin {
|
|
215
215
|
options.unknownContextCritical &&
|
216
216
|
"require function is used in a way in which dependencies cannot be statically extracted";
|
217
217
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
218
|
-
dep.optional =
|
218
|
+
dep.optional = Boolean(parser.scope.inTry);
|
219
219
|
parser.state.current.addDependency(dep);
|
220
220
|
return true;
|
221
221
|
};
|
222
222
|
parser.hooks.expression
|
223
223
|
.for("require")
|
224
224
|
.tap("CommonJsImportsParserPlugin", requireAsExpressionHandler);
|
225
|
-
|
225
|
+
// #endregion
|
226
226
|
|
227
|
-
|
227
|
+
// #region Require
|
228
228
|
/**
|
229
229
|
* @param {CallExpression | NewExpression} expr expression
|
230
230
|
* @param {BasicEvaluatedExpression} param param
|
@@ -238,7 +238,7 @@ class CommonJsImportsParserPlugin {
|
|
238
238
|
getContext()
|
239
239
|
);
|
240
240
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
241
|
-
dep.optional =
|
241
|
+
dep.optional = Boolean(parser.scope.inTry);
|
242
242
|
parser.state.current.addDependency(dep);
|
243
243
|
return true;
|
244
244
|
}
|
@@ -264,7 +264,7 @@ class CommonJsImportsParserPlugin {
|
|
264
264
|
);
|
265
265
|
if (!dep) return;
|
266
266
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
267
|
-
dep.optional =
|
267
|
+
dep.optional = Boolean(parser.scope.inTry);
|
268
268
|
parser.state.current.addDependency(dep);
|
269
269
|
return true;
|
270
270
|
};
|
@@ -288,21 +288,17 @@ class CommonJsImportsParserPlugin {
|
|
288
288
|
);
|
289
289
|
}
|
290
290
|
}
|
291
|
-
if (requireOptions) {
|
292
|
-
if (requireOptions.webpackIgnore !==
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
if (requireOptions.webpackIgnore) {
|
303
|
-
return true;
|
304
|
-
}
|
305
|
-
}
|
291
|
+
if (requireOptions && requireOptions.webpackIgnore !== undefined) {
|
292
|
+
if (typeof requireOptions.webpackIgnore !== "boolean") {
|
293
|
+
parser.state.module.addWarning(
|
294
|
+
new UnsupportedFeatureWarning(
|
295
|
+
`\`webpackIgnore\` expected a boolean, but received: ${requireOptions.webpackIgnore}.`,
|
296
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
297
|
+
)
|
298
|
+
);
|
299
|
+
} else if (requireOptions.webpackIgnore) {
|
300
|
+
// Do not instrument `require()` if `webpackIgnore` is `true`
|
301
|
+
return true;
|
306
302
|
}
|
307
303
|
}
|
308
304
|
}
|
@@ -370,9 +366,9 @@ class CommonJsImportsParserPlugin {
|
|
370
366
|
parser.hooks.new
|
371
367
|
.for("module.require")
|
372
368
|
.tap("CommonJsImportsParserPlugin", createRequireHandler(true));
|
373
|
-
|
369
|
+
// #endregion
|
374
370
|
|
375
|
-
|
371
|
+
// #region Require with property access
|
376
372
|
/**
|
377
373
|
* @param {Expression} expr expression
|
378
374
|
* @param {string[]} calleeMembers callee members
|
@@ -403,7 +399,7 @@ class CommonJsImportsParserPlugin {
|
|
403
399
|
dep.asiSafe = !parser.isAsiPosition(
|
404
400
|
/** @type {Range} */ (expr.range)[0]
|
405
401
|
);
|
406
|
-
dep.optional =
|
402
|
+
dep.optional = Boolean(parser.scope.inTry);
|
407
403
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
408
404
|
parser.state.current.addDependency(dep);
|
409
405
|
return true;
|
@@ -440,7 +436,7 @@ class CommonJsImportsParserPlugin {
|
|
440
436
|
dep.asiSafe = !parser.isAsiPosition(
|
441
437
|
/** @type {Range} */ (expr.range)[0]
|
442
438
|
);
|
443
|
-
dep.optional =
|
439
|
+
dep.optional = Boolean(parser.scope.inTry);
|
444
440
|
dep.loc = /** @type {DependencyLocation} */ (expr.callee.loc);
|
445
441
|
parser.state.current.addDependency(dep);
|
446
442
|
parser.walkExpressions(expr.arguments);
|
@@ -459,9 +455,9 @@ class CommonJsImportsParserPlugin {
|
|
459
455
|
parser.hooks.callMemberChainOfCallMemberChain
|
460
456
|
.for("module.require")
|
461
457
|
.tap("CommonJsImportsParserPlugin", callChainHandler);
|
462
|
-
|
458
|
+
// #endregion
|
463
459
|
|
464
|
-
|
460
|
+
// #region Require.resolve
|
465
461
|
/**
|
466
462
|
* @param {CallExpression} expr call expression
|
467
463
|
* @param {boolean} weak weak
|
@@ -485,18 +481,17 @@ class CommonJsImportsParserPlugin {
|
|
485
481
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
486
482
|
parser.state.module.addPresentationalDependency(dep);
|
487
483
|
return true;
|
488
|
-
} else {
|
489
|
-
const result = processResolveItem(expr, param, weak);
|
490
|
-
if (result === undefined) {
|
491
|
-
processResolveContext(expr, param, weak);
|
492
|
-
}
|
493
|
-
const dep = new RequireResolveHeaderDependency(
|
494
|
-
/** @type {Range} */ (expr.callee.range)
|
495
|
-
);
|
496
|
-
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
497
|
-
parser.state.module.addPresentationalDependency(dep);
|
498
|
-
return true;
|
499
484
|
}
|
485
|
+
const result = processResolveItem(expr, param, weak);
|
486
|
+
if (result === undefined) {
|
487
|
+
processResolveContext(expr, param, weak);
|
488
|
+
}
|
489
|
+
const dep = new RequireResolveHeaderDependency(
|
490
|
+
/** @type {Range} */ (expr.callee.range)
|
491
|
+
);
|
492
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
493
|
+
parser.state.module.addPresentationalDependency(dep);
|
494
|
+
return true;
|
500
495
|
};
|
501
496
|
/**
|
502
497
|
* @param {CallExpression} expr call expression
|
@@ -512,7 +507,7 @@ class CommonJsImportsParserPlugin {
|
|
512
507
|
getContext()
|
513
508
|
);
|
514
509
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
515
|
-
dep.optional =
|
510
|
+
dep.optional = Boolean(parser.scope.inTry);
|
516
511
|
dep.weak = weak;
|
517
512
|
parser.state.current.addDependency(dep);
|
518
513
|
return true;
|
@@ -540,24 +535,20 @@ class CommonJsImportsParserPlugin {
|
|
540
535
|
);
|
541
536
|
if (!dep) return;
|
542
537
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
543
|
-
dep.optional =
|
538
|
+
dep.optional = Boolean(parser.scope.inTry);
|
544
539
|
parser.state.current.addDependency(dep);
|
545
540
|
return true;
|
546
541
|
};
|
547
542
|
|
548
543
|
parser.hooks.call
|
549
544
|
.for("require.resolve")
|
550
|
-
.tap("CommonJsImportsParserPlugin", expr =>
|
551
|
-
return processResolve(expr, false);
|
552
|
-
});
|
545
|
+
.tap("CommonJsImportsParserPlugin", expr => processResolve(expr, false));
|
553
546
|
parser.hooks.call
|
554
547
|
.for("require.resolveWeak")
|
555
|
-
.tap("CommonJsImportsParserPlugin", expr =>
|
556
|
-
|
557
|
-
});
|
558
|
-
//#endregion
|
548
|
+
.tap("CommonJsImportsParserPlugin", expr => processResolve(expr, true));
|
549
|
+
// #endregion
|
559
550
|
|
560
|
-
|
551
|
+
// #region Create require
|
561
552
|
|
562
553
|
if (!options.createRequire) return;
|
563
554
|
|
@@ -610,12 +601,12 @@ class CommonJsImportsParserPlugin {
|
|
610
601
|
});
|
611
602
|
parser.hooks.unhandledExpressionMemberChain
|
612
603
|
.for(createdRequireIdentifierTag)
|
613
|
-
.tap("CommonJsImportsParserPlugin", (expr, members) =>
|
614
|
-
|
604
|
+
.tap("CommonJsImportsParserPlugin", (expr, members) =>
|
605
|
+
expressionIsUnsupported(
|
615
606
|
parser,
|
616
607
|
`createRequire().${members.join(".")} is not supported by webpack.`
|
617
|
-
)(expr)
|
618
|
-
|
608
|
+
)(expr)
|
609
|
+
);
|
619
610
|
parser.hooks.canRename
|
620
611
|
.for(createdRequireIdentifierTag)
|
621
612
|
.tap("CommonJsImportsParserPlugin", () => true);
|
@@ -789,7 +780,7 @@ class CommonJsImportsParserPlugin {
|
|
789
780
|
parser.state.module.addPresentationalDependency(clearDep);
|
790
781
|
return true;
|
791
782
|
});
|
792
|
-
|
783
|
+
// #endregion
|
793
784
|
}
|
794
785
|
}
|
795
786
|
module.exports = CommonJsImportsParserPlugin;
|
@@ -50,7 +50,7 @@ class CommonJsSelfReferenceDependency extends NullDependency {
|
|
50
50
|
* @returns {string | null} an identifier to merge equal requests
|
51
51
|
*/
|
52
52
|
getResourceIdentifier() {
|
53
|
-
return
|
53
|
+
return "self";
|
54
54
|
}
|
55
55
|
|
56
56
|
/**
|
@@ -108,19 +108,17 @@ CommonJsSelfReferenceDependency.Template = class CommonJsSelfReferenceDependency
|
|
108
108
|
{ module, moduleGraph, runtime, runtimeRequirements }
|
109
109
|
) {
|
110
110
|
const dep = /** @type {CommonJsSelfReferenceDependency} */ (dependency);
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
used = moduleGraph.getExportsInfo(module).getUsedName(dep.names, runtime);
|
116
|
-
}
|
111
|
+
const used =
|
112
|
+
dep.names.length === 0
|
113
|
+
? dep.names
|
114
|
+
: moduleGraph.getExportsInfo(module).getUsedName(dep.names, runtime);
|
117
115
|
if (!used) {
|
118
116
|
throw new Error(
|
119
117
|
"Self-reference dependency has unused export name: This should not happen"
|
120
118
|
);
|
121
119
|
}
|
122
120
|
|
123
|
-
let base
|
121
|
+
let base;
|
124
122
|
switch (dep.base) {
|
125
123
|
case "exports":
|
126
124
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
@@ -44,7 +44,7 @@ class ConstDependency extends NullDependency {
|
|
44
44
|
*/
|
45
45
|
updateHash(hash, context) {
|
46
46
|
if (this._hashUpdate === undefined) {
|
47
|
-
let hashUpdate =
|
47
|
+
let hashUpdate = `${this.range}|${this.expression}`;
|
48
48
|
if (this.runtimeRequirements) {
|
49
49
|
for (const item of this.runtimeRequirements) {
|
50
50
|
hashUpdate += "|";
|
@@ -27,7 +27,7 @@ const getCriticalDependencyWarning = memoize(() =>
|
|
27
27
|
* @param {RegExp | null | undefined} r regexp
|
28
28
|
* @returns {string} stringified regexp
|
29
29
|
*/
|
30
|
-
const regExpToString = r => (r ? r
|
30
|
+
const regExpToString = r => (r ? String(r) : "");
|
31
31
|
|
32
32
|
class ContextDependency extends Dependency {
|
33
33
|
/**
|
@@ -91,7 +91,12 @@ class ContextDependency extends Dependency {
|
|
91
91
|
this.options.include
|
92
92
|
)} ${regExpToString(this.options.exclude)} ` +
|
93
93
|
`${this.options.mode} ${this.options.chunkName} ` +
|
94
|
-
`${JSON.stringify(this.options.groupOptions)}`
|
94
|
+
`${JSON.stringify(this.options.groupOptions)}` +
|
95
|
+
`${
|
96
|
+
this.options.referencedExports
|
97
|
+
? ` ${JSON.stringify(this.options.referencedExports)}`
|
98
|
+
: ""
|
99
|
+
}`
|
95
100
|
);
|
96
101
|
}
|
97
102
|
|
@@ -22,9 +22,7 @@ const { parseResource } = require("../util/identifier");
|
|
22
22
|
* @param {string} str String to quote
|
23
23
|
* @returns {string} Escaped string
|
24
24
|
*/
|
25
|
-
const quoteMeta = str => {
|
26
|
-
return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
27
|
-
};
|
25
|
+
const quoteMeta = str => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
28
26
|
|
29
27
|
/**
|
30
28
|
* @param {string} prefix prefix
|
@@ -57,7 +55,7 @@ const splitContextFromPrefix = prefix => {
|
|
57
55
|
* @param {...any} depArgs depArgs
|
58
56
|
* @returns {ContextDependency} the created Dependency
|
59
57
|
*/
|
60
|
-
exports.create = (
|
58
|
+
module.exports.create = (
|
61
59
|
Dep,
|
62
60
|
range,
|
63
61
|
param,
|
@@ -69,8 +67,8 @@ exports.create = (
|
|
69
67
|
) => {
|
70
68
|
if (param.isTemplateString()) {
|
71
69
|
const quasis = /** @type {BasicEvaluatedExpression[]} */ (param.quasis);
|
72
|
-
|
73
|
-
|
70
|
+
const prefixRaw = /** @type {string} */ (quasis[0].string);
|
71
|
+
const postfixRaw =
|
74
72
|
/** @type {string} */
|
75
73
|
(quasis.length > 1 ? quasis[quasis.length - 1].string : "");
|
76
74
|
|
@@ -84,7 +82,7 @@ exports.create = (
|
|
84
82
|
|
85
83
|
// When there are more than two quasis, the generated RegExp can be more precise
|
86
84
|
// We join the quasis with the expression regexp
|
87
|
-
const innerQuasis = quasis.slice(1,
|
85
|
+
const innerQuasis = quasis.slice(1, -1);
|
88
86
|
const innerRegExp =
|
89
87
|
/** @type {RegExp} */ (options.wrappedContextRegExp).source +
|
90
88
|
innerQuasis
|
@@ -125,14 +123,14 @@ exports.create = (
|
|
125
123
|
const replaces = [];
|
126
124
|
const parts = /** @type {BasicEvaluatedExpression[]} */ (param.parts);
|
127
125
|
|
128
|
-
parts.
|
126
|
+
for (const [i, part] of parts.entries()) {
|
129
127
|
if (i % 2 === 0) {
|
130
128
|
// Quasis or merged quasi
|
131
129
|
let range = /** @type {Range} */ (part.range);
|
132
130
|
let value = /** @type {string} */ (part.string);
|
133
131
|
if (param.templateStringKind === "cooked") {
|
134
132
|
value = JSON.stringify(value);
|
135
|
-
value = value.slice(1,
|
133
|
+
value = value.slice(1, -1);
|
136
134
|
}
|
137
135
|
if (i === 0) {
|
138
136
|
// prefix
|
@@ -151,14 +149,14 @@ exports.create = (
|
|
151
149
|
/** @type {Range} */ (part.range)[0],
|
152
150
|
/** @type {Range} */ (param.range)[1]
|
153
151
|
];
|
154
|
-
value = value
|
152
|
+
value = `${value}\``;
|
155
153
|
} else if (
|
156
154
|
part.expression &&
|
157
155
|
part.expression.type === "TemplateElement" &&
|
158
156
|
part.expression.value.raw === value
|
159
157
|
) {
|
160
158
|
// Shortcut when it's a single quasi and doesn't need to be replaced
|
161
|
-
|
159
|
+
continue;
|
162
160
|
}
|
163
161
|
replaces.push({
|
164
162
|
range,
|
@@ -168,7 +166,7 @@ exports.create = (
|
|
168
166
|
// Expression
|
169
167
|
parser.walkExpression(part.expression);
|
170
168
|
}
|
171
|
-
}
|
169
|
+
}
|
172
170
|
|
173
171
|
dep.replaces = replaces;
|
174
172
|
dep.critical =
|
@@ -180,10 +178,10 @@ exports.create = (
|
|
180
178
|
((param.prefix && param.prefix.isString()) ||
|
181
179
|
(param.postfix && param.postfix.isString()))
|
182
180
|
) {
|
183
|
-
|
181
|
+
const prefixRaw =
|
184
182
|
/** @type {string} */
|
185
183
|
(param.prefix && param.prefix.isString() ? param.prefix.string : "");
|
186
|
-
|
184
|
+
const postfixRaw =
|
187
185
|
/** @type {string} */
|
188
186
|
(param.postfix && param.postfix.isString() ? param.postfix.string : "");
|
189
187
|
const prefixRange =
|
@@ -240,26 +238,25 @@ exports.create = (
|
|
240
238
|
}
|
241
239
|
|
242
240
|
return dep;
|
243
|
-
}
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
241
|
+
}
|
242
|
+
const dep = new Dep(
|
243
|
+
{
|
244
|
+
request: /** @type {string} */ (options.exprContextRequest),
|
245
|
+
recursive: /** @type {boolean} */ (options.exprContextRecursive),
|
246
|
+
regExp: /** @type {RegExp} */ (options.exprContextRegExp),
|
247
|
+
mode: "sync",
|
248
|
+
...contextOptions
|
249
|
+
},
|
250
|
+
range,
|
251
|
+
/** @type {Range} */ (param.range),
|
252
|
+
...depArgs
|
253
|
+
);
|
254
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
255
|
+
dep.critical =
|
256
|
+
options.exprContextCritical &&
|
257
|
+
"the request of a dependency is an expression";
|
260
258
|
|
261
|
-
|
259
|
+
parser.walkExpression(param.expression);
|
262
260
|
|
263
|
-
|
264
|
-
}
|
261
|
+
return dep;
|
265
262
|
};
|
@@ -9,7 +9,10 @@ const Dependency = require("../Dependency");
|
|
9
9
|
const makeSerializable = require("../util/makeSerializable");
|
10
10
|
const ModuleDependency = require("./ModuleDependency");
|
11
11
|
|
12
|
+
/** @typedef {import("../ContextModule")} ContextModule */
|
12
13
|
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
14
|
+
/** @typedef {import("../Module")} Module */
|
15
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
13
16
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
14
17
|
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
15
18
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
@@ -20,9 +23,9 @@ class ContextElementDependency extends ModuleDependency {
|
|
20
23
|
/**
|
21
24
|
* @param {string} request request
|
22
25
|
* @param {string|undefined} userRequest user request
|
23
|
-
* @param {string} typePrefix type prefix
|
26
|
+
* @param {string | undefined} typePrefix type prefix
|
24
27
|
* @param {string} category category
|
25
|
-
* @param {string[][]=} referencedExports referenced exports
|
28
|
+
* @param {(string[][] | null)=} referencedExports referenced exports
|
26
29
|
* @param {string=} context context
|
27
30
|
* @param {ImportAttributes=} attributes import assertions
|
28
31
|
*/
|
@@ -67,12 +70,36 @@ class ContextElementDependency extends ModuleDependency {
|
|
67
70
|
* @returns {(string[] | ReferencedExport)[]} referenced exports
|
68
71
|
*/
|
69
72
|
getReferencedExports(moduleGraph, runtime) {
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
if (!this.referencedExports) return Dependency.EXPORTS_OBJECT_REFERENCED;
|
74
|
+
const refs = [];
|
75
|
+
for (const referencedExport of this.referencedExports) {
|
76
|
+
if (
|
77
|
+
this._typePrefix === "import()" &&
|
78
|
+
referencedExport[0] === "default"
|
79
|
+
) {
|
80
|
+
const selfModule =
|
81
|
+
/** @type {ContextModule} */
|
82
|
+
(moduleGraph.getParentModule(this));
|
83
|
+
const importedModule =
|
84
|
+
/** @type {Module} */
|
85
|
+
(moduleGraph.getModule(this));
|
86
|
+
const exportsType = importedModule.getExportsType(
|
87
|
+
moduleGraph,
|
88
|
+
selfModule.options.namespaceObject === "strict"
|
89
|
+
);
|
90
|
+
if (
|
91
|
+
exportsType === "default-only" ||
|
92
|
+
exportsType === "default-with-named"
|
93
|
+
) {
|
94
|
+
return Dependency.EXPORTS_OBJECT_REFERENCED;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
refs.push({
|
98
|
+
name: referencedExport,
|
99
|
+
canMangle: false
|
100
|
+
});
|
101
|
+
}
|
102
|
+
return refs;
|
76
103
|
}
|
77
104
|
|
78
105
|
/**
|