webpack/lib/dependencies/HarmonyCompatibilityDepende...

67 lines
2.0 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 RuntimeGlobals = require("../RuntimeGlobals");
const AsyncModuleInitFragment = require("../async-modules/AsyncModuleInitFragment");
2018-10-09 20:30:59 +08:00
const makeSerializable = require("../util/makeSerializable");
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";
}
}
2018-10-09 20:30:59 +08:00
makeSerializable(
HarmonyCompatibilityDependency,
"webpack/lib/dependencies/HarmonyCompatibilityDependency"
);
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,
2018-11-17 01:18:44 +08:00
{ module, runtimeTemplate, moduleGraph, initFragments, runtimeRequirements }
) {
const usedExports = moduleGraph.getUsedExports(module);
if (usedExports === true || usedExports === null) {
const content = runtimeTemplate.defineEsModuleFlagStatement({
2018-11-17 01:18:44 +08:00
exportsArgument: module.exportsArgument,
runtimeRequirements
});
initFragments.push(
2018-07-30 16:15:18 +08:00
new InitFragment(
content,
InitFragment.STAGE_HARMONY_EXPORTS,
0,
"harmony compatibility"
)
);
}
if (module.buildMeta.exportsType === "async") {
runtimeRequirements.add(RuntimeGlobals.module);
initFragments.push(
new AsyncModuleInitFragment(module.moduleArgument, [])
);
}
}
2017-01-11 17:51:58 +08:00
};
module.exports = HarmonyCompatibilityDependency;