@rollup/plugin-commonjs 25.0.1 → 25.0.3

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/dist/cjs/index.js CHANGED
@@ -11,7 +11,7 @@ var estreeWalker = require('estree-walker');
11
11
  var MagicString = require('magic-string');
12
12
  var isReference = require('is-reference');
13
13
 
14
- var version = "25.0.1";
14
+ var version = "25.0.3";
15
15
  var peerDependencies = {
16
16
  rollup: "^2.68.0||^3.0.0"
17
17
  };
@@ -365,10 +365,7 @@ export function getAugmentedNamespace(n) {
365
365
  if (typeof f == "function") {
366
366
  var a = function a () {
367
367
  if (this instanceof a) {
368
- var args = [null];
369
- args.push.apply(args, arguments);
370
- var Ctor = Function.bind.apply(f, args);
371
- return new Ctor();
368
+ return Reflect.construct(f, arguments, this.constructor);
372
369
  }
373
370
  return f.apply(this, arguments);
374
371
  };
@@ -1497,6 +1494,7 @@ async function transformCommonjs(
1497
1494
  let scope = pluginutils.attachScopes(ast, 'scope');
1498
1495
  let lexicalDepth = 0;
1499
1496
  let programDepth = 0;
1497
+ let classBodyDepth = 0;
1500
1498
  let currentTryBlockEnd = null;
1501
1499
  let shouldWrap = false;
1502
1500
 
@@ -1679,6 +1677,9 @@ async function transformCommonjs(
1679
1677
  }
1680
1678
  return;
1681
1679
  }
1680
+ case 'ClassBody':
1681
+ classBodyDepth += 1;
1682
+ return;
1682
1683
  case 'ConditionalExpression':
1683
1684
  case 'IfStatement':
1684
1685
  // skip dead branches
@@ -1775,7 +1776,7 @@ async function transformCommonjs(
1775
1776
  return;
1776
1777
  case 'ThisExpression':
1777
1778
  // rewrite top-level `this` as `commonjsHelpers.commonjsGlobal`
1778
- if (lexicalDepth === 0) {
1779
+ if (lexicalDepth === 0 && !classBodyDepth) {
1779
1780
  uses.global = true;
1780
1781
  if (!ignoreGlobal) {
1781
1782
  replacedGlobal.push(node);
@@ -1826,6 +1827,7 @@ async function transformCommonjs(
1826
1827
  programDepth -= 1;
1827
1828
  if (node.scope) scope = scope.parent;
1828
1829
  if (functionType.test(node.type)) lexicalDepth -= 1;
1830
+ if (node.type === 'ClassBody') classBodyDepth -= 1;
1829
1831
  }
1830
1832
  });
1831
1833
 
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 = "25.0.1";
10
+ var version = "25.0.3";
11
11
  var peerDependencies = {
12
12
  rollup: "^2.68.0||^3.0.0"
13
13
  };
@@ -361,10 +361,7 @@ export function getAugmentedNamespace(n) {
361
361
  if (typeof f == "function") {
362
362
  var a = function a () {
363
363
  if (this instanceof a) {
364
- var args = [null];
365
- args.push.apply(args, arguments);
366
- var Ctor = Function.bind.apply(f, args);
367
- return new Ctor();
364
+ return Reflect.construct(f, arguments, this.constructor);
368
365
  }
369
366
  return f.apply(this, arguments);
370
367
  };
@@ -1493,6 +1490,7 @@ async function transformCommonjs(
1493
1490
  let scope = attachScopes(ast, 'scope');
1494
1491
  let lexicalDepth = 0;
1495
1492
  let programDepth = 0;
1493
+ let classBodyDepth = 0;
1496
1494
  let currentTryBlockEnd = null;
1497
1495
  let shouldWrap = false;
1498
1496
 
@@ -1675,6 +1673,9 @@ async function transformCommonjs(
1675
1673
  }
1676
1674
  return;
1677
1675
  }
1676
+ case 'ClassBody':
1677
+ classBodyDepth += 1;
1678
+ return;
1678
1679
  case 'ConditionalExpression':
1679
1680
  case 'IfStatement':
1680
1681
  // skip dead branches
@@ -1771,7 +1772,7 @@ async function transformCommonjs(
1771
1772
  return;
1772
1773
  case 'ThisExpression':
1773
1774
  // rewrite top-level `this` as `commonjsHelpers.commonjsGlobal`
1774
- if (lexicalDepth === 0) {
1775
+ if (lexicalDepth === 0 && !classBodyDepth) {
1775
1776
  uses.global = true;
1776
1777
  if (!ignoreGlobal) {
1777
1778
  replacedGlobal.push(node);
@@ -1822,6 +1823,7 @@ async function transformCommonjs(
1822
1823
  programDepth -= 1;
1823
1824
  if (node.scope) scope = scope.parent;
1824
1825
  if (functionType.test(node.type)) lexicalDepth -= 1;
1826
+ if (node.type === 'ClassBody') classBodyDepth -= 1;
1825
1827
  }
1826
1828
  });
1827
1829
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rollup/plugin-commonjs",
3
- "version": "25.0.1",
3
+ "version": "25.0.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },