1 |
|
2 |
|
3 |
|
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 |
|
15 |
|
16 |
|
17 |
|
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 |
|
35 |
|
36 |
|
37 |
|
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__, __webpack_async_result__) => { try {\n`
|
78 | : `${RuntimeGlobals.asyncModule}(${module.moduleArgument}, async function (__webpack_handle_async_dependencies__, __webpack_async_result__) { try {\n`,
|
79 | InitFragment.STAGE_ASYNC_BOUNDARY,
|
80 | 0,
|
81 | undefined,
|
82 | `\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } }${
|
83 | module.buildMeta.async ? ", 1" : ""
|
84 | });`
|
85 | )
|
86 | );
|
87 | }
|
88 | }
|
89 | };
|
90 |
|
91 | module.exports = HarmonyCompatibilityDependency;
|