webpack/lib/dependencies/ModuleDecoratorDependency.js

74 lines
2.5 KiB
JavaScript
Raw Normal View History

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const InitFragment = require("../InitFragment");
2018-10-09 20:30:59 +08:00
const makeSerializable = require("../util/makeSerializable");
const ModuleDependency = require("./ModuleDependency");
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
/** @typedef {import("../ChunkGraph")} ChunkGraph */
/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../DependencyTemplates")} DependencyTemplates */
2018-07-17 22:42:05 +08:00
/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
/** @typedef {import("../util/createHash").Hash} Hash */
class ModuleDecoratorDependency extends ModuleDependency {
/**
* Update the hash
* @param {Hash} hash hash to be updated
* @param {ChunkGraph} chunkGraph chunk graph
* @returns {void}
*/
updateHash(hash, chunkGraph) {
super.updateHash(hash, chunkGraph);
hash.update("module decorator");
}
}
2018-10-09 20:30:59 +08:00
makeSerializable(
ModuleDecoratorDependency,
"webpack/lib/dependencies/ModuleDecoratorDependency"
);
ModuleDecoratorDependency.Template = class ModuleDecoratorDependencyTemplate extends ModuleDependency.Template {
/**
* @param {Dependency} dependency the dependency for which the template should be applied
* @param {ReplaceSource} source the current replace source which can be modified
* @param {DependencyTemplateContext} templateContext the context object
* @returns {void}
*/
apply(dependency, source, templateContext) {}
/**
* @param {Dependency} dependency the dependency for which the template should be applied
* @param {DependencyTemplateContext} templateContext the template context
* @returns {InitFragment[]|null} the init fragments
*/
getInitFragments(dependency, { runtimeTemplate, moduleGraph, chunkGraph }) {
const dep = /** @type {ModuleDecoratorDependency} */ (dependency);
const originModule = moduleGraph.getOrigin(dep);
return [
new InitFragment(
`/* module decorator */ ${
originModule.moduleArgument
} = ${runtimeTemplate.moduleExports({
module: moduleGraph.getModule(dep),
chunkGraph,
request: dep.request
})}(${originModule.moduleArgument});\n`,
InitFragment.STAGE_PROVIDES,
0,
`module decorator ${chunkGraph.getModuleId(originModule)}`
)
];
}
};
module.exports = ModuleDecoratorDependency;