@rollup/plugin-commonjs 22.0.0-13 → 22.0.0-14
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.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/index.js +15 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.js +15 -6
- package/dist/es/index.js.map +1 -1
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { walk } from 'estree-walker';
|
|
|
7
7
|
import MagicString from 'magic-string';
|
|
8
8
|
import isReference from 'is-reference';
|
|
9
9
|
|
|
10
|
-
var version = "22.0.0-
|
|
10
|
+
var version = "22.0.0-14";
|
|
11
11
|
var peerDependencies = {
|
|
12
12
|
rollup: "^2.68.0"
|
|
13
13
|
};
|
|
@@ -1202,7 +1202,7 @@ function getRequireStringArg(node) {
|
|
|
1202
1202
|
function getRequireHandlers() {
|
|
1203
1203
|
const requireExpressions = [];
|
|
1204
1204
|
|
|
1205
|
-
function
|
|
1205
|
+
function addRequireExpression(
|
|
1206
1206
|
sourceId,
|
|
1207
1207
|
node,
|
|
1208
1208
|
scope,
|
|
@@ -1282,7 +1282,7 @@ function getRequireHandlers() {
|
|
|
1282
1282
|
}
|
|
1283
1283
|
|
|
1284
1284
|
return {
|
|
1285
|
-
|
|
1285
|
+
addRequireExpression,
|
|
1286
1286
|
rewriteRequireExpressionsAndGetImportBlock
|
|
1287
1287
|
};
|
|
1288
1288
|
}
|
|
@@ -1408,7 +1408,7 @@ async function transformCommonjs(
|
|
|
1408
1408
|
// unconditional require elsewhere.
|
|
1409
1409
|
let currentConditionalNodeEnd = null;
|
|
1410
1410
|
const conditionalNodes = new Set();
|
|
1411
|
-
const {
|
|
1411
|
+
const { addRequireExpression, rewriteRequireExpressionsAndGetImportBlock } = getRequireHandlers();
|
|
1412
1412
|
|
|
1413
1413
|
// See which names are assigned to. This is necessary to prevent
|
|
1414
1414
|
// illegally replacing `var foo = require('foo')` with `import foo from 'foo'`,
|
|
@@ -1563,14 +1563,22 @@ async function transformCommonjs(
|
|
|
1563
1563
|
const requireStringArg = getRequireStringArg(node);
|
|
1564
1564
|
if (!ignoreRequire(requireStringArg)) {
|
|
1565
1565
|
const usesReturnValue = parent.type !== 'ExpressionStatement';
|
|
1566
|
-
|
|
1566
|
+
const toBeRemoved =
|
|
1567
|
+
parent.type === 'ExpressionStatement' &&
|
|
1568
|
+
(!currentConditionalNodeEnd ||
|
|
1569
|
+
// We should completely remove requires directly in a try-catch
|
|
1570
|
+
// so that Rollup can remove up the try-catch
|
|
1571
|
+
(currentTryBlockEnd !== null && currentTryBlockEnd < currentConditionalNodeEnd))
|
|
1572
|
+
? parent
|
|
1573
|
+
: node;
|
|
1574
|
+
addRequireExpression(
|
|
1567
1575
|
requireStringArg,
|
|
1568
1576
|
node,
|
|
1569
1577
|
scope,
|
|
1570
1578
|
usesReturnValue,
|
|
1571
1579
|
currentTryBlockEnd !== null,
|
|
1572
1580
|
currentConditionalNodeEnd !== null,
|
|
1573
|
-
|
|
1581
|
+
toBeRemoved
|
|
1574
1582
|
);
|
|
1575
1583
|
if (parent.type === 'VariableDeclarator' && parent.id.type === 'Identifier') {
|
|
1576
1584
|
for (const name of extractAssignedNames(parent.id)) {
|
|
@@ -1772,6 +1780,7 @@ async function transformCommonjs(
|
|
|
1772
1780
|
!(
|
|
1773
1781
|
shouldWrap ||
|
|
1774
1782
|
isRequired ||
|
|
1783
|
+
needsRequireWrapper ||
|
|
1775
1784
|
uses.module ||
|
|
1776
1785
|
uses.exports ||
|
|
1777
1786
|
uses.require ||
|