Skip to content

Commit e98927b

Browse files
committedSep 23, 2024Β·
chore(commonjs): revert #1618
1 parent 5e977e2 commit e98927b

File tree

5 files changed

+8
-22
lines changed

5 files changed

+8
-22
lines changed
 

β€Žpackages/commonjs/CHANGELOG.md

-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
# @rollup/plugin-commonjs ChangeLog
22

3-
## v26.0.2
4-
5-
_2024-09-23_
6-
7-
### Bugfixes
8-
9-
- fix: replace top-level this with exports name (#1618)
10-
113
## v26.0.1
124

135
_2024-06-05_

β€Žpackages/commonjs/src/transform-commonjs.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ export default async function transformCommonjs(
102102
const topLevelAssignments = new Set();
103103
const topLevelDefineCompiledEsmExpressions = [];
104104
const replacedGlobal = [];
105-
const replacedThis = [];
106105
const replacedDynamicRequires = [];
107106
const importedVariables = new Set();
108107
const indentExclusionRanges = [];
@@ -370,7 +369,7 @@ export default async function transformCommonjs(
370369
if (lexicalDepth === 0 && !classBodyDepth) {
371370
uses.global = true;
372371
if (!ignoreGlobal) {
373-
replacedThis.push(node);
372+
replacedGlobal.push(node);
374373
}
375374
}
376375
return;
@@ -445,11 +444,6 @@ export default async function transformCommonjs(
445444
storeName: true
446445
});
447446
}
448-
for (const node of replacedThis) {
449-
magicString.overwrite(node.start, node.end, exportsName, {
450-
storeName: true
451-
});
452-
}
453447
for (const node of replacedDynamicRequires) {
454448
magicString.overwrite(
455449
node.start,

β€Žpackages/commonjs/test/fixtures/function/this/main.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
const { augmentThis, classThis, y } = require('./foo');
1+
const { augmentThis, classThis } = require('./foo');
22

33
const obj = {};
44
augmentThis.call(obj);
55

66
t.is(obj.x, 'x');
7-
t.is(this.y, undefined);
8-
t.is(y, 'y');
7+
t.is(this.y, 'y');
98

109
const instance = new classThis();
1110

β€Žpackages/commonjs/test/snapshots/function.js.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -7286,6 +7286,8 @@ Generated by [AVA](https://avajs.dev).
72867286
{
72877287
'main.js': `'use strict';␊
72887288
␊
7289+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊
7290+
␊
72897291
var main = {};␊
72907292
␊
72917293
var foo = {};␊
@@ -7294,7 +7296,7 @@ Generated by [AVA](https://avajs.dev).
72947296
this.x = 'x';␊
72957297
};␊
72967298
␊
7297-
foo.y = 'y';␊
7299+
commonjsGlobal.y = 'y';␊
72987300
␊
72997301
foo.classThis = class classThis {␊
73007302
constructor(){␊
@@ -7308,14 +7310,13 @@ Generated by [AVA](https://avajs.dev).
73087310
yy = this.y␊
73097311
};␊
73107312
␊
7311-
const { augmentThis, classThis, y } = foo;␊
7313+
const { augmentThis, classThis } = foo;␊
73127314
␊
73137315
const obj = {};␊
73147316
augmentThis.call(obj);␊
73157317
␊
73167318
t.is(obj.x, 'x');␊
7317-
t.is(main.y, undefined);␊
7318-
t.is(y, 'y');␊
7319+
t.is(commonjsGlobal.y, 'y');␊
73197320
␊
73207321
const instance = new classThis();␊
73217322
␊
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.