webpack 5.3.2 → 5.4.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/lib/Module.js +4 -3
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/config/browserslistTargetHandler.js +175 -51
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +0 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +5 -1
- package/lib/javascript/JavascriptParser.js +51 -5
- package/lib/optimize/ConcatenatedModule.js +53 -29
- package/package.json +1 -1
- package/types.d.ts +1 -0
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-
|
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-
|
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-
|
469
|
+
return strict ? "default-with-named" : "dynamic";
|
469
470
|
}
|
470
471
|
}
|
471
472
|
|
@@ -124,7 +124,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
124
124
|
}
|
125
125
|
case "module":
|
126
126
|
throw new Error(
|
127
|
-
"EcmaScript Module
|
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
|
109
|
-
if (!
|
110
|
-
const [
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
-
|
122
|
-
const
|
123
|
-
|
124
|
-
|
125
|
-
|
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:
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
-
|
260
|
+
and_chr: 71,
|
140
261
|
edge: 79,
|
141
262
|
firefox: 65,
|
142
|
-
|
263
|
+
and_ff: 65,
|
143
264
|
// ie: Not supported,
|
144
|
-
nodejs: 12,
|
145
265
|
opera: 58,
|
146
|
-
|
266
|
+
op_mob: 50,
|
147
267
|
safari: [12, 1],
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
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,
|
@@ -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;
|
@@ -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(
|
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
|
-
|
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
|
-
|
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) return true;
|
3342
3378
|
return (
|
3343
|
-
currentStatement.range[
|
3344
|
-
|
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 {
|
@@ -1045,16 +1056,20 @@ class ConcatenatedModule extends Module {
|
|
1045
1056
|
// get all global names
|
1046
1057
|
for (const info of modulesWithInfo) {
|
1047
1058
|
if (info.type === "concatenated") {
|
1048
|
-
const superClassExpressions = [];
|
1049
|
-
|
1050
1059
|
// ignore symbols from moduleScope
|
1051
1060
|
if (info.moduleScope) {
|
1052
1061
|
ignoredScopes.add(info.moduleScope);
|
1062
|
+
}
|
1053
1063
|
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1064
|
+
// The super class expression in class scopes behaves weird
|
1065
|
+
// We get ranges of all super class expressions to make
|
1066
|
+
// renaming to work correctly
|
1067
|
+
const superClassCache = new WeakMap();
|
1068
|
+
const getSuperClassExpressions = scope => {
|
1069
|
+
const cacheEntry = superClassCache.get(scope);
|
1070
|
+
if (cacheEntry !== undefined) return cacheEntry;
|
1071
|
+
const superClassExpressions = [];
|
1072
|
+
for (const childScope of scope.childScopes) {
|
1058
1073
|
if (childScope.type !== "class") continue;
|
1059
1074
|
const block = childScope.block;
|
1060
1075
|
if (
|
@@ -1068,7 +1083,9 @@ class ConcatenatedModule extends Module {
|
|
1068
1083
|
});
|
1069
1084
|
}
|
1070
1085
|
}
|
1071
|
-
|
1086
|
+
superClassCache.set(scope, superClassExpressions);
|
1087
|
+
return superClassExpressions;
|
1088
|
+
};
|
1072
1089
|
|
1073
1090
|
// add global symbols
|
1074
1091
|
if (info.globalScope) {
|
@@ -1101,7 +1118,7 @@ class ConcatenatedModule extends Module {
|
|
1101
1118
|
binding.info.module.identifier(),
|
1102
1119
|
"name" in binding ? binding.name : ""
|
1103
1120
|
);
|
1104
|
-
for (const expr of
|
1121
|
+
for (const expr of getSuperClassExpressions(reference.from)) {
|
1105
1122
|
if (
|
1106
1123
|
expr.range[0] <= reference.identifier.range[0] &&
|
1107
1124
|
expr.range[1] >= reference.identifier.range[1]
|
@@ -1209,12 +1226,7 @@ class ConcatenatedModule extends Module {
|
|
1209
1226
|
break;
|
1210
1227
|
}
|
1211
1228
|
}
|
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
|
-
) {
|
1229
|
+
if (info.module.buildMeta.exportsType !== "namespace") {
|
1218
1230
|
const externalNameInterop = this.findNewName(
|
1219
1231
|
"namespaceObject",
|
1220
1232
|
allUsedNames,
|
@@ -1224,6 +1236,19 @@ class ConcatenatedModule extends Module {
|
|
1224
1236
|
allUsedNames.add(externalNameInterop);
|
1225
1237
|
info.interopNamespaceObjectName = externalNameInterop;
|
1226
1238
|
}
|
1239
|
+
if (
|
1240
|
+
info.module.buildMeta.exportsType === "default" &&
|
1241
|
+
info.module.buildMeta.defaultObject !== "redirect"
|
1242
|
+
) {
|
1243
|
+
const externalNameInterop = this.findNewName(
|
1244
|
+
"namespaceObject2",
|
1245
|
+
allUsedNames,
|
1246
|
+
namespaceObjectUsedNames,
|
1247
|
+
info.module.readableIdentifier(requestShortener)
|
1248
|
+
);
|
1249
|
+
allUsedNames.add(externalNameInterop);
|
1250
|
+
info.interopNamespaceObject2Name = externalNameInterop;
|
1251
|
+
}
|
1227
1252
|
if (
|
1228
1253
|
info.module.buildMeta.exportsType === "dynamic" ||
|
1229
1254
|
!info.module.buildMeta.exportsType
|
@@ -1471,21 +1496,16 @@ ${defineGetters}`
|
|
1471
1496
|
throw new Error(`Unsupported concatenation entry type ${info.type}`);
|
1472
1497
|
}
|
1473
1498
|
if (info.interopNamespaceObjectUsed) {
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
)
|
1484
|
-
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
1485
|
-
result.add(
|
1486
|
-
`\nvar ${info.interopNamespaceObjectName} = /*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${name});`
|
1487
|
-
);
|
1488
|
-
}
|
1499
|
+
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
1500
|
+
result.add(
|
1501
|
+
`\nvar ${info.interopNamespaceObjectName} = /*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${name}, 2);`
|
1502
|
+
);
|
1503
|
+
}
|
1504
|
+
if (info.interopNamespaceObject2Used) {
|
1505
|
+
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
1506
|
+
result.add(
|
1507
|
+
`\nvar ${info.interopNamespaceObject2Name} = /*#__PURE__*/${RuntimeGlobals.createFakeNamespaceObject}(${name});`
|
1508
|
+
);
|
1489
1509
|
}
|
1490
1510
|
if (info.interopDefaultAccessUsed) {
|
1491
1511
|
runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);
|
@@ -1634,6 +1654,8 @@ ${defineGetters}`
|
|
1634
1654
|
namespaceObjectName: undefined,
|
1635
1655
|
interopNamespaceObjectUsed: false,
|
1636
1656
|
interopNamespaceObjectName: undefined,
|
1657
|
+
interopNamespaceObject2Used: false,
|
1658
|
+
interopNamespaceObject2Name: undefined,
|
1637
1659
|
interopDefaultAccessUsed: false,
|
1638
1660
|
interopDefaultAccessName: undefined
|
1639
1661
|
};
|
@@ -1647,6 +1669,8 @@ ${defineGetters}`
|
|
1647
1669
|
name: undefined,
|
1648
1670
|
interopNamespaceObjectUsed: false,
|
1649
1671
|
interopNamespaceObjectName: undefined,
|
1672
|
+
interopNamespaceObject2Used: false,
|
1673
|
+
interopNamespaceObject2Name: undefined,
|
1650
1674
|
interopDefaultAccessUsed: false,
|
1651
1675
|
interopDefaultAccessName: undefined
|
1652
1676
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.4.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",
|
package/types.d.ts
CHANGED
@@ -4320,6 +4320,7 @@ declare class JavascriptParser extends Parser {
|
|
4320
4320
|
): boolean;
|
4321
4321
|
getComments(range?: any): any;
|
4322
4322
|
isAsiPosition(pos: number): boolean;
|
4323
|
+
unsetAsiPosition(pos: number): void;
|
4323
4324
|
isStatementLevelExpression(expr?: any): boolean;
|
4324
4325
|
getTagData(name?: any, tag?: any): any;
|
4325
4326
|
tagVariable(name?: any, tag?: any, data?: any): void;
|