[6a3a178] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const { UsageState } = require("../ExportsInfo");
|
---|
| 9 | const InitFragment = require("../InitFragment");
|
---|
| 10 | const RuntimeGlobals = require("../RuntimeGlobals");
|
---|
| 11 | const makeSerializable = require("../util/makeSerializable");
|
---|
| 12 | const NullDependency = require("./NullDependency");
|
---|
| 13 |
|
---|
| 14 | /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
---|
| 15 | /** @typedef {import("../Dependency")} Dependency */
|
---|
| 16 | /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
---|
| 17 | /** @typedef {import("../Module")} Module */
|
---|
| 18 |
|
---|
| 19 | class HarmonyCompatibilityDependency extends NullDependency {
|
---|
| 20 | get type() {
|
---|
| 21 | return "harmony export header";
|
---|
| 22 | }
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | makeSerializable(
|
---|
| 26 | HarmonyCompatibilityDependency,
|
---|
| 27 | "webpack/lib/dependencies/HarmonyCompatibilityDependency"
|
---|
| 28 | );
|
---|
| 29 |
|
---|
| 30 | HarmonyCompatibilityDependency.Template = class HarmonyExportDependencyTemplate extends (
|
---|
| 31 | NullDependency.Template
|
---|
| 32 | ) {
|
---|
| 33 | /**
|
---|
| 34 | * @param {Dependency} dependency the dependency for which the template should be applied
|
---|
| 35 | * @param {ReplaceSource} source the current replace source which can be modified
|
---|
| 36 | * @param {DependencyTemplateContext} templateContext the context object
|
---|
| 37 | * @returns {void}
|
---|
| 38 | */
|
---|
| 39 | apply(
|
---|
| 40 | dependency,
|
---|
| 41 | source,
|
---|
| 42 | {
|
---|
| 43 | module,
|
---|
| 44 | runtimeTemplate,
|
---|
| 45 | moduleGraph,
|
---|
| 46 | initFragments,
|
---|
| 47 | runtimeRequirements,
|
---|
| 48 | runtime,
|
---|
| 49 | concatenationScope
|
---|
| 50 | }
|
---|
| 51 | ) {
|
---|
| 52 | if (concatenationScope) return;
|
---|
| 53 | const exportsInfo = moduleGraph.getExportsInfo(module);
|
---|
| 54 | if (
|
---|
| 55 | exportsInfo.getReadOnlyExportInfo("__esModule").getUsed(runtime) !==
|
---|
| 56 | UsageState.Unused
|
---|
| 57 | ) {
|
---|
| 58 | const content = runtimeTemplate.defineEsModuleFlagStatement({
|
---|
| 59 | exportsArgument: module.exportsArgument,
|
---|
| 60 | runtimeRequirements
|
---|
| 61 | });
|
---|
| 62 | initFragments.push(
|
---|
| 63 | new InitFragment(
|
---|
| 64 | content,
|
---|
| 65 | InitFragment.STAGE_HARMONY_EXPORTS,
|
---|
| 66 | 0,
|
---|
| 67 | "harmony compatibility"
|
---|
| 68 | )
|
---|
| 69 | );
|
---|
| 70 | }
|
---|
| 71 | if (moduleGraph.isAsync(module)) {
|
---|
| 72 | runtimeRequirements.add(RuntimeGlobals.module);
|
---|
| 73 | runtimeRequirements.add(RuntimeGlobals.asyncModule);
|
---|
| 74 | initFragments.push(
|
---|
| 75 | new InitFragment(
|
---|
| 76 | runtimeTemplate.supportsArrowFunction()
|
---|
| 77 | ? `${RuntimeGlobals.asyncModule}(${module.moduleArgument}, async (__webpack_handle_async_dependencies__) => {\n`
|
---|
| 78 | : `${RuntimeGlobals.asyncModule}(${module.moduleArgument}, async function (__webpack_handle_async_dependencies__) {\n`,
|
---|
| 79 | InitFragment.STAGE_ASYNC_BOUNDARY,
|
---|
| 80 | 0,
|
---|
| 81 | undefined,
|
---|
| 82 | module.buildMeta.async
|
---|
| 83 | ? `\n__webpack_handle_async_dependencies__();\n}, 1);`
|
---|
| 84 | : "\n});"
|
---|
| 85 | )
|
---|
| 86 | );
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | };
|
---|
| 90 |
|
---|
| 91 | module.exports = HarmonyCompatibilityDependency;
|
---|