2015-01-13 00:45:30 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2017-01-05 02:42:15 +08:00
|
|
|
"use strict";
|
2018-07-23 23:33:29 +08:00
|
|
|
|
2018-07-23 20:53:50 +08:00
|
|
|
const InitFragment = require("../InitFragment");
|
2017-01-05 02:42:15 +08:00
|
|
|
const NullDependency = require("./NullDependency");
|
|
|
|
|
2018-07-23 23:33:29 +08:00
|
|
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
2018-07-30 23:08:51 +08:00
|
|
|
/** @typedef {import("../Dependency")} Dependency */
|
2018-07-25 15:33:48 +08:00
|
|
|
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
2018-07-18 01:38:42 +08:00
|
|
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
2018-07-17 22:34:36 +08:00
|
|
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
2018-07-23 23:33:29 +08:00
|
|
|
|
2017-01-05 02:42:15 +08:00
|
|
|
class HarmonyExportSpecifierDependency extends NullDependency {
|
2018-08-07 20:20:53 +08:00
|
|
|
constructor(id, name) {
|
2017-01-05 02:42:15 +08:00
|
|
|
super();
|
|
|
|
this.id = id;
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
get type() {
|
|
|
|
return "harmony export specifier";
|
|
|
|
}
|
|
|
|
|
2018-07-25 15:33:48 +08:00
|
|
|
/**
|
|
|
|
* Returns the exported names
|
2018-07-17 22:34:36 +08:00
|
|
|
* @param {ModuleGraph} moduleGraph module graph
|
2018-07-25 15:33:48 +08:00
|
|
|
* @returns {ExportsSpec | undefined} export names
|
|
|
|
*/
|
2018-07-17 22:34:36 +08:00
|
|
|
getExports(moduleGraph) {
|
2017-01-05 02:42:15 +08:00
|
|
|
return {
|
2018-04-04 19:42:37 +08:00
|
|
|
exports: [this.name],
|
|
|
|
dependencies: undefined
|
2017-01-05 02:42:15 +08:00
|
|
|
};
|
|
|
|
}
|
2015-01-13 00:45:30 +08:00
|
|
|
}
|
|
|
|
|
2018-07-23 23:33:29 +08:00
|
|
|
HarmonyExportSpecifierDependency.Template = class HarmonyExportSpecifierDependencyTemplate extends NullDependency.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-23 23:33:29 +08:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-07-18 01:38:42 +08:00
|
|
|
apply(dependency, source, templateContext) {
|
2018-07-23 23:33:29 +08:00
|
|
|
// no-op
|
|
|
|
}
|
2017-08-08 15:32:43 +08:00
|
|
|
|
2018-07-27 17:45:12 +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-27 17:45:12 +08:00
|
|
|
* @returns {InitFragment[]|null} the init fragments
|
|
|
|
*/
|
2018-08-07 20:20:53 +08:00
|
|
|
getInitFragments(dependency, { module, moduleGraph }) {
|
2018-07-30 16:15:18 +08:00
|
|
|
return [
|
|
|
|
new InitFragment(
|
2018-08-07 20:20:53 +08:00
|
|
|
this.getContent(dependency, module, moduleGraph),
|
2018-07-30 16:15:18 +08:00
|
|
|
InitFragment.STAGE_HARMONY_EXPORTS,
|
|
|
|
1
|
|
|
|
)
|
|
|
|
];
|
2016-09-06 05:41:03 +08:00
|
|
|
}
|
2017-01-05 02:42:15 +08:00
|
|
|
|
2018-08-07 20:20:53 +08:00
|
|
|
getContent(dep, module, moduleGraph) {
|
|
|
|
const used = module.getUsedName(moduleGraph, dep.name);
|
2018-02-25 09:00:20 +08:00
|
|
|
if (!used) {
|
|
|
|
return `/* unused harmony export ${dep.name || "namespace"} */\n`;
|
2017-01-05 02:42:15 +08:00
|
|
|
}
|
|
|
|
|
2018-08-07 20:20:53 +08:00
|
|
|
const exportsName = module.exportsArgument;
|
2017-01-05 02:42:15 +08:00
|
|
|
|
2018-03-26 22:56:10 +08:00
|
|
|
return `/* harmony export (binding) */ __webpack_require__.d(${exportsName}, ${JSON.stringify(
|
|
|
|
used
|
|
|
|
)}, function() { return ${dep.id}; });\n`;
|
2015-01-13 00:45:30 +08:00
|
|
|
}
|
2017-01-11 17:51:58 +08:00
|
|
|
};
|
2015-01-13 00:45:30 +08:00
|
|
|
|
2017-01-05 02:42:15 +08:00
|
|
|
module.exports = HarmonyExportSpecifierDependency;
|