Skip to content

Commit 8b2d570

Browse files
michaelfaithljharb
authored andcommitted
[utils] [fix] unambiguous detect modules exported from minified code
This change adjusts the regex pattern used to detect modules to support detection on minified code. Fixes import-js#3107
1 parent f0727a6 commit 8b2d570

File tree

7 files changed

+17
-1
lines changed

7 files changed

+17
-1
lines changed

tests/files/minified/no-newline.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function y() {
2+
console.log("y");
3+
}export {y};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function a(){console.log('foo')}export{a as foo};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function a(){return true}export{a};

tests/files/minified/one-line.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function a(){console.log("foo")};export{a};

tests/src/core/getExports.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ describe('ExportMap', function () {
465465
['bar.js', true],
466466
['deep-es7/b.js', true],
467467
['common.js', false],
468+
['./minified/no-newline.js', true],
469+
['./minified/one-line-no-semi-renamed.js', true],
470+
['./minified/one-line-no-semi.js', true],
471+
['./minified/one-line.js', true],
468472
];
469473

470474
for (const [testFile, expectedRegexResult] of testFiles) {

utils/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
55

66
## Unreleased
77

8+
### Fixed
9+
- `unambiguous`: detect modules exported from minified code ([#3124], thanks [@michaelfaith])
10+
811
### Changed
912
- [refactor] `parse`: avoid using a regex here (thanks [@ljharb])
1013

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

186+
[#3124]: https://github.com/import-js/eslint-plugin-import/pull/3124
183187
[#3072]: https://github.com/import-js/eslint-plugin-import/pull/3072
184188
[#3061]: https://github.com/import-js/eslint-plugin-import/pull/3061
185189
[#3057]: https://github.com/import-js/eslint-plugin-import/pull/3057
@@ -230,6 +234,7 @@ Yanked due to critical issue with cache key resulting from #839.
230234
[@JounQin]: https://github.com/JounQin
231235
[@kaiyoma]: https://github.com/kaiyoma
232236
[@leipert]: https://github.com/leipert
237+
[@ljharb]: https://github.com/ljharb
233238
[@manuth]: https://github.com/manuth
234239
[@maxkomarychev]: https://github.com/maxkomarychev
235240
[@mgwalker]: https://github.com/mgwalker
@@ -238,6 +243,7 @@ Yanked due to critical issue with cache key resulting from #839.
238243
[@nicolo-ribaudo]: https://github.com/nicolo-ribaudo
239244
[@pmcelhaney]: https://github.com/pmcelhaney
240245
[@sergei-startsev]: https://github.com/sergei-startsev
246+
[@silverwind]: https://github.com/silverwind
241247
[@sompylasar]: https://github.com/sompylasar
242248
[@timkraut]: https://github.com/timkraut
243249
[@vikr01]: https://github.com/vikr01

utils/unambiguous.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports.__esModule = true;
44

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

0 commit comments

Comments
 (0)