webpack 3.5.6 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/Module.js CHANGED
@@ -1,250 +1,250 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const util = require("util");
8
-
9
- const DependenciesBlock = require("./DependenciesBlock");
10
- const ModuleReason = require("./ModuleReason");
11
- const SortableSet = require("./util/SortableSet");
12
- const Template = require("./Template");
13
-
14
- let debugId = 1000;
15
-
16
- const sortById = (a, b) => {
17
- return a.id - b.id;
18
- };
19
-
20
- const sortByDebugId = (a, b) => {
21
- return a.debugId - b.debugId;
22
- };
23
-
24
- class Module extends DependenciesBlock {
25
-
26
- constructor() {
27
- super();
28
- this.context = null;
29
- this.reasons = [];
30
- this.debugId = debugId++;
31
- this.id = null;
32
- this.portableId = null;
33
- this.index = null;
34
- this.index2 = null;
35
- this.depth = null;
36
- this.used = null;
37
- this.usedExports = null;
38
- this.providedExports = null;
39
- this._chunks = new SortableSet(undefined, sortById);
40
- this._chunksDebugIdent = undefined;
41
- this.warnings = [];
42
- this.dependenciesWarnings = [];
43
- this.errors = [];
44
- this.dependenciesErrors = [];
45
- this.strict = false;
46
- this.meta = {};
47
- this.optimizationBailout = [];
48
- }
49
-
50
- disconnect() {
51
- this.reasons.length = 0;
52
- this.id = null;
53
- this.index = null;
54
- this.index2 = null;
55
- this.depth = null;
56
- this.used = null;
57
- this.usedExports = null;
58
- this.providedExports = null;
59
- this._chunks.clear();
60
- this._chunksDebugIdent = undefined;
61
- this.optimizationBailout.length = 0;
62
- super.disconnect();
63
- }
64
-
65
- unseal() {
66
- this.id = null;
67
- this.index = null;
68
- this.index2 = null;
69
- this.depth = null;
70
- this._chunks.clear();
71
- this._chunksDebugIdent = undefined;
72
- super.unseal();
73
- }
74
-
75
- setChunks(chunks) {
76
- this._chunks = new SortableSet(chunks, sortById);
77
- this._chunksDebugIdent = undefined;
78
- }
79
-
80
- addChunk(chunk) {
81
- this._chunks.add(chunk);
82
- this._chunksDebugIdent = undefined;
83
- }
84
-
85
- removeChunk(chunk) {
86
- if(this._chunks.delete(chunk)) {
87
- this._chunksDebugIdent = undefined;
88
- chunk.removeModule(this);
89
- return true;
90
- }
91
- return false;
92
- }
93
-
94
- isInChunk(chunk) {
95
- return this._chunks.has(chunk);
96
- }
97
-
98
- getChunkIdsIdent() {
99
- if(this._chunksDebugIdent !== undefined) return this._chunksDebugIdent;
100
- this._chunks.sortWith(sortByDebugId);
101
- const chunks = this._chunks;
102
- const list = [];
103
- for(const chunk of chunks) {
104
- const debugId = chunk.debugId;
105
-
106
- if(typeof debugId !== "number") {
107
- return this._chunksDebugIdent = null;
108
- }
109
-
110
- list.push(debugId);
111
- }
112
-
113
- return this._chunksDebugIdent = list.join(",");
114
- }
115
-
116
- forEachChunk(fn) {
117
- this._chunks.forEach(fn);
118
- }
119
-
120
- mapChunks(fn) {
121
- return Array.from(this._chunks, fn);
122
- }
123
-
124
- getChunks() {
125
- return Array.from(this._chunks);
126
- }
127
-
128
- getNumberOfChunks() {
129
- return this._chunks.size;
130
- }
131
-
132
- hasEqualsChunks(otherModule) {
133
- if(this._chunks.size !== otherModule._chunks.size) return false;
134
- this._chunks.sortWith(sortByDebugId);
135
- otherModule._chunks.sortWith(sortByDebugId);
136
- const a = this._chunks[Symbol.iterator]();
137
- const b = otherModule._chunks[Symbol.iterator]();
138
- while(true) { // eslint-disable-line
139
- const aItem = a.next();
140
- const bItem = b.next();
141
- if(aItem.done) return true;
142
- if(aItem.value !== bItem.value) return false;
143
- }
144
- }
145
-
146
- addReason(module, dependency) {
147
- this.reasons.push(new ModuleReason(module, dependency));
148
- }
149
-
150
- removeReason(module, dependency) {
151
- for(let i = 0; i < this.reasons.length; i++) {
152
- let r = this.reasons[i];
153
- if(r.module === module && r.dependency === dependency) {
154
- this.reasons.splice(i, 1);
155
- return true;
156
- }
157
- }
158
- return false;
159
- }
160
-
161
- hasReasonForChunk(chunk) {
162
- for(let i = 0; i < this.reasons.length; i++) {
163
- if(this.reasons[i].hasChunk(chunk))
164
- return true;
165
- }
166
- return false;
167
- }
168
-
169
- rewriteChunkInReasons(oldChunk, newChunks) {
170
- for(let i = 0; i < this.reasons.length; i++) {
171
- this.reasons[i].rewriteChunks(oldChunk, newChunks);
172
- }
173
- }
174
-
175
- isUsed(exportName) {
176
- if(this.used === null) return exportName;
177
- if(!exportName) return !!this.used;
178
- if(!this.used) return false;
179
- if(!this.usedExports) return false;
180
- if(this.usedExports === true) return exportName;
181
- let idx = this.usedExports.indexOf(exportName);
182
- if(idx < 0) return false;
183
- if(this.isProvided(exportName))
184
- return Template.numberToIdentifer(idx);
185
- return exportName;
186
- }
187
-
188
- isProvided(exportName) {
189
- if(!Array.isArray(this.providedExports))
190
- return null;
191
- return this.providedExports.indexOf(exportName) >= 0;
192
- }
193
-
194
- toString() {
195
- return `Module[${this.id || this.debugId}]`;
196
- }
197
-
198
- needRebuild(fileTimestamps, contextTimestamps) {
199
- return true;
200
- }
201
-
202
- updateHash(hash) {
203
- hash.update(this.id + "" + this.used);
204
- hash.update(JSON.stringify(this.usedExports));
205
- super.updateHash(hash);
206
- }
207
-
208
- sortItems(sortChunks) {
209
- super.sortItems();
210
- if(sortChunks)
211
- this._chunks.sort();
212
- this.reasons.sort((a, b) => sortById(a.module, b.module));
213
- if(Array.isArray(this.usedExports)) {
214
- this.usedExports.sort();
215
- }
216
- }
217
-
218
- unbuild() {
219
- this.disconnect();
220
- }
221
- }
222
-
223
- Object.defineProperty(Module.prototype, "entry", {
224
- configurable: false,
225
- get() {
226
- throw new Error("Module.entry was removed. Use Chunk.entryModule");
227
- },
228
- set() {
229
- throw new Error("Module.entry was removed. Use Chunk.entryModule");
230
- }
231
- });
232
-
233
- Object.defineProperty(Module.prototype, "chunks", {
234
- configurable: false,
235
- get: util.deprecate(function() {
236
- return Array.from(this._chunks);
237
- }, "Module.chunks: Use Module.forEachChunk/mapChunks/getNumberOfChunks/isInChunk/addChunk/removeChunk instead"),
238
- set() {
239
- throw new Error("Readonly. Use Module.addChunk/removeChunk to modify chunks.");
240
- }
241
- });
242
-
243
- Module.prototype.identifier = null;
244
- Module.prototype.readableIdentifier = null;
245
- Module.prototype.build = null;
246
- Module.prototype.source = null;
247
- Module.prototype.size = null;
248
- Module.prototype.nameForCondition = null;
249
-
250
- module.exports = Module;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const util = require("util");
8
+
9
+ const DependenciesBlock = require("./DependenciesBlock");
10
+ const ModuleReason = require("./ModuleReason");
11
+ const SortableSet = require("./util/SortableSet");
12
+ const Template = require("./Template");
13
+
14
+ let debugId = 1000;
15
+
16
+ const sortById = (a, b) => {
17
+ return a.id - b.id;
18
+ };
19
+
20
+ const sortByDebugId = (a, b) => {
21
+ return a.debugId - b.debugId;
22
+ };
23
+
24
+ class Module extends DependenciesBlock {
25
+
26
+ constructor() {
27
+ super();
28
+ this.context = null;
29
+ this.reasons = [];
30
+ this.debugId = debugId++;
31
+ this.id = null;
32
+ this.portableId = null;
33
+ this.index = null;
34
+ this.index2 = null;
35
+ this.depth = null;
36
+ this.used = null;
37
+ this.usedExports = null;
38
+ this.providedExports = null;
39
+ this._chunks = new SortableSet(undefined, sortById);
40
+ this._chunksDebugIdent = undefined;
41
+ this.warnings = [];
42
+ this.dependenciesWarnings = [];
43
+ this.errors = [];
44
+ this.dependenciesErrors = [];
45
+ this.strict = false;
46
+ this.meta = {};
47
+ this.optimizationBailout = [];
48
+ }
49
+
50
+ disconnect() {
51
+ this.reasons.length = 0;
52
+ this.id = null;
53
+ this.index = null;
54
+ this.index2 = null;
55
+ this.depth = null;
56
+ this.used = null;
57
+ this.usedExports = null;
58
+ this.providedExports = null;
59
+ this._chunks.clear();
60
+ this._chunksDebugIdent = undefined;
61
+ this.optimizationBailout.length = 0;
62
+ super.disconnect();
63
+ }
64
+
65
+ unseal() {
66
+ this.id = null;
67
+ this.index = null;
68
+ this.index2 = null;
69
+ this.depth = null;
70
+ this._chunks.clear();
71
+ this._chunksDebugIdent = undefined;
72
+ super.unseal();
73
+ }
74
+
75
+ setChunks(chunks) {
76
+ this._chunks = new SortableSet(chunks, sortById);
77
+ this._chunksDebugIdent = undefined;
78
+ }
79
+
80
+ addChunk(chunk) {
81
+ this._chunks.add(chunk);
82
+ this._chunksDebugIdent = undefined;
83
+ }
84
+
85
+ removeChunk(chunk) {
86
+ if(this._chunks.delete(chunk)) {
87
+ this._chunksDebugIdent = undefined;
88
+ chunk.removeModule(this);
89
+ return true;
90
+ }
91
+ return false;
92
+ }
93
+
94
+ isInChunk(chunk) {
95
+ return this._chunks.has(chunk);
96
+ }
97
+
98
+ getChunkIdsIdent() {
99
+ if(this._chunksDebugIdent !== undefined) return this._chunksDebugIdent;
100
+ this._chunks.sortWith(sortByDebugId);
101
+ const chunks = this._chunks;
102
+ const list = [];
103
+ for(const chunk of chunks) {
104
+ const debugId = chunk.debugId;
105
+
106
+ if(typeof debugId !== "number") {
107
+ return this._chunksDebugIdent = null;
108
+ }
109
+
110
+ list.push(debugId);
111
+ }
112
+
113
+ return this._chunksDebugIdent = list.join(",");
114
+ }
115
+
116
+ forEachChunk(fn) {
117
+ this._chunks.forEach(fn);
118
+ }
119
+
120
+ mapChunks(fn) {
121
+ return Array.from(this._chunks, fn);
122
+ }
123
+
124
+ getChunks() {
125
+ return Array.from(this._chunks);
126
+ }
127
+
128
+ getNumberOfChunks() {
129
+ return this._chunks.size;
130
+ }
131
+
132
+ hasEqualsChunks(otherModule) {
133
+ if(this._chunks.size !== otherModule._chunks.size) return false;
134
+ this._chunks.sortWith(sortByDebugId);
135
+ otherModule._chunks.sortWith(sortByDebugId);
136
+ const a = this._chunks[Symbol.iterator]();
137
+ const b = otherModule._chunks[Symbol.iterator]();
138
+ while(true) { // eslint-disable-line
139
+ const aItem = a.next();
140
+ const bItem = b.next();
141
+ if(aItem.done) return true;
142
+ if(aItem.value !== bItem.value) return false;
143
+ }
144
+ }
145
+
146
+ addReason(module, dependency) {
147
+ this.reasons.push(new ModuleReason(module, dependency));
148
+ }
149
+
150
+ removeReason(module, dependency) {
151
+ for(let i = 0; i < this.reasons.length; i++) {
152
+ let r = this.reasons[i];
153
+ if(r.module === module && r.dependency === dependency) {
154
+ this.reasons.splice(i, 1);
155
+ return true;
156
+ }
157
+ }
158
+ return false;
159
+ }
160
+
161
+ hasReasonForChunk(chunk) {
162
+ for(let i = 0; i < this.reasons.length; i++) {
163
+ if(this.reasons[i].hasChunk(chunk))
164
+ return true;
165
+ }
166
+ return false;
167
+ }
168
+
169
+ rewriteChunkInReasons(oldChunk, newChunks) {
170
+ for(let i = 0; i < this.reasons.length; i++) {
171
+ this.reasons[i].rewriteChunks(oldChunk, newChunks);
172
+ }
173
+ }
174
+
175
+ isUsed(exportName) {
176
+ if(this.used === null) return exportName;
177
+ if(!exportName) return !!this.used;
178
+ if(!this.used) return false;
179
+ if(!this.usedExports) return false;
180
+ if(this.usedExports === true) return exportName;
181
+ let idx = this.usedExports.indexOf(exportName);
182
+ if(idx < 0) return false;
183
+ if(this.isProvided(exportName))
184
+ return Template.numberToIdentifer(idx);
185
+ return exportName;
186
+ }
187
+
188
+ isProvided(exportName) {
189
+ if(!Array.isArray(this.providedExports))
190
+ return null;
191
+ return this.providedExports.indexOf(exportName) >= 0;
192
+ }
193
+
194
+ toString() {
195
+ return `Module[${this.id || this.debugId}]`;
196
+ }
197
+
198
+ needRebuild(fileTimestamps, contextTimestamps) {
199
+ return true;
200
+ }
201
+
202
+ updateHash(hash) {
203
+ hash.update(this.id + "" + this.used);
204
+ hash.update(JSON.stringify(this.usedExports));
205
+ super.updateHash(hash);
206
+ }
207
+
208
+ sortItems(sortChunks) {
209
+ super.sortItems();
210
+ if(sortChunks)
211
+ this._chunks.sort();
212
+ this.reasons.sort((a, b) => sortById(a.module, b.module));
213
+ if(Array.isArray(this.usedExports)) {
214
+ this.usedExports.sort();
215
+ }
216
+ }
217
+
218
+ unbuild() {
219
+ this.disconnect();
220
+ }
221
+ }
222
+
223
+ Object.defineProperty(Module.prototype, "entry", {
224
+ configurable: false,
225
+ get() {
226
+ throw new Error("Module.entry was removed. Use Chunk.entryModule");
227
+ },
228
+ set() {
229
+ throw new Error("Module.entry was removed. Use Chunk.entryModule");
230
+ }
231
+ });
232
+
233
+ Object.defineProperty(Module.prototype, "chunks", {
234
+ configurable: false,
235
+ get: util.deprecate(function() {
236
+ return Array.from(this._chunks);
237
+ }, "Module.chunks: Use Module.forEachChunk/mapChunks/getNumberOfChunks/isInChunk/addChunk/removeChunk instead"),
238
+ set() {
239
+ throw new Error("Readonly. Use Module.addChunk/removeChunk to modify chunks.");
240
+ }
241
+ });
242
+
243
+ Module.prototype.identifier = null;
244
+ Module.prototype.readableIdentifier = null;
245
+ Module.prototype.build = null;
246
+ Module.prototype.source = null;
247
+ Module.prototype.size = null;
248
+ Module.prototype.nameForCondition = null;
249
+
250
+ module.exports = Module;