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 makeSerializable = require("../util/makeSerializable");
|
---|
9 | const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
|
---|
10 | const NullDependency = require("./NullDependency");
|
---|
11 |
|
---|
12 | /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
---|
13 | /** @typedef {import("../Dependency")} Dependency */
|
---|
14 | /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
---|
15 | /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
---|
16 | /** @typedef {import("../ModuleGraph")} ModuleGraph */
|
---|
17 | /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
---|
18 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
---|
19 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
---|
20 |
|
---|
21 | class HarmonyExportSpecifierDependency extends NullDependency {
|
---|
22 | /**
|
---|
23 | * @param {TODO} id id
|
---|
24 | * @param {TODO} name name
|
---|
25 | */
|
---|
26 | constructor(id, name) {
|
---|
27 | super();
|
---|
28 | this.id = id;
|
---|
29 | this.name = name;
|
---|
30 | }
|
---|
31 |
|
---|
32 | get type() {
|
---|
33 | return "harmony export specifier";
|
---|
34 | }
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Returns the exported names
|
---|
38 | * @param {ModuleGraph} moduleGraph module graph
|
---|
39 | * @returns {ExportsSpec | undefined} export names
|
---|
40 | */
|
---|
41 | getExports(moduleGraph) {
|
---|
42 | return {
|
---|
43 | exports: [this.name],
|
---|
44 | priority: 1,
|
---|
45 | terminalBinding: true,
|
---|
46 | dependencies: undefined
|
---|
47 | };
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * @param {ModuleGraph} moduleGraph the module graph
|
---|
52 | * @returns {ConnectionState} how this dependency connects the module to referencing modules
|
---|
53 | */
|
---|
54 | getModuleEvaluationSideEffectsState(moduleGraph) {
|
---|
55 | return false;
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * @param {ObjectSerializerContext} context context
|
---|
60 | */
|
---|
61 | serialize(context) {
|
---|
62 | const { write } = context;
|
---|
63 | write(this.id);
|
---|
64 | write(this.name);
|
---|
65 | super.serialize(context);
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * @param {ObjectDeserializerContext} context context
|
---|
70 | */
|
---|
71 | deserialize(context) {
|
---|
72 | const { read } = context;
|
---|
73 | this.id = read();
|
---|
74 | this.name = read();
|
---|
75 | super.deserialize(context);
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | makeSerializable(
|
---|
80 | HarmonyExportSpecifierDependency,
|
---|
81 | "webpack/lib/dependencies/HarmonyExportSpecifierDependency"
|
---|
82 | );
|
---|
83 |
|
---|
84 | HarmonyExportSpecifierDependency.Template = class HarmonyExportSpecifierDependencyTemplate extends (
|
---|
85 | NullDependency.Template
|
---|
86 | ) {
|
---|
87 | /**
|
---|
88 | * @param {Dependency} dependency the dependency for which the template should be applied
|
---|
89 | * @param {ReplaceSource} source the current replace source which can be modified
|
---|
90 | * @param {DependencyTemplateContext} templateContext the context object
|
---|
91 | * @returns {void}
|
---|
92 | */
|
---|
93 | apply(
|
---|
94 | dependency,
|
---|
95 | source,
|
---|
96 | { module, moduleGraph, initFragments, runtime, concatenationScope }
|
---|
97 | ) {
|
---|
98 | const dep = /** @type {HarmonyExportSpecifierDependency} */ (dependency);
|
---|
99 | if (concatenationScope) {
|
---|
100 | concatenationScope.registerExport(dep.name, dep.id);
|
---|
101 | return;
|
---|
102 | }
|
---|
103 | const used = moduleGraph
|
---|
104 | .getExportsInfo(module)
|
---|
105 | .getUsedName(dep.name, runtime);
|
---|
106 | if (!used) {
|
---|
107 | const set = new Set();
|
---|
108 | set.add(dep.name || "namespace");
|
---|
109 | initFragments.push(
|
---|
110 | new HarmonyExportInitFragment(module.exportsArgument, undefined, set)
|
---|
111 | );
|
---|
112 | return;
|
---|
113 | }
|
---|
114 |
|
---|
115 | const map = new Map();
|
---|
116 | map.set(used, `/* binding */ ${dep.id}`);
|
---|
117 | initFragments.push(
|
---|
118 | new HarmonyExportInitFragment(module.exportsArgument, map, undefined)
|
---|
119 | );
|
---|
120 | }
|
---|
121 | };
|
---|
122 |
|
---|
123 | module.exports = HarmonyExportSpecifierDependency;
|
---|