Skip to content

Commit

Permalink
Do not transform the class property keys
Browse files Browse the repository at this point in the history
  • Loading branch information
TrickyPi committed Mar 6, 2024
1 parent c7002c3 commit 44c5137
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
15 changes: 7 additions & 8 deletions packages/commonjs/src/transform-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,16 @@ export default async function transformCommonjs(
return;
case 'Identifier': {
const { name } = node;
if (!isReference(node, parent) || scope.contains(name)) return;
const isClassBodyPropertyKey =
parent.type === 'PropertyDefinition' && parent.key === node;
if (
!isReference(node, parent) ||
scope.contains(name) ||
(parent.type === 'PropertyDefinition' && parent.key === node)
)
return;
switch (name) {
case 'require':
uses.require = true;
if (isNodeRequirePropertyAccess(parent) || isClassBodyPropertyKey) {
if (isNodeRequirePropertyAccess(parent)) {
return;
}
if (!ignoreDynamicRequires) {
Expand All @@ -318,14 +321,10 @@ export default async function transformCommonjs(
case 'global':
uses.global = true;
if (!ignoreGlobal) {
if (isClassBodyPropertyKey && !parent.value) {
magicString.prependLeft(node.start, 'global = ');
}
replacedGlobal.push(node);
}
return;
case 'define':
if (isClassBodyPropertyKey) return;
magicString.overwrite(node.start, node.end, 'undefined', {
storeName: true
});
Expand Down
4 changes: 1 addition & 3 deletions packages/commonjs/test/snapshots/function.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,12 @@ Generated by [AVA](https://avajs.dev).
␊
Object.defineProperty(exports, '__esModule', { value: true });␊
␊
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊
␊
var main = {};␊
␊
class Rollup {␊
define;␊
require;␊
global = commonjsGlobal;␊
global;␊
}␊
␊
var Rollup_1 = main.Rollup = Rollup;␊
Expand Down
Binary file modified packages/commonjs/test/snapshots/function.js.snap
Binary file not shown.

0 comments on commit 44c5137

Please sign in to comment.