1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const Dependency = require("../Dependency");
|
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 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | class ModuleDecoratorDependency extends NullDependency {
|
25 | |
26 |
|
27 |
|
28 |
|
29 | constructor(decorator, allowExportsAccess) {
|
30 | super();
|
31 | this.decorator = decorator;
|
32 | this.allowExportsAccess = allowExportsAccess;
|
33 | this._hashUpdate = undefined;
|
34 | }
|
35 |
|
36 | |
37 |
|
38 |
|
39 | get type() {
|
40 | return "module decorator";
|
41 | }
|
42 |
|
43 | get category() {
|
44 | return "self";
|
45 | }
|
46 |
|
47 | |
48 |
|
49 |
|
50 | getResourceIdentifier() {
|
51 | return `self`;
|
52 | }
|
53 |
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | getReferencedExports(moduleGraph, runtime) {
|
61 | return this.allowExportsAccess
|
62 | ? Dependency.EXPORTS_OBJECT_REFERENCED
|
63 | : Dependency.NO_EXPORTS_REFERENCED;
|
64 | }
|
65 |
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | updateHash(hash, context) {
|
73 | if (this._hashUpdate === undefined) {
|
74 | this._hashUpdate = `${this.decorator}${this.allowExportsAccess}`;
|
75 | }
|
76 | hash.update(this._hashUpdate);
|
77 | }
|
78 |
|
79 | serialize(context) {
|
80 | const { write } = context;
|
81 | write(this.decorator);
|
82 | write(this.allowExportsAccess);
|
83 | super.serialize(context);
|
84 | }
|
85 |
|
86 | deserialize(context) {
|
87 | const { read } = context;
|
88 | this.decorator = read();
|
89 | this.allowExportsAccess = read();
|
90 | super.deserialize(context);
|
91 | }
|
92 | }
|
93 |
|
94 | makeSerializable(
|
95 | ModuleDecoratorDependency,
|
96 | "webpack/lib/dependencies/ModuleDecoratorDependency"
|
97 | );
|
98 |
|
99 | ModuleDecoratorDependency.Template = class ModuleDecoratorDependencyTemplate extends (
|
100 | NullDependency.Template
|
101 | ) {
|
102 | |
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | apply(
|
109 | dependency,
|
110 | source,
|
111 | { module, chunkGraph, initFragments, runtimeRequirements }
|
112 | ) {
|
113 | const dep = (dependency);
|
114 | runtimeRequirements.add(RuntimeGlobals.moduleLoaded);
|
115 | runtimeRequirements.add(RuntimeGlobals.moduleId);
|
116 | runtimeRequirements.add(RuntimeGlobals.module);
|
117 | runtimeRequirements.add(dep.decorator);
|
118 | initFragments.push(
|
119 | new InitFragment(
|
120 | `/* module decorator */ ${module.moduleArgument} = ${dep.decorator}(${module.moduleArgument});\n`,
|
121 | InitFragment.STAGE_PROVIDES,
|
122 | 0,
|
123 | `module decorator ${chunkGraph.getModuleId(module)}`
|
124 | )
|
125 | );
|
126 | }
|
127 | };
|
128 |
|
129 | module.exports = ModuleDecoratorDependency;
|