webpack 5.98.0 → 5.99.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 -3
- package/lib/AsyncDependenciesBlock.js +3 -1
- package/lib/BannerPlugin.js +1 -1
- package/lib/Cache.js +9 -7
- package/lib/CacheFacade.js +5 -5
- package/lib/Chunk.js +2 -2
- package/lib/ChunkGraph.js +21 -16
- package/lib/ChunkTemplate.js +6 -6
- package/lib/CleanPlugin.js +10 -10
- package/lib/CodeGenerationResults.js +4 -3
- package/lib/CompatibilityPlugin.js +4 -1
- package/lib/Compilation.js +326 -152
- package/lib/Compiler.js +13 -18
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +3 -3
- package/lib/ContextReplacementPlugin.js +43 -16
- package/lib/DefinePlugin.js +25 -24
- package/lib/DelegatedModule.js +4 -2
- package/lib/DelegatedModuleFactoryPlugin.js +2 -1
- package/lib/Dependency.js +19 -13
- package/lib/DependencyTemplates.js +4 -3
- package/lib/DllModule.js +4 -2
- package/lib/DllModuleFactory.js +2 -2
- package/lib/DllReferencePlugin.js +2 -1
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/ExportsInfo.js +72 -40
- package/lib/ExternalModule.js +14 -5
- package/lib/ExternalModuleFactoryPlugin.js +24 -12
- package/lib/FileSystemInfo.js +129 -94
- package/lib/FlagDependencyExportsPlugin.js +6 -4
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +29 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +3 -9
- package/lib/IgnoreErrorModuleFactory.js +2 -2
- package/lib/IgnorePlugin.js +0 -5
- package/lib/InitFragment.js +1 -1
- package/lib/LoaderOptionsPlugin.js +8 -5
- package/lib/MainTemplate.js +7 -7
- package/lib/Module.js +40 -17
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +4 -3
- package/lib/ModuleDependencyWarning.js +4 -3
- package/lib/ModuleFactory.js +9 -3
- package/lib/ModuleFilenameHelpers.js +13 -13
- package/lib/ModuleGraph.js +20 -14
- package/lib/ModuleGraphConnection.js +7 -13
- package/lib/ModuleNotFoundError.js +1 -1
- package/lib/ModuleParseError.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +11 -0
- package/lib/ModuleTemplate.js +5 -5
- package/lib/ModuleTypeConstants.js +15 -0
- package/lib/MultiCompiler.js +4 -4
- package/lib/MultiStats.js +1 -1
- package/lib/NormalModule.js +101 -54
- package/lib/NormalModuleFactory.js +38 -33
- package/lib/NormalModuleReplacementPlugin.js +3 -2
- package/lib/NullFactory.js +2 -2
- package/lib/Parser.js +4 -3
- package/lib/ProgressPlugin.js +1 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +6 -2
- package/lib/RequestShortener.js +3 -1
- package/lib/ResolverFactory.js +12 -9
- package/lib/RuntimeModule.js +4 -2
- package/lib/RuntimeTemplate.js +2 -1
- package/lib/SelfModuleFactory.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +0 -8
- package/lib/Template.js +6 -5
- package/lib/TemplatedPathPlugin.js +15 -12
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/asset/AssetGenerator.js +237 -170
- package/lib/asset/AssetModulesPlugin.js +50 -8
- package/lib/asset/AssetSourceGenerator.js +18 -0
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/buildChunkGraph.js +14 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +137 -121
- package/lib/cache/ResolverCachePlugin.js +15 -7
- package/lib/cache/getLazyHashedEtag.js +4 -3
- package/lib/cli.js +23 -15
- package/lib/config/defaults.js +93 -26
- package/lib/config/normalization.js +14 -13
- package/lib/config/target.js +8 -8
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerEntryModuleFactory.js +2 -2
- package/lib/container/FallbackModule.js +4 -2
- package/lib/container/FallbackModuleFactory.js +2 -2
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/options.js +5 -5
- package/lib/css/CssGenerator.js +71 -9
- package/lib/css/CssModulesPlugin.js +30 -5
- package/lib/css/CssParser.js +37 -17
- package/lib/css/walkCssTokens.js +17 -17
- package/lib/debug/ProfilingPlugin.js +98 -38
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
- package/lib/dependencies/AMDPlugin.js +5 -2
- package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
- package/lib/dependencies/AMDRequireContextDependency.js +2 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
- package/lib/dependencies/AMDRuntimeModules.js +3 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsImportsParserPlugin.js +8 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +13 -6
- package/lib/dependencies/CssIcssExportDependency.js +15 -12
- package/lib/dependencies/CssIcssImportDependency.js +4 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +17 -14
- package/lib/dependencies/ExportsInfoDependency.js +6 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +8 -6
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
- package/lib/dependencies/JsonExportsDependency.js +24 -8
- package/lib/dependencies/LoaderPlugin.js +4 -14
- package/lib/dependencies/RequireContextDependency.js +2 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
- package/lib/dependencies/RequireResolveContextDependency.js +1 -1
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
- package/lib/dependencies/WorkerDependency.js +6 -3
- package/lib/dependencies/WorkerPlugin.js +100 -41
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +32 -24
- package/lib/hmr/lazyCompilationBackend.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/ids/IdHelpers.js +15 -14
- package/lib/ids/SyncModuleIdsPlugin.js +9 -5
- package/lib/index.js +5 -5
- package/lib/javascript/BasicEvaluatedExpression.js +6 -6
- package/lib/javascript/JavascriptGenerator.js +11 -1
- package/lib/javascript/JavascriptModulesPlugin.js +51 -31
- package/lib/javascript/JavascriptParser.js +272 -188
- package/lib/javascript/JavascriptParserHelpers.js +10 -9
- package/lib/javascript/StartupHelpers.js +4 -1
- package/lib/json/JsonData.js +4 -4
- package/lib/json/JsonGenerator.js +54 -22
- package/lib/json/JsonModulesPlugin.js +16 -2
- package/lib/json/JsonParser.js +8 -4
- package/lib/library/AbstractLibraryPlugin.js +7 -3
- package/lib/library/AssignLibraryPlugin.js +29 -1
- package/lib/library/EnableLibraryPlugin.js +7 -10
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +121 -15
- package/lib/logging/Logger.js +2 -2
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/node/NodeEnvironmentPlugin.js +6 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +3 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +19 -12
- package/lib/optimize/InnerGraph.js +3 -2
- package/lib/optimize/InnerGraphPlugin.js +13 -7
- package/lib/optimize/LimitChunkCountPlugin.js +20 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
- package/lib/optimize/RealContentHashPlugin.js +8 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
- package/lib/optimize/SplitChunksPlugin.js +87 -65
- package/lib/rules/BasicEffectRulePlugin.js +9 -1
- package/lib/rules/BasicMatcherRulePlugin.js +15 -4
- package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
- package/lib/rules/RuleSetCompiler.js +25 -14
- package/lib/rules/UseEffectRulePlugin.js +47 -17
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
- package/lib/schemes/HttpUriPlugin.js +38 -17
- package/lib/serialization/BinaryMiddleware.js +52 -19
- package/lib/serialization/FileMiddleware.js +78 -48
- package/lib/serialization/ObjectMiddleware.js +78 -29
- package/lib/serialization/PlainObjectSerializer.js +1 -1
- package/lib/serialization/Serializer.js +15 -10
- package/lib/serialization/SerializerMiddleware.js +80 -41
- package/lib/serialization/SingleItemMiddleware.js +10 -7
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
- package/lib/sharing/utils.js +2 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +80 -78
- package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
- package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
- package/lib/stats/StatsFactory.js +11 -11
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/ArrayHelpers.js +2 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +41 -23
- package/lib/util/LazySet.js +3 -2
- package/lib/util/MapHelpers.js +1 -1
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Semaphore.js +3 -3
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/SortableSet.js +9 -7
- package/lib/util/TupleQueue.js +9 -8
- package/lib/util/TupleSet.js +2 -2
- package/lib/util/WeakTupleMap.js +12 -11
- package/lib/util/binarySearchBounds.js +2 -1
- package/lib/util/cleverMerge.js +84 -54
- package/lib/util/comparators.js +22 -21
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +6 -4
- package/lib/util/create-schema-validation.js +4 -4
- package/lib/util/createHash.js +2 -2
- package/lib/util/deprecation.js +35 -33
- package/lib/util/deterministicGrouping.js +6 -6
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +39 -39
- package/lib/util/hash/wasm-hash.js +2 -2
- package/lib/util/identifier.js +15 -18
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/memoize.js +4 -1
- package/lib/util/objectToMap.js +3 -2
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +0 -1
- package/lib/util/registerExternalSerializer.js +15 -18
- package/lib/util/removeBOM.js +25 -0
- package/lib/util/runtime.js +34 -27
- package/lib/util/serialization.js +5 -16
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
- package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +9 -4
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
- package/package.json +19 -17
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +48 -13
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
- package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/types.d.ts +918 -615
- package/lib/library/ModernModuleLibraryPlugin.js +0 -144
@@ -14,6 +14,7 @@ const ModuleDependency = require("./ModuleDependency");
|
|
14
14
|
/** @typedef {import("../Dependency")} Dependency */
|
15
15
|
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
16
16
|
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
17
|
+
/** @typedef {import("../Module")} Module */
|
17
18
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
18
19
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
19
20
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
@@ -74,7 +75,9 @@ CssIcssImportDependency.Template = class CssIcssImportDependencyTemplate extends
|
|
74
75
|
apply(dependency, source, templateContext) {
|
75
76
|
const dep = /** @type {CssIcssImportDependency} */ (dependency);
|
76
77
|
const { range } = dep;
|
77
|
-
const module =
|
78
|
+
const module =
|
79
|
+
/** @type {Module} */
|
80
|
+
(templateContext.moduleGraph.getModule(dep));
|
78
81
|
let value;
|
79
82
|
|
80
83
|
for (const item of module.dependencies) {
|
@@ -41,9 +41,10 @@ const getCssParser = memoize(() => require("../css/CssParser"));
|
|
41
41
|
* @returns {string} local ident
|
42
42
|
*/
|
43
43
|
const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
|
44
|
+
const generator = /** @type {CssGenerator} */ (module.generator);
|
44
45
|
const localIdentName =
|
45
|
-
/** @type {
|
46
|
-
(
|
46
|
+
/** @type {CssGeneratorLocalIdentName} */
|
47
|
+
(generator.localIdentName);
|
47
48
|
const relativeResourcePath = makePathsRelative(
|
48
49
|
/** @type {string} */
|
49
50
|
(module.context),
|
@@ -120,10 +121,11 @@ class CssLocalIdentifierDependency extends NullDependency {
|
|
120
121
|
*/
|
121
122
|
getExports(moduleGraph) {
|
122
123
|
const module = /** @type {CssModule} */ (moduleGraph.getParentModule(this));
|
123
|
-
const
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
const generator = /** @type {CssGenerator} */ (module.generator);
|
125
|
+
const names = this.getExportsConventionNames(
|
126
|
+
this.name,
|
127
|
+
/** @type {CssGeneratorExportsConvention} */ (generator.convention)
|
128
|
+
);
|
127
129
|
return {
|
128
130
|
exports: names.map(name => ({
|
129
131
|
name,
|
@@ -144,12 +146,11 @@ class CssLocalIdentifierDependency extends NullDependency {
|
|
144
146
|
const module =
|
145
147
|
/** @type {CssModule} */
|
146
148
|
(chunkGraph.moduleGraph.getParentModule(this));
|
147
|
-
const generator =
|
148
|
-
/** @type {CssGenerator} */
|
149
|
-
(module.generator);
|
149
|
+
const generator = /** @type {CssGenerator} */ (module.generator);
|
150
150
|
const names = this.getExportsConventionNames(
|
151
151
|
this.name,
|
152
|
-
|
152
|
+
/** @type {CssGeneratorExportsConvention} */
|
153
|
+
(generator.convention)
|
153
154
|
);
|
154
155
|
this._hashUpdate = `exportsConvention|${JSON.stringify(names)}|localIdentName|${JSON.stringify(generator.localIdentName)}`;
|
155
156
|
}
|
@@ -214,10 +215,12 @@ CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTempla
|
|
214
215
|
const { module: m, moduleGraph, runtime, cssData } = templateContext;
|
215
216
|
const dep = /** @type {CssLocalIdentifierDependency} */ (dependency);
|
216
217
|
const module = /** @type {CssModule} */ (m);
|
217
|
-
const
|
218
|
-
|
219
|
-
|
220
|
-
|
218
|
+
const generator = /** @type {CssGenerator} */ (module.generator);
|
219
|
+
const names = dep.getExportsConventionNames(
|
220
|
+
dep.name,
|
221
|
+
/** @type {CssGeneratorExportsConvention} */
|
222
|
+
(generator.convention)
|
223
|
+
);
|
221
224
|
const usedNames =
|
222
225
|
/** @type {(string)[]} */
|
223
226
|
(
|
@@ -22,13 +22,18 @@ const NullDependency = require("./NullDependency");
|
|
22
22
|
/** @typedef {import("../util/Hash")} Hash */
|
23
23
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
24
24
|
|
25
|
+
/**
|
26
|
+
* @template T
|
27
|
+
* @typedef {import("../util/SortableSet")<T>} SortableSet
|
28
|
+
*/
|
29
|
+
|
25
30
|
/**
|
26
31
|
* @param {ModuleGraph} moduleGraph the module graph
|
27
32
|
* @param {Module} module the module
|
28
33
|
* @param {string[] | null} _exportName name of the export if any
|
29
34
|
* @param {string | null} property name of the requested property
|
30
35
|
* @param {RuntimeSpec} runtime for which runtime
|
31
|
-
* @returns {
|
36
|
+
* @returns {undefined | null | number | boolean | string[] | SortableSet<string>} value of the property
|
32
37
|
*/
|
33
38
|
const getProperty = (moduleGraph, module, _exportName, property, runtime) => {
|
34
39
|
if (!_exportName) {
|
@@ -30,8 +30,8 @@ class HarmonyEvaluatedImportSpecifierDependency extends HarmonyImportSpecifierDe
|
|
30
30
|
/**
|
31
31
|
* @param {string} request the request string
|
32
32
|
* @param {number} sourceOrder source order
|
33
|
-
* @param {
|
34
|
-
* @param {
|
33
|
+
* @param {string[]} ids ids
|
34
|
+
* @param {string} name name
|
35
35
|
* @param {Range} range location in source code
|
36
36
|
* @param {ImportAttributes} attributes import assertions
|
37
37
|
* @param {string} operator operator
|
@@ -79,9 +79,9 @@ HarmonyEvaluatedImportSpecifierDependency.Template = class HarmonyEvaluatedImpor
|
|
79
79
|
* @returns {void}
|
80
80
|
*/
|
81
81
|
apply(dependency, source, templateContext) {
|
82
|
-
const dep =
|
83
|
-
|
84
|
-
|
82
|
+
const dep =
|
83
|
+
/** @type {HarmonyEvaluatedImportSpecifierDependency} */
|
84
|
+
(dependency);
|
85
85
|
const { module, moduleGraph, runtime } = templateContext;
|
86
86
|
const connection = moduleGraph.getConnection(dep);
|
87
87
|
// Skip rendering depending when dependency is conditional
|
@@ -20,6 +20,7 @@ const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDepe
|
|
20
20
|
|
21
21
|
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
22
22
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
23
|
+
/** @typedef {import("../javascript/JavascriptParser").ClassDeclaration} ClassDeclaration */
|
23
24
|
/** @typedef {import("../javascript/JavascriptParser").FunctionDeclaration} FunctionDeclaration */
|
24
25
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
25
26
|
|
@@ -90,9 +91,9 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
90
91
|
);
|
91
92
|
parser.hooks.exportExpression.tap(
|
92
93
|
"HarmonyExportDependencyParserPlugin",
|
93
|
-
(statement,
|
94
|
-
const isFunctionDeclaration =
|
95
|
-
const exprRange = /** @type {Range} */ (
|
94
|
+
(statement, node) => {
|
95
|
+
const isFunctionDeclaration = node.type === "FunctionDeclaration";
|
96
|
+
const exprRange = /** @type {Range} */ (node.range);
|
96
97
|
const statementRange = /** @type {Range} */ (statement.range);
|
97
98
|
const comments = parser.getComments([statementRange[0], exprRange[0]]);
|
98
99
|
const dep = new HarmonyExportExpressionDependency(
|
@@ -109,20 +110,22 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
109
110
|
return "";
|
110
111
|
})
|
111
112
|
.join(""),
|
112
|
-
|
113
|
-
|
113
|
+
node.type.endsWith("Declaration") &&
|
114
|
+
/** @type {FunctionDeclaration | ClassDeclaration} */ (node).id
|
115
|
+
? /** @type {FunctionDeclaration | ClassDeclaration} */
|
116
|
+
(node).id.name
|
114
117
|
: isFunctionDeclaration
|
115
118
|
? {
|
116
119
|
range: [
|
117
120
|
exprRange[0],
|
118
|
-
|
119
|
-
? /** @type {Range} */ (
|
120
|
-
: /** @type {Range} */ (
|
121
|
+
node.params.length > 0
|
122
|
+
? /** @type {Range} */ (node.params[0].range)[0]
|
123
|
+
: /** @type {Range} */ (node.body.range)[0]
|
121
124
|
],
|
122
|
-
prefix: `${
|
123
|
-
|
125
|
+
prefix: `${node.async ? "async " : ""}function${
|
126
|
+
node.generator ? "*" : ""
|
124
127
|
} `,
|
125
|
-
suffix: `(${
|
128
|
+
suffix: `(${node.params.length > 0 ? "" : ") "}`
|
126
129
|
}
|
127
130
|
: undefined
|
128
131
|
);
|
@@ -133,8 +136,10 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
133
136
|
parser.state.current.addDependency(dep);
|
134
137
|
InnerGraph.addVariableUsage(
|
135
138
|
parser,
|
136
|
-
|
137
|
-
|
139
|
+
node.type.endsWith("Declaration") &&
|
140
|
+
/** @type {FunctionDeclaration | ClassDeclaration} */ (node).id
|
141
|
+
? /** @type {FunctionDeclaration | ClassDeclaration} */ (node).id
|
142
|
+
.name
|
138
143
|
: "*default*",
|
139
144
|
"default"
|
140
145
|
);
|
@@ -159,7 +164,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
159
164
|
null,
|
160
165
|
exportPresenceMode,
|
161
166
|
null,
|
162
|
-
settings.
|
167
|
+
settings.attributes
|
163
168
|
)
|
164
169
|
: new HarmonyExportSpecifierDependency(id, name);
|
165
170
|
dep.loc = Object.create(
|
@@ -189,6 +194,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
189
194
|
harmonyStarExports = parser.state.harmonyStarExports =
|
190
195
|
parser.state.harmonyStarExports || new HarmonyStarExportsList();
|
191
196
|
}
|
197
|
+
const attributes = getImportAttributes(statement);
|
192
198
|
const dep = new HarmonyExportImportedSpecifierDependency(
|
193
199
|
/** @type {string} */ (source),
|
194
200
|
parser.state.lastHarmonyImportOrder,
|
@@ -197,7 +203,8 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
197
203
|
harmonyNamedExports,
|
198
204
|
harmonyStarExports && harmonyStarExports.slice(),
|
199
205
|
exportPresenceMode,
|
200
|
-
harmonyStarExports
|
206
|
+
harmonyStarExports,
|
207
|
+
attributes
|
201
208
|
);
|
202
209
|
if (harmonyStarExports) {
|
203
210
|
harmonyStarExports.push(dep);
|
@@ -51,6 +51,7 @@ const processExportInfo = require("./processExportInfo");
|
|
51
51
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
52
52
|
/** @typedef {import("../util/Hash")} Hash */
|
53
53
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
54
|
+
/** @typedef {import("./HarmonyImportDependency").ExportPresenceMode} ExportPresenceMode */
|
54
55
|
/** @typedef {import("./processExportInfo").ReferencedExports} ReferencedExports */
|
55
56
|
|
56
57
|
/** @typedef {"missing"|"unused"|"empty-star"|"reexport-dynamic-default"|"reexport-named-default"|"reexport-namespace-object"|"reexport-fake-namespace-object"|"reexport-undefined"|"normal-reexport"|"dynamic-reexport"} ExportModeType */
|
@@ -115,11 +116,14 @@ class ExportMode {
|
|
115
116
|
}
|
116
117
|
}
|
117
118
|
|
119
|
+
/** @typedef {string[]} Names */
|
120
|
+
/** @typedef {number[]} DependencyIndices */
|
121
|
+
|
118
122
|
/**
|
119
123
|
* @param {ModuleGraph} moduleGraph module graph
|
120
|
-
* @param {
|
124
|
+
* @param {HarmonyExportImportedSpecifierDependency[]} dependencies dependencies
|
121
125
|
* @param {TODO=} additionalDependency additional dependency
|
122
|
-
* @returns {
|
126
|
+
* @returns {{ names: Names, dependencyIndices: DependencyIndices }} result
|
123
127
|
*/
|
124
128
|
const determineExportAssignments = (
|
125
129
|
moduleGraph,
|
@@ -157,6 +161,14 @@ const determineExportAssignments = (
|
|
157
161
|
return { names: Array.from(names), dependencyIndices };
|
158
162
|
};
|
159
163
|
|
164
|
+
/**
|
165
|
+
* @param {object} options options
|
166
|
+
* @param {Names} options.names names
|
167
|
+
* @param {DependencyIndices} options.dependencyIndices dependency indices
|
168
|
+
* @param {string} name name
|
169
|
+
* @param {Iterable<HarmonyExportImportedSpecifierDependency>} dependencies dependencies
|
170
|
+
* @returns {HarmonyExportImportedSpecifierDependency | undefined} found dependency or nothing
|
171
|
+
*/
|
160
172
|
const findDependencyForName = (
|
161
173
|
{ names, dependencyIndices },
|
162
174
|
name,
|
@@ -359,7 +371,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
359
371
|
* @param {string | null} name the export name of for this module
|
360
372
|
* @param {Set<string>} activeExports other named exports in the module
|
361
373
|
* @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | Iterable<HarmonyExportImportedSpecifierDependency> | null} otherStarExports other star exports in the module before this import
|
362
|
-
* @param {
|
374
|
+
* @param {ExportPresenceMode} exportPresenceMode mode of checking export names
|
363
375
|
* @param {HarmonyStarExportsList | null} allStarExports all star exports in the module
|
364
376
|
* @param {ImportAttributes=} attributes import attributes
|
365
377
|
*/
|
@@ -424,8 +436,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
424
436
|
* @returns {void}
|
425
437
|
*/
|
426
438
|
setIds(moduleGraph, ids) {
|
427
|
-
|
428
|
-
(moduleGraph.getMeta(this))[idsSymbol] = ids;
|
439
|
+
moduleGraph.getMeta(this)[idsSymbol] = ids;
|
429
440
|
}
|
430
441
|
|
431
442
|
/**
|
@@ -619,7 +630,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
619
630
|
|
620
631
|
/**
|
621
632
|
* @param {ModuleGraph} moduleGraph the module graph
|
622
|
-
* @returns {{ names:
|
633
|
+
* @returns {{ names: Names, namesSlice: number, dependencyIndices: DependencyIndices, dependencyIndex: number } | undefined} exported names and their origin dependency
|
623
634
|
*/
|
624
635
|
_discoverActiveExportsFromOtherStarExports(moduleGraph) {
|
625
636
|
if (!this.otherStarExports) return;
|
@@ -796,7 +807,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
796
807
|
|
797
808
|
/**
|
798
809
|
* @param {ModuleGraph} moduleGraph module graph
|
799
|
-
* @returns {
|
810
|
+
* @returns {ExportPresenceMode} effective mode
|
800
811
|
*/
|
801
812
|
_getEffectiveExportPresenceLevel(moduleGraph) {
|
802
813
|
if (this.exportPresenceMode !== ExportPresenceModes.AUTO)
|
@@ -871,7 +882,11 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
871
882
|
exportInfo.name,
|
872
883
|
this.allStarExports
|
873
884
|
? this.allStarExports.dependencies
|
874
|
-
: [
|
885
|
+
: [
|
886
|
+
.../** @type {Iterable<HarmonyExportImportedSpecifierDependency>} */
|
887
|
+
(this.otherStarExports),
|
888
|
+
this
|
889
|
+
]
|
875
890
|
);
|
876
891
|
if (!conflictingDependency) continue;
|
877
892
|
const target = exportInfo.getTerminalBinding(moduleGraph);
|
@@ -20,8 +20,8 @@ const NullDependency = require("./NullDependency");
|
|
20
20
|
|
21
21
|
class HarmonyExportSpecifierDependency extends NullDependency {
|
22
22
|
/**
|
23
|
-
* @param {
|
24
|
-
* @param {
|
23
|
+
* @param {string} id the id
|
24
|
+
* @param {string} name the name
|
25
25
|
*/
|
26
26
|
constructor(id, name) {
|
27
27
|
super();
|
@@ -32,14 +32,16 @@ const ModuleDependency = require("./ModuleDependency");
|
|
32
32
|
/** @typedef {import("../util/Hash")} Hash */
|
33
33
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
34
34
|
|
35
|
+
/** @typedef {0 | 1 | 2 | 3 | false} ExportPresenceMode */
|
36
|
+
|
35
37
|
const ExportPresenceModes = {
|
36
|
-
NONE: /** @type {
|
37
|
-
WARN: /** @type {
|
38
|
-
AUTO: /** @type {
|
39
|
-
ERROR: /** @type {
|
38
|
+
NONE: /** @type {ExportPresenceMode} */ (0),
|
39
|
+
WARN: /** @type {ExportPresenceMode} */ (1),
|
40
|
+
AUTO: /** @type {ExportPresenceMode} */ (2),
|
41
|
+
ERROR: /** @type {ExportPresenceMode} */ (3),
|
40
42
|
/**
|
41
43
|
* @param {string | false} str param
|
42
|
-
* @returns {
|
44
|
+
* @returns {ExportPresenceMode} result
|
43
45
|
*/
|
44
46
|
fromUserOption(str) {
|
45
47
|
switch (str) {
|
@@ -89,7 +91,7 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
89
91
|
*/
|
90
92
|
getImportVar(moduleGraph) {
|
91
93
|
const module = /** @type {Module} */ (moduleGraph.getParentModule(this));
|
92
|
-
const meta =
|
94
|
+
const meta = moduleGraph.getMeta(module);
|
93
95
|
let importVarMap = meta.importVarMap;
|
94
96
|
if (!importVarMap) meta.importVarMap = importVarMap = new Map();
|
95
97
|
let importVar = importVarMap.get(
|
@@ -17,6 +17,7 @@ const { ExportPresenceModes } = require("./HarmonyImportDependency");
|
|
17
17
|
const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
|
18
18
|
const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
|
19
19
|
|
20
|
+
/** @typedef {import("estree").Expression} Expression */
|
20
21
|
/** @typedef {import("estree").Identifier} Identifier */
|
21
22
|
/** @typedef {import("estree").Literal} Literal */
|
22
23
|
/** @typedef {import("estree").MemberExpression} MemberExpression */
|
@@ -33,6 +34,7 @@ const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDepend
|
|
33
34
|
/** @typedef {import("../javascript/JavascriptParser").ImportDeclaration} ImportDeclaration */
|
34
35
|
/** @typedef {import("../javascript/JavascriptParser").ImportExpression} ImportExpression */
|
35
36
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
37
|
+
/** @typedef {import("../javascript/JavascriptParser").TagData} TagData */
|
36
38
|
/** @typedef {import("../optimize/InnerGraph").InnerGraph} InnerGraph */
|
37
39
|
/** @typedef {import("../optimize/InnerGraph").TopLevelSymbol} TopLevelSymbol */
|
38
40
|
/** @typedef {import("./HarmonyImportDependency")} HarmonyImportDependency */
|
@@ -46,7 +48,7 @@ const harmonySpecifierTag = Symbol("harmony import");
|
|
46
48
|
* @property {number} sourceOrder
|
47
49
|
* @property {string} name
|
48
50
|
* @property {boolean} await
|
49
|
-
* @property {Record<string, any> | undefined}
|
51
|
+
* @property {Record<string, any> | undefined} attributes
|
50
52
|
*/
|
51
53
|
|
52
54
|
module.exports = class HarmonyImportDependencyParserPlugin {
|
@@ -86,7 +88,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
86
88
|
/**
|
87
89
|
* @param {TODO} node member expression
|
88
90
|
* @param {number} count count
|
89
|
-
* @returns {
|
91
|
+
* @returns {Expression} member expression
|
90
92
|
*/
|
91
93
|
function getNonOptionalMemberChain(node, count) {
|
92
94
|
while (count--) node = node.object;
|
@@ -138,7 +140,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
138
140
|
source,
|
139
141
|
ids,
|
140
142
|
sourceOrder: parser.state.lastHarmonyImportOrder,
|
141
|
-
|
143
|
+
attributes: getImportAttributes(statement)
|
142
144
|
});
|
143
145
|
return true;
|
144
146
|
}
|
@@ -164,7 +166,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
164
166
|
rootInfo.tagInfo.tag !== harmonySpecifierTag
|
165
167
|
)
|
166
168
|
return;
|
167
|
-
const settings = rootInfo.tagInfo.data;
|
169
|
+
const settings = /** @type {TagData} */ (rootInfo.tagInfo.data);
|
168
170
|
const members =
|
169
171
|
/** @type {(() => string[])} */
|
170
172
|
(rightPart.getMembers)();
|
@@ -174,7 +176,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
174
176
|
settings.ids.concat(members).concat([leftPart]),
|
175
177
|
settings.name,
|
176
178
|
/** @type {Range} */ (expression.range),
|
177
|
-
settings.
|
179
|
+
settings.attributes,
|
178
180
|
"in"
|
179
181
|
);
|
180
182
|
dep.directImport = members.length === 0;
|
@@ -196,9 +198,10 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
196
198
|
settings.sourceOrder,
|
197
199
|
settings.ids,
|
198
200
|
settings.name,
|
199
|
-
/** @type {Range} */
|
201
|
+
/** @type {Range} */
|
202
|
+
(expr.range),
|
200
203
|
exportPresenceMode,
|
201
|
-
settings.
|
204
|
+
settings.attributes,
|
202
205
|
[]
|
203
206
|
);
|
204
207
|
dep.referencedPropertiesInDestructuring =
|
@@ -219,9 +222,9 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
219
222
|
.tap(
|
220
223
|
"HarmonyImportDependencyParserPlugin",
|
221
224
|
(expression, members, membersOptionals, memberRanges) => {
|
222
|
-
const settings =
|
223
|
-
|
224
|
-
|
225
|
+
const settings =
|
226
|
+
/** @type {HarmonySettings} */
|
227
|
+
(parser.currentTagData);
|
225
228
|
const nonOptionalMembers = getNonOptionalPart(
|
226
229
|
members,
|
227
230
|
membersOptionals
|
@@ -244,15 +247,17 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
244
247
|
settings.sourceOrder,
|
245
248
|
ids,
|
246
249
|
settings.name,
|
247
|
-
/** @type {Range} */
|
250
|
+
/** @type {Range} */
|
251
|
+
(expr.range),
|
248
252
|
exportPresenceMode,
|
249
|
-
settings.
|
253
|
+
settings.attributes,
|
250
254
|
ranges
|
251
255
|
);
|
252
256
|
dep.referencedPropertiesInDestructuring =
|
253
257
|
parser.destructuringAssignmentPropertiesFor(expr);
|
254
258
|
dep.asiSafe = !parser.isAsiPosition(
|
255
|
-
/** @type {Range} */
|
259
|
+
/** @type {Range} */
|
260
|
+
(expr.range)[0]
|
256
261
|
);
|
257
262
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
258
263
|
parser.state.module.addDependency(dep);
|
@@ -293,7 +298,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
293
298
|
settings.name,
|
294
299
|
/** @type {Range} */ (expr.range),
|
295
300
|
exportPresenceMode,
|
296
|
-
settings.
|
301
|
+
settings.attributes,
|
297
302
|
ranges
|
298
303
|
);
|
299
304
|
dep.directImport = members.length === 0;
|
@@ -35,6 +35,7 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
|
|
35
35
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
36
36
|
/** @typedef {import("../util/Hash")} Hash */
|
37
37
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
38
|
+
/** @typedef {import("./HarmonyImportDependency").ExportPresenceMode} ExportPresenceMode */
|
38
39
|
|
39
40
|
const idsSymbol = Symbol("HarmonyImportSpecifierDependency.ids");
|
40
41
|
|
@@ -47,7 +48,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
47
48
|
* @param {string[]} ids ids
|
48
49
|
* @param {string} name name
|
49
50
|
* @param {Range} range range
|
50
|
-
* @param {
|
51
|
+
* @param {ExportPresenceMode} exportPresenceMode export presence mode
|
51
52
|
* @param {ImportAttributes | undefined} attributes import attributes
|
52
53
|
* @param {Range[] | undefined} idRanges ranges for members of ids; the two arrays are right-aligned
|
53
54
|
*/
|
@@ -104,7 +105,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
104
105
|
getIds(moduleGraph) {
|
105
106
|
const meta = moduleGraph.getMetaIfExisting(this);
|
106
107
|
if (meta === undefined) return this.ids;
|
107
|
-
const ids = meta[
|
108
|
+
const ids = meta[idsSymbol];
|
108
109
|
return ids !== undefined ? ids : this.ids;
|
109
110
|
}
|
110
111
|
|
@@ -114,8 +115,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
114
115
|
* @returns {void}
|
115
116
|
*/
|
116
117
|
setIds(moduleGraph, ids) {
|
117
|
-
|
118
|
-
(moduleGraph.getMeta(this))[idsSymbol] = ids;
|
118
|
+
moduleGraph.getMeta(this)[idsSymbol] = ids;
|
119
119
|
}
|
120
120
|
|
121
121
|
/**
|
@@ -204,7 +204,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
204
204
|
|
205
205
|
/**
|
206
206
|
* @param {ModuleGraph} moduleGraph module graph
|
207
|
-
* @returns {
|
207
|
+
* @returns {ExportPresenceMode} effective mode
|
208
208
|
*/
|
209
209
|
_getEffectiveExportPresenceLevel(moduleGraph) {
|
210
210
|
if (this.exportPresenceMode !== ExportPresenceModes.AUTO)
|
@@ -12,10 +12,11 @@ const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTempl
|
|
12
12
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
13
13
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
14
14
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
15
|
+
/** @typedef {import("./ContextDependency").ContextDependencyOptions} ContextDependencyOptions */
|
15
16
|
|
16
17
|
class ImportContextDependency extends ContextDependency {
|
17
18
|
/**
|
18
|
-
* @param {
|
19
|
+
* @param {ContextDependencyOptions} options options
|
19
20
|
* @param {Range} range range
|
20
21
|
* @param {Range} valueRange value range
|
21
22
|
*/
|
@@ -14,6 +14,7 @@ const ImportMetaContextDependency = require("./ImportMetaContextDependency");
|
|
14
14
|
/** @typedef {import("estree").Expression} Expression */
|
15
15
|
/** @typedef {import("estree").ObjectExpression} ObjectExpression */
|
16
16
|
/** @typedef {import("estree").Property} Property */
|
17
|
+
/** @typedef {import("estree").Identifier} Identifier */
|
17
18
|
/** @typedef {import("estree").SourceLocation} SourceLocation */
|
18
19
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
19
20
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
@@ -24,16 +25,18 @@ const ImportMetaContextDependency = require("./ImportMetaContextDependency");
|
|
24
25
|
/** @typedef {Pick<ContextModuleOptions, 'mode'|'recursive'|'regExp'|'include'|'exclude'|'chunkName'>&{groupOptions: RawChunkGroupOptions, exports?: ContextModuleOptions["referencedExports"]}} ImportMetaContextOptions */
|
25
26
|
|
26
27
|
/**
|
27
|
-
* @param {
|
28
|
+
* @param {Property} prop property
|
28
29
|
* @param {string} expect except message
|
29
30
|
* @returns {WebpackError} error
|
30
31
|
*/
|
31
32
|
function createPropertyParseError(prop, expect) {
|
32
33
|
return createError(
|
33
34
|
`Parsing import.meta.webpackContext options failed. Unknown value for property ${JSON.stringify(
|
34
|
-
|
35
|
+
/** @type {Identifier} */
|
36
|
+
(prop.key).name
|
35
37
|
)}, expected type ${expect}.`,
|
36
|
-
|
38
|
+
/** @type {DependencyLocation} */
|
39
|
+
(prop.value.loc)
|
37
40
|
);
|
38
41
|
}
|
39
42
|
|
@@ -98,7 +101,8 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
98
101
|
errors.push(
|
99
102
|
createError(
|
100
103
|
"Parsing import.meta.webpackContext options failed.",
|
101
|
-
/** @type {DependencyLocation} */
|
104
|
+
/** @type {DependencyLocation} */
|
105
|
+
(optionsNode.loc)
|
102
106
|
)
|
103
107
|
);
|
104
108
|
break;
|
@@ -14,39 +14,55 @@ const NullDependency = require("./NullDependency");
|
|
14
14
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
15
15
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
16
16
|
/** @typedef {import("../json/JsonData")} JsonData */
|
17
|
-
/** @typedef {import("../json/JsonData").
|
17
|
+
/** @typedef {import("../json/JsonData").JsonValue} JsonValue */
|
18
18
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
19
19
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
20
20
|
/** @typedef {import("../util/Hash")} Hash */
|
21
21
|
|
22
|
+
/**
|
23
|
+
* @callback GetExportsFromDataFn
|
24
|
+
* @param {JsonValue} data raw json data
|
25
|
+
* @param {number} [curDepth] current depth
|
26
|
+
* @returns {ExportSpec[] | null} export spec or nothing
|
27
|
+
*/
|
28
|
+
|
22
29
|
/**
|
23
30
|
* @param {number} exportsDepth exportsDepth
|
24
|
-
* @returns {
|
31
|
+
* @returns {GetExportsFromDataFn} value
|
25
32
|
*/
|
26
33
|
const getExportsWithDepth = exportsDepth =>
|
34
|
+
/** @type {GetExportsFromDataFn} */
|
27
35
|
function getExportsFromData(data, curDepth = 1) {
|
28
|
-
if (curDepth > exportsDepth)
|
36
|
+
if (curDepth > exportsDepth) {
|
37
|
+
return null;
|
38
|
+
}
|
39
|
+
|
29
40
|
if (data && typeof data === "object") {
|
30
41
|
if (Array.isArray(data)) {
|
31
42
|
return data.length < 100
|
32
43
|
? data.map((item, idx) => ({
|
33
44
|
name: `${idx}`,
|
34
45
|
canMangle: true,
|
35
|
-
exports: getExportsFromData(item, curDepth + 1)
|
46
|
+
exports: getExportsFromData(item, curDepth + 1) || undefined
|
36
47
|
}))
|
37
|
-
:
|
48
|
+
: null;
|
38
49
|
}
|
50
|
+
|
51
|
+
/** @type {ExportSpec[]} */
|
39
52
|
const exports = [];
|
53
|
+
|
40
54
|
for (const key of Object.keys(data)) {
|
41
55
|
exports.push({
|
42
56
|
name: key,
|
43
57
|
canMangle: true,
|
44
|
-
exports: getExportsFromData(data[key], curDepth + 1)
|
58
|
+
exports: getExportsFromData(data[key], curDepth + 1) || undefined
|
45
59
|
});
|
46
60
|
}
|
61
|
+
|
47
62
|
return exports;
|
48
63
|
}
|
49
|
-
|
64
|
+
|
65
|
+
return null;
|
50
66
|
};
|
51
67
|
|
52
68
|
class JsonExportsDependency extends NullDependency {
|
@@ -72,7 +88,7 @@ class JsonExportsDependency extends NullDependency {
|
|
72
88
|
getExports(moduleGraph) {
|
73
89
|
return {
|
74
90
|
exports: getExportsWithDepth(this.exportsDepth)(
|
75
|
-
this.data && /** @type {
|
91
|
+
this.data && /** @type {JsonValue} */ (this.data.get())
|
76
92
|
),
|
77
93
|
dependencies: undefined
|
78
94
|
};
|