1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const Dependency = require("../Dependency");
|
9 | const makeSerializable = require("../util/makeSerializable");
|
10 | const ModuleDependency = require("./ModuleDependency");
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | class ContextElementDependency extends ModuleDependency {
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | constructor(
|
26 | request,
|
27 | userRequest,
|
28 | typePrefix,
|
29 | category,
|
30 | referencedExports,
|
31 | context
|
32 | ) {
|
33 | super(request);
|
34 | this.referencedExports = referencedExports;
|
35 | this._typePrefix = typePrefix;
|
36 | this._category = category;
|
37 | this._context = context || undefined;
|
38 |
|
39 | if (userRequest) {
|
40 | this.userRequest = userRequest;
|
41 | }
|
42 | }
|
43 |
|
44 | get type() {
|
45 | if (this._typePrefix) {
|
46 | return `${this._typePrefix} context element`;
|
47 | }
|
48 |
|
49 | return "context element";
|
50 | }
|
51 |
|
52 | |
53 |
|
54 |
|
55 | getContext() {
|
56 | return this._context;
|
57 | }
|
58 |
|
59 | |
60 |
|
61 |
|
62 | getResourceIdentifier() {
|
63 | return `context${this._context || ""}|${super.getResourceIdentifier()}`;
|
64 | }
|
65 |
|
66 | get category() {
|
67 | return this._category;
|
68 | }
|
69 |
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | getReferencedExports(moduleGraph, runtime) {
|
77 | return this.referencedExports
|
78 | ? this.referencedExports.map(e => ({
|
79 | name: e,
|
80 | canMangle: false
|
81 | }))
|
82 | : Dependency.EXPORTS_OBJECT_REFERENCED;
|
83 | }
|
84 |
|
85 | serialize(context) {
|
86 | const { write } = context;
|
87 | write(this._typePrefix);
|
88 | write(this._category);
|
89 | write(this._context);
|
90 | write(this.referencedExports);
|
91 | super.serialize(context);
|
92 | }
|
93 |
|
94 | deserialize(context) {
|
95 | const { read } = context;
|
96 | this._typePrefix = read();
|
97 | this._category = read();
|
98 | this._context = read();
|
99 | this.referencedExports = read();
|
100 | super.deserialize(context);
|
101 | }
|
102 | }
|
103 |
|
104 | makeSerializable(
|
105 | ContextElementDependency,
|
106 | "webpack/lib/dependencies/ContextElementDependency"
|
107 | );
|
108 |
|
109 | module.exports = ContextElementDependency;
|