webpack/lib/dependencies/HarmonyCompatibilityDepende...

59 lines
1.8 KiB
JavaScript
Raw Normal View History

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
2018-07-30 23:08:51 +08:00
"use strict";
2018-07-30 01:26:57 +08:00
const InitFragment = require("../InitFragment");
const NullDependency = require("./NullDependency");
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
2018-07-30 23:08:51 +08:00
/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../Module")} Module */
class HarmonyCompatibilityDependency extends NullDependency {
get type() {
return "harmony export header";
}
}
HarmonyCompatibilityDependency.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
* @param {DependencyTemplateContext} templateContext the context object
* @returns {void}
*/
apply(dependency, source, templateContext) {
// no-op
}
2018-07-30 01:26:57 +08:00
/**
* @param {Dependency} dependency the dependency for which the template should be applied
* @param {DependencyTemplateContext} templateContext the template context
2018-07-30 01:26:57 +08:00
* @returns {InitFragment[]|null} the init fragments
*/
getInitFragments(dependency, { module, runtimeTemplate, moduleGraph }) {
const usedExports = moduleGraph.getUsedExports(module);
if (usedExports === true || usedExports === null) {
const content = runtimeTemplate.defineEsModuleFlagStatement({
exportsArgument: module.exportsArgument
});
2018-07-30 16:15:18 +08:00
return [
new InitFragment(
content,
InitFragment.STAGE_HARMONY_EXPORTS,
0,
"harmony compatibility"
)
];
2018-07-30 01:26:57 +08:00
} else {
return null;
}
}
2017-01-11 17:51:58 +08:00
};
module.exports = HarmonyCompatibilityDependency;