Skip to content

Commit

Permalink
[utils] [fix] unambiguous detect modules exported from minified code
Browse files Browse the repository at this point in the history
This change adjusts the regex pattern used to detect modules to support detection on minified code.

Fixes #3107
  • Loading branch information
michaelfaith authored and ljharb committed Dec 16, 2024
1 parent f0727a6 commit 8b2d570
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/files/minified/no-newline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function y() {
console.log("y");
}export {y};
1 change: 1 addition & 0 deletions tests/files/minified/one-line-no-semi-renamed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function a(){console.log('foo')}export{a as foo};
1 change: 1 addition & 0 deletions tests/files/minified/one-line-no-semi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function a(){return true}export{a};
1 change: 1 addition & 0 deletions tests/files/minified/one-line.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function a(){console.log("foo")};export{a};
4 changes: 4 additions & 0 deletions tests/src/core/getExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ describe('ExportMap', function () {
['bar.js', true],
['deep-es7/b.js', true],
['common.js', false],
['./minified/no-newline.js', true],
['./minified/one-line-no-semi-renamed.js', true],
['./minified/one-line-no-semi.js', true],
['./minified/one-line.js', true],
];

for (const [testFile, expectedRegexResult] of testFiles) {
Expand Down
6 changes: 6 additions & 0 deletions utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

## Unreleased

### Fixed
- `unambiguous`: detect modules exported from minified code ([#3124], thanks [@michaelfaith])

### Changed
- [refactor] `parse`: avoid using a regex here (thanks [@ljharb])

Expand Down Expand Up @@ -180,6 +183,7 @@ Yanked due to critical issue with cache key resulting from #839.
### Fixed
- `unambiguous.test()` regex is now properly in multiline mode

[#3124]: https://github.com/import-js/eslint-plugin-import/pull/3124
[#3072]: https://github.com/import-js/eslint-plugin-import/pull/3072
[#3061]: https://github.com/import-js/eslint-plugin-import/pull/3061
[#3057]: https://github.com/import-js/eslint-plugin-import/pull/3057
Expand Down Expand Up @@ -230,6 +234,7 @@ Yanked due to critical issue with cache key resulting from #839.
[@JounQin]: https://github.com/JounQin
[@kaiyoma]: https://github.com/kaiyoma
[@leipert]: https://github.com/leipert
[@ljharb]: https://github.com/ljharb
[@manuth]: https://github.com/manuth
[@maxkomarychev]: https://github.com/maxkomarychev
[@mgwalker]: https://github.com/mgwalker
Expand All @@ -238,6 +243,7 @@ Yanked due to critical issue with cache key resulting from #839.
[@nicolo-ribaudo]: https://github.com/nicolo-ribaudo
[@pmcelhaney]: https://github.com/pmcelhaney
[@sergei-startsev]: https://github.com/sergei-startsev
[@silverwind]: https://github.com/silverwind
[@sompylasar]: https://github.com/sompylasar
[@timkraut]: https://github.com/timkraut
[@vikr01]: https://github.com/vikr01
Expand Down
2 changes: 1 addition & 1 deletion utils/unambiguous.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports.__esModule = true;

const pattern = /(^|;)\s*(export|import)((\s+\w)|(\s*[{*=]))|import\(/m;
const pattern = /(^|[;})])\s*(export|import)((\s+\w)|(\s*[{*=]))|import\(/m;
/**
* detect possible imports/exports without a full parse.
*
Expand Down

0 comments on commit 8b2d570

Please sign in to comment.