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-10-09 20:30:59 +08:00
|
|
|
const makeSerializable = require("../util/makeSerializable");
|
2019-08-23 20:07:01 +08:00
|
|
|
const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
|
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],
|
2020-08-12 00:06:27 +08:00
|
|
|
terminalBinding: true,
|
2018-04-04 19:42:37 +08:00
|
|
|
dependencies: undefined
|
2017-01-05 02:42:15 +08:00
|
|
|
};
|
|
|
|
}
|
2018-10-09 20:30:59 +08:00
|
|
|
|
|
|
|
serialize(context) {
|
|
|
|
const { write } = context;
|
|
|
|
write(this.id);
|
|
|
|
write(this.name);
|
|
|
|
super.serialize(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
deserialize(context) {
|
|
|
|
const { read } = context;
|
|
|
|
this.id = read();
|
|
|
|
this.name = read();
|
|
|
|
super.deserialize(context);
|
|
|
|
}
|
2015-01-13 00:45:30 +08:00
|
|
|
}
|
|
|
|
|
2018-10-09 20:30:59 +08:00
|
|
|
makeSerializable(
|
|
|
|
HarmonyExportSpecifierDependency,
|
|
|
|
"webpack/lib/dependencies/HarmonyExportSpecifierDependency"
|
|
|
|
);
|
|
|
|
|
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-11-17 01:18:44 +08:00
|
|
|
apply(
|
|
|
|
dependency,
|
|
|
|
source,
|
2020-09-11 15:26:12 +08:00
|
|
|
{ module, moduleGraph, initFragments, runtime, concatenationScope }
|
2018-11-17 01:18:44 +08:00
|
|
|
) {
|
2020-09-11 15:26:12 +08:00
|
|
|
if (concatenationScope) return;
|
2019-08-23 20:07:01 +08:00
|
|
|
const dep = /** @type {HarmonyExportSpecifierDependency} */ (dependency);
|
2020-07-28 00:09:48 +08:00
|
|
|
const used = moduleGraph
|
|
|
|
.getExportsInfo(module)
|
|
|
|
.getUsedName(dep.name, runtime);
|
2018-02-25 09:00:20 +08:00
|
|
|
if (!used) {
|
2019-08-23 20:07:01 +08:00
|
|
|
const set = new Set();
|
|
|
|
set.add(dep.name || "namespace");
|
|
|
|
initFragments.push(
|
|
|
|
new HarmonyExportInitFragment(module.exportsArgument, undefined, set)
|
|
|
|
);
|
|
|
|
return;
|
2017-01-05 02:42:15 +08:00
|
|
|
}
|
|
|
|
|
2019-08-23 20:07:01 +08:00
|
|
|
const map = new Map();
|
|
|
|
map.set(used, `/* binding */ ${dep.id}`);
|
|
|
|
initFragments.push(
|
|
|
|
new HarmonyExportInitFragment(module.exportsArgument, map, undefined)
|
|
|
|
);
|
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;
|