mirror of https://github.com/webpack/webpack.git
fix compat for Module.source() method
This commit is contained in:
parent
115aa13577
commit
44882683a9
|
|
@ -699,14 +699,29 @@ class Module extends DependenciesBlock {
|
|||
/**
|
||||
* @abstract
|
||||
* @deprecated Use codeGeneration() instead
|
||||
* @param {SourceContext} sourceContext source context
|
||||
* @param {DependencyTemplates} dependencyTemplates the dependency templates
|
||||
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
||||
* @param {string=} type the type of source that should be generated
|
||||
* @returns {Source} generated source
|
||||
*/
|
||||
source(sourceContext) {
|
||||
source(dependencyTemplates, runtimeTemplate, type = "javascript") {
|
||||
if (this.codeGeneration === Module.prototype.codeGeneration) {
|
||||
const AbstractMethodError = require("./AbstractMethodError");
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
const chunkGraph = ChunkGraph.getChunkGraphForModule(
|
||||
this,
|
||||
"Module.source() is deprecated. Use Compilation.codeGenerationResults.get(module).sources.get(type) instead",
|
||||
"DEP_WEBPACK_MODULE_SOURCE"
|
||||
);
|
||||
/** @type {SourceContext} */
|
||||
const sourceContext = {
|
||||
dependencyTemplates,
|
||||
runtimeTemplate,
|
||||
type,
|
||||
moduleGraph: chunkGraph.moduleGraph,
|
||||
chunkGraph
|
||||
};
|
||||
const sources = this.codeGeneration(sourceContext).sources;
|
||||
return sourceContext.type
|
||||
? sources.get(sourceContext.type)
|
||||
|
|
@ -764,10 +779,11 @@ class Module extends DependenciesBlock {
|
|||
if (type !== "unknown") {
|
||||
sources.set(
|
||||
type,
|
||||
this.source({
|
||||
...context,
|
||||
this.source(
|
||||
context.dependencyTemplates,
|
||||
context.runtimeTemplate,
|
||||
type
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue