webpack 5.3.2 → 5.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

package/bin/webpack.js CHANGED
File without changes
@@ -175,6 +175,7 @@ const { getRuntimeKey } = require("./util/runtime");
175
175
  /**
176
176
  * @typedef {Object} AssetInfo
177
177
  * @property {boolean=} immutable true, if the asset can be long term cached forever (contains a hash)
178
+ * @property {boolean=} minimized whether the asset is minimized
178
179
  * @property {string | string[]=} fullhash the value(s) of the full hash used for this asset
179
180
  * @property {string | string[]=} chunkhash the value(s) of the chunk hash used for this asset
180
181
  * @property {string | string[]=} modulehash the value(s) of the module hash used for this asset
@@ -553,18 +553,26 @@ class ContextModule extends Module {
553
553
  : "";
554
554
  }
555
555
 
556
- getReturn(type) {
556
+ getReturn(type, asyncModule) {
557
557
  if (type === 9) {
558
558
  return "__webpack_require__(id)";
559
559
  }
560
- return `${RuntimeGlobals.createFakeNamespaceObject}(id, ${type})`;
560
+ return `${RuntimeGlobals.createFakeNamespaceObject}(id, ${type}${
561
+ asyncModule ? " | 16" : ""
562
+ })`;
561
563
  }
562
564
 
563
- getReturnModuleObjectSource(fakeMap, fakeMapDataExpression = "fakeMap[id]") {
565
+ getReturnModuleObjectSource(
566
+ fakeMap,
567
+ asyncModule,
568
+ fakeMapDataExpression = "fakeMap[id]"
569
+ ) {
564
570
  if (typeof fakeMap === "number") {
565
571
  return `return ${this.getReturn(fakeMap)};`;
566
572
  }
567
- return `return ${RuntimeGlobals.createFakeNamespaceObject}(id, ${fakeMapDataExpression})`;
573
+ return `return ${
574
+ RuntimeGlobals.createFakeNamespaceObject
575
+ }(id, ${fakeMapDataExpression}${asyncModule ? " | 16" : ""})`;
568
576
  }
569
577
 
570
578
  /**
@@ -652,7 +660,7 @@ module.exports = webpackContext;`;
652
660
  const arrow = runtimeTemplate.supportsArrowFunction();
653
661
  const map = this.getUserRequestMap(dependencies, chunkGraph);
654
662
  const fakeMap = this.getFakeMap(dependencies, chunkGraph);
655
- const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
663
+ const returnModuleObject = this.getReturnModuleObjectSource(fakeMap, true);
656
664
 
657
665
  return `var map = ${JSON.stringify(map, null, "\t")};
658
666
  ${this.getFakeMapInitStatement(fakeMap)}
@@ -755,7 +763,7 @@ module.exports = webpackAsyncContext;`;
755
763
  const thenFunction =
756
764
  fakeMap !== 9
757
765
  ? `${arrow ? "id =>" : "function(id)"} {
758
- ${this.getReturnModuleObjectSource(fakeMap)};
766
+ ${this.getReturnModuleObjectSource(fakeMap, true)};
759
767
  }`
760
768
  : "__webpack_require__";
761
769
 
@@ -853,12 +861,13 @@ module.exports = webpackAsyncContext;`;
853
861
  : `${RuntimeGlobals.ensureChunk}(ids[${chunksStartPosition}])`;
854
862
  const returnModuleObject = this.getReturnModuleObjectSource(
855
863
  fakeMap,
864
+ true,
856
865
  shortMode ? "invalid" : "ids[1]"
857
866
  );
858
867
 
859
868
  const webpackAsyncContext =
860
869
  requestPrefix === "Promise.resolve()"
861
- ? `${shortMode ? "" : ""}
870
+ ? `
862
871
  function webpackAsyncContext(req) {
863
872
  return Promise.resolve().then(${arrow ? "() =>" : "function()"} {
864
873
  if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
@@ -1211,25 +1211,27 @@ class ExportInfo {
1211
1211
  * @param {ModuleGraph} moduleGraph the module graph
1212
1212
  * @param {function({ module: Module, export: string[] | undefined }): boolean} resolveTargetFilter filter function to further resolve target
1213
1213
  * @param {Set<ExportInfo> | undefined} alreadyVisited set of already visited export info to avoid circular references
1214
- * @returns {{ module: Module, export: string[] | undefined } | CIRCULAR | undefined} the target
1214
+ * @returns {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined } | CIRCULAR | undefined} the target
1215
1215
  */
