@depup/webpack 5.110.3-depup.0 → 5.111.1-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -8
- package/changes.json +7 -11
- package/lib/APIPlugin.js +26 -11
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/Cache.js +8 -3
- package/lib/CacheFacade.js +1 -1
- package/lib/CircularModulesPlugin.js +157 -55
- package/lib/CleanPlugin.js +2 -2
- package/lib/CompatibilityPlugin.js +3 -4
- package/lib/Compilation.js +336 -337
- package/lib/Compiler.js +213 -51
- package/lib/ConstPlugin.js +16 -132
- package/lib/CopyPlugin.js +1054 -0
- package/lib/DefinePlugin.js +24 -8
- package/lib/DependencyTemplate.js +2 -1
- package/lib/DotenvPlugin.js +24 -28
- package/lib/ErrorHelpers.js +113 -0
- package/lib/ExportsInfo.js +20 -16
- package/lib/ExternalModule.js +47 -22
- package/lib/FileSystemInfo.js +17 -14
- package/lib/FlagDependencyExportsPlugin.js +53 -34
- package/lib/FlagDependencyUsagePlugin.js +9 -13
- package/lib/Generator.js +24 -2
- package/lib/HotModuleReplacementPlugin.js +55 -7
- package/lib/IgnorePlugin.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +5 -3
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/MainTemplate.js +5 -1
- package/lib/Module.js +19 -10
- package/lib/ModuleGraph.js +6 -9
- package/lib/MultiCompiler.js +7 -17
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +135 -50
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/RuntimeGlobals.js +21 -7
- package/lib/RuntimeModule.js +28 -12
- package/lib/RuntimePlugin.js +30 -3
- package/lib/RuntimeTemplate.js +813 -518
- package/lib/SourceMapDevToolPlugin.js +54 -104
- package/lib/TemplatedPathPlugin.js +16 -59
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +84 -91
- package/lib/asset/AssetBytesGenerator.js +7 -1
- package/lib/asset/AssetGenerator.js +50 -24
- package/lib/asset/AssetModule.js +3 -0
- package/lib/asset/AssetSourceGenerator.js +7 -1
- package/lib/asset/WebManifestParser.js +7 -5
- package/lib/buildChunkGraph.js +11 -15
- package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
- package/lib/cache/IdleFileCachePlugin.js +2 -2
- package/lib/cache/MemoryCachePlugin.js +4 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
- package/lib/cache/PackFileCacheStrategy.js +17 -19
- package/lib/cache/getLazyHashedEtag.js +3 -5
- package/lib/config/browserslistTargetHandler.js +17 -4
- package/lib/config/defaults.js +138 -128
- package/lib/config/getClaimedAssetTypes.js +10 -11
- package/lib/config/normalization.js +82 -12
- package/lib/config/target.js +13 -4
- package/lib/container/ContainerReferencePlugin.js +6 -0
- package/lib/container/RemoteRuntimeModule.js +9 -0
- package/lib/container/declaredRemotes.js +39 -0
- package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
- package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
- package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
- package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
- package/lib/css/CssGenerator.js +27 -11
- package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
- package/lib/css/CssLoadingRuntimeModule.js +94 -36
- package/lib/css/CssModule.js +1 -1
- package/lib/css/CssModulesPlugin.js +7 -6
- package/lib/css/CssParser.js +162 -31
- package/lib/css/CssServerStylesRuntimeModule.js +9 -0
- package/lib/css/cssMinify.js +43 -32
- package/lib/css/data.js +3514 -869
- package/lib/css/syntax.js +6370 -1220
- package/lib/debug/ProfilingPlugin.js +7 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
- package/lib/dependencies/AMDRuntimeModules.js +18 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
- package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
- package/lib/dependencies/CommonJsPlugin.js +19 -3
- package/lib/dependencies/CommonJsRequireDependency.js +14 -5
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -9
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +13 -9
- package/lib/dependencies/CssIcssImportDependency.js +3 -6
- package/lib/dependencies/CssUrlDependency.js +3 -5
- package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +10 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +74 -17
- package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
- package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
- package/lib/dependencies/HarmonyImportDependency.js +6 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +111 -17
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +3 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
- package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
- package/lib/dependencies/HtmlEntryDependency.js +124 -102
- package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
- package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
- package/lib/dependencies/ImportMetaMainDependency.js +104 -0
- package/lib/dependencies/ImportMetaPlugin.js +67 -25
- package/lib/dependencies/ImportParserPlugin.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +26 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/SystemRuntimeModule.js +9 -0
- package/lib/dependencies/URLContextDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +6 -5
- package/lib/dependencies/WorkerAndWorkletPlugin.js +15 -21
- package/lib/dependencies/WorkerDependency.js +7 -7
- package/lib/dependencies/WorkletDependency.js +7 -11
- package/lib/dll/DelegatedModule.js +18 -1
- package/lib/dll/DllReferencePlugin.js +11 -8
- package/lib/dll/LibManifestPlugin.js +1 -1
- package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
- package/lib/errors/DuplicateModulesWarning.js +12 -7
- package/lib/errors/EmptyCopyPatternWarning.js +26 -0
- package/lib/errors/ExternalStarReexportError.js +44 -0
- package/lib/errors/HookWebpackError.js +3 -2
- package/lib/errors/MissingSourceMapsWarning.js +36 -0
- package/lib/errors/ModuleParseError.js +2 -1
- package/lib/errors/UnusedAssetsWarning.js +36 -0
- package/lib/errors/UnusedFederationWarning.js +35 -0
- package/lib/errors/UnusedModulesWarning.js +38 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
- package/lib/esm/ModuleChunkLoadingPlugin.js +30 -11
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
- package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
- package/lib/hmr/LazyCompilationPlugin.js +3 -5
- package/lib/html/HtmlGenerator.js +72 -87
- package/lib/html/HtmlModulesPlugin.js +418 -200
- package/lib/html/HtmlParser.js +110 -147
- package/lib/html/builtinEmbeddedRenderer.js +107 -0
- package/lib/html/data.js +142 -7
- package/lib/html/htmlMinify.js +92 -122
- package/lib/html/syntax.js +1618 -1391
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/index.js +49 -3
- package/lib/javascript/ChunkFormatHelpers.js +4 -3
- package/lib/javascript/JavascriptGenerator.js +8 -1
- package/lib/javascript/JavascriptModule.js +1 -0
- package/lib/javascript/JavascriptModulesPlugin.js +73 -72
- package/lib/javascript/JavascriptParser.js +1970 -900
- package/lib/javascript/StartupHelpers.js +27 -3
- package/lib/javascript/data.js +172 -0
- package/lib/javascript/grammar.js +5546 -0
- package/lib/javascript/parser.js +1500 -0
- package/lib/javascript/regexp.js +1762 -0
- package/lib/javascript/regexpData.js +51 -0
- package/lib/javascript/syntax.js +9061 -5262
- package/lib/json/JsonGenerator.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +171 -132
- package/lib/loaders/LoaderRunner.js +137 -9
- package/lib/node/NodeWatchFileSystem.js +3 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
- package/lib/optimize/AggressiveMergingPlugin.js +3 -5
- package/lib/optimize/ConcatenatedModule.js +178 -120
- package/lib/optimize/ConstExportsPlugin.js +50 -39
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
- package/lib/optimize/InlineExports.js +20 -123
- package/lib/optimize/InnerGraphPlugin.js +7 -13
- package/lib/optimize/LimitChunkCountPlugin.js +5 -8
- package/lib/optimize/MangleExportsPlugin.js +13 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
- package/lib/optimize/RealContentHashPlugin.js +68 -9
- package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
- package/lib/optimize/SplitChunksPlugin.js +2 -4
- package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
- package/lib/performance/BroadContextsPlugin.js +1 -1
- package/lib/performance/CacheEffectivenessPlugin.js +7 -7
- package/lib/performance/DuplicateModulesPlugin.js +57 -13
- package/lib/performance/EvalUsagePlugin.js +5 -2
- package/lib/performance/MissingSourceMapsPlugin.js +115 -0
- package/lib/performance/PureAnnotationsPlugin.js +6 -3
- package/lib/performance/SizeLimitsPlugin.js +2 -4
- package/lib/performance/TopLevelThisPlugin.js +5 -4
- package/lib/performance/UnusedAssetsPlugin.js +109 -0
- package/lib/performance/UnusedFederationPlugin.js +147 -0
- package/lib/performance/UnusedModulesPlugin.js +141 -0
- package/lib/performance/UnusedReexportsPlugin.js +1 -55
- package/lib/performance/isOnlyReexported.js +65 -0
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ResourceHintPlugin.js +18 -23
- package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
- package/lib/rules/RuleSetCompiler.js +211 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +98 -66
- package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
- package/lib/runtime/BaseUriRuntimeModule.js +9 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
- package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
- package/lib/runtime/GlobalRuntimeModule.js +11 -4
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
- package/lib/runtime/HelperRuntimeModule.js +10 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +305 -224
- package/lib/runtime/NonceRuntimeModule.js +9 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
- package/lib/runtime/PublicPathRuntimeModule.js +9 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
- package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
- package/lib/runtime/SystemContextRuntimeModule.js +9 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
- package/lib/schemes/DataUriPlugin.js +3 -6
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +9 -9
- package/lib/serialization/FileMiddleware.js +16 -16
- package/lib/serialization/ObjectMiddleware.js +168 -139
- package/lib/sharing/ConsumeSharedPlugin.js +12 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
- package/lib/sharing/ShareRuntimeModule.js +9 -0
- package/lib/sharing/declaredShared.js +47 -0
- package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
- package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
- package/lib/typescript/TypeScriptPlugin.js +2 -3
- package/lib/url/URLParserPlugin.js +6 -8
- package/lib/util/LocConverter.js +4 -7
- package/lib/util/SourceProcessor.js +91 -91
- package/lib/util/async.js +292 -0
- package/lib/util/buildDiagnostics.js +69 -0
- package/lib/util/chainedImports.js +3 -4
- package/lib/util/concatenate.js +4 -4
- package/lib/util/createHooksRegistry.js +1 -2
- package/lib/util/dataURL.js +2 -3
- package/lib/util/deterministicGrouping.js +8 -13
- package/lib/util/findGraphRoots.js +6 -13
- package/lib/util/fs.js +27 -1
- package/lib/util/globUtils.js +1 -1
- package/lib/util/handlerKeys.js +40 -0
- package/lib/util/hash/wasm-hash.js +3 -4
- package/lib/util/identifier.js +20 -0
- package/lib/util/internalSerializables.js +5 -1
- package/lib/util/registerExternalSerializer.js +6 -45
- package/lib/util/semver.js +5 -3
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
- package/package.json +55 -46
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +379 -66
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/types.d.ts +1723 -604
- package/lib/dependencies/ExportBindingInitFragment.js +0 -191
- package/lib/errors/EntrypointOverlapWarning.js +0 -45
- package/lib/performance/EntrypointOverlapPlugin.js +0 -122
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Alexander Akait @alexander-akait
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const { ASSET_TYPE } = require("../ModuleSourceTypeConstants");
|
|
9
|
+
const makeSerializable = require("../util/makeSerializable");
|
|
10
|
+
const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
|
|
11
|
+
|
|
12
|
+
/** @import Module from "../Module" */
|
|
13
|
+
/** @import ModuleGraph from "../ModuleGraph" */
|
|
14
|
+
/** @import { GetConditionFn } from "../Dependency" */
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether a module is emitted as a file of its own, asked of the module so a
|
|
18
|
+
* plugin emitting the same way is treated alike. `buildInfo.filename` cannot
|
|
19
|
+
* serve here: generation sets it long after a connection has to know whether
|
|
20
|
+
* it is active.
|
|
21
|
+
* @param {Module} module the module to look up
|
|
22
|
+
* @returns {boolean} true when it emits a file
|
|
23
|
+
*/
|
|
24
|
+
const emitsOwnFile = (module) => module.getSourceTypes().has(ASSET_TYPE);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* An `import "..."` that declares no binding. It is a separate class rather
|
|
28
|
+
* than a flag so it costs nothing per instance, and the bound form — much the
|
|
29
|
+
* more common one — keeps the base class and its inline caches untouched.
|
|
30
|
+
*/
|
|
31
|
+
class HarmonyImportBareSideEffectDependency extends HarmonyImportSideEffectDependency {
|
|
32
|
+
/**
|
|
33
|
+
* Returns function to determine if the connection is active.
|
|
34
|
+
* @param {ModuleGraph} moduleGraph module graph
|
|
35
|
+
* @returns {null | false | GetConditionFn} function to determine if the connection is active
|
|
36
|
+
*/
|
|
37
|
+
getCondition(moduleGraph) {
|
|
38
|
+
return (connection) => {
|
|
39
|
+
const refModule = connection.resolvedModule;
|
|
40
|
+
|
|
41
|
+
if (!refModule) return true;
|
|
42
|
+
// Nothing reads the module, so emitting its file is the only thing the
|
|
43
|
+
// import can have been written for.
|
|
44
|
+
if (emitsOwnFile(refModule)) return true;
|
|
45
|
+
|
|
46
|
+
return refModule.getSideEffectsConnectionState(moduleGraph);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
makeSerializable(
|
|
52
|
+
HarmonyImportBareSideEffectDependency,
|
|
53
|
+
"webpack/lib/dependencies/HarmonyImportBareSideEffectDependency"
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
HarmonyImportBareSideEffectDependency.Template =
|
|
57
|
+
HarmonyImportSideEffectDependency.Template;
|
|
58
|
+
|
|
59
|
+
module.exports = HarmonyImportBareSideEffectDependency;
|
|
@@ -114,7 +114,12 @@ const getDeferredExports = (module) => {
|
|
|
114
114
|
for (const dep of module.dependencies) {
|
|
115
115
|
// TODO remove in webpack 6
|
|
116
116
|
// These may be missing on custom dependency types not extending the base Dependency
|
|
117
|
-
if (
|
|
117
|
+
if (
|
|
118
|
+
typeof dep.getLazyUntil !== "function" ||
|
|
119
|
+
typeof dep.isLazy !== "function"
|
|
120
|
+
) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
118
123
|
if (!dep.isLazy()) continue;
|
|
119
124
|
const until = dep.getLazyUntil();
|
|
120
125
|
if (until === Dependency.LAZY_UNTIL_FALLBACK) return true;
|
|
@@ -18,6 +18,7 @@ const HarmonyAcceptDependency = require("./HarmonyAcceptDependency");
|
|
|
18
18
|
const HarmonyAcceptImportDependency = require("./HarmonyAcceptImportDependency");
|
|
19
19
|
const HarmonyEvaluatedImportSpecifierDependency = require("./HarmonyEvaluatedImportSpecifierDependency");
|
|
20
20
|
const HarmonyExports = require("./HarmonyExports");
|
|
21
|
+
const HarmonyImportBareSideEffectDependency = require("./HarmonyImportBareSideEffectDependency");
|
|
21
22
|
const {
|
|
22
23
|
ExportPresenceModes,
|
|
23
24
|
getNonOptionalPart
|
|
@@ -35,7 +36,9 @@ const { ImportPhaseUtils, createGetImportPhase } = require("./ImportPhase");
|
|
|
35
36
|
* Expression,
|
|
36
37
|
* PrivateIdentifier,
|
|
37
38
|
* Identifier,
|
|
38
|
-
* MemberExpression
|
|
39
|
+
* MemberExpression,
|
|
40
|
+
* Pattern,
|
|
41
|
+
* UpdateExpression
|
|
39
42
|
* } from "estree"
|
|
40
43
|
*/
|
|
41
44
|
/**
|
|
@@ -49,7 +52,8 @@ const { ImportPhaseUtils, createGetImportPhase } = require("./ImportPhase");
|
|
|
49
52
|
* @import JavascriptParser, {
|
|
50
53
|
* ImportAttributes,
|
|
51
54
|
* Range,
|
|
52
|
-
* Members
|
|
55
|
+
* Members,
|
|
56
|
+
* WriteStatement
|
|
53
57
|
* } from "../javascript/JavascriptParser"
|
|
54
58
|
*/
|
|
55
59
|
/** @import { Ids, ExportPresenceMode } from "./HarmonyImportDependency" */
|
|
@@ -233,15 +237,18 @@ class HarmonyImportDependencyParserPlugin {
|
|
|
233
237
|
this.options.sourceImport
|
|
234
238
|
);
|
|
235
239
|
|
|
236
|
-
// Parsers are reused across modules, so
|
|
240
|
+
// Parsers are reused across modules, so all three are reset per program.
|
|
237
241
|
/** @type {HarmonySettings[]} */
|
|
238
242
|
const declaredSpecifiers = [];
|
|
239
243
|
/** @type {HarmonyImportSideEffectDependency | undefined} */
|
|
240
244
|
let lastSideEffectDependency;
|
|
245
|
+
/** @type {Identifier | MemberExpression | undefined} */
|
|
246
|
+
let assignmentTarget;
|
|
241
247
|
|
|
242
248
|
parser.hooks.program.tap(PLUGIN_NAME, () => {
|
|
243
249
|
declaredSpecifiers.length = 0;
|
|
244
250
|
lastSideEffectDependency = undefined;
|
|
251
|
+
assignmentTarget = undefined;
|
|
245
252
|
});
|
|
246
253
|
parser.hooks.finish.tap(PLUGIN_NAME, () => {
|
|
247
254
|
for (const settings of declaredSpecifiers) {
|
|
@@ -260,6 +267,7 @@ class HarmonyImportDependencyParserPlugin {
|
|
|
260
267
|
}
|
|
261
268
|
declaredSpecifiers.length = 0;
|
|
262
269
|
lastSideEffectDependency = undefined;
|
|
270
|
+
assignmentTarget = undefined;
|
|
263
271
|
});
|
|
264
272
|
|
|
265
273
|
/**
|
|
@@ -311,7 +319,13 @@ class HarmonyImportDependencyParserPlugin {
|
|
|
311
319
|
parser.state.current.addError(error);
|
|
312
320
|
}
|
|
313
321
|
|
|
314
|
-
|
|
322
|
+
// A declaration binding nothing was written for what importing produces,
|
|
323
|
+
// which for a module emitting its own file is that file.
|
|
324
|
+
const SideEffectDependency =
|
|
325
|
+
statement.specifiers.length === 0
|
|
326
|
+
? HarmonyImportBareSideEffectDependency
|
|
327
|
+
: HarmonyImportSideEffectDependency;
|
|
328
|
+
const sideEffectDep = new SideEffectDependency(
|
|
315
329
|
/** @type {string} */ (source),
|
|
316
330
|
parser.state.lastHarmonyImportOrder,
|
|
317
331
|
phase,
|
|
@@ -392,14 +406,48 @@ class HarmonyImportDependencyParserPlugin {
|
|
|
392
406
|
}
|
|
393
407
|
}
|
|
394
408
|
);
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
409
|
+
/**
|
|
410
|
+
* The reference a write lands on, which is a pattern for a
|
|
411
|
+
* destructuring write.
|
|
412
|
+
* @param {WriteStatement} node the construct performing the write
|
|
413
|
+
* @returns {Pattern | MemberExpression} the written reference
|
|
414
|
+
*/
|
|
415
|
+
const writeTargetOf = (node) =>
|
|
416
|
+
/** @type {Pattern | MemberExpression} */ (
|
|
417
|
+
node.type === "UpdateExpression" ? node.argument : node.left
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Whether a member write lands on the namespace object itself, which is
|
|
422
|
+
* read-only. A property of an imported object is an ordinary write.
|
|
423
|
+
* @param {HarmonySettings} settings the specifier's settings
|
|
424
|
+
* @param {Members} members the member chain
|
|
425
|
+
* @returns {boolean} true when the write targets a namespace member
|
|
426
|
+
*/
|
|
427
|
+
const isNamespaceMemberWrite = (settings, members) =>
|
|
428
|
+
settings.ids.length === 0 && members.length === 1;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Keeps the module whole, for a write whose reference the output has no
|
|
432
|
+
* way to flag.
|
|
433
|
+
* @returns {void}
|
|
434
|
+
*/
|
|
435
|
+
const bailOutOfConcatenation = () => {
|
|
400
436
|
/** @type {JavascriptModuleBuildInfo} */
|
|
401
437
|
(parser.state.module.buildInfo).moduleConcatenationBailout =
|
|
402
438
|
"assignment to an imported binding";
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Records the write target of an assignment or update to an imported
|
|
443
|
+
* binding, so the reference walked next renders as a throwing write.
|
|
444
|
+
* @param {WriteStatement} expr the write
|
|
445
|
+
* @param {Identifier | MemberExpression | undefined} target the written reference, if any
|
|
446
|
+
* @returns {void}
|
|
447
|
+
*/
|
|
448
|
+
const markImportedBindingWrite = (expr, target) => {
|
|
449
|
+
const settings = /** @type {HarmonySettings} */ (parser.currentTagData);
|
|
450
|
+
markUsed(settings);
|
|
403
451
|
// A named import is written through the namespace's getter-only
|
|
404
452
|
// property, which throws on its own. A namespace one is the binding
|
|
405
453
|
// itself, and nothing webpack can emit for it throws, so report it.
|
|
@@ -407,8 +455,48 @@ class HarmonyImportDependencyParserPlugin {
|
|
|
407
455
|
const error = new ImportedBindingAssignmentError(settings.name);
|
|
408
456
|
error.loc = parser.getLocation(expr);
|
|
409
457
|
parser.state.module.addError(error);
|
|
458
|
+
} else if (target) {
|
|
459
|
+
assignmentTarget = target;
|
|
460
|
+
} else {
|
|
461
|
+
// A destructuring target emits no reference to flag, so the whole
|
|
462
|
+
// module stays out of concatenation.
|
|
463
|
+
bailOutOfConcatenation();
|
|
410
464
|
}
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
parser.hooks.assign.for(harmonySpecifierTag).tap(PLUGIN_NAME, (expr) => {
|
|
468
|
+
markImportedBindingWrite(
|
|
469
|
+
expr,
|
|
470
|
+
expr.left.type === "Identifier" ? expr.left : undefined
|
|
471
|
+
);
|
|
472
|
+
});
|
|
473
|
+
parser.hooks.write.for(harmonySpecifierTag).tap(PLUGIN_NAME, (node) => {
|
|
474
|
+
const written = writeTargetOf(node);
|
|
475
|
+
const target =
|
|
476
|
+
written.type === "Identifier"
|
|
477
|
+
? /** @type {Identifier} */ (written)
|
|
478
|
+
: undefined;
|
|
479
|
+
markImportedBindingWrite(node, target);
|
|
480
|
+
// A loop's binding walks nothing on its own, so the reference the
|
|
481
|
+
// write renders as has to be walked here to exist at all.
|
|
482
|
+
if (!target || node.type === "UpdateExpression") return;
|
|
483
|
+
parser.walkExpression(target);
|
|
484
|
+
return true;
|
|
411
485
|
});
|
|
486
|
+
// A namespace member is written through the reference its member chain
|
|
487
|
+
// emits, so both write forms flag that reference rather than the binding.
|
|
488
|
+
parser.hooks.writeMemberChain
|
|
489
|
+
.for(harmonySpecifierTag)
|
|
490
|
+
.tap(PLUGIN_NAME, (node, members) => {
|
|
491
|
+
const settings = /** @type {HarmonySettings} */ (parser.currentTagData);
|
|
492
|
+
if (!isNamespaceMemberWrite(settings, members)) return;
|
|
493
|
+
const written = writeTargetOf(node);
|
|
494
|
+
if (written.type === "MemberExpression") {
|
|
495
|
+
assignmentTarget = written;
|
|
496
|
+
} else {
|
|
497
|
+
bailOutOfConcatenation();
|
|
498
|
+
}
|
|
499
|
+
});
|
|
412
500
|
parser.hooks.expression
|
|
413
501
|
.for(harmonySpecifierTag)
|
|
414
502
|
.tap(PLUGIN_NAME, (expr) => {
|
|
@@ -436,6 +524,10 @@ class HarmonyImportDependencyParserPlugin {
|
|
|
436
524
|
);
|
|
437
525
|
dep.loc = parser.getLocation(expr);
|
|
438
526
|
dep.call = parser.scope.inTaggedTemplateTag;
|
|
527
|
+
if (assignmentTarget === expr) {
|
|
528
|
+
dep.assignment = true;
|
|
529
|
+
assignmentTarget = undefined;
|
|
530
|
+
}
|
|
439
531
|
parser.state.module.addDependency(dep);
|
|
440
532
|
attachDependencyGuards(parser, dep);
|
|
441
533
|
getInnerGraphUtils(parser.state.compilation).onUsage(
|
|
@@ -489,6 +581,10 @@ class HarmonyImportDependencyParserPlugin {
|
|
|
489
581
|
(expr.range)[0]
|
|
490
582
|
);
|
|
491
583
|
dep.loc = parser.getLocation(expr);
|
|
584
|
+
if (assignmentTarget === expression) {
|
|
585
|
+
dep.assignment = true;
|
|
586
|
+
assignmentTarget = undefined;
|
|
587
|
+
}
|
|
492
588
|
parser.state.module.addDependency(dep);
|
|
493
589
|
attachDependencyGuards(parser, dep);
|
|
494
590
|
getInnerGraphUtils(parser.state.compilation).onUsage(
|
|
@@ -557,19 +653,17 @@ class HarmonyImportDependencyParserPlugin {
|
|
|
557
653
|
return true;
|
|
558
654
|
}
|
|
559
655
|
);
|
|
560
|
-
//
|
|
561
|
-
//
|
|
562
|
-
//
|
|
563
|
-
// whose `.a` getter eagerly requires (and thus evaluates) the
|
|
564
|
-
// deferred module. For top-level `ns.foo = value`, walk only the
|
|
565
|
-
// bare `ns` identifier so it gets replaced with the deferred
|
|
566
|
-
// namespace proxy (whose set trap returns false), and leave the
|
|
567
|
-
// `.foo = value` part as plain code.
|
|
656
|
+
// `[[Set]]` on a Module Namespace returns false without evaluating, yet the
|
|
657
|
+
// member-chain path emits `<importVar>.a.foo`, whose getter evaluates. So
|
|
658
|
+
// only the bare `ns` is walked, leaving `.foo = value` as plain code.
|
|
568
659
|
parser.hooks.assignMemberChain
|
|
569
660
|
.for(harmonySpecifierTag)
|
|
570
661
|
.tap(PLUGIN_NAME, (expression, members) => {
|
|
571
662
|
const settings = /** @type {HarmonySettings} */ (parser.currentTagData);
|
|
572
663
|
settings.used = true;
|
|
664
|
+
if (isNamespaceMemberWrite(settings, members)) {
|
|
665
|
+
assignmentTarget = /** @type {MemberExpression} */ (expression.left);
|
|
666
|
+
}
|
|
573
667
|
if (!ImportPhaseUtils.isDefer(settings.phase)) return;
|
|
574
668
|
if (expression.operator !== "=") return;
|
|
575
669
|
if (members.length !== 1) return;
|
|
@@ -226,10 +226,9 @@ HarmonyImportSideEffectDependency.Template = class HarmonyImportSideEffectDepend
|
|
|
226
226
|
if (ImportPhaseUtils.isDefer(dep.phase)) return;
|
|
227
227
|
const connection = moduleGraph.getConnection(dep);
|
|
228
228
|
if (!connection || !connection.isTargetActive(runtime)) return;
|
|
229
|
-
// A hoisted body cannot be deferred, so its imports evaluate
|
|
230
|
-
//
|
|
231
|
-
//
|
|
232
|
-
// before its importers, so it never learns whether it is itself eager.
|
|
229
|
+
// A hoisted body cannot be deferred, so its imports evaluate in their own
|
|
230
|
+
// slots; calling from here would run them after everything hoisted in
|
|
231
|
+
// between. Eagerness stops at one level, generation order allowing no more.
|
|
233
232
|
if (concatenationScope.isWrapped()) {
|
|
234
233
|
initFragments.push(
|
|
235
234
|
new InitFragment(
|
|
@@ -26,10 +26,11 @@ const HarmonyImportGuard = require("./HarmonyImportGuard");
|
|
|
26
26
|
const { ImportPhaseUtils } = require("./ImportPhase");
|
|
27
27
|
|
|
28
28
|
/** @import { ReplaceSource } from "webpack-sources" */
|
|
29
|
-
/** @import { GetConditionFn, ReferencedExports } from "../Dependency" */
|
|
29
|
+
/** @import { GetConditionFn, ReferencedExports, UpdateHashContext } from "../Dependency" */
|
|
30
30
|
/** @import { DependencyTemplateContext } from "../DependencyTemplate" */
|
|
31
31
|
/** @import Module, { BuildMeta } from "../Module" */
|
|
32
32
|
/** @import ModuleGraph from "../ModuleGraph" */
|
|
33
|
+
/** @import Hash from "../util/Hash" */
|
|
33
34
|
/**
|
|
34
35
|
* @import ModuleGraphConnection, {
|
|
35
36
|
* ConnectionState
|
|
@@ -133,6 +134,8 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
|
133
134
|
this.referencedPropertiesInDestructuring = undefined;
|
|
134
135
|
/** @type {DependencyGuard[] | undefined} */
|
|
135
136
|
this.branchGuards = undefined;
|
|
137
|
+
/** @type {undefined | boolean} this reference is an assignment target */
|
|
138
|
+
this.assignment = undefined;
|
|
136
139
|
}
|
|
137
140
|
|
|
138
141
|
// TODO webpack 6 remove
|
|
@@ -262,6 +265,28 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
|
262
265
|
return condition;
|
|
263
266
|
}
|
|
264
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Updates the hash with the data contributed by this instance.
|
|
270
|
+
* @param {Hash} hash hash to be updated
|
|
271
|
+
* @param {UpdateHashContext} context context
|
|
272
|
+
* @returns {void}
|
|
273
|
+
*/
|
|
274
|
+
updateHash(hash, context) {
|
|
275
|
+
const { chunkGraph, runtime } = context;
|
|
276
|
+
const moduleGraph = chunkGraph.moduleGraph;
|
|
277
|
+
if (!isInlineExportsEnabled(moduleGraph)) return;
|
|
278
|
+
const module = moduleGraph.getModule(this);
|
|
279
|
+
if (!module || !isInlineEnabled(module)) return;
|
|
280
|
+
const ids = this.getIds(moduleGraph);
|
|
281
|
+
if (ids.length === 0) return;
|
|
282
|
+
const exportsInfo = moduleGraph.getExportsInfo(module);
|
|
283
|
+
if (!exportsInfo.hasInlinedUsedName(ids, runtime)) return;
|
|
284
|
+
const usedName = exportsInfo.getUsedName(ids, runtime);
|
|
285
|
+
if (usedName instanceof InlinedUsedName) {
|
|
286
|
+
usedName.updateHash(hash);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
265
290
|
/**
|
|
266
291
|
* Gets module evaluation side effects state.
|
|
267
292
|
* @param {ModuleGraph} moduleGraph the module graph
|
|
@@ -356,8 +381,9 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
|
356
381
|
{
|
|
357
382
|
name: ids,
|
|
358
383
|
canMangle: true,
|
|
359
|
-
// Need access the export value to trigger side effects for deferred module
|
|
360
|
-
|
|
384
|
+
// Need access the export value to trigger side effects for deferred module.
|
|
385
|
+
// An inlined literal cannot be an assignment target at all.
|
|
386
|
+
canInline: !this.assignment && !ImportPhaseUtils.isDefer(this.phase)
|
|
361
387
|
}
|
|
362
388
|
]
|
|
363
389
|
: Dependency.EXPORTS_OBJECT_REFERENCED;
|
|
@@ -450,6 +476,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
|
450
476
|
write(this.usedByExports);
|
|
451
477
|
write(this.referencedPropertiesInDestructuring);
|
|
452
478
|
write(this.branchGuards);
|
|
479
|
+
write(this.assignment);
|
|
453
480
|
super.serialize(context);
|
|
454
481
|
}
|
|
455
482
|
|
|
@@ -472,6 +499,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
|
472
499
|
this.usedByExports = read();
|
|
473
500
|
this.referencedPropertiesInDestructuring = read();
|
|
474
501
|
this.branchGuards = read();
|
|
502
|
+
this.assignment = read();
|
|
475
503
|
super.deserialize(context);
|
|
476
504
|
}
|
|
477
505
|
}
|
|
@@ -654,6 +682,15 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
|
654
682
|
deferredImport: ImportPhaseUtils.isDefer(dep.phase)
|
|
655
683
|
}
|
|
656
684
|
);
|
|
685
|
+
// Concatenation merges the binding into a plain local a write would
|
|
686
|
+
// succeed against. Routing the write at a getter-only property of a
|
|
687
|
+
// throwaway object restores the TypeError the namespace gave it.
|
|
688
|
+
if (dep.assignment) {
|
|
689
|
+
// the local binding, the one name here an export is free not to
|
|
690
|
+
// spell as an identifier: `import { "a-b" as ab }`
|
|
691
|
+
const holder = `{ get ${dep.name}() { return ${exportExpr}; } }`;
|
|
692
|
+
exportExpr = `${dep.asiSafe ? "" : ";"}(${holder}).${dep.name}`;
|
|
693
|
+
}
|
|
657
694
|
}
|
|
658
695
|
} else {
|
|
659
696
|
super.apply(dep, source, templateContext);
|
|
@@ -20,6 +20,7 @@ const HarmonyExportExpressionDependency = require("./HarmonyExportExpressionDepe
|
|
|
20
20
|
const HarmonyExportHeaderDependency = require("./HarmonyExportHeaderDependency");
|
|
21
21
|
const HarmonyExportImportedSpecifierDependency = require("./HarmonyExportImportedSpecifierDependency");
|
|
22
22
|
const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDependency");
|
|
23
|
+
const HarmonyImportBareSideEffectDependency = require("./HarmonyImportBareSideEffectDependency");
|
|
23
24
|
const HarmonyImportDependencyParserPlugin = require("./HarmonyImportDependencyParserPlugin");
|
|
24
25
|
const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
|
|
25
26
|
const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
|
|
@@ -34,6 +35,7 @@ const TopLevelAwaitDependency = require("./TopLevelAwaitDependency");
|
|
|
34
35
|
*/
|
|
35
36
|
/** @import Compiler from "../Compiler" */
|
|
36
37
|
/** @import Parser from "../javascript/JavascriptParser" */
|
|
38
|
+
/** @import { BuildInfo } from "../Module" */
|
|
37
39
|
|
|
38
40
|
/**
|
|
39
41
|
* Defines the harmony modules plugin options type used by this module.
|
|
@@ -81,6 +83,15 @@ class HarmonyModulesPlugin {
|
|
|
81
83
|
new HarmonyImportSideEffectDependency.Template()
|
|
82
84
|
);
|
|
83
85
|
|
|
86
|
+
compilation.dependencyFactories.set(
|
|
87
|
+
HarmonyImportBareSideEffectDependency,
|
|
88
|
+
normalModuleFactory
|
|
89
|
+
);
|
|
90
|
+
compilation.dependencyTemplates.set(
|
|
91
|
+
HarmonyImportBareSideEffectDependency,
|
|
92
|
+
new HarmonyImportBareSideEffectDependency.Template()
|
|
93
|
+
);
|
|
94
|
+
|
|
84
95
|
compilation.dependencyFactories.set(
|
|
85
96
|
HarmonyImportSpecifierDependency,
|
|
86
97
|
normalModuleFactory
|
|
@@ -149,6 +160,15 @@ class HarmonyModulesPlugin {
|
|
|
149
160
|
return;
|
|
150
161
|
}
|
|
151
162
|
|
|
163
|
+
if (parserOptions.specNamespaceObject) {
|
|
164
|
+
// Recorded on the module, because an importer asks the module it
|
|
165
|
+
// imports whether its namespace is a spec exotic object.
|
|
166
|
+
parser.hooks.program.tap(PLUGIN_NAME, () => {
|
|
167
|
+
/** @type {BuildInfo} */
|
|
168
|
+
(parser.state.module.buildInfo).specNamespaceObject = true;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
152
172
|
new HarmonyDetectionParserPlugin().apply(parser);
|
|
153
173
|
new HarmonyImportDependencyParserPlugin(parserOptions).apply(parser);
|
|
154
174
|
new HarmonyExportDependencyParserPlugin(parserOptions).apply(parser);
|