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 00:21:57 +08:00
|
|
|
"use strict";
|
2018-07-23 23:33:29 +08:00
|
|
|
|
2017-01-05 00:21:57 +08:00
|
|
|
const NullDependency = require("./NullDependency");
|
2015-01-13 00:45:30 +08:00
|
|
|
|
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 00:21:57 +08:00
|
|
|
class HarmonyExportExpressionDependency extends NullDependency {
|
2018-09-18 16:13:54 +08:00
|
|
|
constructor(range, rangeStatement, prefix) {
|
2017-01-05 00:21:57 +08:00
|
|
|
super();
|
|
|
|
this.range = range;
|
|
|
|
this.rangeStatement = rangeStatement;
|
2018-09-17 20:58:55 +08:00
|
|
|
this.prefix = prefix;
|
2017-01-05 00:21:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
get type() {
|
|
|
|
return "harmony export expression";
|
|
|
|
}
|
|
|
|
|
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 00:21:57 +08:00
|
|
|
return {
|
2018-04-04 19:42:37 +08:00
|
|
|
exports: ["default"],
|
|
|
|
dependencies: undefined
|
2017-01-05 00:21:57 +08:00
|
|
|
};
|
|
|
|
}
|
2015-01-13 00:45:30 +08:00
|
|
|
}
|
|
|
|
|
2018-07-23 23:33:29 +08:00
|
|
|
HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTemplate 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-08-07 20:20:53 +08:00
|
|
|
apply(dependency, source, { module, moduleGraph }) {
|
2018-07-23 23:33:29 +08:00
|
|
|
const dep = /** @type {HarmonyExportExpressionDependency} */ (dependency);
|
2018-08-07 20:20:53 +08:00
|
|
|
const used = module.getUsedName(moduleGraph, "default");
|
|
|
|
const content = this.getContent(module, used);
|
2017-01-05 00:21:57 +08:00
|
|
|
|
2018-02-25 09:00:20 +08:00
|
|
|
if (dep.range) {
|
2018-09-17 20:58:55 +08:00
|
|
|
source.replace(
|
|
|
|
dep.rangeStatement[0],
|
|
|
|
dep.range[0] - 1,
|
|
|
|
content + "(" + dep.prefix
|
|
|
|
);
|
2017-01-18 05:26:38 +08:00
|
|
|
source.replace(dep.range[1], dep.rangeStatement[1] - 1, ");");
|
2017-01-05 00:21:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-15 05:41:06 +08:00
|
|
|
source.replace(dep.rangeStatement[0], dep.rangeStatement[1] - 1, content);
|
|
|
|
}
|
2017-01-05 00:21:57 +08:00
|
|
|
|
2017-01-11 17:51:58 +08:00
|
|
|
getContent(module, used) {
|
2017-11-12 01:48:29 +08:00
|
|
|
const exportsName = module.exportsArgument;
|
2018-02-25 09:00:20 +08:00
|
|
|
if (used) {
|
|
|
|
return `/* harmony default export */ ${exportsName}[${JSON.stringify(
|
|
|
|
used
|
|
|
|
)}] = `;
|
2017-01-05 00:21:57 +08:00
|
|
|
}
|
|
|
|
return "/* unused harmony default export */ var _unused_webpack_default_export = ";
|
|
|
|
}
|
2017-01-11 17:51:58 +08:00
|
|
|
};
|
2017-01-05 00:21:57 +08:00
|
|
|
|
|
|
|
module.exports = HarmonyExportExpressionDependency;
|