Skip to content

Commit

Permalink
chore(commonjs): revert #1618
Browse files Browse the repository at this point in the history
  • Loading branch information
shellscape committed Sep 23, 2024
1 parent 5e977e2 commit e98927b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 22 deletions.
8 changes: 0 additions & 8 deletions packages/commonjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# @rollup/plugin-commonjs ChangeLog

## v26.0.2

_2024-09-23_

### Bugfixes

- fix: replace top-level this with exports name (#1618)

## v26.0.1

_2024-06-05_
Expand Down
8 changes: 1 addition & 7 deletions packages/commonjs/src/transform-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export default async function transformCommonjs(
const topLevelAssignments = new Set();
const topLevelDefineCompiledEsmExpressions = [];
const replacedGlobal = [];
const replacedThis = [];
const replacedDynamicRequires = [];
const importedVariables = new Set();
const indentExclusionRanges = [];
Expand Down Expand Up @@ -370,7 +369,7 @@ export default async function transformCommonjs(
if (lexicalDepth === 0 && !classBodyDepth) {
uses.global = true;
if (!ignoreGlobal) {
replacedThis.push(node);
replacedGlobal.push(node);
}
}
return;
Expand Down Expand Up @@ -445,11 +444,6 @@ export default async function transformCommonjs(
storeName: true
});
}
for (const node of replacedThis) {
magicString.overwrite(node.start, node.end, exportsName, {
storeName: true
});
}
for (const node of replacedDynamicRequires) {
magicString.overwrite(
node.start,
Expand Down
5 changes: 2 additions & 3 deletions packages/commonjs/test/fixtures/function/this/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const { augmentThis, classThis, y } = require('./foo');
const { augmentThis, classThis } = require('./foo');

const obj = {};
augmentThis.call(obj);

t.is(obj.x, 'x');
t.is(this.y, undefined);
t.is(y, 'y');
t.is(this.y, 'y');

const instance = new classThis();

Expand Down
9 changes: 5 additions & 4 deletions packages/commonjs/test/snapshots/function.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -7286,6 +7286,8 @@ Generated by [AVA](https://avajs.dev).
{
'main.js': `'use strict';␊
␊
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊
␊
var main = {};␊
␊
var foo = {};␊
Expand All @@ -7294,7 +7296,7 @@ Generated by [AVA](https://avajs.dev).
this.x = 'x';␊
};␊
␊
foo.y = 'y';␊
commonjsGlobal.y = 'y';␊
␊
foo.classThis = class classThis {␊
constructor(){␊
Expand All @@ -7308,14 +7310,13 @@ Generated by [AVA](https://avajs.dev).
yy = this.y␊
};␊
␊
const { augmentThis, classThis, y } = foo;␊
const { augmentThis, classThis } = foo;␊
␊
const obj = {};␊
augmentThis.call(obj);␊
␊
t.is(obj.x, 'x');␊
t.is(main.y, undefined);␊
t.is(y, 'y');␊
t.is(commonjsGlobal.y, 'y');␊
␊
const instance = new classThis();␊
␊
Expand Down
Binary file modified packages/commonjs/test/snapshots/function.js.snap
Binary file not shown.

0 comments on commit e98927b

Please sign in to comment.