webpack 5.107.2 → 5.108.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/hot/dev-server.js +2 -0
- package/lib/APIPlugin.js +8 -4
- package/lib/CacheFacade.js +7 -0
- package/lib/Chunk.js +4 -0
- package/lib/ChunkGraph.js +30 -9
- package/lib/CircularModulesPlugin.js +190 -0
- package/lib/CleanPlugin.js +2 -1
- package/lib/Compilation.js +396 -65
- package/lib/Compiler.js +25 -11
- package/lib/ConcatenationScope.js +10 -3
- package/lib/ContextExclusionPlugin.js +1 -0
- package/lib/ContextModule.js +92 -47
- package/lib/ContextReplacementPlugin.js +4 -0
- package/lib/DefinePlugin.js +89 -15
- package/lib/Dependency.js +111 -7
- package/lib/EntryOptionPlugin.js +39 -2
- package/lib/EntryPlugin.js +2 -0
- package/lib/ExportsInfo.js +314 -73
- package/lib/ExternalModule.js +82 -34
- package/lib/ExternalModuleFactoryPlugin.js +1 -0
- package/lib/ExternalsPlugin.js +1 -0
- package/lib/FileSystemInfo.js +173 -23
- package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
- package/lib/FlagDependencyExportsPlugin.js +23 -0
- package/lib/FlagDependencyUsagePlugin.js +87 -5
- package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
- package/lib/Generator.js +8 -0
- package/lib/HotModuleReplacementPlugin.js +65 -28
- package/lib/IgnorePlugin.js +1 -0
- package/lib/InitFragment.js +5 -0
- package/lib/JavascriptMetaInfoPlugin.js +7 -5
- package/lib/LazyBarrel.js +361 -0
- package/lib/LoaderTargetPlugin.js +1 -0
- package/lib/Module.js +21 -42
- package/lib/ModuleGraph.js +3 -2
- package/lib/ModuleProfile.js +27 -1
- package/lib/ModuleTemplate.js +2 -0
- package/lib/MultiCompiler.js +2 -0
- package/lib/MultiStats.js +1 -0
- package/lib/MultiWatching.js +2 -0
- package/lib/NodeStuffPlugin.js +22 -17
- package/lib/NormalModule.js +142 -80
- package/lib/NormalModuleReplacementPlugin.js +2 -0
- package/lib/PrefetchPlugin.js +2 -0
- package/lib/ProgressPlugin.js +8 -0
- package/lib/ProvidePlugin.js +1 -0
- package/lib/RawModule.js +20 -16
- package/lib/RecordIdsPlugin.js +1 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimePlugin.js +58 -26
- package/lib/RuntimeTemplate.js +278 -21
- package/lib/SelfModuleFactory.js +1 -0
- package/lib/SourceMapDevToolPlugin.js +3 -5
- package/lib/Stats.js +1 -0
- package/lib/Template.js +8 -2
- package/lib/TemplatedPathPlugin.js +473 -131
- package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
- package/lib/WarnDeprecatedOptionPlugin.js +4 -0
- package/lib/WarnNoModeSetPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -0
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +50 -5
- package/lib/asset/AssetBytesGenerator.js +11 -3
- package/lib/asset/AssetGenerator.js +47 -22
- package/lib/asset/AssetModule.js +47 -0
- package/lib/asset/AssetModulesPlugin.js +14 -14
- package/lib/asset/AssetParser.js +2 -2
- package/lib/asset/AssetSourceGenerator.js +8 -0
- package/lib/asset/RawDataUrlModule.js +12 -13
- package/lib/buildChunkGraph.js +64 -7
- package/lib/bun/BunTargetPlugin.js +48 -0
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
- package/lib/cache/AddManagedPathsPlugin.js +3 -0
- package/lib/cache/IdleFileCachePlugin.js +4 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +1 -0
- package/lib/cache/ResolverCachePlugin.js +2 -0
- package/lib/cache/mergeEtags.js +2 -0
- package/lib/cli.js +109 -19
- package/lib/config/browserslistTargetHandler.js +99 -0
- package/lib/config/defaults.js +147 -7
- package/lib/config/defineConfig.js +31 -0
- package/lib/config/normalization.js +5 -0
- package/lib/config/target.js +181 -2
- package/lib/container/ContainerEntryModule.js +15 -14
- package/lib/container/ContainerExposedDependency.js +2 -2
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackDependency.js +5 -7
- package/lib/container/FallbackModule.js +10 -9
- package/lib/container/RemoteModule.js +20 -10
- package/lib/container/RemoteRuntimeModule.js +14 -12
- package/lib/css/CssGenerator.js +353 -327
- package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
- package/lib/css/CssLoadingRuntimeModule.js +118 -47
- package/lib/css/CssModule.js +52 -23
- package/lib/css/CssModulesPlugin.js +107 -124
- package/lib/css/CssParser.js +2759 -2205
- package/lib/css/syntax.js +2859 -0
- package/lib/debug/ProfilingPlugin.js +2 -0
- package/lib/deno/DenoTargetPlugin.js +47 -0
- package/lib/dependencies/AMDDefineDependency.js +22 -17
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
- package/lib/dependencies/AMDRequireContextDependency.js +7 -11
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireDependency.js +24 -20
- package/lib/dependencies/CachedConstDependency.js +3 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
- package/lib/dependencies/CommonJsExportsDependency.js +21 -16
- package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
- package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
- package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
- package/lib/dependencies/CommonJsPlugin.js +1 -1
- package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
- package/lib/dependencies/CommonJsRequireDependency.js +42 -11
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
- package/lib/dependencies/ConstDependency.js +16 -11
- package/lib/dependencies/ContextDependency.js +4 -0
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +23 -14
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
- package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +512 -574
- package/lib/dependencies/CssIcssImportDependency.js +9 -9
- package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
- package/lib/dependencies/CssImportDependency.js +25 -1
- package/lib/dependencies/CssUrlDependency.js +23 -14
- package/lib/dependencies/DllEntryDependency.js +9 -13
- package/lib/dependencies/ExportBindingInitFragment.js +164 -0
- package/lib/dependencies/ExportsInfoDependency.js +12 -12
- package/lib/dependencies/ExternalModuleDependency.js +8 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
- package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
- package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
- package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
- package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
- package/lib/dependencies/HarmonyExportInitFragment.js +18 -15
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
- package/lib/dependencies/HarmonyExports.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +24 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
- package/lib/dependencies/HarmonyImportGuard.js +254 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
- package/lib/dependencies/HarmonyLinkingError.js +1 -0
- package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
- package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +261 -109
- package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
- package/lib/dependencies/HtmlInlineScriptDependency.js +17 -13
- package/lib/dependencies/HtmlInlineStyleDependency.js +45 -11
- package/lib/dependencies/ImportContextDependency.js +5 -9
- package/lib/dependencies/ImportDependency.js +44 -2
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +74 -30
- package/lib/dependencies/ImportParserPlugin.js +19 -0
- package/lib/dependencies/ImportWeakDependency.js +1 -0
- package/lib/dependencies/JsonExportsDependency.js +9 -9
- package/lib/dependencies/LoaderImportDependency.js +1 -0
- package/lib/dependencies/LocalModule.js +11 -12
- package/lib/dependencies/LocalModuleDependency.js +11 -13
- package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
- package/lib/dependencies/ModuleDependency.js +7 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
- package/lib/dependencies/ProvidedDependency.js +31 -27
- package/lib/dependencies/PureExpressionDependency.js +7 -9
- package/lib/dependencies/RequireEnsureDependency.js +12 -13
- package/lib/dependencies/RequireHeaderDependency.js +3 -4
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
- package/lib/dependencies/RequireResolveContextDependency.js +7 -11
- package/lib/dependencies/RequireResolveDependency.js +1 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
- package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
- package/lib/dependencies/StaticExportsDependency.js +10 -10
- package/lib/dependencies/SystemPlugin.js +2 -0
- package/lib/dependencies/URLContextDependency.js +5 -7
- package/lib/dependencies/URLDependency.js +14 -16
- package/lib/dependencies/UnsupportedDependency.js +8 -13
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
- package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +19 -8
- package/lib/dependencies/WorkerPlugin.js +22 -6
- package/lib/dependencies/processExportInfo.js +13 -11
- package/lib/dll/DelegatedModule.js +29 -15
- package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
- package/lib/dll/DelegatedPlugin.js +1 -0
- package/lib/dll/DllEntryPlugin.js +3 -0
- package/lib/dll/DllModule.js +3 -2
- package/lib/dll/DllPlugin.js +16 -0
- package/lib/dll/DllReferencePlugin.js +3 -0
- package/lib/dll/LibManifestPlugin.js +1 -0
- package/lib/electron/ElectronTargetPlugin.js +22 -4
- package/lib/errors/ConcurrentCompilationError.js +1 -0
- package/lib/errors/HookWebpackError.js +11 -13
- package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
- package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
- package/lib/errors/JSONParseError.js +9 -8
- package/lib/errors/ModuleBuildError.js +16 -13
- package/lib/errors/ModuleDependencyError.js +8 -1
- package/lib/errors/ModuleDependencyWarning.js +8 -1
- package/lib/errors/ModuleError.js +5 -11
- package/lib/errors/ModuleHashingError.js +4 -0
- package/lib/errors/ModuleNotFoundError.js +3 -0
- package/lib/errors/ModuleParseError.js +5 -11
- package/lib/errors/ModuleRestoreError.js +2 -0
- package/lib/errors/ModuleStoreError.js +3 -0
- package/lib/errors/ModuleWarning.js +7 -11
- package/lib/errors/NodeStuffInWebError.js +1 -0
- package/lib/errors/NonErrorEmittedError.js +2 -0
- package/lib/errors/UnhandledSchemeError.js +1 -0
- package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
- package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
- package/lib/hmr/LazyCompilationPlugin.js +30 -6
- package/lib/html/HtmlGenerator.js +217 -23
- package/lib/html/HtmlModule.js +40 -0
- package/lib/html/HtmlModulesPlugin.js +219 -55
- package/lib/html/HtmlParser.js +1108 -1099
- package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
- package/lib/ids/IdHelpers.js +4 -2
- package/lib/index.js +19 -0
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
- package/lib/javascript/JavascriptGenerator.js +6 -2
- package/lib/javascript/JavascriptModule.js +54 -0
- package/lib/javascript/JavascriptModulesPlugin.js +257 -102
- package/lib/javascript/JavascriptParser.js +285 -158
- package/lib/json/JsonModule.js +40 -0
- package/lib/json/JsonModulesPlugin.js +7 -0
- package/lib/json/JsonParser.js +4 -2
- package/lib/library/AssignLibraryPlugin.js +5 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
- package/lib/library/FalseIIFEUmdWarning.js +1 -0
- package/lib/library/ModuleLibraryPlugin.js +24 -5
- package/lib/library/SystemLibraryPlugin.js +3 -3
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +1 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
- package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
- package/lib/optimize/ConcatenatedModule.js +395 -77
- package/lib/optimize/ConstExportsPlugin.js +211 -0
- package/lib/optimize/InlineExports.js +178 -0
- package/lib/optimize/InnerGraph.js +372 -275
- package/lib/optimize/InnerGraphPlugin.js +196 -99
- package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
- package/lib/optimize/RealContentHashPlugin.js +14 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
- package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
- package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
- package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
- package/lib/runtime/WorkerRuntimeModule.js +33 -0
- package/lib/schemes/HttpUriPlugin.js +3 -2
- package/lib/serialization/AggregateErrorSerializer.js +7 -6
- package/lib/serialization/ArraySerializer.js +4 -8
- package/lib/serialization/BinaryMiddleware.js +538 -468
- package/lib/serialization/DateObjectSerializer.js +2 -2
- package/lib/serialization/ErrorObjectSerializer.js +7 -6
- package/lib/serialization/MapObjectSerializer.js +5 -9
- package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
- package/lib/serialization/ObjectMiddleware.js +50 -13
- package/lib/serialization/PlainObjectSerializer.js +9 -8
- package/lib/serialization/RegExpObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +1 -0
- package/lib/serialization/SetObjectSerializer.js +4 -8
- package/lib/sharing/ConsumeSharedModule.js +6 -7
- package/lib/sharing/ConsumeSharedPlugin.js +1 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
- package/lib/sharing/ProvideSharedDependency.js +30 -15
- package/lib/sharing/ProvideSharedModule.js +30 -11
- package/lib/sharing/ProvideSharedPlugin.js +4 -2
- package/lib/sharing/SharePlugin.js +3 -0
- package/lib/sharing/ShareRuntimeModule.js +18 -16
- package/lib/sharing/resolveMatchedConfigs.js +2 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
- package/lib/stats/StatsFactory.js +11 -9
- package/lib/stats/StatsPrinter.js +9 -2
- package/lib/url/URLParserPlugin.js +5 -2
- package/lib/util/AsyncQueue.js +10 -0
- package/lib/util/LazyBucketSortedSet.js +5 -0
- package/lib/util/LazySet.js +6 -4
- package/lib/util/LocConverter.js +11 -1
- package/lib/util/Semaphore.js +1 -0
- package/lib/util/SourceProcessor.js +106 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/WeakTupleMap.js +27 -1
- package/lib/util/chainedImports.js +3 -3
- package/lib/util/comparators.js +2 -2
- package/lib/util/concatenate.js +31 -7
- package/lib/util/createHash.js +0 -1
- package/lib/util/deterministicGrouping.js +19 -12
- package/lib/util/extractSourceMap.js +1 -1
- package/lib/util/findGraphRoots.js +2 -0
- package/lib/util/fs.js +10 -5
- package/lib/util/hash/DebugHash.js +1 -0
- package/lib/util/hash/hash-digest.js +24 -15
- package/lib/util/identifier.js +7 -0
- package/lib/util/internalSerializables.js +11 -2
- package/lib/util/magicComment.js +42 -0
- package/lib/util/makeSerializable.js +1 -0
- package/lib/util/nonNumericOnlyHash.js +30 -1
- package/lib/util/property.js +7 -1
- package/lib/util/publicPathPlaceholder.js +64 -0
- package/lib/util/registerExternalSerializer.js +4 -4
- package/lib/wasm-async/AsyncWasmModule.js +77 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
- package/lib/wasm-sync/SyncWasmModule.js +39 -0
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +7 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
- package/package.json +35 -27
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +212 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
- package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
- package/schemas/plugins/HtmlParserOptions.check.js +6 -0
- package/schemas/plugins/HtmlParserOptions.json +3 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +1456 -290
- package/lib/css/walkCssTokens.js +0 -2020
- package/lib/util/AppendOnlyStackedSet.js +0 -93
|
@@ -16,9 +16,9 @@ const NullDependency = require("./NullDependency");
|
|
|
16
16
|
/** @typedef {import("../Dependency")} Dependency */
|
|
17
17
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
18
18
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
19
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
20
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
21
19
|
/** @typedef {import("./HarmonyAcceptImportDependency")} HarmonyAcceptImportDependency */
|
|
20
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[Range, HarmonyAcceptImportDependency[], boolean]>} ObjectDeserializerContext */
|
|
21
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[Range, HarmonyAcceptImportDependency[], boolean]>} ObjectSerializerContext */
|
|
22
22
|
/** @typedef {import("../Module")} Module */
|
|
23
23
|
/** @typedef {import("../Module").ModuleId} ModuleId */
|
|
24
24
|
|
|
@@ -32,7 +32,9 @@ class HarmonyAcceptDependency extends NullDependency {
|
|
|
32
32
|
constructor(range, dependencies, hasCallback) {
|
|
33
33
|
super();
|
|
34
34
|
this.range = range;
|
|
35
|
+
/** @type {HarmonyAcceptImportDependency[]} */
|
|
35
36
|
this.dependencies = dependencies;
|
|
37
|
+
/** @type {boolean} */
|
|
36
38
|
this.hasCallback = hasCallback;
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -45,10 +47,7 @@ class HarmonyAcceptDependency extends NullDependency {
|
|
|
45
47
|
* @param {ObjectSerializerContext} context context
|
|
46
48
|
*/
|
|
47
49
|
serialize(context) {
|
|
48
|
-
|
|
49
|
-
write(this.range);
|
|
50
|
-
write(this.dependencies);
|
|
51
|
-
write(this.hasCallback);
|
|
50
|
+
context.write(this.range).write(this.dependencies).write(this.hasCallback);
|
|
52
51
|
super.serialize(context);
|
|
53
52
|
}
|
|
54
53
|
|
|
@@ -57,11 +56,12 @@ class HarmonyAcceptDependency extends NullDependency {
|
|
|
57
56
|
* @param {ObjectDeserializerContext} context context
|
|
58
57
|
*/
|
|
59
58
|
deserialize(context) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this.dependencies = read();
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
this.range = context.read();
|
|
60
|
+
const c1 = context.rest;
|
|
61
|
+
this.dependencies = c1.read();
|
|
62
|
+
const c2 = c1.rest;
|
|
63
|
+
this.hasCallback = c2.read();
|
|
64
|
+
super.deserialize(c2.rest);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -10,6 +10,7 @@ const EnvironmentNotSupportAsyncWarning = require("../errors/EnvironmentNotSuppo
|
|
|
10
10
|
const DynamicExports = require("./DynamicExports");
|
|
11
11
|
const HarmonyCompatibilityDependency = require("./HarmonyCompatibilityDependency");
|
|
12
12
|
const HarmonyExports = require("./HarmonyExports");
|
|
13
|
+
const { IMPORT_META_NAMES } = require("./ImportMetaPlugin");
|
|
13
14
|
|
|
14
15
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
15
16
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
|
@@ -23,6 +24,33 @@ module.exports = class HarmonyDetectionParserPlugin {
|
|
|
23
24
|
* @returns {void}
|
|
24
25
|
*/
|
|
25
26
|
apply(parser) {
|
|
27
|
+
// `import.meta`/top-level `await` only parse as modules, so their presence
|
|
28
|
+
// alone marks the module as ESM (matching Node.js syntax detection).
|
|
29
|
+
/**
|
|
30
|
+
* @param {boolean} isStrictHarmony strict harmony mode should be enabled
|
|
31
|
+
* @returns {void}
|
|
32
|
+
*/
|
|
33
|
+
const enableHarmony = (isStrictHarmony) => {
|
|
34
|
+
if (HarmonyExports.isEnabled(parser.state)) return;
|
|
35
|
+
const module = parser.state.module;
|
|
36
|
+
const compatDep = new HarmonyCompatibilityDependency();
|
|
37
|
+
compatDep.loc = {
|
|
38
|
+
start: {
|
|
39
|
+
line: -1,
|
|
40
|
+
column: 0
|
|
41
|
+
},
|
|
42
|
+
end: {
|
|
43
|
+
line: -1,
|
|
44
|
+
column: 0
|
|
45
|
+
},
|
|
46
|
+
index: -3
|
|
47
|
+
};
|
|
48
|
+
module.addPresentationalDependency(compatDep);
|
|
49
|
+
DynamicExports.bailout(parser.state);
|
|
50
|
+
HarmonyExports.enable(parser.state, isStrictHarmony);
|
|
51
|
+
parser.scope.isStrict = true;
|
|
52
|
+
};
|
|
53
|
+
|
|
26
54
|
parser.hooks.program.tap(PLUGIN_NAME, (ast) => {
|
|
27
55
|
const isStrictHarmony =
|
|
28
56
|
parser.state.module.type === JAVASCRIPT_MODULE_TYPE_ESM;
|
|
@@ -36,33 +64,13 @@ module.exports = class HarmonyDetectionParserPlugin {
|
|
|
36
64
|
statement.type === "ExportAllDeclaration"
|
|
37
65
|
);
|
|
38
66
|
if (isHarmony) {
|
|
39
|
-
|
|
40
|
-
const compatDep = new HarmonyCompatibilityDependency();
|
|
41
|
-
compatDep.loc = {
|
|
42
|
-
start: {
|
|
43
|
-
line: -1,
|
|
44
|
-
column: 0
|
|
45
|
-
},
|
|
46
|
-
end: {
|
|
47
|
-
line: -1,
|
|
48
|
-
column: 0
|
|
49
|
-
},
|
|
50
|
-
index: -3
|
|
51
|
-
};
|
|
52
|
-
module.addPresentationalDependency(compatDep);
|
|
53
|
-
DynamicExports.bailout(parser.state);
|
|
54
|
-
HarmonyExports.enable(parser.state, isStrictHarmony);
|
|
55
|
-
parser.scope.isStrict = true;
|
|
67
|
+
enableHarmony(isStrictHarmony);
|
|
56
68
|
}
|
|
57
69
|
});
|
|
58
70
|
|
|
59
71
|
parser.hooks.topLevelAwait.tap(PLUGIN_NAME, () => {
|
|
60
72
|
const module = parser.state.module;
|
|
61
|
-
|
|
62
|
-
throw new Error(
|
|
63
|
-
"Top-level-await is only supported in EcmaScript Modules"
|
|
64
|
-
);
|
|
65
|
-
}
|
|
73
|
+
enableHarmony(false);
|
|
66
74
|
/** @type {BuildMeta} */
|
|
67
75
|
(module.buildMeta).async = true;
|
|
68
76
|
EnvironmentNotSupportAsyncWarning.check(
|
|
@@ -72,6 +80,23 @@ module.exports = class HarmonyDetectionParserPlugin {
|
|
|
72
80
|
);
|
|
73
81
|
});
|
|
74
82
|
|
|
83
|
+
// Using `import.meta` only parses as a module, so it marks the module ESM.
|
|
84
|
+
// Non-bailing and run before ImportMetaPlugin so its handling still runs;
|
|
85
|
+
// unknown members go through `unhandledExpressionMemberChain`.
|
|
86
|
+
const onImportMeta = () => {
|
|
87
|
+
enableHarmony(false);
|
|
88
|
+
};
|
|
89
|
+
for (const name of IMPORT_META_NAMES) {
|
|
90
|
+
parser.hooks.expression.for(name).tap(PLUGIN_NAME, onImportMeta);
|
|
91
|
+
parser.hooks.typeof.for(name).tap(PLUGIN_NAME, onImportMeta);
|
|
92
|
+
}
|
|
93
|
+
parser.hooks.expressionMemberChain
|
|
94
|
+
.for("import.meta")
|
|
95
|
+
.tap(PLUGIN_NAME, onImportMeta);
|
|
96
|
+
parser.hooks.unhandledExpressionMemberChain
|
|
97
|
+
.for("import.meta")
|
|
98
|
+
.tap(PLUGIN_NAME, onImportMeta);
|
|
99
|
+
|
|
75
100
|
/**
|
|
76
101
|
* Returns true if in harmony.
|
|
77
102
|
* @returns {boolean | undefined} true if in harmony
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
+
const { InlinedUsedName } = require("../optimize/InlineExports");
|
|
9
|
+
const {
|
|
10
|
+
getDependencyUsedByExportsCondition
|
|
11
|
+
} = require("../optimize/InnerGraph");
|
|
8
12
|
const makeSerializable = require("../util/makeSerializable");
|
|
9
13
|
const { ExportPresenceModes } = require("./HarmonyImportDependency");
|
|
10
14
|
const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
|
|
@@ -12,13 +16,15 @@ const { ImportPhase } = require("./ImportPhase");
|
|
|
12
16
|
|
|
13
17
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
14
18
|
/** @typedef {import("../Dependency")} Dependency */
|
|
19
|
+
/** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
|
|
15
20
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
16
21
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
22
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
17
23
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
|
18
24
|
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
|
19
25
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
20
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
21
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
26
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<string[]>} ObjectDeserializerContext */
|
|
27
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<string[]>} ObjectSerializerContext */
|
|
22
28
|
/** @typedef {import("./HarmonyImportDependency").Ids} Ids */
|
|
23
29
|
|
|
24
30
|
/**
|
|
@@ -51,6 +57,7 @@ class HarmonyEvaluatedImportSpecifierDependency extends HarmonyImportSpecifierDe
|
|
|
51
57
|
attributes,
|
|
52
58
|
[]
|
|
53
59
|
);
|
|
60
|
+
/** @type {string} */
|
|
54
61
|
this.operator = operator;
|
|
55
62
|
}
|
|
56
63
|
|
|
@@ -58,6 +65,17 @@ class HarmonyEvaluatedImportSpecifierDependency extends HarmonyImportSpecifierDe
|
|
|
58
65
|
return `evaluated X ${this.operator} harmony import specifier`;
|
|
59
66
|
}
|
|
60
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Returns function to determine if the connection is active.
|
|
70
|
+
* @param {ModuleGraph} moduleGraph module graph
|
|
71
|
+
* @returns {null | false | GetConditionFn} function to determine if the connection is active
|
|
72
|
+
*/
|
|
73
|
+
getCondition(moduleGraph) {
|
|
74
|
+
// Existence check is independent of inlining; skip the base class's
|
|
75
|
+
// inline-sensitivity, which would wrongly deactivate the connection.
|
|
76
|
+
return getDependencyUsedByExportsCondition(this, moduleGraph);
|
|
77
|
+
}
|
|
78
|
+
|
|
61
79
|
/**
|
|
62
80
|
* Serializes this instance into the provided serializer context.
|
|
63
81
|
* @param {ObjectSerializerContext} context context
|
|
@@ -149,6 +167,14 @@ HarmonyEvaluatedImportSpecifierDependency.Template = class HarmonyEvaluatedImpor
|
|
|
149
167
|
} else {
|
|
150
168
|
const usedName = exportsInfo.getUsedName(ids, runtime);
|
|
151
169
|
|
|
170
|
+
if (usedName instanceof InlinedUsedName) {
|
|
171
|
+
// Inlined exports only work with ESM export dependency
|
|
172
|
+
// which only existed in modules with `namespace` exportsType.
|
|
173
|
+
throw new Error(
|
|
174
|
+
"Evaluated import specifier dependency has inlined export name: This should not happen"
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
152
178
|
const code = this._getCodeForIds(
|
|
153
179
|
dep,
|
|
154
180
|
source,
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
const CompatibilityPlugin = require("../CompatibilityPlugin");
|
|
9
9
|
const WebpackError = require("../errors/WebpackError");
|
|
10
10
|
const { getImportAttributes } = require("../javascript/JavascriptParser");
|
|
11
|
-
const
|
|
11
|
+
const { CONST_BINDING_TAG } = require("../optimize/ConstExportsPlugin");
|
|
12
|
+
const { toInlinedValue } = require("../optimize/InlineExports");
|
|
13
|
+
const { getInnerGraphUtils } = require("../optimize/InnerGraph");
|
|
12
14
|
const ConstDependency = require("./ConstDependency");
|
|
13
15
|
const HarmonyExportExpressionDependency = require("./HarmonyExportExpressionDependency");
|
|
14
16
|
const HarmonyExportHeaderDependency = require("./HarmonyExportHeaderDependency");
|
|
@@ -21,6 +23,7 @@ const {
|
|
|
21
23
|
const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
|
|
22
24
|
const { ImportPhaseUtils, createGetImportPhase } = require("./ImportPhase");
|
|
23
25
|
|
|
26
|
+
/** @typedef {import("estree").Expression} Expression */
|
|
24
27
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
|
25
28
|
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
|
26
29
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
|
@@ -40,6 +43,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
40
43
|
* @param {JavascriptParserOptions} options options
|
|
41
44
|
*/
|
|
42
45
|
constructor(options) {
|
|
46
|
+
/** @type {JavascriptParserOptions} */
|
|
43
47
|
this.options = options;
|
|
44
48
|
this.exportPresenceMode = ExportPresenceModes.resolveFromOptions(
|
|
45
49
|
options.reexportExportsPresence,
|
|
@@ -66,10 +70,10 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
66
70
|
),
|
|
67
71
|
/** @type {Range} */ (statement.range)
|
|
68
72
|
);
|
|
69
|
-
dep.
|
|
70
|
-
/** @type {DependencyLocation} */ (statement.loc)
|
|
73
|
+
dep.setLocWithIndex(
|
|
74
|
+
/** @type {DependencyLocation} */ (statement.loc),
|
|
75
|
+
-1
|
|
71
76
|
);
|
|
72
|
-
dep.loc.index = -1;
|
|
73
77
|
parser.state.module.addPresentationalDependency(dep);
|
|
74
78
|
return true;
|
|
75
79
|
});
|
|
@@ -80,8 +84,10 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
80
84
|
"",
|
|
81
85
|
/** @type {Range} */ (statement.range)
|
|
82
86
|
);
|
|
83
|
-
clearDep.
|
|
84
|
-
|
|
87
|
+
clearDep.setLocWithIndex(
|
|
88
|
+
/** @type {DependencyLocation} */ (statement.loc),
|
|
89
|
+
-1
|
|
90
|
+
);
|
|
85
91
|
parser.state.module.addPresentationalDependency(clearDep);
|
|
86
92
|
|
|
87
93
|
const phase = getImportPhase(parser, statement);
|
|
@@ -98,10 +104,10 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
98
104
|
phase,
|
|
99
105
|
getImportAttributes(statement)
|
|
100
106
|
);
|
|
101
|
-
sideEffectDep.
|
|
102
|
-
/** @type {DependencyLocation} */ (statement.loc)
|
|
107
|
+
sideEffectDep.setLocWithIndex(
|
|
108
|
+
/** @type {DependencyLocation} */ (statement.loc),
|
|
109
|
+
-1
|
|
103
110
|
);
|
|
104
|
-
sideEffectDep.loc.index = -1;
|
|
105
111
|
parser.state.current.addDependency(sideEffectDep);
|
|
106
112
|
return true;
|
|
107
113
|
});
|
|
@@ -110,6 +116,11 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
110
116
|
const exprRange = /** @type {Range} */ (node.range);
|
|
111
117
|
const statementRange = /** @type {Range} */ (statement.range);
|
|
112
118
|
const comments = parser.getComments([statementRange[0], exprRange[0]]);
|
|
119
|
+
const constValue = node.type.endsWith("Declaration")
|
|
120
|
+
? undefined
|
|
121
|
+
: toInlinedValue(
|
|
122
|
+
parser.evaluateExpression(/** @type {Expression} */ (node))
|
|
123
|
+
);
|
|
113
124
|
const dep = new HarmonyExportExpressionDependency(
|
|
114
125
|
exprRange,
|
|
115
126
|
statementRange,
|
|
@@ -141,7 +152,8 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
141
152
|
} `,
|
|
142
153
|
suffix: `(${node.params.length > 0 ? "" : ") "}`
|
|
143
154
|
}
|
|
144
|
-
: undefined
|
|
155
|
+
: undefined,
|
|
156
|
+
constValue
|
|
145
157
|
);
|
|
146
158
|
dep.isAnonymousDefault =
|
|
147
159
|
this.options.anonymousDefaultExportName !== false &&
|
|
@@ -151,12 +163,12 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
151
163
|
node.type === "ClassDeclaration" ||
|
|
152
164
|
node.type === "ClassExpression") &&
|
|
153
165
|
!node.id));
|
|
154
|
-
dep.
|
|
155
|
-
/** @type {DependencyLocation} */ (statement.loc)
|
|
166
|
+
dep.setLocWithIndex(
|
|
167
|
+
/** @type {DependencyLocation} */ (statement.loc),
|
|
168
|
+
-1
|
|
156
169
|
);
|
|
157
|
-
dep.loc.index = -1;
|
|
158
170
|
parser.state.current.addDependency(dep);
|
|
159
|
-
|
|
171
|
+
getInnerGraphUtils(parser.state.compilation).addVariableUsage(
|
|
160
172
|
parser,
|
|
161
173
|
node.type.endsWith("Declaration") &&
|
|
162
174
|
/** @type {FunctionDeclaration | ClassDeclaration} */ (node).id
|
|
@@ -187,7 +199,15 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
187
199
|
const harmonyNamedExports = (parser.state.harmonyNamedExports =
|
|
188
200
|
parser.state.harmonyNamedExports || new Set());
|
|
189
201
|
harmonyNamedExports.add(name);
|
|
190
|
-
|
|
202
|
+
getInnerGraphUtils(parser.state.compilation).addVariableUsage(
|
|
203
|
+
parser,
|
|
204
|
+
id,
|
|
205
|
+
name
|
|
206
|
+
);
|
|
207
|
+
const tagData = settings
|
|
208
|
+
? undefined
|
|
209
|
+
: /** @type {{ value?: import("../optimize/InlineExports").InlinedValue } | undefined} */
|
|
210
|
+
(parser.getTagData(id, CONST_BINDING_TAG));
|
|
191
211
|
const dep = settings
|
|
192
212
|
? new HarmonyExportImportedSpecifierDependency(
|
|
193
213
|
settings.source,
|
|
@@ -201,11 +221,15 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
201
221
|
settings.phase,
|
|
202
222
|
settings.attributes
|
|
203
223
|
)
|
|
204
|
-
: new HarmonyExportSpecifierDependency(
|
|
205
|
-
|
|
206
|
-
|
|
224
|
+
: new HarmonyExportSpecifierDependency(
|
|
225
|
+
id,
|
|
226
|
+
name,
|
|
227
|
+
tagData ? tagData.value || null : undefined
|
|
228
|
+
);
|
|
229
|
+
dep.setLocWithIndex(
|
|
230
|
+
/** @type {DependencyLocation} */ (statement.loc),
|
|
231
|
+
/** @type {number} */ (idx)
|
|
207
232
|
);
|
|
208
|
-
dep.loc.index = idx;
|
|
209
233
|
const isAsiSafe = !parser.isAsiPosition(
|
|
210
234
|
/** @type {Range} */
|
|
211
235
|
(statement.range)[0]
|
|
@@ -249,10 +273,10 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
249
273
|
if (harmonyStarExports) {
|
|
250
274
|
harmonyStarExports.push(dep);
|
|
251
275
|
}
|
|
252
|
-
dep.
|
|
253
|
-
/** @type {DependencyLocation} */ (statement.loc)
|
|
276
|
+
dep.setLocWithIndex(
|
|
277
|
+
/** @type {DependencyLocation} */ (statement.loc),
|
|
278
|
+
/** @type {number} */ (idx)
|
|
254
279
|
);
|
|
255
|
-
dep.loc.index = idx;
|
|
256
280
|
const isAsiSafe = !parser.isAsiPosition(
|
|
257
281
|
/** @type {Range} */
|
|
258
282
|
(statement.range)[0]
|
|
@@ -6,23 +6,31 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const ConcatenationScope = require("../ConcatenationScope");
|
|
9
|
+
const Dependency = require("../Dependency");
|
|
9
10
|
const InitFragment = require("../InitFragment");
|
|
10
11
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
12
|
+
const { InlinedUsedName } = require("../optimize/InlineExports");
|
|
11
13
|
const makeSerializable = require("../util/makeSerializable");
|
|
12
14
|
const { propertyAccess } = require("../util/property");
|
|
15
|
+
const ExportBindingInitFragment = require("./ExportBindingInitFragment");
|
|
13
16
|
const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
|
|
14
17
|
const NullDependency = require("./NullDependency");
|
|
15
18
|
|
|
19
|
+
const DEFAULT_EXPORT_NAME = "default";
|
|
20
|
+
|
|
16
21
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
17
|
-
/** @typedef {import("../Dependency")} Dependency */
|
|
18
22
|
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
|
23
|
+
/** @typedef {import("../Dependency").LazyUntil} LazyUntil */
|
|
19
24
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
20
25
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
21
26
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
|
27
|
+
/** @typedef {import("../optimize/InlineExports").InlinedValue} InlinedValue */
|
|
22
28
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
23
|
-
/** @typedef {
|
|
24
|
-
/** @typedef {import("../serialization/ObjectMiddleware").
|
|
29
|
+
/** @typedef {string | { id?: string | undefined, range: Range, prefix: string, suffix: string }} DeclarationId */
|
|
30
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[Range, Range, string, DeclarationId | undefined, boolean]>} ObjectDeserializerContext */
|
|
31
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[Range, Range, string, DeclarationId | undefined, boolean]>} ObjectSerializerContext */
|
|
25
32
|
/** @typedef {import("./HarmonyExportInitFragment").ExportMap} ExportMap */
|
|
33
|
+
/** @typedef {import("../javascript/JavascriptModule").JavascriptModuleBuildInfo} JavascriptModuleBuildInfo */
|
|
26
34
|
|
|
27
35
|
class HarmonyExportExpressionDependency extends NullDependency {
|
|
28
36
|
/**
|
|
@@ -31,13 +39,17 @@ class HarmonyExportExpressionDependency extends NullDependency {
|
|
|
31
39
|
* @param {Range} rangeStatement range statement
|
|
32
40
|
* @param {string} prefix prefix
|
|
33
41
|
* @param {string | { id?: string | undefined, range: Range, prefix: string, suffix: string }=} declarationId declaration id
|
|
42
|
+
* @param {InlinedValue=} constValue inlined primitive when `export default <const>` is inline-eligible
|
|
34
43
|
*/
|
|
35
|
-
constructor(range, rangeStatement, prefix, declarationId) {
|
|
44
|
+
constructor(range, rangeStatement, prefix, declarationId, constValue) {
|
|
36
45
|
super();
|
|
37
46
|
this.range = range;
|
|
38
47
|
this.rangeStatement = rangeStatement;
|
|
48
|
+
/** @type {string} */
|
|
39
49
|
this.prefix = prefix;
|
|
40
50
|
this.declarationId = declarationId;
|
|
51
|
+
this.constValue = constValue;
|
|
52
|
+
/** @type {boolean} */
|
|
41
53
|
this.isAnonymousDefault = false;
|
|
42
54
|
}
|
|
43
55
|
|
|
@@ -45,14 +57,45 @@ class HarmonyExportExpressionDependency extends NullDependency {
|
|
|
45
57
|
return "harmony export expression";
|
|
46
58
|
}
|
|
47
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Returns how this dependency may be deferred when its parent module is side-effect-free (lazy barrel optimization).
|
|
62
|
+
* @returns {LazyUntil | null} lazy classification, null when it must be processed eagerly
|
|
63
|
+
*/
|
|
64
|
+
getLazyUntil() {
|
|
65
|
+
return Dependency.LAZY_UNTIL_LOCAL;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Returns the export name for a `LAZY_UNTIL_LOCAL`/`LAZY_UNTIL_ID` classification (lazy barrel optimization).
|
|
70
|
+
* @returns {string | null} export name, null when not applicable
|
|
71
|
+
*/
|
|
72
|
+
getLazyName() {
|
|
73
|
+
return DEFAULT_EXPORT_NAME;
|
|
74
|
+
}
|
|
75
|
+
|
|
48
76
|
/**
|
|
49
77
|
* Returns the exported names
|
|
50
78
|
* @param {ModuleGraph} moduleGraph module graph
|
|
51
79
|
* @returns {ExportsSpec | undefined} export names
|
|
52
80
|
*/
|
|
53
81
|
getExports(moduleGraph) {
|
|
82
|
+
const module = moduleGraph.getParentModule(this);
|
|
83
|
+
const pureFunctions =
|
|
84
|
+
module &&
|
|
85
|
+
module.buildInfo &&
|
|
86
|
+
/** @type {JavascriptModuleBuildInfo} */ (module.buildInfo).pureFunctions;
|
|
87
|
+
const isPure = Boolean(
|
|
88
|
+
pureFunctions && pureFunctions.has(DEFAULT_EXPORT_NAME)
|
|
89
|
+
);
|
|
90
|
+
|
|
54
91
|
return {
|
|
55
|
-
exports: [
|
|
92
|
+
exports: [
|
|
93
|
+
{
|
|
94
|
+
name: DEFAULT_EXPORT_NAME,
|
|
95
|
+
isPure: isPure || undefined,
|
|
96
|
+
inlined: this.constValue
|
|
97
|
+
}
|
|
98
|
+
],
|
|
56
99
|
priority: 1,
|
|
57
100
|
terminalBinding: true,
|
|
58
101
|
dependencies: undefined
|
|
@@ -74,12 +117,13 @@ class HarmonyExportExpressionDependency extends NullDependency {
|
|
|
74
117
|
* @param {ObjectSerializerContext} context context
|
|
75
118
|
*/
|
|
76
119
|
serialize(context) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
120
|
+
context
|
|
121
|
+
.write(this.range)
|
|
122
|
+
.write(this.rangeStatement)
|
|
123
|
+
.write(this.prefix)
|
|
124
|
+
.write(this.declarationId)
|
|
125
|
+
.write(this.isAnonymousDefault)
|
|
126
|
+
.write(this.constValue);
|
|
83
127
|
super.serialize(context);
|
|
84
128
|
}
|
|
85
129
|
|
|
@@ -88,13 +132,18 @@ class HarmonyExportExpressionDependency extends NullDependency {
|
|
|
88
132
|
* @param {ObjectDeserializerContext} context context
|
|
89
133
|
*/
|
|
90
134
|
deserialize(context) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this.rangeStatement = read();
|
|
94
|
-
|
|
95
|
-
this.
|
|
96
|
-
|
|
97
|
-
|
|
135
|
+
this.range = context.read();
|
|
136
|
+
const c1 = context.rest;
|
|
137
|
+
this.rangeStatement = c1.read();
|
|
138
|
+
const c2 = c1.rest;
|
|
139
|
+
this.prefix = c2.read();
|
|
140
|
+
const c3 = c2.rest;
|
|
141
|
+
this.declarationId = c3.read();
|
|
142
|
+
const c4 = c3.rest;
|
|
143
|
+
this.isAnonymousDefault = c4.read();
|
|
144
|
+
const c5 = c4.rest;
|
|
145
|
+
this.constValue = c5.read();
|
|
146
|
+
super.deserialize(c5.rest);
|
|
98
147
|
}
|
|
99
148
|
}
|
|
100
149
|
|
|
@@ -145,10 +194,12 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
|
|
|
145
194
|
|
|
146
195
|
const used = concatenationScope
|
|
147
196
|
? undefined
|
|
148
|
-
: moduleGraph
|
|
197
|
+
: moduleGraph
|
|
198
|
+
.getExportsInfo(module)
|
|
199
|
+
.getUsedName(DEFAULT_EXPORT_NAME, runtime);
|
|
149
200
|
|
|
150
201
|
if (concatenationScope) {
|
|
151
|
-
concatenationScope.registerExport(
|
|
202
|
+
concatenationScope.registerExport(DEFAULT_EXPORT_NAME, name);
|
|
152
203
|
} else if (used) {
|
|
153
204
|
/** @type {ExportMap} */
|
|
154
205
|
const map = new Map();
|
|
@@ -186,30 +237,56 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
|
|
|
186
237
|
if (runtimeTemplate.supportsConst()) {
|
|
187
238
|
content = `/* harmony default export */ const ${name} = `;
|
|
188
239
|
if (concatenationScope) {
|
|
189
|
-
concatenationScope.registerExport(
|
|
240
|
+
concatenationScope.registerExport(DEFAULT_EXPORT_NAME, name);
|
|
190
241
|
} else {
|
|
191
242
|
const used = moduleGraph
|
|
192
243
|
.getExportsInfo(module)
|
|
193
|
-
.getUsedName(
|
|
194
|
-
if (used) {
|
|
244
|
+
.getUsedName(DEFAULT_EXPORT_NAME, runtime);
|
|
245
|
+
if (used instanceof InlinedUsedName) {
|
|
246
|
+
content = `/* inlined harmony default export */ const ${name} = `;
|
|
247
|
+
} else if (used) {
|
|
195
248
|
defaultIsUsed = true;
|
|
196
249
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
250
|
+
// `export default <expr>` binds an immutable const declaration
|
|
251
|
+
const canUseValueBinding =
|
|
252
|
+
/** @type {import("../Module").BuildInfo} */ (module.buildInfo)
|
|
253
|
+
.isCircular === false;
|
|
254
|
+
if (canUseValueBinding) {
|
|
255
|
+
initFragments.push(
|
|
256
|
+
new ExportBindingInitFragment(
|
|
257
|
+
exportsName,
|
|
258
|
+
[
|
|
259
|
+
{
|
|
260
|
+
name: used,
|
|
261
|
+
value: `/* export default binding */ ${name}`,
|
|
262
|
+
bindingType: "value"
|
|
263
|
+
}
|
|
264
|
+
],
|
|
265
|
+
true
|
|
266
|
+
)
|
|
267
|
+
);
|
|
268
|
+
} else {
|
|
269
|
+
/** @type {ExportMap} */
|
|
270
|
+
const map = new Map();
|
|
271
|
+
map.set(used, name);
|
|
272
|
+
initFragments.push(
|
|
273
|
+
new HarmonyExportInitFragment(exportsName, map)
|
|
274
|
+
);
|
|
275
|
+
}
|
|
201
276
|
} else {
|
|
202
277
|
content = `/* unused harmony default export */ var ${name} = `;
|
|
203
278
|
}
|
|
204
279
|
}
|
|
205
280
|
} else if (concatenationScope) {
|
|
206
281
|
content = `/* harmony default export */ var ${name} = `;
|
|
207
|
-
concatenationScope.registerExport(
|
|
282
|
+
concatenationScope.registerExport(DEFAULT_EXPORT_NAME, name);
|
|
208
283
|
} else {
|
|
209
284
|
const used = moduleGraph
|
|
210
285
|
.getExportsInfo(module)
|
|
211
|
-
.getUsedName(
|
|
212
|
-
if (used) {
|
|
286
|
+
.getUsedName(DEFAULT_EXPORT_NAME, runtime);
|
|
287
|
+
if (used instanceof InlinedUsedName) {
|
|
288
|
+
content = `/* inlined harmony default export */ var ${name} = `;
|
|
289
|
+
} else if (used) {
|
|
213
290
|
defaultIsUsed = true;
|
|
214
291
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
215
292
|
// This is a little bit incorrect as TDZ is not correct, but we can't use const.
|
|
@@ -12,8 +12,8 @@ const NullDependency = require("./NullDependency");
|
|
|
12
12
|
/** @typedef {import("../Dependency")} Dependency */
|
|
13
13
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
14
14
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
15
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
16
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
15
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[Range | false, Range]>} ObjectDeserializerContext */
|
|
16
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[Range | false, Range]>} ObjectSerializerContext */
|
|
17
17
|
|
|
18
18
|
class HarmonyExportHeaderDependency extends NullDependency {
|
|
19
19
|
/**
|
|
@@ -36,9 +36,7 @@ class HarmonyExportHeaderDependency extends NullDependency {
|
|
|
36
36
|
* @param {ObjectSerializerContext} context context
|
|
37
37
|
*/
|
|
38
38
|
serialize(context) {
|
|
39
|
-
|
|
40
|
-
write(this.range);
|
|
41
|
-
write(this.rangeStatement);
|
|
39
|
+
context.write(this.range).write(this.rangeStatement);
|
|
42
40
|
super.serialize(context);
|
|
43
41
|
}
|
|
44
42
|
|
|
@@ -47,10 +45,10 @@ class HarmonyExportHeaderDependency extends NullDependency {
|
|
|
47
45
|
* @param {ObjectDeserializerContext} context context
|
|
48
46
|
*/
|
|
49
47
|
deserialize(context) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.rangeStatement = read();
|
|
53
|
-
super.deserialize(
|
|
48
|
+
this.range = context.read();
|
|
49
|
+
const c1 = context.rest;
|
|
50
|
+
this.rangeStatement = c1.read();
|
|
51
|
+
super.deserialize(c1.rest);
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
|