Skip to content

Commit

Permalink
Merge branch 'rollup:master' into fix/1691
Browse files Browse the repository at this point in the history
  • Loading branch information
younggglcy authored May 27, 2024
2 parents 641b68f + 0090e72 commit 308f24f
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@
"lib/client*.js",
"test/"
]
}
},
"packageManager": "[email protected]+sha512.d1a029e1a447ad90bc96cd58b0fad486d2993d531856396f7babf2d83eb1823bb83c5a3d0fc18f675b2d10321d49eb161fece36fe8134aa5823ecd215feed392"
}
8 changes: 8 additions & 0 deletions packages/commonjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @rollup/plugin-commonjs ChangeLog

## v25.0.8

_2024-05-22_

### Bugfixes

- fix: preserve the class body property keys even if they are special keywords (#1688)

## v25.0.7

_2023-10-15_
Expand Down
2 changes: 1 addition & 1 deletion packages/commonjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-commonjs",
"version": "25.0.7",
"version": "25.0.8",
"publishConfig": {
"access": "public"
},
Expand Down
7 changes: 6 additions & 1 deletion packages/commonjs/src/transform-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,12 @@ export default async function transformCommonjs(
return;
case 'Identifier': {
const { name } = node;
if (!isReference(node, parent) || scope.contains(name)) return;
if (
!isReference(node, parent) ||
scope.contains(name) ||
(parent.type === 'PropertyDefinition' && parent.key === node)
)
return;
switch (name) {
case 'require':
uses.require = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
description: 'preserve the class body property keys even if they are special keywords',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Rollup {
define;
require;
global;
}

exports.Rollup = Rollup;
24 changes: 24 additions & 0 deletions packages/commonjs/test/snapshots/function.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,30 @@ Generated by [AVA](https://avajs.dev).
`,
}

## class-body-property-keys-are-special-keywords

> Snapshot 1
{
'main.js': `'use strict';␊
␊
Object.defineProperty(exports, '__esModule', { value: true });␊
␊
var main = {};␊
␊
class Rollup {␊
define;␊
require;␊
global;␊
}␊
␊
var Rollup_1 = main.Rollup = Rollup;␊
␊
exports.Rollup = Rollup_1;␊
exports.default = main;␊
`,
}

## compiled-esm-default-is-module-exports-false

> Snapshot 1
Expand Down
Binary file modified packages/commonjs/test/snapshots/function.js.snap
Binary file not shown.
8 changes: 8 additions & 0 deletions packages/esm-shim/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @rollup/plugin-esm-shim ChangeLog

## v0.1.6

_2024-04-05_

### Bugfixes

- fix: do not insert shims at `import` literal (#1696)

## v0.1.5

_2023-11-05_
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-shim/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-esm-shim",
"version": "0.1.5",
"version": "0.1.6",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-shim/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ const require = cjsModule.createRequire(import.meta.url);
`;

export const ESMStaticImportRegex =
/(?<=\s|^|;)import\s*([\s"']*(?<imports>[\w\t\n\r $*,/{}]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gm;
/(?<=\s|^|;)import\s*([\s"']*(?<imports>[\w\t\n\r $*,/{}]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"\n]*[^\s"](?=\s*")|(?<='\s*)[^'\n]*[^\s'](?=\s*'))\s*["'][\s;]*/gm;
6 changes: 6 additions & 0 deletions packages/esm-shim/test/fixtures/cjs-import-literal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const dn = __dirname;

module.exports = {
keyword: ' import',
dn
};
20 changes: 20 additions & 0 deletions packages/esm-shim/test/snapshots/test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,23 @@ Generated by [AVA](https://avajs.dev).
␊
export { c, child, s };␊
`

## inject cjs shim should not break on valid js object with `import` literal value

> Snapshot 1
`␊
// -- Shims --␊
import cjsUrl from 'node:url';␊
import cjsPath from 'node:path';␊
import cjsModule from 'node:module';␊
const __filename = cjsUrl.fileURLToPath(import.meta.url);␊
const __dirname = cjsPath.dirname(__filename);␊
const require = cjsModule.createRequire(import.meta.url);␊
const dn = __dirname;␊
␊
module.exports = {␊
keyword: ' import',␊
dn␊
};␊
`
Binary file modified packages/esm-shim/test/snapshots/test.js.snap
Binary file not shown.
16 changes: 16 additions & 0 deletions packages/esm-shim/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,19 @@ test.serial('inject cjs shim for esm output with multiple import statements', as
t.snapshot(output.code);
t.falsy(output.map);
});

// see issue #1649 https://github.com/rollup/plugins/issues/1649
test.serial(
'inject cjs shim should not break on valid js object with `import` literal value',
async (t) => {
const bundle = await rollup({
input: 'test/fixtures/cjs-import-literal.js',
plugins: [esmShim()]
});
const result = await bundle.generate({ format: 'es' });
t.is(result.output.length, 1);
const [output] = result.output;
t.snapshot(output.code);
t.falsy(output.map);
}
);

0 comments on commit 308f24f

Please sign in to comment.