webpack 5.106.2 → 5.107.1
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 +2 -2
- package/lib/APIPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -4
- package/lib/Cache.js +3 -6
- package/lib/Chunk.js +21 -25
- package/lib/ChunkGroup.js +57 -15
- package/lib/CompatibilityPlugin.js +8 -7
- package/lib/Compilation.js +67 -37
- package/lib/Compiler.js +4 -13
- package/lib/ContextModule.js +2 -2
- package/lib/DefinePlugin.js +2 -2
- package/lib/Dependency.js +22 -1
- package/lib/DependencyTemplate.js +2 -1
- package/lib/EnvironmentPlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +8 -10
- package/lib/ExportsInfo.js +30 -34
- package/lib/ExternalModule.js +91 -26
- package/lib/ExternalModuleFactoryPlugin.js +7 -1
- package/lib/FileSystemInfo.js +187 -72
- package/lib/Generator.js +3 -3
- package/lib/HotModuleReplacementPlugin.js +26 -8
- package/lib/IgnorePlugin.js +2 -1
- package/lib/Module.js +20 -19
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleNotFoundError.js +3 -84
- package/lib/ModuleSourceTypeConstants.js +51 -19
- package/lib/ModuleTypeConstants.js +12 -3
- package/lib/MultiCompiler.js +2 -2
- package/lib/NodeStuffPlugin.js +1 -1
- package/lib/NormalModule.js +119 -77
- package/lib/NormalModuleFactory.js +47 -27
- package/lib/Parser.js +1 -1
- package/lib/ProgressPlugin.js +129 -56
- package/lib/RuntimeGlobals.js +5 -5
- package/lib/RuntimeModule.js +9 -7
- package/lib/RuntimePlugin.js +12 -1
- package/lib/SourceMapDevToolPlugin.js +250 -49
- package/lib/Template.js +1 -1
- package/lib/TemplatedPathPlugin.js +22 -4
- package/lib/WarnCaseSensitiveModulesPlugin.js +70 -2
- package/lib/WarnDeprecatedOptionPlugin.js +1 -1
- package/lib/WarnNoModeSetPlugin.js +16 -1
- package/lib/Watching.js +2 -3
- package/lib/WebpackError.js +3 -77
- package/lib/WebpackIsIncludedPlugin.js +1 -1
- package/lib/WebpackOptionsApply.js +13 -1
- package/lib/asset/AssetBytesGenerator.js +12 -8
- package/lib/asset/AssetGenerator.js +36 -22
- package/lib/asset/AssetModulesPlugin.js +6 -8
- package/lib/asset/AssetSourceGenerator.js +12 -8
- package/lib/buildChunkGraph.js +4 -6
- package/lib/cache/PackFileCacheStrategy.js +4 -4
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +197 -10
- package/lib/config/normalization.js +3 -1
- package/lib/css/CssGenerator.js +320 -105
- package/lib/css/CssInjectStyleRuntimeModule.js +44 -42
- package/lib/css/CssLoadingRuntimeModule.js +22 -4
- package/lib/{CssModule.js → css/CssModule.js} +15 -15
- package/lib/css/CssModulesPlugin.js +168 -88
- package/lib/css/CssParser.js +566 -269
- package/lib/css/walkCssTokens.js +148 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +63 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +54 -10
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsFullRequireDependency.js +32 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +112 -4
- package/lib/dependencies/CommonJsRequireDependency.js +67 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -1
- package/lib/dependencies/CriticalDependencyWarning.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +332 -67
- package/lib/dependencies/CssIcssImportDependency.js +49 -7
- package/lib/dependencies/CssIcssSymbolDependency.js +11 -3
- package/lib/dependencies/CssImportDependency.js +8 -0
- package/lib/dependencies/CssUrlDependency.js +28 -2
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +22 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +22 -14
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +110 -3
- package/lib/dependencies/HarmonyImportDependency.js +10 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +22 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +1 -1
- package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +5 -3
- package/lib/dependencies/HtmlInlineScriptDependency.js +133 -0
- package/lib/dependencies/HtmlInlineStyleDependency.js +101 -0
- package/lib/dependencies/HtmlScriptSrcDependency.js +557 -0
- package/lib/dependencies/HtmlSourceDependency.js +128 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +2 -2
- package/lib/dependencies/ImportPhase.js +1 -1
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +1 -1
- package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +7 -7
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +31 -31
- package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +4 -4
- package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +2 -2
- package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +4 -4
- package/lib/{DllModule.js → dll/DllModule.js} +24 -24
- package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +4 -4
- package/lib/{DllPlugin.js → dll/DllPlugin.js} +6 -5
- package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +14 -14
- package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +9 -9
- package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +2 -2
- package/lib/errors/BuildCycleError.js +1 -1
- package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
- package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
- package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +3 -3
- package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +4 -2
- package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +4 -4
- package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +5 -5
- package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +4 -4
- package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +3 -3
- package/lib/errors/JSONParseError.js +114 -0
- package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +5 -5
- package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +2 -2
- package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +4 -4
- package/lib/{ModuleError.js → errors/ModuleError.js} +5 -5
- package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +1 -1
- package/lib/errors/ModuleNotFoundError.js +91 -0
- package/lib/{ModuleParseError.js → errors/ModuleParseError.js} +8 -6
- package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +1 -1
- package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +1 -1
- package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +5 -5
- package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +4 -4
- package/lib/errors/NonErrorEmittedError.js +28 -0
- package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +2 -2
- package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +3 -3
- package/lib/errors/WebpackError.js +84 -0
- package/lib/html/HtmlGenerator.js +379 -0
- package/lib/html/HtmlModulesPlugin.js +429 -0
- package/lib/html/HtmlParser.js +1489 -0
- package/lib/html/walkHtmlTokens.js +3249 -0
- package/lib/ids/IdHelpers.js +2 -1
- package/lib/index.js +36 -15
- package/lib/javascript/JavascriptModulesPlugin.js +91 -10
- package/lib/javascript/JavascriptParser.js +197 -16
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/json/JsonParser.js +7 -16
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/EnableLibraryPlugin.js +1 -1
- package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +1 -1
- package/lib/library/ModuleLibraryPlugin.js +74 -0
- package/lib/node/NodeEnvironmentPlugin.js +4 -2
- package/lib/node/nodeConsole.js +113 -64
- package/lib/optimize/ConcatenatedModule.js +51 -6
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +11 -1
- package/lib/optimize/MinMaxSizeWarning.js +4 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +15 -7
- package/lib/optimize/RealContentHashPlugin.js +89 -26
- package/lib/optimize/SideEffectsFlagPlugin.js +112 -5
- package/lib/optimize/SplitChunksPlugin.js +5 -5
- package/lib/performance/AssetsOverSizeLimitWarning.js +2 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
- package/lib/performance/NoAsyncChunksWarning.js +5 -3
- package/lib/performance/SizeLimitsPlugin.js +1 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -1
- package/lib/rules/UseEffectRulePlugin.js +4 -3
- package/lib/runtime/AutoPublicPathRuntimeModule.js +3 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -5
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +119 -13
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +35 -0
- package/lib/schemes/DataUriPlugin.js +13 -1
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +4 -10
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +5 -5
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +2 -2
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +1 -1
- package/lib/typescript/TypeScriptPlugin.js +210 -0
- package/lib/url/URLParserPlugin.js +2 -2
- package/lib/util/AsyncQueue.js +2 -2
- package/lib/util/Hash.js +2 -2
- package/lib/util/LocConverter.js +53 -0
- package/lib/util/SortableSet.js +1 -1
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +3 -3
- package/lib/util/concatenate.js +3 -3
- package/lib/util/conventions.js +42 -1
- package/lib/util/createMappings.js +118 -0
- package/lib/{formatLocation.js → util/formatLocation.js} +2 -2
- package/lib/{SizeFormatHelpers.js → util/formatSize.js} +3 -1
- package/lib/util/fs.js +8 -8
- package/lib/util/hash/md4.js +1 -1
- package/lib/util/hash/xxhash64.js +1 -1
- package/lib/util/identifier.js +48 -0
- package/lib/util/internalSerializables.js +35 -19
- package/lib/util/magicComment.js +10 -7
- package/lib/util/parseJson.js +2 -73
- package/lib/util/source.js +21 -0
- package/lib/util/topologicalSort.js +69 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -4
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +5 -3
- package/lib/webpack.js +3 -1
- package/package.json +24 -22
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +129 -12
- package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
- package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
- package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.json +22 -0
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
- package/schemas/plugins/{DllReferencePlugin.check.d.ts → css/CssAutoOrModuleParserOptions.check.d.ts} +1 -1
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
- package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
- package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
- package/types.d.ts +1153 -233
- package/lib/CaseSensitiveModulesWarning.js +0 -80
- package/lib/GraphHelpers.js +0 -49
- package/lib/NoModeWarning.js +0 -23
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -57
- /package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +0 -0
- /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
- /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
package/lib/NormalModule.js
CHANGED
|
@@ -20,18 +20,17 @@ const {
|
|
|
20
20
|
SourceMapSource
|
|
21
21
|
} = require("webpack-sources");
|
|
22
22
|
const Compilation = require("./Compilation");
|
|
23
|
-
const HookWebpackError = require("./HookWebpackError");
|
|
24
23
|
const Module = require("./Module");
|
|
25
|
-
const ModuleBuildError = require("./ModuleBuildError");
|
|
26
|
-
const ModuleError = require("./ModuleError");
|
|
27
24
|
const ModuleGraphConnection = require("./ModuleGraphConnection");
|
|
28
|
-
const ModuleParseError = require("./ModuleParseError");
|
|
29
25
|
const { JAVASCRIPT_MODULE_TYPE_AUTO } = require("./ModuleTypeConstants");
|
|
30
|
-
const ModuleWarning = require("./ModuleWarning");
|
|
31
26
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
27
|
+
const HookWebpackError = require("./errors/HookWebpackError");
|
|
28
|
+
const ModuleBuildError = require("./errors/ModuleBuildError");
|
|
29
|
+
const ModuleError = require("./errors/ModuleError");
|
|
30
|
+
const ModuleParseError = require("./errors/ModuleParseError");
|
|
31
|
+
const ModuleWarning = require("./errors/ModuleWarning");
|
|
32
|
+
const NonErrorEmittedError = require("./errors/NonErrorEmittedError");
|
|
33
|
+
const UnhandledSchemeError = require("./errors/UnhandledSchemeError");
|
|
35
34
|
const LazySet = require("./util/LazySet");
|
|
36
35
|
const { isSubset } = require("./util/SetHelpers");
|
|
37
36
|
const { getScheme } = require("./util/URLAbsoluteSpecifier");
|
|
@@ -44,6 +43,7 @@ const {
|
|
|
44
43
|
} = require("./util/comparators");
|
|
45
44
|
const createHash = require("./util/createHash");
|
|
46
45
|
const { createFakeHook } = require("./util/deprecation");
|
|
46
|
+
const formatLocation = require("./util/formatLocation");
|
|
47
47
|
const { join } = require("./util/fs");
|
|
48
48
|
const {
|
|
49
49
|
absolutify,
|
|
@@ -61,6 +61,7 @@ const parseJson = require("./util/parseJson");
|
|
|
61
61
|
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
|
62
62
|
/** @typedef {import("../declarations/WebpackOptions").NoParse} NoParse */
|
|
63
63
|
/** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
|
|
64
|
+
/** @typedef {import("./Dependency")} Dependency */
|
|
64
65
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
|
65
66
|
/** @typedef {import("./Generator")} Generator */
|
|
66
67
|
/** @typedef {import("./Generator").GenerateErrorFn} GenerateErrorFn */
|
|
@@ -85,8 +86,13 @@ const parseJson = require("./util/parseJson");
|
|
|
85
86
|
/** @typedef {import("./Module").UnsafeCacheData} UnsafeCacheData */
|
|
86
87
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
|
87
88
|
/** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
|
|
89
|
+
/** @typedef {Iterator<SideEffectsWalk, ConnectionState, ConnectionState>} SideEffectsWalk */
|
|
88
90
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
|
89
91
|
/** @typedef {import("./NormalModuleFactory").NormalModuleTypes} NormalModuleTypes */
|
|
92
|
+
/** @typedef {import("./NormalModuleFactory").ParserByType} ParserByType */
|
|
93
|
+
/** @typedef {import("./NormalModuleFactory").ParserOptionsByType} ParserOptionsByType */
|
|
94
|
+
/** @typedef {import("./NormalModuleFactory").GeneratorByType} GeneratorByType */
|
|
95
|
+
/** @typedef {import("./NormalModuleFactory").GeneratorOptionsByType} GeneratorOptionsByType */
|
|
90
96
|
/** @typedef {import("./NormalModuleFactory").ResourceSchemeData} ResourceSchemeData */
|
|
91
97
|
/** @typedef {import("./Parser")} Parser */
|
|
92
98
|
/** @typedef {import("./Parser").PreparsedAst} PreparsedAst */
|
|
@@ -119,13 +125,94 @@ const parseJson = require("./util/parseJson");
|
|
|
119
125
|
/** @typedef {(content: string) => boolean} NoParseFn */
|
|
120
126
|
|
|
121
127
|
const getInvalidDependenciesModuleWarning = memoize(() =>
|
|
122
|
-
require("./InvalidDependenciesModuleWarning")
|
|
128
|
+
require("./errors/InvalidDependenciesModuleWarning")
|
|
123
129
|
);
|
|
124
130
|
|
|
125
131
|
const getExtractSourceMap = memoize(() => require("./util/extractSourceMap"));
|
|
126
132
|
|
|
127
133
|
const getValidate = memoize(() => require("schema-utils").validate);
|
|
128
134
|
|
|
135
|
+
const getHarmonyImportSideEffectDependency = memoize(() =>
|
|
136
|
+
require("./dependencies/HarmonyImportSideEffectDependency")
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @param {NormalModule} mod the module
|
|
141
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
|
142
|
+
* @param {Dependency} dep the dep that triggered the bailout
|
|
143
|
+
*/
|
|
144
|
+
const recordSideEffectsBailout = (mod, moduleGraph, dep) => {
|
|
145
|
+
if (mod._addedSideEffectsBailout === undefined) {
|
|
146
|
+
mod._addedSideEffectsBailout = new WeakSet();
|
|
147
|
+
} else if (mod._addedSideEffectsBailout.has(moduleGraph)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
mod._addedSideEffectsBailout.add(moduleGraph);
|
|
151
|
+
moduleGraph
|
|
152
|
+
.getOptimizationBailout(mod)
|
|
153
|
+
.push(
|
|
154
|
+
() =>
|
|
155
|
+
`Dependency (${dep.type}) with side effects at ${formatLocation(dep.loc)}`
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Generator form of `getSideEffectsConnectionState` — descends through
|
|
161
|
+
* `HarmonyImportSideEffectDependency` via `yield` so the trampoline in
|
|
162
|
+
* `getSideEffectsConnectionState` can drive the walk iteratively (#20986).
|
|
163
|
+
* @param {NormalModule} mod the module being evaluated
|
|
164
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
|
165
|
+
* @returns {SideEffectsWalk} the generator
|
|
166
|
+
*/
|
|
167
|
+
function* walkSideEffects(mod, moduleGraph) {
|
|
168
|
+
if (mod.factoryMeta !== undefined) {
|
|
169
|
+
if (mod.factoryMeta.sideEffectFree) return false;
|
|
170
|
+
if (mod.factoryMeta.sideEffectFree === false) return true;
|
|
171
|
+
}
|
|
172
|
+
if (!(mod.buildMeta !== undefined && mod.buildMeta.sideEffectFree)) {
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
if (mod._isEvaluatingSideEffects) {
|
|
176
|
+
return ModuleGraphConnection.CIRCULAR_CONNECTION;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const SideEffectDep = getHarmonyImportSideEffectDependency();
|
|
180
|
+
mod._isEvaluatingSideEffects = true;
|
|
181
|
+
/** @type {ConnectionState} */
|
|
182
|
+
let current = false;
|
|
183
|
+
|
|
184
|
+
for (const dep of mod.dependencies) {
|
|
185
|
+
/** @type {ConnectionState} */
|
|
186
|
+
let state;
|
|
187
|
+
if (dep instanceof SideEffectDep) {
|
|
188
|
+
const refModule = moduleGraph.getModule(dep);
|
|
189
|
+
if (!refModule) {
|
|
190
|
+
state = true;
|
|
191
|
+
} else if (refModule instanceof NormalModule) {
|
|
192
|
+
state = yield walkSideEffects(refModule, moduleGraph);
|
|
193
|
+
} else {
|
|
194
|
+
state = refModule.getSideEffectsConnectionState(moduleGraph);
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
state = dep.getModuleEvaluationSideEffectsState(moduleGraph);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (state === true) {
|
|
201
|
+
recordSideEffectsBailout(mod, moduleGraph, dep);
|
|
202
|
+
mod._isEvaluatingSideEffects = false;
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
if (state !== ModuleGraphConnection.CIRCULAR_CONNECTION) {
|
|
206
|
+
current = ModuleGraphConnection.addConnectionStates(current, state);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
mod._isEvaluatingSideEffects = false;
|
|
211
|
+
// When caching is implemented here, make sure to not cache when
|
|
212
|
+
// at least one circular connection was folded into `current`.
|
|
213
|
+
return current;
|
|
214
|
+
}
|
|
215
|
+
|
|
129
216
|
const ABSOLUTE_PATH_REGEX = /^(?:[a-z]:\\|\\\\|\/)/i;
|
|
130
217
|
|
|
131
218
|
/**
|
|
@@ -207,24 +294,6 @@ const asBuffer = (input) => {
|
|
|
207
294
|
return input;
|
|
208
295
|
};
|
|
209
296
|
|
|
210
|
-
class NonErrorEmittedError extends WebpackError {
|
|
211
|
-
/**
|
|
212
|
-
* @param {EXPECTED_ANY} error value which is not an instance of Error
|
|
213
|
-
*/
|
|
214
|
-
constructor(error) {
|
|
215
|
-
super();
|
|
216
|
-
|
|
217
|
-
this.name = "NonErrorEmittedError";
|
|
218
|
-
this.message = `(Emitted value instead of an instance of Error) ${error}`;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
makeSerializable(
|
|
223
|
-
NonErrorEmittedError,
|
|
224
|
-
"webpack/lib/NormalModule",
|
|
225
|
-
"NonErrorEmittedError"
|
|
226
|
-
);
|
|
227
|
-
|
|
228
297
|
/** @typedef {[string | Buffer, string | RawSourceMap | undefined, PreparsedAst | undefined]} Result */
|
|
229
298
|
|
|
230
299
|
/** @typedef {LoaderContext<EXPECTED_ANY>} AnyLoaderContext */
|
|
@@ -247,9 +316,10 @@ makeSerializable(
|
|
|
247
316
|
*/
|
|
248
317
|
|
|
249
318
|
/**
|
|
319
|
+
* @template {NormalModuleTypes | ""} [T=NormalModuleTypes | ""]
|
|
250
320
|
* @typedef {object} NormalModuleCreateData
|
|
251
321
|
* @property {string=} layer an optional layer in which the module is
|
|
252
|
-
* @property {
|
|
322
|
+
* @property {T} type module type. When deserializing, this is set to an empty string "".
|
|
253
323
|
* @property {string} request request string
|
|
254
324
|
* @property {string} userRequest request intended by user (without loaders from config)
|
|
255
325
|
* @property {string} rawRequest request without resolving
|
|
@@ -258,10 +328,10 @@ makeSerializable(
|
|
|
258
328
|
* @property {(ResourceSchemeData & Partial<ResolveRequest>)=} resourceResolveData resource resolve data
|
|
259
329
|
* @property {string} context context directory for resolving
|
|
260
330
|
* @property {string=} matchResource path + query of the matched resource (virtual)
|
|
261
|
-
* @property {
|
|
262
|
-
* @property {
|
|
263
|
-
* @property {
|
|
264
|
-
* @property {
|
|
331
|
+
* @property {ParserByType[T]} parser the parser used
|
|
332
|
+
* @property {ParserOptionsByType[T]=} parserOptions the options of the parser used
|
|
333
|
+
* @property {GeneratorByType[T]} generator the generator used
|
|
334
|
+
* @property {GeneratorOptionsByType[T]=} generatorOptions the options of the generator used
|
|
265
335
|
* @property {ResolveOptions=} resolveOptions options used for resolving requests from this module
|
|
266
336
|
* @property {boolean} extractSourceMap enable/disable extracting source map
|
|
267
337
|
*/
|
|
@@ -394,7 +464,7 @@ class NormalModule extends Module {
|
|
|
394
464
|
this.extractSourceMap = extractSourceMap;
|
|
395
465
|
|
|
396
466
|
// Info from Build
|
|
397
|
-
/** @type {
|
|
467
|
+
/** @type {Error | null} */
|
|
398
468
|
this.error = null;
|
|
399
469
|
/**
|
|
400
470
|
* @private
|
|
@@ -423,12 +493,10 @@ class NormalModule extends Module {
|
|
|
423
493
|
*/
|
|
424
494
|
this._forceBuild = true;
|
|
425
495
|
/**
|
|
426
|
-
* @private
|
|
427
496
|
* @type {boolean}
|
|
428
497
|
*/
|
|
429
498
|
this._isEvaluatingSideEffects = false;
|
|
430
499
|
/**
|
|
431
|
-
* @private
|
|
432
500
|
* @type {WeakSet<ModuleGraph> | undefined}
|
|
433
501
|
*/
|
|
434
502
|
this._addedSideEffectsBailout = undefined;
|
|
@@ -1176,7 +1244,7 @@ class NormalModule extends Module {
|
|
|
1176
1244
|
}
|
|
1177
1245
|
|
|
1178
1246
|
/**
|
|
1179
|
-
* @param {
|
|
1247
|
+
* @param {Error} error the error
|
|
1180
1248
|
* @returns {void}
|
|
1181
1249
|
*/
|
|
1182
1250
|
markModuleAsErrored(error) {
|
|
@@ -1328,7 +1396,7 @@ class NormalModule extends Module {
|
|
|
1328
1396
|
try {
|
|
1329
1397
|
hooks.beforeSnapshot.call(this);
|
|
1330
1398
|
} catch (err) {
|
|
1331
|
-
this.markModuleAsErrored(/** @type {
|
|
1399
|
+
this.markModuleAsErrored(/** @type {Error} */ (err));
|
|
1332
1400
|
return callback();
|
|
1333
1401
|
}
|
|
1334
1402
|
|
|
@@ -1420,7 +1488,7 @@ class NormalModule extends Module {
|
|
|
1420
1488
|
try {
|
|
1421
1489
|
hooks.beforeParse.call(this);
|
|
1422
1490
|
} catch (err) {
|
|
1423
|
-
this.markModuleAsErrored(/** @type {
|
|
1491
|
+
this.markModuleAsErrored(/** @type {Error} */ (err));
|
|
1424
1492
|
this._initBuildHash(compilation);
|
|
1425
1493
|
return callback();
|
|
1426
1494
|
}
|
|
@@ -1471,47 +1539,21 @@ class NormalModule extends Module {
|
|
|
1471
1539
|
* @returns {ConnectionState} how this module should be connected to referencing modules when consumed for side-effects only
|
|
1472
1540
|
*/
|
|
1473
1541
|
getSideEffectsConnectionState(moduleGraph) {
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
}
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1542
|
+
// Trampoline `walkSideEffects` so the descent doesn't consume the
|
|
1543
|
+
// call stack (#20986).
|
|
1544
|
+
const stack = [walkSideEffects(this, moduleGraph)];
|
|
1545
|
+
/** @type {ConnectionState} */
|
|
1546
|
+
let r = false;
|
|
1547
|
+
while (stack.length > 0) {
|
|
1548
|
+
const step = stack[stack.length - 1].next(r);
|
|
1549
|
+
if (step.done) {
|
|
1550
|
+
stack.pop();
|
|
1551
|
+
r = step.value;
|
|
1552
|
+
} else {
|
|
1553
|
+
stack.push(step.value);
|
|
1481
1554
|
}
|
|
1482
|
-
this._isEvaluatingSideEffects = true;
|
|
1483
|
-
/** @type {ConnectionState} */
|
|
1484
|
-
let current = false;
|
|
1485
|
-
for (const dep of this.dependencies) {
|
|
1486
|
-
const state = dep.getModuleEvaluationSideEffectsState(moduleGraph);
|
|
1487
|
-
if (state === true) {
|
|
1488
|
-
if (
|
|
1489
|
-
this._addedSideEffectsBailout === undefined
|
|
1490
|
-
? ((this._addedSideEffectsBailout = new WeakSet()), true)
|
|
1491
|
-
: !this._addedSideEffectsBailout.has(moduleGraph)
|
|
1492
|
-
) {
|
|
1493
|
-
this._addedSideEffectsBailout.add(moduleGraph);
|
|
1494
|
-
moduleGraph
|
|
1495
|
-
.getOptimizationBailout(this)
|
|
1496
|
-
.push(
|
|
1497
|
-
() =>
|
|
1498
|
-
`Dependency (${
|
|
1499
|
-
dep.type
|
|
1500
|
-
}) with side effects at ${formatLocation(dep.loc)}`
|
|
1501
|
-
);
|
|
1502
|
-
}
|
|
1503
|
-
this._isEvaluatingSideEffects = false;
|
|
1504
|
-
return true;
|
|
1505
|
-
} else if (state !== ModuleGraphConnection.CIRCULAR_CONNECTION) {
|
|
1506
|
-
current = ModuleGraphConnection.addConnectionStates(current, state);
|
|
1507
|
-
}
|
|
1508
|
-
}
|
|
1509
|
-
this._isEvaluatingSideEffects = false;
|
|
1510
|
-
// When caching is implemented here, make sure to not cache when
|
|
1511
|
-
// at least one circular connection was in the loop above
|
|
1512
|
-
return current;
|
|
1513
1555
|
}
|
|
1514
|
-
return
|
|
1556
|
+
return r;
|
|
1515
1557
|
}
|
|
1516
1558
|
|
|
1517
1559
|
/**
|
|
@@ -31,6 +31,7 @@ const { getScheme } = require("./util/URLAbsoluteSpecifier");
|
|
|
31
31
|
const { cachedCleverMerge, cachedSetProperty } = require("./util/cleverMerge");
|
|
32
32
|
const { join } = require("./util/fs");
|
|
33
33
|
const {
|
|
34
|
+
escapeHashInPathRequest,
|
|
34
35
|
parseResource,
|
|
35
36
|
parseResourceWithoutFragment
|
|
36
37
|
} = require("./util/identifier");
|
|
@@ -68,7 +69,7 @@ const {
|
|
|
68
69
|
*/
|
|
69
70
|
|
|
70
71
|
/** @typedef {Pick<RuleSetRule, "type" | "sideEffects" | "parser" | "generator" | "resolve" | "layer" | "extractSourceMap">} ModuleSettings */
|
|
71
|
-
/** @typedef {
|
|
72
|
+
/** @typedef {NormalModuleCreateData & { settings: ModuleSettings }} CreateData */
|
|
72
73
|
|
|
73
74
|
/**
|
|
74
75
|
* Defines the resolve data type used by this module.
|
|
@@ -81,7 +82,7 @@ const {
|
|
|
81
82
|
* @property {ImportAttributes=} attributes
|
|
82
83
|
* @property {ModuleDependency[]} dependencies
|
|
83
84
|
* @property {string} dependencyType
|
|
84
|
-
* @property {CreateData} createData
|
|
85
|
+
* @property {Partial<CreateData>} createData
|
|
85
86
|
* @property {FileSystemDependencies} fileDependencies
|
|
86
87
|
* @property {FileSystemDependencies} missingDependencies
|
|
87
88
|
* @property {FileSystemDependencies} contextDependencies
|
|
@@ -132,8 +133,9 @@ const {
|
|
|
132
133
|
/** @typedef {import("./ModuleTypeConstants").CSS_MODULE_TYPE_GLOBAL} CSS_MODULE_TYPE_GLOBAL */
|
|
133
134
|
/** @typedef {import("./ModuleTypeConstants").CSS_MODULE_TYPE_MODULE} CSS_MODULE_TYPE_MODULE */
|
|
134
135
|
/** @typedef {import("./ModuleTypeConstants").CSS_MODULE_TYPE_AUTO} CSS_MODULE_TYPE_AUTO */
|
|
136
|
+
/** @typedef {import("./ModuleTypeConstants").HTML_MODULE_TYPE} HTML_MODULE_TYPE */
|
|
135
137
|
|
|
136
|
-
/** @typedef {JAVASCRIPT_MODULE_TYPE_AUTO | JAVASCRIPT_MODULE_TYPE_DYNAMIC | JAVASCRIPT_MODULE_TYPE_ESM | JSON_MODULE_TYPE | ASSET_MODULE_TYPE | ASSET_MODULE_TYPE_INLINE | ASSET_MODULE_TYPE_RESOURCE | ASSET_MODULE_TYPE_SOURCE | WEBASSEMBLY_MODULE_TYPE_ASYNC | WEBASSEMBLY_MODULE_TYPE_SYNC | CSS_MODULE_TYPE | CSS_MODULE_TYPE_GLOBAL | CSS_MODULE_TYPE_MODULE | CSS_MODULE_TYPE_AUTO} KnownNormalModuleTypes */
|
|
138
|
+
/** @typedef {JAVASCRIPT_MODULE_TYPE_AUTO | JAVASCRIPT_MODULE_TYPE_DYNAMIC | JAVASCRIPT_MODULE_TYPE_ESM | JSON_MODULE_TYPE | ASSET_MODULE_TYPE | ASSET_MODULE_TYPE_INLINE | ASSET_MODULE_TYPE_RESOURCE | ASSET_MODULE_TYPE_SOURCE | WEBASSEMBLY_MODULE_TYPE_ASYNC | WEBASSEMBLY_MODULE_TYPE_SYNC | CSS_MODULE_TYPE | CSS_MODULE_TYPE_GLOBAL | CSS_MODULE_TYPE_MODULE | CSS_MODULE_TYPE_AUTO | HTML_MODULE_TYPE} KnownNormalModuleTypes */
|
|
137
139
|
/** @typedef {KnownNormalModuleTypes | string} NormalModuleTypes */
|
|
138
140
|
|
|
139
141
|
const EMPTY_RESOLVE_OPTIONS = {};
|
|
@@ -319,6 +321,11 @@ const ruleSetCompiler = new RuleSetCompiler([
|
|
|
319
321
|
/** @typedef {import("../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */
|
|
320
322
|
/** @typedef {import("../declarations/WebpackOptions").CssModuleGeneratorOptions} CssModuleGeneratorOptions */
|
|
321
323
|
|
|
324
|
+
/** @typedef {import("./html/HtmlParser")} HtmlParser */
|
|
325
|
+
/** @typedef {import("../declarations/WebpackOptions").EmptyParserOptions} HtmlParserOptions */
|
|
326
|
+
/** @typedef {import("./html/HtmlGenerator")} HtmlGenerator */
|
|
327
|
+
/** @typedef {import("../declarations/WebpackOptions").HtmlGeneratorOptions} HtmlGeneratorOptions */
|
|
328
|
+
|
|
322
329
|
/* eslint-disable jsdoc/type-formatting */
|
|
323
330
|
/**
|
|
324
331
|
* Defines the shared type used by this module.
|
|
@@ -332,12 +339,13 @@ const ruleSetCompiler = new RuleSetCompiler([
|
|
|
332
339
|
* [ASSET_MODULE_TYPE_RESOURCE, AssetParser, EmptyParserOptions, AssetGenerator, AssetGeneratorOptions],
|
|
333
340
|
* [ASSET_MODULE_TYPE_SOURCE, AssetSourceParser, EmptyParserOptions, AssetSourceGenerator, EmptyGeneratorOptions],
|
|
334
341
|
* [ASSET_MODULE_TYPE_BYTES, AssetBytesParser, EmptyParserOptions, AssetBytesGenerator, EmptyGeneratorOptions],
|
|
335
|
-
* [WEBASSEMBLY_MODULE_TYPE_ASYNC, AsyncWebAssemblyParser, EmptyParserOptions, Generator,
|
|
336
|
-
* [WEBASSEMBLY_MODULE_TYPE_SYNC, WebAssemblyParser, EmptyParserOptions, Generator,
|
|
342
|
+
* [WEBASSEMBLY_MODULE_TYPE_ASYNC, AsyncWebAssemblyParser, EmptyParserOptions, Generator, EmptyGeneratorOptions],
|
|
343
|
+
* [WEBASSEMBLY_MODULE_TYPE_SYNC, WebAssemblyParser, EmptyParserOptions, Generator, EmptyGeneratorOptions],
|
|
337
344
|
* [CSS_MODULE_TYPE, CssParser, CssParserOptions, CssGenerator, CssGeneratorOptions],
|
|
338
345
|
* [CSS_MODULE_TYPE_AUTO, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions],
|
|
339
346
|
* [CSS_MODULE_TYPE_MODULE, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions],
|
|
340
347
|
* [CSS_MODULE_TYPE_GLOBAL, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions],
|
|
348
|
+
* [HTML_MODULE_TYPE, HtmlParser, HtmlParserOptions, HtmlGenerator, HtmlGeneratorOptions],
|
|
341
349
|
* [string, Parser, ParserOptions, Generator, GeneratorOptions],
|
|
342
350
|
* ]} ParsersAndGeneratorsByTypes
|
|
343
351
|
*/
|
|
@@ -358,6 +366,18 @@ const ruleSetCompiler = new RuleSetCompiler([
|
|
|
358
366
|
* @typedef {T extends [infer Head extends [string, ...unknown[]], ...infer Tail extends [string, ...unknown[]][]] ? Record<Head[0], SyncBailHook<ExtractTupleElements<Head, A>, R extends number ? Head[R] : R>> & RecordFactoryFromTuple<Tail, A, R> : unknown } RecordFactoryFromTuple
|
|
359
367
|
*/
|
|
360
368
|
|
|
369
|
+
/**
|
|
370
|
+
* Maps each tuple in `T` to a record from its `[0]` key to its `[I]` value.
|
|
371
|
+
* @template {unknown[]} T
|
|
372
|
+
* @template {number} I
|
|
373
|
+
* @typedef {T extends [infer Head extends [string, ...unknown[]], ...infer Tail extends [string, ...unknown[]][]] ? Record<Head[0], I extends keyof Head ? Head[I] : never> & TupleToTypeMap<Tail, I> : unknown } TupleToTypeMap
|
|
374
|
+
*/
|
|
375
|
+
|
|
376
|
+
/** @typedef {TupleToTypeMap<ParsersAndGeneratorsByTypes, 1>} ParserByType */
|
|
377
|
+
/** @typedef {TupleToTypeMap<ParsersAndGeneratorsByTypes, 2>} ParserOptionsByType */
|
|
378
|
+
/** @typedef {TupleToTypeMap<ParsersAndGeneratorsByTypes, 3>} GeneratorByType */
|
|
379
|
+
/** @typedef {TupleToTypeMap<ParsersAndGeneratorsByTypes, 4>} GeneratorOptionsByType */
|
|
380
|
+
|
|
361
381
|
class NormalModuleFactory extends ModuleFactory {
|
|
362
382
|
/**
|
|
363
383
|
* Creates an instance of NormalModuleFactory.
|
|
@@ -485,7 +505,9 @@ class NormalModuleFactory extends ModuleFactory {
|
|
|
485
505
|
// Ignored
|
|
486
506
|
if (result === false) return callback();
|
|
487
507
|
|
|
488
|
-
const createData =
|
|
508
|
+
const createData =
|
|
509
|
+
/** @type {CreateData} */
|
|
510
|
+
(resolveData.createData);
|
|
489
511
|
|
|
490
512
|
this.hooks.createModule.callAsync(
|
|
491
513
|
createData,
|
|
@@ -498,18 +520,12 @@ class NormalModuleFactory extends ModuleFactory {
|
|
|
498
520
|
|
|
499
521
|
// TODO webpack 6 make it required and move javascript/wasm/asset properties to own module
|
|
500
522
|
createdModule = this.hooks.createModuleClass
|
|
501
|
-
.for(
|
|
502
|
-
/** @type {ModuleSettings} */
|
|
503
|
-
(createData.settings).type
|
|
504
|
-
)
|
|
523
|
+
.for(createData.settings.type)
|
|
505
524
|
.call(createData, resolveData);
|
|
506
525
|
|
|
507
526
|
if (!createdModule) {
|
|
508
527
|
createdModule = /** @type {Module} */ (
|
|
509
|
-
new NormalModule(
|
|
510
|
-
/** @type {NormalModuleCreateData} */
|
|
511
|
-
(createData)
|
|
512
|
-
)
|
|
528
|
+
new NormalModule(createData)
|
|
513
529
|
);
|
|
514
530
|
}
|
|
515
531
|
}
|
|
@@ -910,7 +926,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
|
910
926
|
this.resolveResource(
|
|
911
927
|
contextInfo,
|
|
912
928
|
context,
|
|
913
|
-
unresolvedResource,
|
|
929
|
+
escapeHashInPathRequest(unresolvedResource),
|
|
914
930
|
normalResolver,
|
|
915
931
|
resolveContext,
|
|
916
932
|
(err, _resolvedResource, resolvedResourceResolveData) => {
|
|
@@ -1397,9 +1413,10 @@ If changing the source code is not an option there is also a resolve options cal
|
|
|
1397
1413
|
|
|
1398
1414
|
/**
|
|
1399
1415
|
* Returns parser.
|
|
1400
|
-
* @
|
|
1416
|
+
* @template {string} T
|
|
1417
|
+
* @param {T} type type
|
|
1401
1418
|
* @param {ParserOptions} parserOptions parser options
|
|
1402
|
-
* @returns {
|
|
1419
|
+
* @returns {ParserByType[T]} parser
|
|
1403
1420
|
*/
|
|
1404
1421
|
getParser(type, parserOptions = EMPTY_PARSER_OPTIONS) {
|
|
1405
1422
|
let cache = this.parserCache.get(type);
|
|
@@ -1416,14 +1433,15 @@ If changing the source code is not an option there is also a resolve options cal
|
|
|
1416
1433
|
cache.set(parserOptions, parser);
|
|
1417
1434
|
}
|
|
1418
1435
|
|
|
1419
|
-
return parser;
|
|
1436
|
+
return /** @type {ParserByType[T]} */ (parser);
|
|
1420
1437
|
}
|
|
1421
1438
|
|
|
1422
1439
|
/**
|
|
1423
1440
|
* Creates a parser from the provided type.
|
|
1424
|
-
* @
|
|
1441
|
+
* @template {string} T
|
|
1442
|
+
* @param {T} type type
|
|
1425
1443
|
* @param {ParserOptions} parserOptions parser options
|
|
1426
|
-
* @returns {
|
|
1444
|
+
* @returns {ParserByType[T]} parser
|
|
1427
1445
|
*/
|
|
1428
1446
|
createParser(type, parserOptions = {}) {
|
|
1429
1447
|
parserOptions = mergeGlobalOptions(
|
|
@@ -1436,14 +1454,15 @@ If changing the source code is not an option there is also a resolve options cal
|
|
|
1436
1454
|
throw new Error(`No parser registered for ${type}`);
|
|
1437
1455
|
}
|
|
1438
1456
|
this.hooks.parser.for(type).call(parser, parserOptions);
|
|
1439
|
-
return parser;
|
|
1457
|
+
return /** @type {ParserByType[T]} */ (parser);
|
|
1440
1458
|
}
|
|
1441
1459
|
|
|
1442
1460
|
/**
|
|
1443
1461
|
* Returns generator.
|
|
1444
|
-
* @
|
|
1462
|
+
* @template {string} T
|
|
1463
|
+
* @param {T} type type of generator
|
|
1445
1464
|
* @param {GeneratorOptions} generatorOptions generator options
|
|
1446
|
-
* @returns {
|
|
1465
|
+
* @returns {GeneratorByType[T]} generator
|
|
1447
1466
|
*/
|
|
1448
1467
|
getGenerator(type, generatorOptions = EMPTY_GENERATOR_OPTIONS) {
|
|
1449
1468
|
let cache = this.generatorCache.get(type);
|
|
@@ -1460,14 +1479,15 @@ If changing the source code is not an option there is also a resolve options cal
|
|
|
1460
1479
|
cache.set(generatorOptions, generator);
|
|
1461
1480
|
}
|
|
1462
1481
|
|
|
1463
|
-
return generator;
|
|
1482
|
+
return /** @type {GeneratorByType[T]} */ (generator);
|
|
1464
1483
|
}
|
|
1465
1484
|
|
|
1466
1485
|
/**
|
|
1467
1486
|
* Creates a generator.
|
|
1468
|
-
* @
|
|
1487
|
+
* @template {string} T
|
|
1488
|
+
* @param {T} type type of generator
|
|
1469
1489
|
* @param {GeneratorOptions} generatorOptions generator options
|
|
1470
|
-
* @returns {
|
|
1490
|
+
* @returns {GeneratorByType[T]} generator
|
|
1471
1491
|
*/
|
|
1472
1492
|
createGenerator(type, generatorOptions = {}) {
|
|
1473
1493
|
generatorOptions = mergeGlobalOptions(
|
|
@@ -1482,7 +1502,7 @@ If changing the source code is not an option there is also a resolve options cal
|
|
|
1482
1502
|
throw new Error(`No generator registered for ${type}`);
|
|
1483
1503
|
}
|
|
1484
1504
|
this.hooks.generator.for(type).call(generator, generatorOptions);
|
|
1485
|
-
return generator;
|
|
1505
|
+
return /** @type {GeneratorByType[T]} */ (generator);
|
|
1486
1506
|
}
|
|
1487
1507
|
|
|
1488
1508
|
/**
|
package/lib/Parser.js
CHANGED
|
@@ -33,7 +33,7 @@ class Parser {
|
|
|
33
33
|
* @returns {ParserState} the parser state
|
|
34
34
|
*/
|
|
35
35
|
parse(source, state) {
|
|
36
|
-
const AbstractMethodError = require("./AbstractMethodError");
|
|
36
|
+
const AbstractMethodError = require("./errors/AbstractMethodError");
|
|
37
37
|
|
|
38
38
|
throw new AbstractMethodError();
|
|
39
39
|
}
|