@depup/webpack 5.110.1-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/ChunkGraph.js +20 -18
- package/lib/CircularModulesPlugin.js +157 -55
- package/lib/CleanPlugin.js +2 -2
- package/lib/CompatibilityPlugin.js +3 -4
- package/lib/Compilation.js +337 -338
- package/lib/Compiler.js +213 -51
- package/lib/ConcatenationScope.js +25 -35
- 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 +64 -40
- package/lib/ErrorHelpers.js +113 -0
- package/lib/ExportsInfo.js +30 -16
- package/lib/ExternalModule.js +47 -22
- package/lib/FileSystemInfo.js +17 -14
- package/lib/FlagDependencyExportsPlugin.js +53 -34
- package/lib/FlagDependencyUsagePlugin.js +17 -15
- 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 +148 -70
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/RuntimeGlobals.js +21 -7
- package/lib/RuntimeModule.js +28 -12
- package/lib/RuntimePlugin.js +33 -3
- package/lib/RuntimeTemplate.js +1147 -847
- 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/async-modules/AsyncModuleHelpers.js +10 -4
- 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 +162 -142
- package/lib/config/getClaimedAssetTypes.js +10 -11
- package/lib/config/normalization.js +100 -20
- 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 +92 -15
- package/lib/css/CssModule.js +1 -1
- package/lib/css/CssModulesPlugin.js +3 -10
- 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 +3526 -871
- package/lib/css/syntax.js +6455 -1237
- 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 +32 -9
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -9
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
- 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/HarmonyEvaluatedImportSpecifierDependency.js +10 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +217 -34
- 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 +99 -41
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +198 -25
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +117 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
- package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
- package/lib/dependencies/HtmlEntryDependency.js +136 -104
- package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
- package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
- package/lib/dependencies/ImportContextDependency.js +43 -3
- package/lib/dependencies/ImportDependency.js +8 -29
- 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 +25 -15
- package/lib/dependencies/LoaderPlugin.js +26 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireHeaderDependency.js +20 -21
- 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 +16 -21
- package/lib/dependencies/WorkerDependency.js +12 -18
- package/lib/dependencies/WorkletDependency.js +12 -20
- package/lib/dependencies/importOptionsCheck.js +47 -0
- 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/DotenvFileError.js +29 -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/ImportedBindingAssignmentError.js +30 -0
- 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 +21 -5
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +91 -53
- 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 +479 -215
- 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 +2031 -1556
- 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 +76 -80
- 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 +170 -14
- package/lib/node/NodeWatchFileSystem.js +3 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -15
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
- package/lib/optimize/AggressiveMergingPlugin.js +3 -5
- package/lib/optimize/ConcatenatedModule.js +222 -125
- package/lib/optimize/ConstExportsPlugin.js +50 -34
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
- package/lib/optimize/InlineExports.js +20 -2
- 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 +179 -44
- 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 +29 -35
- 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 +103 -67
- 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 +313 -222
- 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/HttpUriPlugin.js +22 -5
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +9 -9
- package/lib/serialization/FileMiddleware.js +31 -18
- 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 +10 -13
- package/lib/url/URLParserPlugin.js +6 -8
- package/lib/util/ArrayQueue.js +3 -3
- package/lib/util/LocConverter.js +4 -7
- package/lib/util/SourceProcessor.js +115 -99
- package/lib/util/URLAbsoluteSpecifier.js +3 -1
- 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/conventions.js +5 -1
- package/lib/util/createHooksRegistry.js +1 -2
- package/lib/util/createMappings.js +25 -3
- 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 +7 -1
- package/lib/util/registerExternalSerializer.js +6 -45
- package/lib/util/removeBOM.js +82 -1
- package/lib/util/semver.js +5 -3
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +14 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +14 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +7 -12
- 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/FetchCompileAsyncWasmPlugin.js +10 -6
- package/lib/web/FetchCompileWasmPlugin.js +4 -2
- 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 +388 -76
- 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 +1795 -608
- package/lib/dependencies/ExportBindingInitFragment.js +0 -191
- package/lib/errors/EntrypointOverlapWarning.js +0 -45
- package/lib/performance/EntrypointOverlapPlugin.js +0 -122
|
@@ -14,9 +14,11 @@ const Template = require("../Template");
|
|
|
14
14
|
const {
|
|
15
15
|
InlinedUsedName,
|
|
16
16
|
isExportInlined,
|
|
17
|
-
isInlineEnabled
|
|
17
|
+
isInlineEnabled,
|
|
18
|
+
isInlineExportsEnabled
|
|
18
19
|
} = require("../optimize/InlineExports");
|
|
19
20
|
const {
|
|
21
|
+
getKnownExportNames,
|
|
20
22
|
getMakeDeferredNamespaceModeFromExportsType
|
|
21
23
|
} = require("../runtime/MakeDeferredNamespaceObjectRuntime");
|
|
22
24
|
const { countIterable } = require("../util/IterableHelpers");
|
|
@@ -29,6 +31,9 @@ const {
|
|
|
29
31
|
keyToRuntime
|
|
30
32
|
} = require("../util/runtime");
|
|
31
33
|
const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
|
|
34
|
+
|
|
35
|
+
const { ExportBindingType } = HarmonyExportInitFragment;
|
|
36
|
+
|
|
32
37
|
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
|
33
38
|
const HarmonyLinkingError = require("./HarmonyLinkingError");
|
|
34
39
|
const { ImportPhaseUtils } = require("./ImportPhase");
|
|
@@ -44,7 +49,8 @@ const processExportInfo = require("./processExportInfo");
|
|
|
44
49
|
* RawReferencedExports,
|
|
45
50
|
* ReferencedExports,
|
|
46
51
|
* TRANSITIVE,
|
|
47
|
-
* ExportInfoName
|
|
52
|
+
* ExportInfoName,
|
|
53
|
+
* UpdateHashContext
|
|
48
54
|
* } from "../Dependency"
|
|
49
55
|
*/
|
|
50
56
|
/** @import { DependencyTemplateContext } from "../DependencyTemplate" */
|
|
@@ -58,6 +64,7 @@ const processExportInfo = require("./processExportInfo");
|
|
|
58
64
|
* } from "../Module"
|
|
59
65
|
*/
|
|
60
66
|
/** @import ModuleGraph from "../ModuleGraph" */
|
|
67
|
+
/** @import Hash from "../util/Hash" */
|
|
61
68
|
/**
|
|
62
69
|
* @import ModuleGraphConnection, {
|
|
63
70
|
* ConnectionState
|
|
@@ -135,6 +142,11 @@ class ExportMode {
|
|
|
135
142
|
/** @type {InstanceType<ExportInfo> | null} */
|
|
136
143
|
this.partialNamespaceExportInfo = null;
|
|
137
144
|
|
|
145
|
+
// for "reexport-undefined": the name resolves through a circular
|
|
146
|
+
// reexport chain rather than being absent from a non-harmony module
|
|
147
|
+
/** @type {boolean} */
|
|
148
|
+
this.circular = false;
|
|
149
|
+
|
|
138
150
|
// for "dynamic-reexport":
|
|
139
151
|
/** @type {ExportModeIgnored | null} */
|
|
140
152
|
this.ignored = null;
|
|
@@ -232,12 +244,28 @@ const isStarReexportBackToParent = (moduleGraph, exportInfo, parentModule) => {
|
|
|
232
244
|
}
|
|
233
245
|
};
|
|
234
246
|
|
|
247
|
+
/**
|
|
248
|
+
* Two `export *` sources are ambiguous for a name when they resolve to
|
|
249
|
+
* different bindings; a diamond re-export of the same binding is not.
|
|
250
|
+
* @param {ModuleGraph} moduleGraph module graph
|
|
251
|
+
* @param {InstanceType<ExportInfo>} previous export info of the star source that first provided the name
|
|
252
|
+
* @param {InstanceType<ExportInfo>} exportInfo export info of a later star source providing the same name
|
|
253
|
+
* @returns {boolean} true when the two sources provide different bindings
|
|
254
|
+
*/
|
|
255
|
+
const isAmbiguousWith = (moduleGraph, previous, exportInfo) => {
|
|
256
|
+
const previousBinding = previous.getTerminalBinding(moduleGraph);
|
|
257
|
+
if (!previousBinding) return false;
|
|
258
|
+
const binding = exportInfo.getTerminalBinding(moduleGraph);
|
|
259
|
+
if (!binding) return false;
|
|
260
|
+
return previousBinding !== binding;
|
|
261
|
+
};
|
|
262
|
+
|
|
235
263
|
/**
|
|
236
264
|
* Determine export assignments.
|
|
237
265
|
* @param {ModuleGraph} moduleGraph module graph
|
|
238
266
|
* @param {HarmonyExportImportedSpecifierDependency[]} dependencies dependencies
|
|
239
267
|
* @param {HarmonyExportImportedSpecifierDependency=} additionalDependency additional dependency
|
|
240
|
-
* @returns {{ names: ExportInfoName[], dependencyIndices: DependencyIndices }} result
|
|
268
|
+
* @returns {{ names: ExportInfoName[], dependencyIndices: DependencyIndices, conflicting: Set<ExportInfoName> | undefined }} result
|
|
241
269
|
*/
|
|
242
270
|
const determineExportAssignments = (
|
|
243
271
|
moduleGraph,
|
|
@@ -248,6 +276,10 @@ const determineExportAssignments = (
|
|
|
248
276
|
const names = new Set();
|
|
249
277
|
/** @type {DependencyIndices} */
|
|
250
278
|
const dependencyIndices = [];
|
|
279
|
+
/** @type {Map<ExportInfoName, InstanceType<ExportInfo>>} */
|
|
280
|
+
const firstProvider = new Map();
|
|
281
|
+
/** @type {Set<ExportInfoName> | undefined} */
|
|
282
|
+
let conflicting;
|
|
251
283
|
|
|
252
284
|
if (additionalDependency) {
|
|
253
285
|
dependencies = [...dependencies, additionalDependency];
|
|
@@ -265,24 +297,42 @@ const determineExportAssignments = (
|
|
|
265
297
|
if (otherImportedModule) {
|
|
266
298
|
const exportsInfo = moduleGraph.getExportsInfo(otherImportedModule);
|
|
267
299
|
for (const exportInfo of exportsInfo.exports) {
|
|
300
|
+
if (exportInfo.provided !== true || exportInfo.name === "default") {
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (names.has(exportInfo.name)) {
|
|
304
|
+
const previous =
|
|
305
|
+
/** @type {InstanceType<ExportInfo>} */
|
|
306
|
+
(firstProvider.get(exportInfo.name));
|
|
307
|
+
if (
|
|
308
|
+
isAmbiguousWith(moduleGraph, previous, exportInfo) &&
|
|
309
|
+
// A cyclic contribution resolves to nothing, so it never competes
|
|
310
|
+
// with the binding a sibling `export *` provides.
|
|
311
|
+
!(
|
|
312
|
+
parentModule &&
|
|
313
|
+
isStarReexportBackToParent(moduleGraph, exportInfo, parentModule)
|
|
314
|
+
)
|
|
315
|
+
) {
|
|
316
|
+
if (conflicting === undefined) conflicting = new Set();
|
|
317
|
+
conflicting.add(exportInfo.name);
|
|
318
|
+
}
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
268
321
|
if (
|
|
269
|
-
|
|
270
|
-
exportInfo
|
|
271
|
-
!names.has(exportInfo.name) &&
|
|
272
|
-
!(
|
|
273
|
-
parentModule &&
|
|
274
|
-
isStarReexportBackToParent(moduleGraph, exportInfo, parentModule)
|
|
275
|
-
)
|
|
322
|
+
parentModule &&
|
|
323
|
+
isStarReexportBackToParent(moduleGraph, exportInfo, parentModule)
|
|
276
324
|
) {
|
|
277
|
-
|
|
278
|
-
dependencyIndices[i] = names.size;
|
|
325
|
+
continue;
|
|
279
326
|
}
|
|
327
|
+
names.add(exportInfo.name);
|
|
328
|
+
firstProvider.set(exportInfo.name, exportInfo);
|
|
329
|
+
dependencyIndices[i] = names.size;
|
|
280
330
|
}
|
|
281
331
|
}
|
|
282
332
|
}
|
|
283
333
|
dependencyIndices.push(names.size);
|
|
284
334
|
|
|
285
|
-
return { names: [...names], dependencyIndices };
|
|
335
|
+
return { names: [...names], dependencyIndices, conflicting };
|
|
286
336
|
};
|
|
287
337
|
|
|
288
338
|
/**
|
|
@@ -396,6 +446,14 @@ const getMode = (moduleGraph, dep, runtimeKey) => {
|
|
|
396
446
|
mode.name = name;
|
|
397
447
|
break;
|
|
398
448
|
default:
|
|
449
|
+
// forwarding to a circular chain would recurse until the stack
|
|
450
|
+
// blows, so the name resolves to undefined like a missing one
|
|
451
|
+
if (exportInfo.hasCircularTarget(moduleGraph)) {
|
|
452
|
+
mode = new ExportMode("reexport-undefined");
|
|
453
|
+
mode.name = name;
|
|
454
|
+
mode.circular = true;
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
399
457
|
mode = new ExportMode("normal-reexport");
|
|
400
458
|
mode.items = [
|
|
401
459
|
new NormalReexportItem(name, ids, exportInfo, false, false)
|
|
@@ -653,6 +711,12 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
653
711
|
/** @type {IgnoredExports} */
|
|
654
712
|
const ignoredExports = new Set(this.activeExports);
|
|
655
713
|
ignoredExports.add("default");
|
|
714
|
+
// An ambiguous name resolves to no binding at all, so no `export *` in this
|
|
715
|
+
// module may contribute it — not even the first one.
|
|
716
|
+
const conflicting = this._getConflictingStarExportNames(moduleGraph);
|
|
717
|
+
if (conflicting !== undefined) {
|
|
718
|
+
for (const name of conflicting) ignoredExports.add(name);
|
|
719
|
+
}
|
|
656
720
|
|
|
657
721
|
/** @type {Hidden | undefined} */
|
|
658
722
|
let hiddenExports;
|
|
@@ -772,6 +836,31 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
772
836
|
};
|
|
773
837
|
}
|
|
774
838
|
|
|
839
|
+
/**
|
|
840
|
+
* Updates the hash with the data contributed by this instance.
|
|
841
|
+
* @param {Hash} hash hash to be updated
|
|
842
|
+
* @param {UpdateHashContext} context context
|
|
843
|
+
* @returns {void}
|
|
844
|
+
*/
|
|
845
|
+
updateHash(hash, context) {
|
|
846
|
+
const { chunkGraph, runtime } = context;
|
|
847
|
+
const moduleGraph = chunkGraph.moduleGraph;
|
|
848
|
+
if (!isInlineExportsEnabled(moduleGraph)) return;
|
|
849
|
+
const module = moduleGraph.getModule(this);
|
|
850
|
+
if (!module || !isInlineEnabled(module)) return;
|
|
851
|
+
const mode = this.getMode(moduleGraph, runtime);
|
|
852
|
+
if (mode.type !== "normal-reexport") return;
|
|
853
|
+
const exportsInfo = moduleGraph.getExportsInfo(module);
|
|
854
|
+
for (const item of /** @type {NormalReexportItem[]} */ (mode.items)) {
|
|
855
|
+
if (item.hidden || item.checked) continue;
|
|
856
|
+
const usedName = exportsInfo.getUsedName(item.ids, runtime);
|
|
857
|
+
if (usedName instanceof InlinedUsedName) {
|
|
858
|
+
hash.update(`${item.name}:${item.ids.join(".")}:`);
|
|
859
|
+
usedName.updateHash(hash);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
775
864
|
/**
|
|
776
865
|
* Gets module evaluation side effects state.
|
|
777
866
|
* @param {ModuleGraph} moduleGraph the module graph
|
|
@@ -858,6 +947,21 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
858
947
|
}
|
|
859
948
|
}
|
|
860
949
|
|
|
950
|
+
/**
|
|
951
|
+
* Names this module's `export *` sources provide with conflicting bindings.
|
|
952
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
|
953
|
+
* @returns {Set<ExportInfoName> | undefined} ambiguous names, or nothing when there are none
|
|
954
|
+
*/
|
|
955
|
+
_getConflictingStarExportNames(moduleGraph) {
|
|
956
|
+
// Every `export *` carries the module's full star list; a lone one has
|
|
957
|
+
// nothing to be ambiguous with, so skip the walk.
|
|
958
|
+
if (!this.allStarExports) return;
|
|
959
|
+
const { dependencies } = this.allStarExports;
|
|
960
|
+
if (dependencies.length < 2) return;
|
|
961
|
+
return moduleGraph.cached(determineExportAssignments, dependencies)
|
|
962
|
+
.conflicting;
|
|
963
|
+
}
|
|
964
|
+
|
|
861
965
|
/**
|
|
862
966
|
* Discover active exports from other star exports.
|
|
863
967
|
* @param {ModuleGraph} moduleGraph the module graph
|
|
@@ -1059,10 +1163,54 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
1059
1163
|
*/
|
|
1060
1164
|
getWarnings(moduleGraph) {
|
|
1061
1165
|
const exportsPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
|
|
1166
|
+
const circular =
|
|
1167
|
+
this._getCircularReexportPresenceLevel() === ExportPresenceModes.WARN
|
|
1168
|
+
? this._getCircularReexportErrors(moduleGraph)
|
|
1169
|
+
: undefined;
|
|
1062
1170
|
if (exportsPresence === ExportPresenceModes.WARN) {
|
|
1063
|
-
|
|
1171
|
+
const errors = this._getErrors(moduleGraph);
|
|
1172
|
+
if (!circular) return errors;
|
|
1173
|
+
return errors ? [...errors, ...circular] : circular;
|
|
1064
1174
|
}
|
|
1065
|
-
return
|
|
1175
|
+
return circular;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
/**
|
|
1179
|
+
* Reporting level for a circular reexport chain. It skips the promotion to
|
|
1180
|
+
* an error that AUTO gives a strict harmony module — a cycle warns by
|
|
1181
|
+
* default — but an explicit setting still says whether and how to report.
|
|
1182
|
+
* @returns {ExportPresenceMode} effective mode
|
|
1183
|
+
*/
|
|
1184
|
+
_getCircularReexportPresenceLevel() {
|
|
1185
|
+
return this.exportPresenceMode === ExportPresenceModes.AUTO
|
|
1186
|
+
? ExportPresenceModes.WARN
|
|
1187
|
+
: this.exportPresenceMode;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Returns errors for a name resolving through a circular reexport chain.
|
|
1192
|
+
* @param {ModuleGraph} moduleGraph module graph
|
|
1193
|
+
* @returns {WebpackError[] | undefined} errors
|
|
1194
|
+
*/
|
|
1195
|
+
_getCircularReexportErrors(moduleGraph) {
|
|
1196
|
+
const ids = this.getIds(moduleGraph);
|
|
1197
|
+
if (ids.length === 0 || !this.name) return;
|
|
1198
|
+
const parentModule = /** @type {Module} */ (
|
|
1199
|
+
moduleGraph.getParentModule(this)
|
|
1200
|
+
);
|
|
1201
|
+
const exportInfo = moduleGraph
|
|
1202
|
+
.getExportsInfo(parentModule)
|
|
1203
|
+
.getReadOnlyExportInfo(this.name);
|
|
1204
|
+
if (!exportInfo.hasCircularTarget(moduleGraph)) return;
|
|
1205
|
+
return [
|
|
1206
|
+
new HarmonyLinkingError(
|
|
1207
|
+
`export '${ids.join(".")}' (reexported as '${
|
|
1208
|
+
this.name
|
|
1209
|
+
}') is part of a circular reexport chain in '${
|
|
1210
|
+
this.userRequest
|
|
1211
|
+
}' and is undefined`
|
|
1212
|
+
)
|
|
1213
|
+
];
|
|
1066
1214
|
}
|
|
1067
1215
|
|
|
1068
1216
|
/**
|
|
@@ -1072,10 +1220,18 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
1072
1220
|
*/
|
|
1073
1221
|
getErrors(moduleGraph) {
|
|
1074
1222
|
const exportsPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
|
|
1075
|
-
|
|
1076
|
-
|
|
1223
|
+
const errors =
|
|
1224
|
+
exportsPresence === ExportPresenceModes.ERROR
|
|
1225
|
+
? this._getErrors(moduleGraph)
|
|
1226
|
+
: null;
|
|
1227
|
+
if (
|
|
1228
|
+
this._getCircularReexportPresenceLevel() !== ExportPresenceModes.ERROR
|
|
1229
|
+
) {
|
|
1230
|
+
return errors;
|
|
1077
1231
|
}
|
|
1078
|
-
|
|
1232
|
+
const circular = this._getCircularReexportErrors(moduleGraph);
|
|
1233
|
+
if (!circular) return errors;
|
|
1234
|
+
return errors ? [...errors, ...circular] : circular;
|
|
1079
1235
|
}
|
|
1080
1236
|
|
|
1081
1237
|
/**
|
|
@@ -1391,10 +1547,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1391
1547
|
}
|
|
1392
1548
|
|
|
1393
1549
|
case "reexport-fake-namespace-object":
|
|
1394
|
-
// `${name}_namespace_cache` needs an identifier to suffix,
|
|
1395
|
-
//
|
|
1396
|
-
//
|
|
1397
|
-
// the exports type, which is what `fakeType` mirrors.
|
|
1550
|
+
// `${name}_namespace_cache` needs an identifier to suffix, and an in-scope
|
|
1551
|
+
// target is an expression. The concatenation already memoizes the same
|
|
1552
|
+
// object, its interop namespace taking the mode `fakeType` mirrors.
|
|
1398
1553
|
if (inScope) {
|
|
1399
1554
|
initFragments.push(
|
|
1400
1555
|
this.getReexportFragment(
|
|
@@ -1429,7 +1584,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1429
1584
|
initFragments.push(
|
|
1430
1585
|
this.getReexportFragment(
|
|
1431
1586
|
module,
|
|
1432
|
-
|
|
1587
|
+
mode.circular
|
|
1588
|
+
? "reexport circular"
|
|
1589
|
+
: "reexport non-default export from non-harmony",
|
|
1433
1590
|
moduleGraph
|
|
1434
1591
|
.getExportsInfo(module)
|
|
1435
1592
|
.getUsedName(/** @type {string} */ (mode.name), runtime),
|
|
@@ -1455,7 +1612,19 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1455
1612
|
);
|
|
1456
1613
|
break;
|
|
1457
1614
|
|
|
1458
|
-
case "reexport-namespace-object":
|
|
1615
|
+
case "reexport-namespace-object": {
|
|
1616
|
+
let value = namespaceImportVar;
|
|
1617
|
+
|
|
1618
|
+
// The re-exported binding is the namespace itself, so it has to be
|
|
1619
|
+
// the same object every importer of that module is handed.
|
|
1620
|
+
if (
|
|
1621
|
+
importedModule.buildInfo &&
|
|
1622
|
+
importedModule.buildInfo.specNamespaceObject
|
|
1623
|
+
) {
|
|
1624
|
+
runtimeRequirements.add(RuntimeGlobals.specNamespaceObject);
|
|
1625
|
+
value = `${RuntimeGlobals.specNamespaceObject}(${value})`;
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1459
1628
|
initFragments.push(
|
|
1460
1629
|
this.getReexportFragment(
|
|
1461
1630
|
module,
|
|
@@ -1463,12 +1632,13 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1463
1632
|
moduleGraph
|
|
1464
1633
|
.getExportsInfo(module)
|
|
1465
1634
|
.getUsedName(/** @type {string} */ (mode.name), runtime),
|
|
1466
|
-
|
|
1635
|
+
value,
|
|
1467
1636
|
"",
|
|
1468
1637
|
runtimeRequirements
|
|
1469
1638
|
)
|
|
1470
1639
|
);
|
|
1471
1640
|
break;
|
|
1641
|
+
}
|
|
1472
1642
|
|
|
1473
1643
|
case "normal-reexport": {
|
|
1474
1644
|
// loop-invariants hoisted out of the per-item loop below (a barrel
|
|
@@ -1603,7 +1773,10 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1603
1773
|
|
|
1604
1774
|
/** @type {ExportMap} */
|
|
1605
1775
|
const map = new Map();
|
|
1606
|
-
map.set(key,
|
|
1776
|
+
map.set(key, {
|
|
1777
|
+
value: `/* ${comment} */ ${returnValue}`,
|
|
1778
|
+
type: ExportBindingType.Getter
|
|
1779
|
+
});
|
|
1607
1780
|
|
|
1608
1781
|
return new HarmonyExportInitFragment(module.exportsArgument, map);
|
|
1609
1782
|
}
|
|
@@ -1630,12 +1803,12 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1630
1803
|
|
|
1631
1804
|
/** @type {ExportMap} */
|
|
1632
1805
|
const map = new Map();
|
|
1633
|
-
map.set(
|
|
1634
|
-
|
|
1635
|
-
`/* reexport fake namespace object from non-harmony */ ${name}_namespace_cache || (${name}_namespace_cache = ${
|
|
1806
|
+
map.set(key, {
|
|
1807
|
+
value: `/* reexport fake namespace object from non-harmony */ ${name}_namespace_cache || (${name}_namespace_cache = ${
|
|
1636
1808
|
RuntimeGlobals.createFakeNamespaceObject
|
|
1637
|
-
}(${name}${fakeType ? `, ${fakeType}` : ""}))
|
|
1638
|
-
|
|
1809
|
+
}(${name}${fakeType ? `, ${fakeType}` : ""}))`,
|
|
1810
|
+
type: ExportBindingType.Getter
|
|
1811
|
+
});
|
|
1639
1812
|
|
|
1640
1813
|
return [
|
|
1641
1814
|
new InitFragment(
|
|
@@ -1674,10 +1847,20 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1674
1847
|
const map = new Map();
|
|
1675
1848
|
const moduleId = JSON.stringify(chunkGraph.getModuleId(module));
|
|
1676
1849
|
const mode = getMakeDeferredNamespaceModeFromExportsType(exportsType);
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1850
|
+
const names = getKnownExportNames(
|
|
1851
|
+
chunkGraph.moduleGraph,
|
|
1852
|
+
module,
|
|
1853
|
+
exportsType
|
|
1854
|
+
);
|
|
1855
|
+
runtimeRequirements.add(
|
|
1856
|
+
names
|
|
1857
|
+
? RuntimeGlobals.hasSealedDeferredNamespace
|
|
1858
|
+
: RuntimeGlobals.hasSynthesizedDeferredNamespace
|
|
1680
1859
|
);
|
|
1860
|
+
map.set(key, {
|
|
1861
|
+
value: `/* reexport deferred namespace object */ ${name}_deferred_namespace_cache || (${name}_deferred_namespace_cache = ${RuntimeGlobals.makeDeferredNamespaceObject}(${moduleId}, ${mode}${names ? `, ${JSON.stringify(names)}` : ""}))`,
|
|
1862
|
+
type: ExportBindingType.Getter
|
|
1863
|
+
});
|
|
1681
1864
|
|
|
1682
1865
|
return [
|
|
1683
1866
|
new InitFragment(
|
|
@@ -35,9 +35,13 @@ const joinIterableWithComma = (iterable) => {
|
|
|
35
35
|
return str;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
const ExportBindingType = Object.freeze({
|
|
39
|
+
Getter: 0b00,
|
|
40
|
+
Value: 0b01
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/** @typedef {Map<UsedName, { value: string, type: typeof ExportBindingType.Getter | typeof ExportBindingType.Value }>} ExportMap */
|
|
39
44
|
/** @typedef {Set<string>} UnusedExports */
|
|
40
|
-
/** @import { OnDemandGeneration } from "./ExportBindingInitFragment" */
|
|
41
45
|
|
|
42
46
|
/** @type {ExportMap} */
|
|
43
47
|
const EMPTY_MAP = new Map();
|
|
@@ -54,13 +58,13 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
|
54
58
|
* @param {string} exportsArgument the exports identifier
|
|
55
59
|
* @param {ExportMap} exportMap mapping from used name to exposed variable name
|
|
56
60
|
* @param {UnusedExports} unusedExports list of unused export names
|
|
57
|
-
* @param {
|
|
61
|
+
* @param {boolean} onDemand leave the call out of the source and hand it over in the code generation data (see `KnownMeta.onDemandExports`)
|
|
58
62
|
*/
|
|
59
63
|
constructor(
|
|
60
64
|
exportsArgument,
|
|
61
65
|
exportMap = EMPTY_MAP,
|
|
62
66
|
unusedExports = EMPTY_SET,
|
|
63
|
-
onDemand =
|
|
67
|
+
onDemand = false
|
|
64
68
|
) {
|
|
65
69
|
super(undefined, InitFragment.STAGE_HARMONY_EXPORTS, 1, "harmony-exports");
|
|
66
70
|
/** @type {string} */
|
|
@@ -69,8 +73,51 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
|
69
73
|
this.exportMap = exportMap;
|
|
70
74
|
/** @type {UnusedExports} */
|
|
71
75
|
this.unusedExports = unusedExports;
|
|
72
|
-
/** @type {
|
|
76
|
+
/** @type {boolean} */
|
|
73
77
|
this.onDemand = onDemand;
|
|
78
|
+
|
|
79
|
+
this._generated = false;
|
|
80
|
+
this._defsValue = undefined;
|
|
81
|
+
this._defsGetter = undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Returns the source code that will be included as initialization code.
|
|
86
|
+
* @param {GenerateContext} context context
|
|
87
|
+
* @returns {void}
|
|
88
|
+
*/
|
|
89
|
+
_generate({ runtimeTemplate }) {
|
|
90
|
+
if (this._generated) return;
|
|
91
|
+
this._generated = true;
|
|
92
|
+
|
|
93
|
+
if (this.exportMap.size > 0) {
|
|
94
|
+
/** @type {string[]} */
|
|
95
|
+
const _defsValue = [];
|
|
96
|
+
const _defsGetter = [];
|
|
97
|
+
const orderedExportMap =
|
|
98
|
+
this.exportMap.size > 1
|
|
99
|
+
? [...this.exportMap].sort(([a], [b]) => (a < b ? -1 : 1))
|
|
100
|
+
: this.exportMap;
|
|
101
|
+
for (const [key, { value, type }] of orderedExportMap) {
|
|
102
|
+
switch (type) {
|
|
103
|
+
case ExportBindingType.Getter:
|
|
104
|
+
_defsGetter.push(
|
|
105
|
+
`\n/* harmony export */ ${propertyName(
|
|
106
|
+
/** @type {string} */ (key)
|
|
107
|
+
)}: ${runtimeTemplate.returningFunction(value)}`
|
|
108
|
+
);
|
|
109
|
+
break;
|
|
110
|
+
|
|
111
|
+
case ExportBindingType.Value:
|
|
112
|
+
_defsValue.push(
|
|
113
|
+
`\n/* harmony export */ ${JSON.stringify(key)}, 0, ${value}`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
this._defsGetter = _defsGetter;
|
|
119
|
+
this._defsValue = _defsValue;
|
|
120
|
+
}
|
|
74
121
|
}
|
|
75
122
|
|
|
76
123
|
/**
|
|
@@ -85,12 +132,15 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
|
85
132
|
/** @type {undefined | UnusedExports} */
|
|
86
133
|
let unusedExports;
|
|
87
134
|
let unusedExportsOwned = false;
|
|
135
|
+
/** @type {boolean} */
|
|
136
|
+
let onDemand = false;
|
|
88
137
|
|
|
89
138
|
for (const fragment of fragments) {
|
|
90
139
|
if (fragment.exportMap.size !== 0) {
|
|
91
140
|
if (exportMap === undefined) {
|
|
92
141
|
exportMap = fragment.exportMap;
|
|
93
142
|
exportMapOwned = false;
|
|
143
|
+
onDemand = fragment.onDemand;
|
|
94
144
|
} else {
|
|
95
145
|
if (!exportMapOwned) {
|
|
96
146
|
exportMap = new Map(exportMap);
|
|
@@ -98,6 +148,7 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
|
98
148
|
}
|
|
99
149
|
for (const [key, value] of fragment.exportMap) {
|
|
100
150
|
if (!exportMap.has(key)) exportMap.set(key, value);
|
|
151
|
+
onDemand = onDemand || fragment.onDemand;
|
|
101
152
|
}
|
|
102
153
|
}
|
|
103
154
|
}
|
|
@@ -120,7 +171,7 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
|
120
171
|
this.exportsArgument,
|
|
121
172
|
exportMap,
|
|
122
173
|
unusedExports,
|
|
123
|
-
|
|
174
|
+
onDemand
|
|
124
175
|
);
|
|
125
176
|
}
|
|
126
177
|
|
|
@@ -167,7 +218,10 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
|
167
218
|
* @param {GenerateContext} context context
|
|
168
219
|
* @returns {string | Source | undefined} the source code that will be included as initialization code
|
|
169
220
|
*/
|
|
170
|
-
getContent(
|
|
221
|
+
getContent(context) {
|
|
222
|
+
this._generate(context);
|
|
223
|
+
|
|
224
|
+
const { runtimeRequirements, getData } = context;
|
|
171
225
|
const unusedPart =
|
|
172
226
|
this.unusedExports.size > 1
|
|
173
227
|
? `/* unused harmony exports ${joinIterableWithComma(
|
|
@@ -177,35 +231,68 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
|
177
231
|
? `/* unused harmony export ${first(this.unusedExports)} */\n`
|
|
178
232
|
: "";
|
|
179
233
|
let definePart = "";
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const definitions = [];
|
|
183
|
-
const orderedExportMap =
|
|
184
|
-
this.exportMap.size > 1
|
|
185
|
-
? [...this.exportMap].sort(([a], [b]) => (a < b ? -1 : 1))
|
|
186
|
-
: this.exportMap;
|
|
187
|
-
for (const [key, value] of orderedExportMap) {
|
|
188
|
-
definitions.push(
|
|
189
|
-
`\n/* harmony export */ ${propertyName(
|
|
190
|
-
/** @type {string} */ (key)
|
|
191
|
-
)}: ${runtimeTemplate.returningFunction(value)}`
|
|
192
|
-
);
|
|
193
|
-
}
|
|
234
|
+
|
|
235
|
+
if (this._defsGetter && this._defsGetter.length) {
|
|
194
236
|
// Requested even when the call is taken over below: whoever took it may still
|
|
195
237
|
// emit it, and by then the requirement set is closed.
|
|
196
238
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
197
239
|
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
198
240
|
definePart = `/* harmony export */ ${
|
|
199
241
|
RuntimeGlobals.definePropertyGetters
|
|
200
|
-
}(${this.exportsArgument}, {${
|
|
242
|
+
}(${this.exportsArgument}, {${this._defsGetter.join(
|
|
201
243
|
","
|
|
202
244
|
)}\n/* harmony export */ });\n`;
|
|
203
|
-
if (this.onDemand !== undefined
|
|
245
|
+
if (this.onDemand && getData !== undefined) {
|
|
246
|
+
const data = getData();
|
|
247
|
+
const before = data.get("exportsSource");
|
|
248
|
+
data.set(
|
|
249
|
+
"exportsSource",
|
|
250
|
+
before ? `${before}${definePart}` : definePart
|
|
251
|
+
);
|
|
204
252
|
definePart = "";
|
|
205
253
|
}
|
|
206
254
|
}
|
|
255
|
+
|
|
207
256
|
return `${definePart}${unusedPart}`;
|
|
208
257
|
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Returns the source code that will be included at the end of the module.
|
|
261
|
+
* @param {GenerateContext} context context
|
|
262
|
+
* @returns {string | Source | undefined} the source code that will be included at the end of the module
|
|
263
|
+
*/
|
|
264
|
+
getEndContent({ runtimeRequirements, getData }) {
|
|
265
|
+
let definePart = "";
|
|
266
|
+
|
|
267
|
+
if (this._defsValue && this._defsValue.length) {
|
|
268
|
+
// Requested even when the call is taken over below: whoever took it may still
|
|
269
|
+
// emit it, and by then the requirement set is closed.
|
|
270
|
+
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
271
|
+
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
272
|
+
// Only this fragment emits the array form, so the runtime helper drops the
|
|
273
|
+
// branch reading it unless this asks for it.
|
|
274
|
+
runtimeRequirements.add(RuntimeGlobals.definePropertyGettersFromArray);
|
|
275
|
+
definePart = `/* harmony export */ ${
|
|
276
|
+
RuntimeGlobals.definePropertyGetters
|
|
277
|
+
}(${this.exportsArgument}, [${this._defsValue.join(",")}\n/* harmony export */ ]);\n`;
|
|
278
|
+
|
|
279
|
+
if (this.onDemand && getData !== undefined) {
|
|
280
|
+
const data = getData();
|
|
281
|
+
const before = data.get("exportsBindingSource");
|
|
282
|
+
data.set(
|
|
283
|
+
"exportsBindingSource",
|
|
284
|
+
before ? `${before}${definePart}` : definePart
|
|
285
|
+
);
|
|
286
|
+
definePart = "";
|
|
287
|
+
} else {
|
|
288
|
+
definePart = `\n${definePart}`;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return definePart;
|
|
293
|
+
}
|
|
209
294
|
}
|
|
210
295
|
|
|
211
296
|
module.exports = HarmonyExportInitFragment;
|
|
297
|
+
|
|
298
|
+
HarmonyExportInitFragment.ExportBindingType = ExportBindingType;
|