source: frontend/node_modules/webpack/lib/dependencies/HarmonyExportSpecifierDependency.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const makeSerializable = require("../util/makeSerializable");
9const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
10const 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/** @typedef {import("./HarmonyExportInitFragment").UnusedExports} UnusedExports */
21/** @typedef {import("./HarmonyExportInitFragment").ExportMap} ExportMap */
22
23class HarmonyExportSpecifierDependency extends NullDependency {
24 /**
25 * Creates an instance of HarmonyExportSpecifierDependency.
26 * @param {string} id the id
27 * @param {string} name the name
28 */
29 constructor(id, name) {
30 super();
31 this.id = id;
32 this.name = name;
33 }
34
35 get type() {
36 return "harmony export specifier";
37 }
38
39 /**
40 * Returns the exported names
41 * @param {ModuleGraph} moduleGraph module graph
42 * @returns {ExportsSpec | undefined} export names
43 */
44 getExports(moduleGraph) {
45 return {
46 exports: [this.name],
47 priority: 1,
48 terminalBinding: true,
49 dependencies: undefined
50 };
51 }
52
53 /**
54 * Gets module evaluation side effects state.
55 * @param {ModuleGraph} moduleGraph the module graph
56 * @returns {ConnectionState} how this dependency connects the module to referencing modules
57 */
58 getModuleEvaluationSideEffectsState(moduleGraph) {
59 return false;
60 }
61
62 /**
63 * Serializes this instance into the provided serializer context.
64 * @param {ObjectSerializerContext} context context
65 */
66 serialize(context) {
67 const { write } = context;
68 write(this.id);
69 write(this.name);
70 super.serialize(context);
71 }
72
73 /**
74 * Restores this instance from the provided deserializer context.
75 * @param {ObjectDeserializerContext} context context
76 */
77 deserialize(context) {
78 const { read } = context;
79 this.id = read();
80 this.name = read();
81 super.deserialize(context);
82 }
83}
84
85makeSerializable(
86 HarmonyExportSpecifierDependency,
87 "webpack/lib/dependencies/HarmonyExportSpecifierDependency"
88);
89
90HarmonyExportSpecifierDependency.Template = class HarmonyExportSpecifierDependencyTemplate extends (
91 NullDependency.Template
92) {
93 /**
94 * Applies the plugin by registering its hooks on the compiler.
95 * @param {Dependency} dependency the dependency for which the template should be applied
96 * @param {ReplaceSource} source the current replace source which can be modified
97 * @param {DependencyTemplateContext} templateContext the context object
98 * @returns {void}
99 */
100 apply(
101 dependency,
102 source,
103 { module, moduleGraph, initFragments, runtime, concatenationScope }
104 ) {
105 const dep = /** @type {HarmonyExportSpecifierDependency} */ (dependency);
106 if (concatenationScope) {
107 concatenationScope.registerExport(dep.name, dep.id);
108 return;
109 }
110 const used = moduleGraph
111 .getExportsInfo(module)
112 .getUsedName(dep.name, runtime);
113 if (!used) {
114 /** @type {UnusedExports} */
115 const set = new Set();
116 set.add(dep.name || "namespace");
117 initFragments.push(
118 new HarmonyExportInitFragment(module.exportsArgument, undefined, set)
119 );
120 return;
121 }
122
123 /** @type {ExportMap} */
124 const map = new Map();
125 map.set(used, `/* binding */ ${dep.id}`);
126 initFragments.push(
127 new HarmonyExportInitFragment(module.exportsArgument, map, undefined)
128 );
129 }
130};
131
132module.exports = HarmonyExportSpecifierDependency;
Note: See TracBrowser for help on using the repository browser.