1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const makeSerializable = require("../util/makeSerializable");
|
9 | const NullDependency = require("./NullDependency");
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | class ConstDependency extends NullDependency {
|
21 | |
22 |
|
23 |
|
24 |
|
25 |
|
26 | constructor(expression, range, runtimeRequirements) {
|
27 | super();
|
28 | this.expression = expression;
|
29 | this.range = range;
|
30 | this.runtimeRequirements = runtimeRequirements
|
31 | ? new Set(runtimeRequirements)
|
32 | : null;
|
33 | this._hashUpdate = undefined;
|
34 | }
|
35 |
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | updateHash(hash, context) {
|
43 | if (this._hashUpdate === undefined) {
|
44 | let hashUpdate = "" + this.range + "|" + this.expression;
|
45 | if (this.runtimeRequirements) {
|
46 | for (const item of this.runtimeRequirements) {
|
47 | hashUpdate += "|";
|
48 | hashUpdate += item;
|
49 | }
|
50 | }
|
51 | this._hashUpdate = hashUpdate;
|
52 | }
|
53 | hash.update(this._hashUpdate);
|
54 | }
|
55 |
|
56 | |
57 |
|
58 |
|
59 |
|
60 | getModuleEvaluationSideEffectsState(moduleGraph) {
|
61 | return false;
|
62 | }
|
63 |
|
64 | serialize(context) {
|
65 | const { write } = context;
|
66 | write(this.expression);
|
67 | write(this.range);
|
68 | write(this.runtimeRequirements);
|
69 | super.serialize(context);
|
70 | }
|
71 |
|
72 | deserialize(context) {
|
73 | const { read } = context;
|
74 | this.expression = read();
|
75 | this.range = read();
|
76 | this.runtimeRequirements = read();
|
77 | super.deserialize(context);
|
78 | }
|
79 | }
|
80 |
|
81 | makeSerializable(ConstDependency, "webpack/lib/dependencies/ConstDependency");
|
82 |
|
83 | ConstDependency.Template = class ConstDependencyTemplate extends (
|
84 | NullDependency.Template
|
85 | ) {
|
86 | |
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | apply(dependency, source, templateContext) {
|
93 | const dep = (dependency);
|
94 | if (dep.runtimeRequirements) {
|
95 | for (const req of dep.runtimeRequirements) {
|
96 | templateContext.runtimeRequirements.add(req);
|
97 | }
|
98 | }
|
99 | if (typeof dep.range === "number") {
|
100 | source.insert(dep.range, dep.expression);
|
101 | return;
|
102 | }
|
103 |
|
104 | source.replace(dep.range[0], dep.range[1] - 1, dep.expression);
|
105 | }
|
106 | };
|
107 |
|
108 | module.exports = ConstDependency;
|