webpack 5.21.1 → 5.21.2

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.

@@ -111,7 +111,9 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
111
111
  */
112
112
  getReferencedExports(moduleGraph, runtime) {
113
113
  let ids = this.getIds(moduleGraph);
114
- if (ids.length > 0 && ids[0] === "default") {
114
+ if (ids.length === 0) return Dependency.EXPORTS_OBJECT_REFERENCED;
115
+ let namespaceObjectAsContext = this.namespaceObjectAsContext;
116
+ if (ids[0] === "default") {
115
117
  const selfModule = moduleGraph.getParentModule(this);
116
118
  const importedModule = moduleGraph.getModule(this);
117
119
  switch (
@@ -124,13 +126,18 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
124
126
  case "default-with-named":
125
127
  if (ids.length === 1) return Dependency.EXPORTS_OBJECT_REFERENCED;
126
128
  ids = ids.slice(1);
129
+ namespaceObjectAsContext = true;
127
130
  break;
128
131
  case "dynamic":
129
132
  return Dependency.EXPORTS_OBJECT_REFERENCED;
130
133
  }
131
134
  }
132
135
 
133
- if (this.namespaceObjectAsContext) {
136
+ if (
137
+ this.call &&
138
+ !this.directImport &&
139
+ (namespaceObjectAsContext || ids.length > 1)
140
+ ) {
134
141
  if (ids.length === 1) return Dependency.EXPORTS_OBJECT_REFERENCED;
135
142
  ids = ids.slice(0, -1);
136
143
  }
@@ -38,14 +38,13 @@ const stringifySafe = data => {
38
38
  const createObjectForExportsInfo = (data, exportsInfo, runtime) => {
39
39
  if (exportsInfo.otherExportsInfo.getUsed(runtime) !== UsageState.Unused)
40
40
  return data;
41
- const reducedData = Array.isArray(data) ? [] : {};
42
- for (const exportInfo of exportsInfo.exports) {
43
- if (exportInfo.name in reducedData) return data;
44
- }
41
+ const isArray = Array.isArray(data);
42
+ const reducedData = isArray ? [] : {};
45
43
  for (const key of Object.keys(data)) {
46
44
  const exportInfo = exportsInfo.getReadOnlyExportInfo(key);
47
45
  const used = exportInfo.getUsed(runtime);
48
46
  if (used === UsageState.Unused) continue;
47
+
49
48
  let value;
50
49
  if (used === UsageState.OnlyPropertiesUsed && exportInfo.exportsInfo) {
51
50
  value = createObjectForExportsInfo(
@@ -59,7 +58,13 @@ const createObjectForExportsInfo = (data, exportsInfo, runtime) => {
59
58
  const name = exportInfo.getUsedName(key, runtime);
60
59
  reducedData[name] = value;
61
60
  }
62
- if (Array.isArray(reducedData)) {
61
+ if (isArray) {
62
+ let arrayLengthWhenUsed =
63
+ exportsInfo.getReadOnlyExportInfo("length").getUsed(runtime) !==
64
+ UsageState.Unused
65
+ ? data.length
66
+ : undefined;
67
+
63
68
  let sizeObjectMinusArray = 0;
64
69
  for (let i = 0; i < reducedData.length; i++) {
65
70
  if (reducedData[i] === undefined) {
@@ -68,8 +73,24 @@ const createObjectForExportsInfo = (data, exportsInfo, runtime) => {
68
73
  sizeObjectMinusArray += `${i}`.length + 3;
69
74
  }
70
75
  }
71
- if (sizeObjectMinusArray < 0) return Object.assign({}, reducedData);
72
- for (let i = 0; i < reducedData.length; i++) {
76
+ if (arrayLengthWhenUsed !== undefined) {
77
+ sizeObjectMinusArray +=
78
+ `${arrayLengthWhenUsed}`.length +
79
+ 8 -
80
+ (arrayLengthWhenUsed - reducedData.length) * 2;
81
+ }
82
+ if (sizeObjectMinusArray < 0)
83
+ return Object.assign(
84
+ arrayLengthWhenUsed === undefined
85
+ ? {}
86
+ : { length: arrayLengthWhenUsed },
87
+ reducedData
88
+ );
89
+ const generatedLength =
90
+ arrayLengthWhenUsed !== undefined
91
+ ? Math.max(arrayLengthWhenUsed, reducedData.length)
92
+ : reducedData.length;
93
+ for (let i = 0; i < generatedLength; i++) {
73
94
  if (reducedData[i] === undefined) {
74
95
  reducedData[i] = 0;
75
96
  }
@@ -208,12 +208,14 @@ class ObjectMiddleware extends SerializerMiddleware {
208
208
  }
209
209
 
210
210
  static getSerializerFor(object) {
211
- let c = object.constructor;
212
- if (!c) {
213
- if (Object.getPrototypeOf(object) === null) {
214
- // Object created with Object.create(null)
215
- c = null;
216
- } else {
211
+ const proto = Object.getPrototypeOf(object);
212
+ let c;
213
+ if (proto === null) {
214
+ // Object created with Object.create(null)
215
+ c = null;
216
+ } else {
217
+ c = proto.constructor;
218
+ if (!c) {
217
219
  throw new Error(
218
220
  "Serialization of objects with prototype without valid constructor property not possible"
219
221
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.21.1",
3
+ "version": "5.21.2",
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",