2018-07-30 16:33:33 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const InitFragment = require("../InitFragment");
|
|
|
|
const ModuleDependency = require("./ModuleDependency");
|
|
|
|
|
|
|
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
|
|
/** @typedef {import("../Dependency")} Dependency */
|
2018-07-18 01:38:42 +08:00
|
|
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
2018-07-30 16:33:33 +08:00
|
|
|
/** @typedef {import("../DependencyTemplates")} DependencyTemplates */
|
2018-07-17 22:42:05 +08:00
|
|
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
2018-07-30 16:33:33 +08:00
|
|
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
2018-07-30 19:23:59 +08:00
|
|
|
/** @typedef {import("../util/createHash").Hash} Hash */
|
2018-07-30 16:33:33 +08:00
|
|
|
|
|
|
|
class ModuleDecoratorDependency extends ModuleDependency {
|
2018-07-30 19:23:59 +08:00
|
|
|
/**
|
|
|
|
* Update the hash
|
|
|
|
* @param {Hash} hash hash to be updated
|
2018-07-17 22:42:05 +08:00
|
|
|
* @param {ModuleGraph} moduleGraph module graph
|
2018-07-30 19:23:59 +08:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-07-17 22:42:05 +08:00
|
|
|
updateHash(hash, moduleGraph) {
|
|
|
|
super.updateHash(hash, moduleGraph);
|
2018-07-30 19:23:59 +08:00
|
|
|
hash.update("module decorator");
|
|
|
|
}
|
2018-07-30 16:33:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2018-07-18 01:38:42 +08:00
|
|
|
* @param {DependencyTemplateContext} templateContext the context object
|
2018-07-30 16:33:33 +08:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-07-18 01:38:42 +08:00
|
|
|
apply(dependency, source, templateContext) {}
|
2018-07-30 16:33:33 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Dependency} dependency the dependency for which the template should be applied
|
2018-07-18 01:38:42 +08:00
|
|
|
* @param {DependencyTemplateContext} templateContext the template context
|
2018-07-30 16:33:33 +08:00
|
|
|
* @returns {InitFragment[]|null} the init fragments
|
|
|
|
*/
|
2018-07-24 21:30:37 +08:00
|
|
|
getInitFragments(dependency, { runtimeTemplate, moduleGraph }) {
|
2018-07-30 16:33:33 +08:00
|
|
|
const dep = /** @type {ModuleDecoratorDependency} */ (dependency);
|
2018-08-07 20:20:53 +08:00
|
|
|
const originModule = moduleGraph.getOrigin(dep);
|
2018-07-30 16:33:33 +08:00
|
|
|
return [
|
|
|
|
new InitFragment(
|
|
|
|
`/* module decorator */ ${
|
2018-08-07 20:20:53 +08:00
|
|
|
originModule.moduleArgument
|
2018-07-30 16:33:33 +08:00
|
|
|
} = ${runtimeTemplate.moduleExports({
|
2018-07-24 21:30:37 +08:00
|
|
|
module: moduleGraph.getModule(dep),
|
2018-07-30 16:33:33 +08:00
|
|
|
request: dep.request
|
2018-08-07 20:20:53 +08:00
|
|
|
})}(${originModule.moduleArgument});\n`,
|
2018-07-30 16:33:33 +08:00
|
|
|
InitFragment.STAGE_PROVIDES,
|
|
|
|
0,
|
2018-08-07 20:20:53 +08:00
|
|
|
`module decorator ${originModule.id}`
|
2018-07-30 16:33:33 +08:00
|
|
|
)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ModuleDecoratorDependency;
|