webpack 5.2.1 → 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.

@@ -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) return true;
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 (