webpack 3.5.2 → 3.5.6

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.
@@ -1,286 +1,285 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
- const NullDependency = require("./NullDependency");
7
- const HarmonyModulesHelpers = require("./HarmonyModulesHelpers");
8
-
9
- class HarmonyExportImportedSpecifierDependency extends NullDependency {
10
- constructor(originModule, importDependency, importedVar, id, name) {
11
- super();
12
- this.originModule = originModule;
13
- this.importDependency = importDependency;
14
- this.importedVar = importedVar;
15
- this.id = id;
16
- this.name = name;
17
- }
18
-
19
- get type() {
20
- return "harmony export imported specifier";
21
- }
22
-
23
- getReference() {
24
- const name = this.name;
25
- const used = this.originModule.isUsed(name);
26
- const active = HarmonyModulesHelpers.isActive(this.originModule, this);
27
- const importedModule = this.importDependency.module;
28
-
29
- if(!importedModule || !used || !active) return null;
30
- if(!this.originModule.usedExports) return null;
31
-
32
- if(name) {
33
- const nameIsNotInUsedExports = Array.isArray(this.originModule.usedExports) && this.originModule.usedExports.indexOf(name) < 0;
34
- if(nameIsNotInUsedExports) return null;
35
-
36
- // export { name as name }
37
- if(this.id) {
38
- return {
39
- module: importedModule,
40
- importedNames: [this.id]
41
- };
42
- }
43
-
44
- // export { * as name }
45
- return {
46
- module: importedModule,
47
- importedNames: true
48
- };
49
- }
50
-
51
- // export *
52
- if(Array.isArray(this.originModule.usedExports)) {
53
- // reexport * with known used exports
54
- var activeExports = HarmonyModulesHelpers.getActiveExports(this.originModule, this);
55
- if(Array.isArray(importedModule.providedExports)) {
56
- return {
57
- module: importedModule,
58
- importedNames: this.originModule.usedExports.filter((id) => {
59
- const notInActiveExports = activeExports.indexOf(id) < 0;
60
- const notDefault = id !== "default";
61
- const inProvidedExports = importedModule.providedExports.indexOf(id) >= 0;
62
- return notInActiveExports && notDefault && inProvidedExports;
63
- }),
64
- };
65
- }
66
-
67
- return {
68
- module: importedModule,
69
- importedNames: this.originModule.usedExports.filter(id => {
70
- const notInActiveExports = activeExports.indexOf(id) < 0;
71
- const notDefault = id !== "default";
72
- return notInActiveExports && notDefault;
73
- }),
74
- };
75
- }
76
-
77
- if(Array.isArray(importedModule.providedExports)) {
78
- return {
79
- module: importedModule,
80
- importedNames: importedModule.providedExports.filter(id => id !== "default"),
81
- };
82
- }
83
-
84
- return {
85
- module: importedModule,
86
- importedNames: true,
87
- };
88
- }
89
-
90
- getExports() {
91
- if(this.name) {
92
- return {
93
- exports: [this.name]
94
- };
95
- }
96
-
97
- const importedModule = this.importDependency.module;
98
-
99
- if(!importedModule) {
100
- // no imported module available
101
- return {
102
- exports: null
103
- };
104
- }
105
-
106
- if(Array.isArray(importedModule.providedExports)) {
107
- return {
108
- exports: importedModule.providedExports.filter(id => id !== "default"),
109
- dependencies: [importedModule]
110
- };
111
- }
112
-
113
- if(importedModule.providedExports) {
114
- return {
115
- exports: true
116
- };
117
- }
118
-
119
- return {
120
- exports: null,
121
- dependencies: [importedModule]
122
- };
123
- }
124
-
125
- describeHarmonyExport() {
126
- const importedModule = this.importDependency.module;
127
- if(!this.name && importedModule && Array.isArray(importedModule.providedExports)) {
128
- // for a star export and when we know which exports are provided, we can tell so
129
- return {
130
- exportedName: importedModule.providedExports,
131
- precedence: 3
132
- };
133
- }
134
-
135
- return {
136
- exportedName: this.name,
137
- precedence: this.name ? 2 : 3
138
- };
139
- }
140
-
141
- updateHash(hash) {
142
- super.updateHash(hash);
143
- const hashValue = this.getHashValue(this.importDependency.module);
144
- hash.update(hashValue);
145
- }
146
-
147
- getHashValue(importedModule) {
148
- if(!importedModule) {
149
- return "";
150
- }
151
-
152
- const stringifiedUsedExport = JSON.stringify(importedModule.usedExports);
153
- const stringifiedProvidedExport = JSON.stringify(importedModule.providedExports);
154
- return importedModule.used + stringifiedUsedExport + stringifiedProvidedExport;
155
- }
156
- }
157
-
158
- module.exports = HarmonyExportImportedSpecifierDependency;
159
-
160
- HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedSpecifierDependencyTemplate {
161
- apply(dep, source, outputOptions, requestShortener) {
162
- const content = this.getContent(dep);
163
- source.insert(-1, content);
164
- }
165
-
166
- getContent(dep) {
167
- const name = dep.importedVar;
168
- const used = dep.originModule.isUsed(dep.name);
169
- const importedModule = dep.importDependency.module;
170
- const active = HarmonyModulesHelpers.isActive(dep.originModule, dep);
171
- const importsExportsUnknown = !importedModule || !Array.isArray(importedModule.providedExports);
172
-
173
- const getReexportStatement = this.reexportStatementCreator(dep.originModule, importsExportsUnknown, name);
174
-
175
- // we want to rexport something, but the export isn't used
176
- if(!used) {
177
- return "/* unused harmony reexport " + dep.name + " */\n";
178
- }
179
-
180
- // we want to reexport something but another exports overrides this one
181
- if(!active) {
182
- return "/* inactive harmony reexport " + (dep.name || "namespace") + " */\n";
183
- }
184
-
185
- // we want to reexport the default export from a non-hamory module
186
- const isNotAHarmonyModule = !(importedModule && (!importedModule.meta || importedModule.meta.harmonyModule));
187
- if(dep.name && dep.id === "default" && isNotAHarmonyModule) {
188
- return "/* harmony reexport (default from non-hamory) */ " + getReexportStatement(JSON.stringify(used), null);
189
- }
190
-
191
- // we want to reexport a key as new key
192
- if(dep.name && dep.id) {
193
- var idUsed = importedModule && importedModule.isUsed(dep.id);
194
- return "/* harmony reexport (binding) */ " + getReexportStatement(JSON.stringify(used), JSON.stringify(idUsed));
195
- }
196
-
197
- // we want to reexport the module object as named export
198
- if(dep.name) {
199
- return "/* harmony reexport (module object) */ " + getReexportStatement(JSON.stringify(used), "");
200
- }
201
-
202
- // we know which exports are used
203
- if(Array.isArray(dep.originModule.usedExports)) {
204
- const activeExports = HarmonyModulesHelpers.getActiveExports(dep.originModule, dep);
205
- const items = dep.originModule.usedExports.map(function(id) {
206
- if(id === "default") return;
207
- if(activeExports.indexOf(id) >= 0) return;
208
- if(importedModule.isProvided(id) === false) return;
209
- var exportUsed = dep.originModule.isUsed(id);
210
- var idUsed = importedModule && importedModule.isUsed(id);
211
- return [exportUsed, idUsed];
212
- }).filter(Boolean);
213
-
214
- if(items.length === 0) {
215
- return "/* unused harmony namespace reexport */\n";
216
- }
217
-
218
- return items.map(function(item) {
219
- return "/* harmony namespace reexport (by used) */ " + getReexportStatement(JSON.stringify(item[0]), JSON.stringify(item[1]));
220
- }).join("");
221
- }
222
-
223
- // not sure which exports are used, but we know which are provided
224
- if(dep.originModule.usedExports && importedModule && Array.isArray(importedModule.providedExports)) {
225
- const activeExports = HarmonyModulesHelpers.getActiveExports(dep.originModule, dep);
226
- const items = importedModule.providedExports.map(function(id) {
227
- if(id === "default") return;
228
- if(activeExports.indexOf(id) >= 0) return;
229
- var exportUsed = dep.originModule.isUsed(id);
230
- var idUsed = importedModule && importedModule.isUsed(id);
231
- return [exportUsed, idUsed];
232
- }).filter(Boolean);
233
-
234
- if(items.length === 0) {
235
- return "/* empty harmony namespace reexport */\n";
236
- }
237
-
238
- return items.map(function(item) {
239
- return "/* harmony namespace reexport (by provided) */ " + getReexportStatement(JSON.stringify(item[0]), JSON.stringify(item[1]));
240
- }).join("");
241
- }
242
-
243
- // not sure which exports are used and provided
244
- if(dep.originModule.usedExports) {
245
- const activeExports = HarmonyModulesHelpers.getActiveExports(dep.originModule, dep);
246
- let content = "/* harmony namespace reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in " + name + ") ";
247
-
248
- // Filter out exports which are defined by other exports
249
- // and filter out default export because it cannot be reexported with *
250
- if(activeExports.length > 0)
251
- content += "if(" + JSON.stringify(activeExports.concat("default")) + ".indexOf(__WEBPACK_IMPORT_KEY__) < 0) ";
252
- else
253
- content += "if(__WEBPACK_IMPORT_KEY__ !== 'default') ";
254
- const exportsName = dep.originModule.exportsArgument || "exports";
255
- return content + `(function(key) { __webpack_require__.d(${exportsName}, key, function() { return ${name}[key]; }) }(__WEBPACK_IMPORT_KEY__));\n`;
256
- }
257
-
258
- return "/* unused harmony reexport namespace */\n";
259
- }
260
-
261
- reexportStatementCreator(module, importsExportsUnknown, name) {
262
- const exportsName = module.exportsArgument || "exports";
263
- const getReexportStatement = (key, valueKey) => {
264
- const conditional = this.getConditional(importsExportsUnknown, valueKey, name);
265
- const returnValue = this.getReturnValue(valueKey);
266
- return `${conditional}__webpack_require__.d(${exportsName}, ${key}, function() { return ${name}${returnValue}; });\n`;
267
- };
268
- return getReexportStatement;
269
- }
270
-
271
- getConditional(importsExportsUnknown, valueKey, name) {
272
- if(!importsExportsUnknown || !valueKey) {
273
- return "";
274
- }
275
-
276
- return `if(__webpack_require__.o(${name}, ${valueKey})) `;
277
- }
278
-
279
- getReturnValue(valueKey) {
280
- if(valueKey === null) {
281
- return "_default.a";
282
- }
283
-
284
- return valueKey && "[" + valueKey + "]";
285
- }
286
- };
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+ const NullDependency = require("./NullDependency");
7
+ const HarmonyModulesHelpers = require("./HarmonyModulesHelpers");
8
+
9
+ class HarmonyExportImportedSpecifierDependency extends NullDependency {
10
+ constructor(originModule, importDependency, importedVar, id, name) {
11
+ super();
12
+ this.originModule = originModule;
13
+ this.importDependency = importDependency;
14
+ this.importedVar = importedVar;
15
+ this.id = id;
16
+ this.name = name;
17
+ }
18
+
19
+ get type() {
20
+ return "harmony export imported specifier";
21
+ }
22
+
23
+ getReference() {
24
+ const name = this.name;
25
+ const used = this.originModule.isUsed(name);
26
+ const active = HarmonyModulesHelpers.isActive(this.originModule, this);
27
+ const importedModule = this.importDependency.module;
28
+
29
+ if(!importedModule || !used || !active || !this.originModule.usedExports) return null;
30
+
31
+ const hasUsedExports = Array.isArray(this.originModule.usedExports);
32
+
33
+ if(name) {
34
+ const nameIsNotInUsedExports = hasUsedExports && this.originModule.usedExports.indexOf(name) < 0;
35
+ if(nameIsNotInUsedExports) return null;
36
+
37
+ // export { name as name }
38
+ if(this.id) {
39
+ return {
40
+ module: importedModule,
41
+ importedNames: [this.id]
42
+ };
43
+ }
44
+
45
+ // export { * as name }
46
+ return {
47
+ module: importedModule,
48
+ importedNames: true
49
+ };
50
+ }
51
+
52
+ const hasProvidedExports = Array.isArray(importedModule.providedExports);
53
+
54
+ // export *
55
+ if(hasUsedExports) {
56
+ // reexport * with known used exports
57
+ const activeExports = HarmonyModulesHelpers.getActiveExports(this.originModule, this);
58
+ const importedNames = this.originModule.usedExports.filter(id => {
59
+ const notInActiveExports = activeExports.indexOf(id) < 0;
60
+ const notDefault = id !== "default";
61
+
62
+ if(hasProvidedExports) {
63
+ const inProvidedExports = importedModule.providedExports.indexOf(id) >= 0;
64
+ return notInActiveExports && notDefault && inProvidedExports;
65
+ } else {
66
+ return notInActiveExports && notDefault;
67
+ }
68
+ });
69
+
70
+ return {
71
+ module: importedModule,
72
+ importedNames
73
+ };
74
+ }
75
+
76
+ if(hasProvidedExports) {
77
+ return {
78
+ module: importedModule,
79
+ importedNames: importedModule.providedExports.filter(id => id !== "default"),
80
+ };
81
+ }
82
+
83
+ return {
84
+ module: importedModule,
85
+ importedNames: true,
86
+ };
87
+ }
88
+
89
+ getExports() {
90
+ if(this.name) {
91
+ return {
92
+ exports: [this.name]
93
+ };
94
+ }
95
+
96
+ const importedModule = this.importDependency.module;
97
+
98
+ if(!importedModule) {
99
+ // no imported module available
100
+ return {
101
+ exports: null
102
+ };
103
+ }
104
+
105
+ if(Array.isArray(importedModule.providedExports)) {
106
+ return {
107
+ exports: importedModule.providedExports.filter(id => id !== "default"),
108
+ dependencies: [importedModule]
109
+ };
110
+ }
111
+
112
+ if(importedModule.providedExports) {
113
+ return {
114
+ exports: true
115
+ };
116
+ }
117
+
118
+ return {
119
+ exports: null,
120
+ dependencies: [importedModule]
121
+ };
122
+ }
123
+
124
+ describeHarmonyExport() {
125
+ const importedModule = this.importDependency.module;
126
+ if(!this.name && importedModule && Array.isArray(importedModule.providedExports)) {
127
+ // for a star export and when we know which exports are provided, we can tell so
128
+ return {
129
+ exportedName: importedModule.providedExports,
130
+ precedence: 3
131
+ };
132
+ }
133
+
134
+ return {
135
+ exportedName: this.name,
136
+ precedence: this.name ? 2 : 3
137
+ };
138
+ }
139
+
140
+ updateHash(hash) {
141
+ super.updateHash(hash);
142
+ const hashValue = this.getHashValue(this.importDependency.module);
143
+ hash.update(hashValue);
144
+ }
145
+
146
+ getHashValue(importedModule) {
147
+ if(!importedModule) {
148
+ return "";
149
+ }
150
+
151
+ const stringifiedUsedExport = JSON.stringify(importedModule.usedExports);
152
+ const stringifiedProvidedExport = JSON.stringify(importedModule.providedExports);
153
+ return importedModule.used + stringifiedUsedExport + stringifiedProvidedExport;
154
+ }
155
+ }
156
+
157
+ module.exports = HarmonyExportImportedSpecifierDependency;
158
+
159
+ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedSpecifierDependencyTemplate {
160
+ apply(dep, source, outputOptions, requestShortener) {
161
+ const content = this.getContent(dep);
162
+ source.insert(-1, content);
163
+ }
164
+
165
+ getContent(dep) {
166
+ const name = dep.importedVar;
167
+ const used = dep.originModule.isUsed(dep.name);
168
+ const importedModule = dep.importDependency.module;
169
+ const active = HarmonyModulesHelpers.isActive(dep.originModule, dep);
170
+ const importsExportsUnknown = !importedModule || !Array.isArray(importedModule.providedExports);
171
+
172
+ const getReexportStatement = this.reexportStatementCreator(dep.originModule, importsExportsUnknown, name);
173
+
174
+ // we want to rexport something, but the export isn't used
175
+ if(!used) {
176
+ return "/* unused harmony reexport " + dep.name + " */\n";
177
+ }
178
+
179
+ // we want to reexport something but another exports overrides this one
180
+ if(!active) {
181
+ return "/* inactive harmony reexport " + (dep.name || "namespace") + " */\n";
182
+ }
183
+
184
+ // we want to reexport the default export from a non-hamory module
185
+ const isNotAHarmonyModule = !(importedModule && (!importedModule.meta || importedModule.meta.harmonyModule));
186
+ if(dep.name && dep.id === "default" && isNotAHarmonyModule) {
187
+ return "/* harmony reexport (default from non-hamory) */ " + getReexportStatement(JSON.stringify(used), null);
188
+ }
189
+
190
+ // we want to reexport a key as new key
191
+ if(dep.name && dep.id) {
192
+ var idUsed = importedModule && importedModule.isUsed(dep.id);
193
+ return "/* harmony reexport (binding) */ " + getReexportStatement(JSON.stringify(used), JSON.stringify(idUsed));
194
+ }
195
+
196
+ // we want to reexport the module object as named export
197
+ if(dep.name) {
198
+ return "/* harmony reexport (module object) */ " + getReexportStatement(JSON.stringify(used), "");
199
+ }
200
+
201
+ // we know which exports are used
202
+ if(Array.isArray(dep.originModule.usedExports)) {
203
+ const activeExports = HarmonyModulesHelpers.getActiveExports(dep.originModule, dep);
204
+ const items = dep.originModule.usedExports.map(function(id) {
205
+ if(id === "default") return;
206
+ if(activeExports.indexOf(id) >= 0) return;
207
+ if(importedModule.isProvided(id) === false) return;
208
+ var exportUsed = dep.originModule.isUsed(id);
209
+ var idUsed = importedModule && importedModule.isUsed(id);
210
+ return [exportUsed, idUsed];
211
+ }).filter(Boolean);
212
+
213
+ if(items.length === 0) {
214
+ return "/* unused harmony namespace reexport */\n";
215
+ }
216
+
217
+ return items.map(function(item) {
218
+ return "/* harmony namespace reexport (by used) */ " + getReexportStatement(JSON.stringify(item[0]), JSON.stringify(item[1]));
219
+ }).join("");
220
+ }
221
+
222
+ // not sure which exports are used, but we know which are provided
223
+ if(dep.originModule.usedExports && importedModule && Array.isArray(importedModule.providedExports)) {
224
+ const activeExports = HarmonyModulesHelpers.getActiveExports(dep.originModule, dep);
225
+ const items = importedModule.providedExports.map(function(id) {
226
+ if(id === "default") return;
227
+ if(activeExports.indexOf(id) >= 0) return;
228
+ var exportUsed = dep.originModule.isUsed(id);
229
+ var idUsed = importedModule && importedModule.isUsed(id);
230
+ return [exportUsed, idUsed];
231
+ }).filter(Boolean);
232
+
233
+ if(items.length === 0) {
234
+ return "/* empty harmony namespace reexport */\n";
235
+ }
236
+
237
+ return items.map(function(item) {
238
+ return "/* harmony namespace reexport (by provided) */ " + getReexportStatement(JSON.stringify(item[0]), JSON.stringify(item[1]));
239
+ }).join("");
240
+ }
241
+
242
+ // not sure which exports are used and provided
243
+ if(dep.originModule.usedExports) {
244
+ const activeExports = HarmonyModulesHelpers.getActiveExports(dep.originModule, dep);
245
+ let content = "/* harmony namespace reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in " + name + ") ";
246
+
247
+ // Filter out exports which are defined by other exports
248
+ // and filter out default export because it cannot be reexported with *
249
+ if(activeExports.length > 0)
250
+ content += "if(" + JSON.stringify(activeExports.concat("default")) + ".indexOf(__WEBPACK_IMPORT_KEY__) < 0) ";
251
+ else
252
+ content += "if(__WEBPACK_IMPORT_KEY__ !== 'default') ";
253
+ const exportsName = dep.originModule.exportsArgument || "exports";
254
+ return content + `(function(key) { __webpack_require__.d(${exportsName}, key, function() { return ${name}[key]; }) }(__WEBPACK_IMPORT_KEY__));\n`;
255
+ }
256
+
257
+ return "/* unused harmony reexport namespace */\n";
258
+ }
259
+
260
+ reexportStatementCreator(module, importsExportsUnknown, name) {
261
+ const exportsName = module.exportsArgument || "exports";
262
+ const getReexportStatement = (key, valueKey) => {
263
+ const conditional = this.getConditional(importsExportsUnknown, valueKey, name);
264
+ const returnValue = this.getReturnValue(valueKey);
265
+ return `${conditional}__webpack_require__.d(${exportsName}, ${key}, function() { return ${name}${returnValue}; });\n`;
266
+ };
267
+ return getReexportStatement;
268
+ }
269
+
270
+ getConditional(importsExportsUnknown, valueKey, name) {
271
+ if(!importsExportsUnknown || !valueKey) {
272
+ return "";
273
+ }
274
+
275
+ return `if(__webpack_require__.o(${name}, ${valueKey})) `;
276
+ }
277
+
278
+ getReturnValue(valueKey) {
279
+ if(valueKey === null) {
280
+ return "_default.a";
281
+ }
282
+
283
+ return valueKey && "[" + valueKey + "]";
284
+ }
285
+ };