1216
1216
  _getTarget(moduleGraph, resolveTargetFilter, alreadyVisited) {
1217
1217
  /**
1218
1218
  * @param {{ connection: ModuleGraphConnection, export: string[] | undefined } | null} inputTarget unresolved target
1219
1219
  * @param {Set<ExportInfo>} alreadyVisited set of already visited export info to avoid circular references
1220
- * @returns {{ module: Module, export: string[] | undefined } | CIRCULAR | null} resolved target
1220
+ * @returns {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined } | CIRCULAR | null} resolved target
1221
1221
  */
1222
1222
  const resolveTarget = (inputTarget, alreadyVisited) => {
1223
1223
  if (!inputTarget) return null;
1224
1224
  if (!inputTarget.export) {
1225
1225
  return {
1226
1226
  module: inputTarget.connection.module,
1227
+ connection: inputTarget.connection,
1227
1228
  export: undefined
1228
1229
  };
1229
1230
  }
1230
- /** @type {{ module: Module, export: string[] | undefined }} */
1231
+ /** @type {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined }} */
1231
1232
  let target = {
1232
1233
  module: inputTarget.connection.module,
1234
+ connection: inputTarget.connection,
1233
1235
  export: inputTarget.export
1234
1236
  };
1235
1237
  if (!resolveTargetFilter(target)) return target;
@@ -1252,6 +1254,7 @@ class ExportInfo {
1252
1254
  } else {
1253
1255
  target = {
1254
1256
  module: newTarget.module,
1257
+ connection: newTarget.connection,
1255
1258
  export: newTarget.export
1256
1259
  ? newTarget.export.concat(target.export.slice(1))
1257
1260
  : target.export.slice(1)
@@ -1290,6 +1293,24 @@ class ExportInfo {
1290
1293
  return target;
1291
1294
  }
1292
1295
 
1296
+ /**
1297
+ * Move the target forward as long resolveTargetFilter is fulfilled
1298
+ * @param {ModuleGraph} moduleGraph the module graph
1299
+ * @param {function({ module: Module, export: string[] | undefined }): boolean} resolveTargetFilter filter function to further resolve target
1300
+ * @returns {{ module: Module, export: string[] | undefined } | undefined} the target
1301
+ */
1302
+ moveTarget(moduleGraph, resolveTargetFilter) {
1303
+ const target = this._getTarget(moduleGraph, resolveTargetFilter, undefined);
1304
+ if (target === CIRCULAR) return undefined;
1305
+ if (!target) return undefined;
1306
+ this._target.clear();
1307
+ this._target.set(undefined, {
1308
+ connection: target.connection,
1309
+ export: target.export
1310
+ });
1311
+ return target;
1312
+ }
1313
+
1293
1314
  createNestedExportsInfo() {
1294
1315
  if (this.exportsInfoOwned) return this.exportsInfo;
1295
1316
  this.exportsInfoOwned = true;
package/lib/Module.js CHANGED
@@ -415,19 +415,20 @@ class Module extends DependenciesBlock {
415
415
  getExportsType(moduleGraph, strict) {
416
416
  switch (this.buildMeta && this.buildMeta.exportsType) {
417
417
  case "flagged":
418
- return strict ? "default-only" : "namespace";
418
+ return strict ? "default-with-named" : "namespace";
419
419
  case "namespace":
420
420
  return "namespace";
421
421
  case "default":
422
422
  switch (this.buildMeta.defaultObject) {
423
423
  case "redirect":
424
+ return "default-with-named";
424
425
  case "redirect-warn":
425
426
  return strict ? "default-only" : "default-with-named";
426
427
  default:
427
428
  return "default-only";
428
429
  }
429
430
  case "dynamic": {
430
- if (strict) return "default-only";
431
+ if (strict) return "default-with-named";
431
432
  // Try to figure out value of __esModule by following reexports
432
433
  const handleDefault = () => {
433
434
  switch (this.buildMeta.defaultObject) {
@@ -465,7 +466,7 @@ class Module extends DependenciesBlock {
465
466
  }
466
467
  }
467
468
  default:
468
- return strict ? "default-only" : "dynamic";
469
+ return strict ? "default-with-named" : "dynamic";
469
470
  }
470
471
  }
471
472
 
@@ -9,6 +9,7 @@ const createHash = require("./util/createHash");
9
9
 
10
10
  const ModuleFilenameHelpers = exports;
11
11
 
12
+ // TODO webpack 6: consider removing these
12
13
  ModuleFilenameHelpers.ALL_LOADERS_RESOURCE = "[all-loaders][resource]";
13
14
  ModuleFilenameHelpers.REGEXP_ALL_LOADERS_RESOURCE = /\[all-?loaders\]\[resource\]/gi;
14
15
  ModuleFilenameHelpers.LOADERS_RESOURCE = "[loaders][resource]";
@@ -57,6 +58,8 @@ const asRegExp = test => {
57
58
  return test;
58
59
  };
59
60
 
61
+ const REGEXP = /\[\\*([\w-]+)\\*\]/gi;
62
+
60
63
  ModuleFilenameHelpers.createFilename = (
61
64
  module,
62
65
  options,
@@ -92,6 +95,7 @@ ModuleFilenameHelpers.createFilename = (
92
95
  hash = getHash(identifier);
93
96
  }
94
97
  const resource = shortIdentifier.split("!").pop();
98
+
95
99
  const loaders = getBefore(shortIdentifier, "!");
96
100
  const allLoaders = getBefore(identifier, "!");
97
101
  const query = getAfter(resource, "?");
@@ -110,21 +114,58 @@ ModuleFilenameHelpers.createFilename = (
110
114
  namespace: opts.namespace
111
115
  });
112
116
  }
117
+
118
+ // TODO webpack 6: consider removing alternatives without dashes
119
+ /** @type {Map<string, string>} */
120
+ const replacements = new Map([
121
+ ["identifier", identifier],
122
+ ["short-identifier", shortIdentifier],
123
+ ["resource", resource],
124
+ ["resource-path", resourcePath],
125
+ // cSpell:words resourcepath
126
+ ["resourcepath", resourcePath],
127
+ ["absolute-resource-path", absoluteResourcePath],
128
+ ["abs-resource-path", absoluteResourcePath],
129
+ // cSpell:words absoluteresource
130
+ ["absoluteresource-path", absoluteResourcePath],
131
+ // cSpell:words absresource
132
+ ["absresource-path", absoluteResourcePath],
133
+ // cSpell:words resourcepath
134
+ ["absolute-resourcepath", absoluteResourcePath],
135
+ // cSpell:words resourcepath
136
+ ["abs-resourcepath", absoluteResourcePath],
137
+ // cSpell:words absoluteresourcepath
138
+ ["absoluteresourcepath", absoluteResourcePath],
139
+ // cSpell:words absresourcepath
140
+ ["absresourcepath", absoluteResourcePath],
141
+ ["all-loaders", allLoaders],
142
+ // cSpell:words allloaders
143
+ ["allloaders", allLoaders],
144
+ ["loaders", loaders],
145
+ ["query", query],
146
+ ["id", moduleId],
147
+ ["hash", hash],
148
+ ["namespace", opts.namespace]
149
+ ]);
150
+
151
+ // TODO webpack 6: consider removing weird double placeholders
113
152
  return opts.moduleFilenameTemplate
114
- .replace(ModuleFilenameHelpers.REGEXP_ALL_LOADERS_RESOURCE, identifier)
115
- .replace(ModuleFilenameHelpers.REGEXP_LOADERS_RESOURCE, shortIdentifier)
116
- .replace(ModuleFilenameHelpers.REGEXP_RESOURCE, resource)
117
- .replace(ModuleFilenameHelpers.REGEXP_RESOURCE_PATH, resourcePath)
153
+ .replace(ModuleFilenameHelpers.REGEXP_ALL_LOADERS_RESOURCE, "[identifier]")
118
154
  .replace(
119
- ModuleFilenameHelpers.REGEXP_ABSOLUTE_RESOURCE_PATH,
120
- absoluteResourcePath
155
+ ModuleFilenameHelpers.REGEXP_LOADERS_RESOURCE,
156
+ "[short-identifier]"
121
157
  )
122
- .replace(ModuleFilenameHelpers.REGEXP_ALL_LOADERS, allLoaders)
123
- .replace(ModuleFilenameHelpers.REGEXP_LOADERS, loaders)
124
- .replace(ModuleFilenameHelpers.REGEXP_QUERY, query)
125
- .replace(ModuleFilenameHelpers.REGEXP_ID, moduleId)
126
- .replace(ModuleFilenameHelpers.REGEXP_HASH, hash)
127
- .replace(ModuleFilenameHelpers.REGEXP_NAMESPACE, opts.namespace);
158
+ .replace(REGEXP, (match, content) => {
159
+ if (content.length + 2 === match.length) {
160
+ const replacement = replacements.get(content.toLowerCase());
161
+ if (replacement !== undefined) {
162
+ return replacement;
163
+ }
164
+ } else if (match.startsWith("[\\") && match.endsWith("\\]")) {
165
+ return `[${match.slice(2, -2)}]`;
166
+ }
167
+ return match;
168
+ });
128
169
  };
129
170
 
130
171
  ModuleFilenameHelpers.replaceDuplicates = (array, fn, comparator) => {
@@ -497,7 +497,7 @@ class RuntimeTemplate {
497
497
  weak
498
498
  });
499
499
  const exportsType = module.getExportsType(chunkGraph.moduleGraph, strict);
500
- let fakeType = 0;
500
+ let fakeType = 16;
501
501
  switch (exportsType) {
502
502
  case "namespace":
503
503
  if (header) {
@@ -745,6 +745,11 @@ class RuntimeTemplate {
745
745
  "/* non-default import from non-esm module */undefined" +
746
746
  propertyAccess(exportName, 1)
747
747
  );
748
+ } else if (
749
+ exportsType !== "namespace" &&
750
+ exportName[0] === "__esModule"
751
+ ) {
752
+ return "/* __esModule */true";
748
753
  }
749
754
  } else if (
750
755
  exportsType === "default-only" ||
@@ -124,7 +124,7 @@ class WebpackOptionsApply extends OptionsApply {
124
124
  }
125
125
  case "module":
126
126
  throw new Error(
127
- "EcmaScript Module CHunk Format is not implemented yet"
127
+ "EcmaScript Module Chunk Format is not implemented yet"
128
128
  );
129
129
  default:
130
130
  throw new Error(
@@ -75,29 +75,6 @@ const load = (input, context) => {
75
75
  * @returns {EcmaTargetProperties & PlatformTargetProperties & ApiTargetProperties} target properties
76
76
  */
77
77
  const resolve = browsers => {
78
- /**
79
- * Checks only browser against the browserslist feature query
80
- * @param {string} feature an ES feature to test
81
- * @returns {boolean} true if supports
82
- */
83
- const browserslistChecker = feature => {
84
- const supportsFeature = browserslist(`supports ${feature}`);
85
- return browsers.every(v => /^node /.test(v) || supportsFeature.includes(v));
86
- };
87
- /**
88
- * Checks only node.js version against a version
89
- * @param {number} major major version
90
- * @param {number} minor minor version
91
- * @returns {boolean} true if supports
92
- */
93
- const nodeChecker = (major, minor = 0) => {
94
- return browsers.every(v => {
95
- const match = /^node (\d+)(?:\.\d+)?/.exec(v);
96
- if (!match) return true;
97
- const [, v1, v2] = match;
98
- return major === +v1 ? +v2 >= minor : +v1 > major;
99
- });
100
- };
101
78
  /**
102
79
  * Checks all against a version number
103
80
  * @param {Record<string, number | [number, number]>} versions first supported version
@@ -105,50 +82,197 @@ const resolve = browsers => {
105
82
  */
106
83
  const rawChecker = versions => {
107
84
  return browsers.every(v => {
108
- const match = /^([^ ]+) (\d+)(?:\.\d+)?/.exec(v);
109
- if (!match) return false;
110
- const [, name, major, minor] = match;
111
- const version = versions[name];
112
- if (!version) return false;
113
- if (typeof version === "number") return +major >= version;
114
- return version[0] === +major ? +minor >= version[1] : +major > version[0];
85
+ const [name, parsedVersion] = v.split(" ");
86
+ if (!name) return false;
87
+ const requiredVersion = versions[name];
88
+ if (!requiredVersion) return false;
89
+ const [parsedMajor, parserMinor] =
90
+ // safari TP supports all features for normal safari
91
+ parsedVersion === "TP"
92
+ ? [Infinity, Infinity]
93
+ : parsedVersion.split(".");
94
+ if (typeof requiredVersion === "number") {
95
+ return +parsedMajor >= requiredVersion;
96
+ }
97
+ return requiredVersion[0] === +parsedMajor
98
+ ? +parserMinor >= requiredVersion[1]
99
+ : +parsedMajor > requiredVersion[0];
115
100
  });
116
101
  };
117
102
  const anyNode = browsers.some(b => /^node /.test(b));
118
103
  const anyBrowser = browsers.some(b => /^(?!node)/.test(b));
119
104
  const browserProperty = !anyBrowser ? false : anyNode ? null : true;
120
105
  const nodeProperty = !anyNode ? false : anyBrowser ? null : true;
121
- const es6 = browserslistChecker("es6");
122
- const letConst = browserslistChecker("let");
123
- const arrowFunctions = browserslistChecker("arrow-functions");
124
- const es6DynamicImport = browserslistChecker("es6-module-dynamic-import");
125
- const node6 = nodeChecker(6);
106
+ // Internet Explorer Mobile, Blackberry browser and Opera Mini are very old browsers, they do not support new features
107
+ const es6DynamicImport = rawChecker({
108
+ chrome: 63,
109
+ and_chr: 63,
110
+ edge: 79,
111
+ firefox: 67,
112
+ and_ff: 67,
113
+ // ie: Not supported
114
+ opera: 50,
115
+ op_mob: 46,
116
+ safari: [11, 1],
117
+ ios_saf: [11, 3],
118
+ samsung: [8, 2],
119
+ android: 63,
120
+ and_qq: [10, 4],
121
+ // baidu: Not supported
122
+ // and_uc: Not supported
123
+ // kaios: Not supported
124
+ // Since Node.js 13.14.0 no warning about usage, but it was added 8.5.0 with some limitations and it was improved in 12.0.0 and 13.2.0
125
+ node: [13, 14]
126
+ });
127
+
126
128
  return {
127
- const: letConst && node6,
128
- arrowFunction: arrowFunctions && node6,
129
- forOf: es6 && nodeChecker(5),
130
- destructuring: es6 && node6,
131
- bigIntLiteral: browserslistChecker("bigint") && nodeChecker(10, 4),
132
- module: browserslistChecker("es6-module") && nodeChecker(12, 17),
133
- dynamicImport: es6DynamicImport && nodeChecker(10, 17),
134
- dynamicImportInWorker: es6DynamicImport && nodeChecker(Infinity),
129
+ const: rawChecker({
130
+ chrome: 49,
131
+ and_chr: 49,
132
+ edge: 12,
133
+ // Prior to Firefox 13, <code>const</code> is implemented, but re-assignment is not failing.
134
+ // Prior to Firefox 46, a <code>TypeError</code> was thrown on redeclaration instead of a <code>SyntaxError</code>.
135
+ firefox: 36,
136
+ and_ff: 36,
137
+ // Not supported in for-in and for-of loops
138
+ // ie: Not supported
139
+ opera: 36,
140
+ op_mob: 36,
141
+ safari: [10, 0],
142
+ ios_saf: [10, 0],
143
+ // Before 5.0 supported correctly in strict mode, otherwise supported without block scope
144
+ samsung: [5, 0],
145
+ android: 37,
146
+ and_qq: [10, 4],
147
+ // Supported correctly in strict mode, otherwise supported without block scope
148
+ // baidu: Not supported
149
+ and_uc: [12, 12],
150
+ kaios: [2, 5],
151
+ node: [6, 0]
152
+ }),
153
+ arrowFunction: rawChecker({
154
+ chrome: 45,
155
+ and_chr: 45,
156
+ edge: 12,
157
+ // The initial implementation of arrow functions in Firefox made them automatically strict. This has been changed as of Firefox 24. The use of <code>'use strict';</code> is now required.
158
+ // Prior to Firefox 39, a line terminator (<code>\\n</code>) was incorrectly allowed after arrow function arguments. This has been fixed to conform to the ES2015 specification and code like <code>() \\n => {}</code> will now throw a <code>SyntaxError</code> in this and later versions.
159
+ firefox: 39,
160
+ and_ff: 39,
161
+ // ie: Not supported,
162
+ opera: 32,
163
+ op_mob: 32,
164
+ safari: 10,
165
+ ios_saf: 10,
166
+ samsung: [5, 0],
167
+ android: 45,
168
+ and_qq: [10, 4],
169
+ baidu: [7, 12],
170
+ and_uc: [12, 12],
171
+ kaios: [2, 5],
172
+ node: [6, 0]
173
+ }),
174
+ forOf: rawChecker({
175
+ chrome: 38,
176
+ and_chr: 38,
177
+ edge: 12,
178
+ // Prior to Firefox 51, using the for...of loop construct with the const keyword threw a SyntaxError ("missing = in const declaration").
179
+ firefox: 51,
180
+ and_ff: 51,
181
+ // ie: Not supported,
182
+ opera: 25,
183
+ op_mob: 25,
184
+ safari: 7,
185
+ ios_saf: 7,
186
+ samsung: [3, 0],
187
+ android: 38,
188
+ // and_qq: Unknown support
189
+ // baidu: Unknown support
190
+ // and_uc: Unknown support
191
+ // kaios: Unknown support
192
+ node: [0, 12]
193
+ }),
194
+ destructuring: rawChecker({
195
+ chrome: 49,
196
+ and_chr: 49,
197
+ edge: 14,
198
+ firefox: 41,
199
+ and_ff: 41,
200
+ // ie: Not supported,
201
+ opera: 36,
202
+ op_mob: 36,
203
+ safari: 8,
204
+ ios_saf: 8,
205
+ samsung: [5, 0],
206
+ android: 49,
207
+ // and_qq: Unknown support
208
+ // baidu: Unknown support
209
+ // and_uc: Unknown support
210
+ // kaios: Unknown support
211
+ node: [6, 0]
212
+ }),
213
+ bigIntLiteral: rawChecker({
214
+ chrome: 67,
215
+ and_chr: 67,
216
+ edge: 79,
217
+ firefox: 68,
218
+ and_ff: 68,
219
+ // ie: Not supported,
220
+ opera: 54,
221
+ op_mob: 48,
222
+ safari: 14,
223
+ ios_saf: 14,
224
+ samsung: [9, 2],
225
+ android: 67,
226
+ // and_qq: Not supported
227
+ // baidu: Not supported
228
+ // and_uc: Not supported
229
+ // kaios: Not supported
230
+ node: [10, 4]
231
+ }),
232
+ // Support syntax `import` and `export` and no limitations and bugs on Node.js
233
+ // Not include `export * as namespace`
234
+ module: rawChecker({
235
+ chrome: 61,
236
+ and_chr: 61,
237
+ edge: 16,
238
+ firefox: 60,
239
+ and_ff: 60,
240
+ // ie: Not supported,
241
+ opera: 48,
242
+ op_mob: 45,
243
+ safari: [10, 1],
244
+ ios_saf: [10, 3],
245
+ samsung: [8, 0],
246
+ android: 61,
247
+ and_qq: [10, 4],
248
+ // baidu: Not supported
249
+ // and_uc: Not supported
250
+ // kaios: Not supported
251
+ // Since Node.js 13.14.0 no warning about usage, but it was added 8.5.0 with some limitations and it was improved in 12.0.0 and 13.2.0
252
+ node: [13, 14]
253
+ }),
254
+ dynamicImport: es6DynamicImport,
255
+ dynamicImportInWorker: es6DynamicImport && !anyNode,
135
256
  // browserslist does not have info about globalThis
136
257
  // so this is based on mdn-browser-compat-data
137
258
  globalThis: rawChecker({
138
259
  chrome: 71,
139
- chrome_android: 71,
260
+ and_chr: 71,
140
261
  edge: 79,
141
262
  firefox: 65,
142
- firefox_android: 65,
263
+ and_ff: 65,
143
264
  // ie: Not supported,
144
- nodejs: 12,
145
265
  opera: 58,
146
- opera_android: 50,
266
+ op_mob: 50,
147
267
  safari: [12, 1],
148
- safari_ios: [12, 2],
149
- // cspell:word samsunginternet
150
- samsunginternet_android: [10, 0],
151
- webview_android: 71
268
+ ios_saf: [12, 2],
269
+ samsung: [10, 1],
270
+ android: 71,
271
+ // and_qq: Unknown support
272
+ // baidu: Unknown support
273
+ // and_uc: Unknown support
274
+ // kaios: Unknown support
275
+ node: [12, 0]
152
276
  }),
153
277
 
154
278
  browser: browserProperty,
@@ -100,7 +100,7 @@ class CommonJsExportsParserPlugin {
100
100
  const checkNamespace = (topLevel, members, valueExpr) => {
101
101
  if (!DynamicExports.isEnabled(parser.state)) return;
102
102
  if (members.length > 0 && members[0] === "__esModule") {
103
- if (isTruthyLiteral(valueExpr) && topLevel) {
103
+ if (valueExpr && isTruthyLiteral(valueExpr) && topLevel) {
104
104
  DynamicExports.setFlagged(parser.state);
105
105
  } else {
106
106
  DynamicExports.setDynamic(parser.state);
@@ -244,11 +244,6 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
244
244
  mode.fakeType = 2;
245
245
  break;
246
246
  case "dynamic":
247
- mode = new ExportMode("reexport-fake-namespace-object");
248
- mode.name = name;
249
- mode.partialNamespaceExportInfo = exportInfo;
250
- mode.fakeType = 6;
251
- break;
252
247
  default:
253
248
  mode = new ExportMode("reexport-namespace-object");
254
249
  mode.name = name;
@@ -109,52 +109,18 @@ class HarmonyImportDependency extends ModuleDependency {
109
109
  moduleGraph,
110
110
  parentModule.buildMeta.strictHarmonyModule
111
111
  );
112
- switch (exportsType) {
113
- case "default-only":
114
- // It's has only a default export
115
- if (ids.length > 0 && ids[0] !== "default") {
116
- // In strict harmony modules we only support the default export
117
- return [
118
- new HarmonyLinkingError(
119
- `Can't import the named export ${ids
120
- .map(id => `'${id}'`)
121
- .join(
122
- "."
123
- )} ${additionalMessage} from default-exporting module (only default export is available)`
124
- )
125
- ];
126
- }
127
- return;
128
- case "default-with-named":
129
- // It has a default export and named properties redirect
130
- // In some cases we still want to warn here
131
- if (
132
- ids.length > 0 &&
133
- ids[0] !== "default" &&
134
- importedModule.buildMeta.defaultObject === "redirect-warn"
135
- ) {
136
- // For these modules only the default export is supported
137
- return [
138
- new HarmonyLinkingError(
139
- `Should not import the named export ${ids
140
- .map(id => `'${id}'`)
141
- .join(
142
- "."
143
- )} ${additionalMessage} from default-exporting module (only default export is available soon)`
144
- )
145
- ];
146
- }
112
+ if (exportsType === "namespace" || exportsType === "default-with-named") {
113
+ if (ids.length === 0) {
147
114
  return;
148
- case "namespace": {
149
- if (ids.length === 0) {
150
- return;
151
- }
115
+ }
152
116
 
153
- if (moduleGraph.isExportProvided(importedModule, ids) !== false) {
154
- // It's provided or we are not sure
155
- return;
156
- }
117
+ if (
118
+ (exportsType !== "default-with-named" || ids[0] !== "default") &&
119
+ moduleGraph.isExportProvided(importedModule, ids) === false
120
+ ) {
121
+ // We are sure that it's not provided
157
122
 
123
+ // Try to provide detailed info in the error message
158
124
  let pos = 0;
159
125
  let exportsInfo = moduleGraph.getExportsInfo(importedModule);
160
126
  while (pos < ids.length && exportsInfo) {
@@ -180,7 +146,7 @@ class HarmonyImportDependency extends ModuleDependency {
180
146
  exportsInfo = exportInfo.getNestedExportsInfo();
181
147
  }
182
148
 
183
- // We are sure that it's not provided
149
+ // General error message
184
150
  return [
185
151
  new HarmonyLinkingError(
186
152
  `export ${ids
@@ -192,6 +158,43 @@ class HarmonyImportDependency extends ModuleDependency {
192
158
  ];
193
159
  }
194
160
  }
161
+ switch (exportsType) {
162
+ case "default-only":
163
+ // It's has only a default export
164
+ if (ids.length > 0 && ids[0] !== "default") {
165
+ // In strict harmony modules we only support the default export
166
+ return [
167
+ new HarmonyLinkingError(
168
+ `Can't import the named export ${ids
169
+ .map(id => `'${id}'`)
170
+ .join(
171
+ "."
172
+ )} ${additionalMessage} from default-exporting module (only default export is available)`
173
+ )
174
+ ];
175
+ }
176
+ break;
177
+ case "default-with-named":
178
+ // It has a default export and named properties redirect
179
+ // In some cases we still want to warn here
180
+ if (
181
+ ids.length > 0 &&
182
+ ids[0] !== "default" &&
183
+ importedModule.buildMeta.defaultObject === "redirect-warn"
184
+ ) {
185
+ // For these modules only the default export is supported
186
+ return [
187
+ new HarmonyLinkingError(
188
+ `Should not import the named export ${ids
189
+ .map(id => `'${id}'`)
190
+ .join(
191
+ "."
192
+ )} ${additionalMessage} from default-exporting module (only default export is available soon)`
193
+ )
194
+ ];
195
+ }
196
+ break;
197
+ }
195
198
  }
196
199
 
197
200
  /**
@@ -59,9 +59,13 @@ module.exports = class HarmonyImportDependencyParserPlugin {
59
59
  (statement, source) => {
60
60
  parser.state.lastHarmonyImportOrder =
61
61
  (parser.state.lastHarmonyImportOrder || 0) + 1;
62
- const clearDep = new ConstDependency("", statement.range);
62
+ const clearDep = new ConstDependency(
63
+ parser.isAsiPosition(statement.range[0]) ? ";" : "",
64
+ statement.range
65
+ );
63
66
  clearDep.loc = statement.loc;
64
67
  parser.state.module.addPresentationalDependency(clearDep);
68
+ parser.unsetAsiPosition(statement.range[1]);
65
69
  const sideEffectDep = new HarmonyImportSideEffectDependency(
66
70
  source,
67
71
  parser.state.lastHarmonyImportOrder
@@ -1405,7 +1405,11 @@ class JavascriptParser extends Parser {
1405
1405
  }
1406
1406
 
1407
1407
  preWalkStatement(statement) {
1408
- if (this.hooks.preStatement.call(statement)) return;
1408
+ this.statementPath.push(statement);
1409
+ if (this.hooks.preStatement.call(statement)) {
1410
+ this.prevStatement = this.statementPath.pop();
1411
+ return;
1412
+ }
1409
1413
  switch (statement.type) {
1410
1414
  case "BlockStatement":
1411
1415
  this.preWalkBlockStatement(statement);
@@ -1447,10 +1451,15 @@ class JavascriptParser extends Parser {
1447
1451
  this.preWalkWithStatement(statement);
1448
1452
  break;
1449
1453
  }
1454
+ this.prevStatement = this.statementPath.pop();
1450
1455
  }
1451
1456
 
1452
1457
  blockPreWalkStatement(statement) {
1453
- if (this.hooks.blockPreStatement.call(statement)) return;
1458
+ this.statementPath.push(statement);
1459
+ if (this.hooks.blockPreStatement.call(statement)) {
1460
+ this.prevStatement = this.statementPath.pop();
1461
+ return;
1462
+ }
1454
1463
  switch (statement.type) {
1455
1464
  case "ImportDeclaration":
1456
1465
  this.blockPreWalkImportDeclaration(statement);
@@ -1471,6 +1480,7 @@ class JavascriptParser extends Parser {
1471
1480
  this.blockPreWalkClassDeclaration(statement);
1472
1481
  break;
1473
1482
  }
1483
+ this.prevStatement = this.statementPath.pop();
1474
1484
  }
1475
1485
 
1476
1486
  walkStatement(statement) {
@@ -1549,7 +1559,9 @@ class JavascriptParser extends Parser {
1549
1559
  walkBlockStatement(statement) {
1550
1560
  this.inBlockScope(() => {
1551
1561
  const body = statement.body;
1562
+ const prev = this.prevStatement;
1552
1563
  this.blockPreWalkStatements(body);
1564
+ this.prevStatement = prev;
1553
1565
  this.walkStatements(body);
1554
1566
  });
1555
1567
  }
@@ -1689,7 +1701,9 @@ class JavascriptParser extends Parser {
1689
1701
  const body = statement.body;
1690
1702
  if (body.type === "BlockStatement") {
1691
1703
  // no need to add additional scope
1704
+ const prev = this.prevStatement;
1692
1705
  this.blockPreWalkStatements(body.body);
1706
+ this.prevStatement = prev;
1693
1707
  this.walkStatements(body.body);
1694
1708
  } else {
1695
1709
  this.walkStatement(body);
@@ -1716,7 +1730,9 @@ class JavascriptParser extends Parser {
1716
1730
  const body = statement.body;
1717
1731
  if (body.type === "BlockStatement") {
1718
1732
  // no need to add additional scope
1733
+ const prev = this.prevStatement;
1719
1734
  this.blockPreWalkStatements(body.body);
1735
+ this.prevStatement = prev;
1720
1736
  this.walkStatements(body.body);
1721
1737
  } else {
1722
1738
  this.walkStatement(body);
@@ -1746,7 +1762,9 @@ class JavascriptParser extends Parser {
1746
1762
  const body = statement.body;
1747
1763
  if (body.type === "BlockStatement") {
1748
1764
  // no need to add additional scope
1765
+ const prev = this.prevStatement;
1749
1766
  this.blockPreWalkStatements(body.body);
1767
+ this.prevStatement = prev;
1750
1768
  this.walkStatements(body.body);
1751
1769
  } else {
1752
1770
  this.walkStatement(body);
@@ -1770,7 +1788,9 @@ class JavascriptParser extends Parser {
1770
1788
  }
1771
1789
  if (statement.body.type === "BlockStatement") {
1772
1790
  this.detectMode(statement.body.body);
1791
+ const prev = this.prevStatement;
1773
1792
  this.preWalkStatement(statement.body);
1793
+ this.prevStatement = prev;
1774
1794
  this.walkStatement(statement.body);
1775
1795
  } else {
1776
1796
  this.walkExpression(statement.body);
@@ -1848,7 +1868,9 @@ class JavascriptParser extends Parser {
1848
1868
  if (
1849
1869
  !this.hooks.exportDeclaration.call(statement, statement.declaration)
1850
1870
  ) {
1871
+ const prev = this.prevStatement;
1851
1872
  this.preWalkStatement(statement.declaration);
1873
+ this.prevStatement = prev;
1852
1874
  this.blockPreWalkStatement(statement.declaration);
1853
1875
  let index = 0;
1854
1876
  this.enterDeclaration(statement.declaration, def => {
@@ -1896,7 +1918,9 @@ class JavascriptParser extends Parser {
1896
1918
  }
1897
1919
 
1898
1920
  blockPreWalkExportDefaultDeclaration(statement) {
1921
+ const prev = this.prevStatement;
1899
1922
  this.preWalkStatement(statement.declaration);
1923
+ this.prevStatement = prev;
1900
1924
  this.blockPreWalkStatement(statement.declaration);
1901
1925
  if (
1902
1926
  statement.declaration.id &&
@@ -2049,7 +2073,9 @@ class JavascriptParser extends Parser {
2049
2073
  const switchCase = switchCases[index];
2050
2074
 
2051
2075
  if (switchCase.consequent.length > 0) {
2076
+ const prev = this.prevStatement;
2052
2077
  this.blockPreWalkStatements(switchCase.consequent);
2078
+ this.prevStatement = prev;
2053
2079
  }
2054
2080
  }
2055
2081
 
@@ -2079,7 +2105,9 @@ class JavascriptParser extends Parser {
2079
2105
  });
2080
2106
  this.walkPattern(catchClause.param);
2081
2107
  }
2108
+ const prev = this.prevStatement;
2082
2109
  this.blockPreWalkStatement(catchClause.body);
2110
+ this.prevStatement = prev;
2083
2111
  this.walkStatement(catchClause.body);
2084
2112
  });
2085
2113
  }
@@ -2276,7 +2304,9 @@ class JavascriptParser extends Parser {
2276
2304
  }
2277
2305
  if (expression.body.type === "BlockStatement") {
2278
2306
  this.detectMode(expression.body.body);
2307
+ const prev = this.prevStatement;
2279
2308
  this.preWalkStatement(expression.body);
2309
+ this.prevStatement = prev;
2280
2310
  this.walkStatement(expression.body);
2281
2311
  } else {
2282
2312
  this.walkExpression(expression.body);
@@ -2294,7 +2324,9 @@ class JavascriptParser extends Parser {
2294
2324
  }
2295
2325
  if (expression.body.type === "BlockStatement") {
2296
2326
  this.detectMode(expression.body.body);
2327
+ const prev = this.prevStatement;
2297
2328
  this.preWalkStatement(expression.body);
2329
+ this.prevStatement = prev;
2298
2330
  this.walkStatement(expression.body);
2299
2331
  } else {
2300
2332
  this.walkExpression(expression.body);
@@ -2561,7 +2593,9 @@ class JavascriptParser extends Parser {
2561
2593
  }
2562
2594
  if (functionExpression.body.type === "BlockStatement") {
2563
2595
  this.detectMode(functionExpression.body.body);
2596
+ const prev = this.prevStatement;
2564
2597
  this.preWalkStatement(functionExpression.body);
2598
+ this.prevStatement = prev;
2565
2599
  this.walkStatement(functionExpression.body);
2566
2600
  } else {
2567
2601
  this.walkExpression(functionExpression.body);
@@ -3224,7 +3258,9 @@ class JavascriptParser extends Parser {
3224
3258
  if (this.hooks.program.call(ast, comments) === undefined) {
3225
3259
  this.detectMode(ast.body);
3226
3260
  this.preWalkStatements(ast.body);
3261
+ this.prevStatement = undefined;
3227
3262
  this.blockPreWalkStatements(ast.body);
3263
+ this.prevStatement = undefined;
3228
3264
  this.walkStatements(ast.body);
3229
3265
  }
3230
3266
  this.hooks.finish.call(ast, comments);
@@ -3337,14 +3373,24 @@ class JavascriptParser extends Parser {
3337
3373
  * @returns {boolean} true when a semicolon has been inserted before this position, false if not
3338
3374
  */
3339
3375
  isAsiPosition(pos) {
3340
- if (this.prevStatement === undefined) return false;
3341
3376
  const currentStatement = this.statementPath[this.statementPath.length - 1];
3377
+ if (currentStatement === undefined) throw new Error("Not in statement");
3342
3378
  return (
3343
- currentStatement.range[0] === pos &&
3344
- this.semicolons.has(this.prevStatement.range[1])
3379
+ (currentStatement.range[1] === pos && this.semicolons.has(pos)) ||
3380
+ (currentStatement.range[0] === pos &&
3381
+ this.prevStatement !== undefined &&
3382
+ this.semicolons.has(this.prevStatement.range[1]))
3345
3383
  );
3346
3384
  }
3347
3385
 
3386
+ /**
3387
+ * @param {number} pos source code position
3388
+ * @returns {void}
3389
+ */
3390
+ unsetAsiPosition(pos) {
3391
+ this.semicolons.delete(pos);
3392
+ }
3393
+
3348
3394
  isStatementLevelExpression(expr) {
3349
3395
  const currentStatement = this.statementPath[this.statementPath.length - 1];
3350
3396
  return (
@@ -104,6 +104,8 @@ const {
104
104
  * @property {string} namespaceObjectName
105
105
  * @property {boolean} interopNamespaceObjectUsed
106
106
  * @property {string} interopNamespaceObjectName
107
+ * @property {boolean} interopNamespaceObject2Used
108
+ * @property {string} interopNamespaceObject2Name
107
109
  * @property {boolean} interopDefaultAccessUsed
108
110
  * @property {string} interopDefaultAccessName
109
111
  */
@@ -117,6 +119,8 @@ const {
117
119
  * @property {string} name
118
120
  * @property {boolean} interopNamespaceObjectUsed
119
121
  * @property {string} interopNamespaceObjectName
122
+ * @property {boolean} interopNamespaceObject2Used
123
+ * @property {string} interopNamespaceObject2Name
120
124
  * @property {boolean} interopDefaultAccessUsed
121
125
  * @property {string} interopDefaultAccessName
122
126
  */
@@ -241,6 +245,13 @@ const getFinalBinding = (
241
245
  if (exportName.length === 0) {
242
246
  switch (exportsType) {
243
247
  case "default-only":
248
+ info.interopNamespaceObject2Used = true;
249
+ return {
250
+ info,
251
+ rawName: info.interopNamespaceObject2Name,
252
+ ids: exportName,
253
+ exportName
254
+ };
244
255
  case "default-with-named":
245
256
  info.interopNamespaceObjectUsed = true;
246
257
  return {
@@ -260,12 +271,29 @@ const getFinalBinding = (
260
271
  case "namespace":
261
272
  break;
262
273
  case "default-with-named":
263
- if (exportName[0] === "default") {
264
- exportName = exportName.slice(1);
274
+ switch (exportName[0]) {
275
+ case "default":
276
+ exportName = exportName.slice(1);
277
+ break;
278
+ case "__esModule":
279
+ return {
280
+ info,
281
+ rawName: "/* __esModule */true",
282
+ ids: exportName.slice(1),
283
+ exportName
284
+ };
265
285
  }
266
286
  break;
267
287
  case "default-only": {
268
288
  const exportId = exportName[0];
289
+ if (exportId === "__esModule") {
290
+ return {
291
+ info,
292
+ rawName: "/* __esModule */true",
293
+ ids: exportName.slice(1),
294
+ exportName
295
+ };
296
+ }
269
297
  exportName = exportName.slice(1);
270
298
  if (exportId !== "default") {
271
299
  return {
@@ -279,22 +307,31 @@ const getFinalBinding = (
279
307
  break;
280
308
  }
281
309
  case "dynamic":
282
- if (exportName[0] === "default") {
283
- exportName = exportName.slice(1);
284
- info.interopDefaultAccessUsed = true;
285
- const defaultExport = asCall
286
- ? `${info.interopDefaultAccessName}()`
287
- : asiSafe
288
- ? `(${info.interopDefaultAccessName}())`
289
- : asiSafe === false
290
- ? `;(${info.interopDefaultAccessName}())`
291
- : `${info.interopDefaultAccessName}.a`;
292
- return {
293
- info,
294
- rawName: defaultExport,
295
- ids: exportName,
296
- exportName
297
- };
310
+ switch (exportName[0]) {
311
+ case "default": {
312
+ exportName = exportName.slice(1);
313
+ info.interopDefaultAccessUsed = true;
314
+ const defaultExport = asCall
315
+ ? `${info.interopDefaultAccessName}()`
316
+ : asiSafe
317
+ ? `(${info.interopDefaultAccessName}())`
318
+ : asiSafe === false
319
+ ? `;(${info.interopDefaultAccessName}())`
320
+ : `${info.interopDefaultAccessName}.a`;
321
+ return {
322
+ info,
323
+ rawName: defaultExport,
324
+ ids: exportName,
325
+ exportName
326
+ };
327
+ }
328
+ case "__esModule":
329
+ return {
330
+ info,
331
+ rawName: "/* __esModule */true",
332
+ ids: exportName.slice(1),
333
+ exportName
334
+ };
298
335
  }
299
336
  break;
300
337
  default:
@@ -1045,16 +1082,20 @@ class ConcatenatedModule extends Module {
1045
1082
  // get all global names
1046
1083
  for (const info of modulesWithInfo) {
1047
1084
  if (info.type === "concatenated") {
1048
- const superClassExpressions = [];
1049
-
1050
1085
  // ignore symbols from moduleScope
1051
1086
  if (info.moduleScope) {
1052
1087
  ignoredScopes.add(info.moduleScope);
1088
+ }
1053
1089
 
1054
- // The super class expression in class scopes behaves weird
1055
- // We store ranges of all super class expressions to make
1056
- // renaming to work correctly
1057
- for (const childScope of info.moduleScope.childScopes) {
1090
+ // The super class expression in class scopes behaves weird
1091
+ // We get ranges of all super class expressions to make
1092
+ // renaming to work correctly
1093
+ const superClassCache = new WeakMap();
1094
+ const getSuperClassExpressions = scope => {
1095
+ const cacheEntry = superClassCache.get(scope);
1096
+ if (cacheEntry !== undefined) return cacheEntry;
1097
+ const superClassExpressions = [];
1098
+ for (const childScope of scope.childScopes) {
1058
1099
  if (childScope.type !== "class") continue;
1059
1100
  const block = childScope.block;
1060
1101
  if (
@@ -1068,7 +1109,9 @@ class ConcatenatedModule extends Module {
1068
1109
  });
1069
1110
  }
1070
1111
  }
1071
- }
1112
+ superClassCache.set(scope, superClassExpressions);
1113
+ return superClassExpressions;
1114
+ };
1072
1115
 
1073
1116
  // add global symbols
1074
1117
  if (info.globalScope) {
@@ -1101,7 +1144,7 @@ class ConcatenatedModule extends Module {
1101
1144
  binding.info.module.identifier(),
1102
1145
  "name" in binding ? binding.name : ""
1103
1146
  );
1104
- for (const expr of superClassExpressions) {
1147
+ for (const expr of getSuperClassExpressions(reference.from)) {
1105
1148
  if (
1106
1149
  expr.range[0] <= reference.identifier.range[0] &&
1107
1150
  expr.range[1] >= reference.identifier.range[1]
@@ -1209,12 +1252,7 @@ class ConcatenatedModule extends Module {
1209
1252
  break;
1210
1253
  }
1211
1254
  }
1212
- if (
1213
- info.module.buildMeta.exportsType === "default" ||
1214
- info.module.buildMeta.exportsType === "flagged" ||
1215
- info.module.buildMeta.exportsType === "dynamic" ||
1216
- !info.module.buildMeta.exportsType
1217
- ) {
1255
+ if (info.module.buildMeta.exportsType !== "namespace") {
1218
1256
  const externalNameInterop = this.findNewName(
1219
1257
  "namespaceObject",
1220
1258
  allUsedNames,
@@ -1224,6 +1262,19 @@ class ConcatenatedModule extends Module {
1224
1262
  allUsedNames.add(externalNameInterop);
1225
1263
  info.interopNamespaceObjectName = externalNameInterop;
1226
1264
  }
1265
+ if (
1266
+ info.module.buildMeta.exportsType === "default" &&
1267
+ info.module.buildMeta.defaultObject !== "redirect"
1268
+ ) {
1269
+ const externalNameInterop = this.findNewName(
1270
+ "namespaceObject2",
1271
+ allUsedNames,
1272
+ namespaceObjectUsedNames,
1273
+ info.module.readableIdentifier(requestShortener)
1274
+ );
1275
+ allUsedNames.add(externalNameInterop);
1276
+ info.interopNamespaceObject2Name = externalNameInterop;
1277
+ }
1227
1278
  if (
1228
1279
  info.module.buildMeta.exportsType === "dynamic" ||
1229
1280
  !info.module.buildMeta.exportsType
@@ -1425,7 +1476,7 @@ ${defineGetters}`
1425
1476
  switch (info.type) {
1426
1477
  case "concatenated": {
1427
1478
  result.add(
1428
- `\n// CONCATENATED MODULE: ${info.module.readableIdentifier(
1479
+ `\n;// CONCATENATED MODULE: ${info.module.readableIdentifier(
1429
1480
  requestShortener
1430
1481
  )}\n`
1431
1482
  );
@@ -1471,21 +1522,16 @@ ${defineGetters}`
1471
1522
  throw new Error(`Unsupported concatenation entry type ${info.type}`);
1472
1523
  }
1473
1524
  if (info.interopNamespaceObjectUsed) {
1474
- if (info.module.buildMeta.exportsType === "default") {
1475
- runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
1476
- result.add(
1477
- `\nvar ${info.interopNamespaceObjectName} = /*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${name}, 2);`
1478
- );
1479
- } else if (
1480
- info.module.buildMeta.exportsType === "flagged" ||
1481
- info.module.buildMeta.exportsType === "dynamic" ||
1482
- !info.module.buildMeta.exportsType
1483
- ) {
1484
- runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
1485
- result.add(
1486
- `\nvar ${info.interopNamespaceObjectName} = /*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${name});`
1487
- );
1488
- }
1525
+ runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
1526
+ result.add(
1527
+ `\nvar ${info.interopNamespaceObjectName} = /*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${name}, 2);`
1528
+ );
1529
+ }
1530
+ if (info.interopNamespaceObject2Used) {
1531
+ runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
1532
+ result.add(
1533
+ `\nvar ${info.interopNamespaceObject2Name} = /*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${name});`
1534
+ );
1489
1535
  }
1490
1536
  if (info.interopDefaultAccessUsed) {
1491
1537
  runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);
@@ -1634,6 +1680,8 @@ ${defineGetters}`
1634
1680
  namespaceObjectName: undefined,
1635
1681
  interopNamespaceObjectUsed: false,
1636
1682
  interopNamespaceObjectName: undefined,
1683
+ interopNamespaceObject2Used: false,
1684
+ interopNamespaceObject2Name: undefined,
1637
1685
  interopDefaultAccessUsed: false,
1638
1686
  interopDefaultAccessName: undefined
1639
1687
  };
@@ -1647,6 +1695,8 @@ ${defineGetters}`
1647
1695
  name: undefined,
1648
1696
  interopNamespaceObjectUsed: false,
1649
1697
  interopNamespaceObjectName: undefined,
1698
+ interopNamespaceObject2Used: false,
1699
+ interopNamespaceObject2Name: undefined,
1650
1700
  interopDefaultAccessUsed: false,
1651
1701
  interopDefaultAccessName: undefined
1652
1702
  };
@@ -232,16 +232,31 @@ class SideEffectsFlagPlugin {
232
232
  module
233
233
  )) {
234
234
  const dep = connection.dependency;
235
+ let isReexport;
235
236
  if (
236
- dep instanceof HarmonyExportImportedSpecifierDependency ||
237
+ (isReexport =
238
+ dep instanceof HarmonyExportImportedSpecifierDependency) ||
237
239
  (dep instanceof HarmonyImportSpecifierDependency &&
238
240
  !dep.namespaceObjectAsContext)
239
241
  ) {
242
+ // TODO improve for export *
243
+ if (isReexport && dep.name) {
244
+ const exportInfo = moduleGraph.getExportInfo(
245
+ connection.originModule,
246
+ dep.name
247
+ );
248
+ exportInfo.moveTarget(
249
+ moduleGraph,
250
+ ({ module }) =>
251
+ module.getSideEffectsConnectionState(moduleGraph) ===
252
+ false
253
+ );
254
+ }
240
255
  // TODO improve for nested imports
241
256
  const ids = dep.getIds(moduleGraph);
242
257
  if (ids.length > 0) {
243
258
  const exportInfo = exportsInfo.getExportInfo(ids[0]);
244
- const target = exportInfo.getTarget(
259
+ const target = exportInfo.moveTarget(
245
260
  moduleGraph,
246
261
  ({ module }) =>
247
262
  module.getSideEffectsConnectionState(moduleGraph) ===
@@ -23,25 +23,37 @@ class CreateFakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
23
23
  runtimeTemplate.supportsConst();
24
24
  const fn = RuntimeGlobals.createFakeNamespaceObject;
25
25
  return Template.asString([
26
+ `var getProto = Object.getPrototypeOf ? ${runtimeTemplate.returningFunction(
27
+ "Object.getPrototypeOf(obj)",
28
+ "obj"
29
+ )} : ${runtimeTemplate.returningFunction("obj.__proto__", "obj")};`,
30
+ "var leafPrototypes;",
26
31
  "// create a fake namespace object",
27
32
  "// mode & 1: value is a module id, require it",
28
33
  "// mode & 2: merge all properties of value into the ns",
29
34
  "// mode & 4: return value when already ns object",
35
+ "// mode & 16: return value when it's Promise-like",
30
36
  "// mode & 8|1: behave like require",
31
37
  // Note: must be a function (not arrow), because this is used in body!
32
38
  `${fn} = function(value, mode) {`,
33
39
  Template.indent([
34
40
  `if(mode & 1) value = this(value);`,
35
41
  `if(mode & 8) return value;`,
36
- "if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;",
42
+ "if(typeof value === 'object' && value) {",
43
+ Template.indent([
44
+ "if((mode & 4) && value.__esModule) return value;",
45
+ "if((mode & 16) && typeof value.then === 'function') return value;"
46
+ ]),
47
+ "}",
37
48
  "var ns = Object.create(null);",
38
49
  `${RuntimeGlobals.makeNamespaceObject}(ns);`,
39
50
  "var def = {};",
40
- "if(mode & 2 && typeof value == 'object' && value) {",
51
+ "leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)];",
52
+ "for(var current = mode & 2 && value; typeof current == 'object' && !~leafPrototypes.indexOf(current); current = getProto(current)) {",
41
53
  Template.indent([
42
54
  modern
43
- ? `for(const key in value) def[key] = () => value[key];`
44
- : `for(var key in value) def[key] = function(key) { return value[key]; }.bind(null, key);`
55
+ ? `Object.getOwnPropertyNames(current).forEach(key => def[key] = () => value[key]);`
56
+ : `Object.getOwnPropertyNames(current).forEach(function(key) { def[key] = function() { return value[key]; }; });`
45
57
  ]),
46
58
  "}",
47
59
  modern
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.3.2",
3
+ "version": "5.6.0",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "license": "MIT",
@@ -115,7 +115,9 @@
115
115
  },
116
116
  "homepage": "https://github.com/webpack/webpack",
117
117
  "main": "lib/index.js",
118
- "bin": "./bin/webpack.js",
118
+ "bin": {
119
+ "webpack": "bin/webpack.js"
120
+ },
119
121
  "types": "types.d.ts",
120
122
  "files": [
121
123
  "lib/",
package/types.d.ts CHANGED
@@ -214,6 +214,11 @@ declare interface AssetInfo {
214
214
  */
215
215
  immutable?: boolean;
216
216
 
217
+ /**
218
+ * whether the asset is minimized
219
+ */
220
+ minimized?: boolean;
221
+
217
222
  /**
218
223
  * the value(s) of the full hash used for this asset
219
224
  */
@@ -3025,6 +3030,14 @@ declare abstract class ExportInfo {
3025
3030
  export: string[];
3026
3031
  }) => boolean
3027
3032
  ): { module: Module; export: string[] };
3033
+
3034
+ /**
3035
+ * Move the target forward as long resolveTargetFilter is fulfilled
3036
+ */
3037
+ moveTarget(
3038
+ moduleGraph: ModuleGraph,
3039
+ resolveTargetFilter: (arg0: { module: Module; export: string[] }) => boolean
3040
+ ): { module: Module; export: string[] };
3028
3041
  createNestedExportsInfo(): ExportsInfo;
3029
3042
  getNestedExportsInfo(): ExportsInfo;
3030
3043
  updateHash(hash?: any, runtime?: any): void;
@@ -4320,6 +4333,7 @@ declare class JavascriptParser extends Parser {
4320
4333
  ): boolean;
4321
4334
  getComments(range?: any): any;
4322
4335
  isAsiPosition(pos: number): boolean;
4336
+ unsetAsiPosition(pos: number): void;
4323
4337
  isStatementLevelExpression(expr?: any): boolean;
4324
4338
  getTagData(name?: any, tag?: any): any;
4325
4339
  tagVariable(name?: any, tag?: any, data?: any): void;