2016-12-05 06:47:19 +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-04 13:22:09 +08:00
|
|
|
"use strict";
|
2018-07-23 23:33:29 +08:00
|
|
|
|
2018-07-30 01:26:57 +08:00
|
|
|
const InitFragment = require("../InitFragment");
|
2019-05-23 02:11:16 +08:00
|
|
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
|
|
const AsyncModuleInitFragment = require("../async-modules/AsyncModuleInitFragment");
|
2018-10-09 20:30:59 +08:00
|
|
|
const makeSerializable = require("../util/makeSerializable");
|
2017-01-04 13:22:09 +08:00
|
|
|
const NullDependency = require("./NullDependency");
|
2016-12-05 06:47:19 +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-18 01:38:42 +08:00
|
|
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
2018-08-07 01:39:43 +08:00
|
|
|
/** @typedef {import("../Module")} Module */
|
2018-07-23 23:33:29 +08:00
|
|
|
|
2017-01-20 02:43:42 +08:00
|
|
|
class HarmonyCompatibilityDependency extends NullDependency {
|
2019-05-24 21:19:45 +08:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.hasAwait = false;
|
|
|
|
}
|
|
|
|
|
2017-01-04 13:22:09 +08:00
|
|
|
get type() {
|
|
|
|
return "harmony export header";
|
|
|
|
}
|
|
|
|
}
|
2016-12-05 06:47:19 +08:00
|
|
|
|
2018-10-09 20:30:59 +08:00
|
|
|
makeSerializable(
|
|
|
|
HarmonyCompatibilityDependency,
|
|
|
|
"webpack/lib/dependencies/HarmonyCompatibilityDependency"
|
|
|
|
);
|
|
|
|
|
2018-07-23 23:33:29 +08:00
|
|
|
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
|
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-16 23:40:03 +08:00
|
|
|
apply(
|
|
|
|
dependency,
|
|
|
|
source,
|
2018-11-17 01:18:44 +08:00
|
|
|
{ module, runtimeTemplate, moduleGraph, initFragments, runtimeRequirements }
|
2018-11-16 23:40:03 +08:00
|
|
|
) {
|
2019-05-24 21:19:45 +08:00
|
|
|
const dep = /** @type {HarmonyCompatibilityDependency} */ (dependency);
|
2018-08-16 19:55:41 +08:00
|
|
|
const usedExports = moduleGraph.getUsedExports(module);
|
2018-08-07 01:39:43 +08:00
|
|
|
if (usedExports === true || usedExports === null) {
|
2018-07-23 23:33:29 +08:00
|
|
|
const content = runtimeTemplate.defineEsModuleFlagStatement({
|
2018-11-17 01:18:44 +08:00
|
|
|
exportsArgument: module.exportsArgument,
|
|
|
|
runtimeRequirements
|
2017-12-19 22:50:09 +08:00
|
|
|
});
|
2018-11-16 23:40:03 +08:00
|
|
|
initFragments.push(
|
2018-07-30 16:15:18 +08:00
|
|
|
new InitFragment(
|
|
|
|
content,
|
|
|
|
InitFragment.STAGE_HARMONY_EXPORTS,
|
|
|
|
0,
|
|
|
|
"harmony compatibility"
|
|
|
|
)
|
2018-11-16 23:40:03 +08:00
|
|
|
);
|
2017-01-04 13:22:09 +08:00
|
|
|
}
|
2019-06-05 17:15:25 +08:00
|
|
|
if (moduleGraph.isAsync(module)) {
|
2019-05-23 02:11:16 +08:00
|
|
|
runtimeRequirements.add(RuntimeGlobals.module);
|
2019-05-24 18:30:43 +08:00
|
|
|
initFragments.push(
|
2019-05-24 21:19:45 +08:00
|
|
|
new AsyncModuleInitFragment(module.moduleArgument, dep.hasAwait, [])
|
2019-05-24 18:30:43 +08:00
|
|
|
);
|
2019-05-23 02:11:16 +08:00
|
|
|
}
|
2016-12-05 06:47:19 +08:00
|
|
|
}
|
2017-01-11 17:51:58 +08:00
|
|
|
};
|
2017-01-04 13:22:09 +08:00
|
|
|
|
2017-01-20 02:43:42 +08:00
|
|
|
module.exports = HarmonyCompatibilityDependency;
|