From 44f224a35578531060b42011c9446869cbc03759 Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Fri, 15 Apr 2022 12:43:39 +0100 Subject: [PATCH 1/2] chore(jest-haste-map): Remove legacy `isRegExpSupported` --- .../lib/__tests__/dependencyExtractor.test.js | 27 +++++++++---------- .../lib/__tests__/isRegExpSupported.test.js | 18 ------------- .../src/lib/dependencyExtractor.ts | 6 +---- .../src/lib/isRegExpSupported.ts | 16 ----------- 4 files changed, 13 insertions(+), 54 deletions(-) delete mode 100644 packages/jest-haste-map/src/lib/__tests__/isRegExpSupported.test.js delete mode 100644 packages/jest-haste-map/src/lib/isRegExpSupported.ts diff --git a/packages/jest-haste-map/src/lib/__tests__/dependencyExtractor.test.js b/packages/jest-haste-map/src/lib/__tests__/dependencyExtractor.test.js index f2b142dfc675..84f42db86d28 100644 --- a/packages/jest-haste-map/src/lib/__tests__/dependencyExtractor.test.js +++ b/packages/jest-haste-map/src/lib/__tests__/dependencyExtractor.test.js @@ -6,9 +6,6 @@ */ import {extractor} from '../dependencyExtractor'; -import isRegExpSupported from '../isRegExpSupported'; - -const COMMENT_NO_NEG_LB = isRegExpSupported('(? { it('should not extract dependencies inside comments', () => { @@ -65,8 +62,8 @@ describe('dependencyExtractor', () => { }, depDefault from 'dep4'; // Bad - ${COMMENT_NO_NEG_LB} foo . import ('inv1'); - ${COMMENT_NO_NEG_LB} foo . export ('inv2'); + foo . import ('inv1'); + foo . export ('inv2'); `; expect(extractor.extract(code)).toEqual( new Set(['dep1', 'dep2', 'dep3', 'dep4']), @@ -114,8 +111,8 @@ describe('dependencyExtractor', () => { }, depDefault from 'dep4'; // Bad - ${COMMENT_NO_NEG_LB} foo . export ('inv1'); - ${COMMENT_NO_NEG_LB} foo . export ('inv2'); + foo . export ('inv1'); + foo . export ('inv2'); `; expect(extractor.extract(code)).toEqual( new Set(['dep1', 'dep2', 'dep3', 'dep4']), @@ -137,8 +134,8 @@ describe('dependencyExtractor', () => { }, depDefault from 'dep4'; // Bad - ${COMMENT_NO_NEG_LB} foo . export ('inv1'); - ${COMMENT_NO_NEG_LB} foo . export ('inv2'); + foo . export ('inv1'); + foo . export ('inv2'); `; expect(extractor.extract(code)).toEqual( new Set(['dep1', 'dep2', 'dep3', 'dep4']), @@ -164,7 +161,7 @@ describe('dependencyExtractor', () => { if (await import(\`dep3\`)) {} // Bad - ${COMMENT_NO_NEG_LB} await foo . import('inv1') + await foo . import('inv1') await ximport('inv2'); importx('inv3'); import('inv4', 'inv5'); @@ -182,7 +179,7 @@ describe('dependencyExtractor', () => { if (require(\`dep3\`).cond) {} // Bad - ${COMMENT_NO_NEG_LB} foo . require('inv1') + foo . require('inv1') xrequire('inv2'); requirex('inv3'); require('inv4', 'inv5'); @@ -202,7 +199,7 @@ describe('dependencyExtractor', () => { .requireActual('dep4'); // Bad - ${COMMENT_NO_NEG_LB} foo . jest.requireActual('inv1') + foo . jest.requireActual('inv1') xjest.requireActual('inv2'); jest.requireActualx('inv3'); jest.requireActual('inv4', 'inv5'); @@ -224,7 +221,7 @@ describe('dependencyExtractor', () => { .requireMock('dep4'); // Bad - ${COMMENT_NO_NEG_LB} foo . jest.requireMock('inv1') + foo . jest.requireMock('inv1') xjest.requireMock('inv2'); jest.requireMockx('inv3'); jest.requireMock('inv4', 'inv5'); @@ -246,7 +243,7 @@ describe('dependencyExtractor', () => { .requireMock('dep4'); // Bad - ${COMMENT_NO_NEG_LB} foo . jest.genMockFromModule('inv1') + foo . jest.genMockFromModule('inv1') xjest.genMockFromModule('inv2'); jest.genMockFromModulex('inv3'); jest.genMockFromModule('inv4', 'inv5'); @@ -268,7 +265,7 @@ describe('dependencyExtractor', () => { .requireMock('dep4'); // Bad - ${COMMENT_NO_NEG_LB} foo . jest.createMockFromModule('inv1') + foo . jest.createMockFromModule('inv1') xjest.createMockFromModule('inv2'); jest.createMockFromModulex('inv3'); jest.createMockFromModule('inv4', 'inv5'); diff --git a/packages/jest-haste-map/src/lib/__tests__/isRegExpSupported.test.js b/packages/jest-haste-map/src/lib/__tests__/isRegExpSupported.test.js deleted file mode 100644 index b27295eaa320..000000000000 --- a/packages/jest-haste-map/src/lib/__tests__/isRegExpSupported.test.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -import isRegExpSupported from '../isRegExpSupported'; - -describe('isRegExpSupported', () => { - it('should return true when passing valid regular expression', () => { - expect(isRegExpSupported('(?:foo|bar)')).toBe(true); - }); - - it('should return false when passing an invalid regular expression', () => { - expect(isRegExpSupported('(?_foo|bar)')).toBe(false); - }); -}); diff --git a/packages/jest-haste-map/src/lib/dependencyExtractor.ts b/packages/jest-haste-map/src/lib/dependencyExtractor.ts index 8a54303346dd..73dcf0db0e30 100644 --- a/packages/jest-haste-map/src/lib/dependencyExtractor.ts +++ b/packages/jest-haste-map/src/lib/dependencyExtractor.ts @@ -6,12 +6,8 @@ */ import type {DependencyExtractor} from '../types'; -import isRegExpSupported from './isRegExpSupported'; -// Negative look behind is only supported in Node 9+ -const NOT_A_DOT = isRegExpSupported('(? `([\`'"])([^'"\`]*?)(?:\\${pos})`; const WORD_SEPARATOR = '\\b'; diff --git a/packages/jest-haste-map/src/lib/isRegExpSupported.ts b/packages/jest-haste-map/src/lib/isRegExpSupported.ts deleted file mode 100644 index b8db382928f3..000000000000 --- a/packages/jest-haste-map/src/lib/isRegExpSupported.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -export default function isRegExpSupported(value: string): boolean { - try { - // eslint-disable-next-line no-new - new RegExp(value); - return true; - } catch { - return false; - } -} From d62e5a435539fff6b737b70310077be418586b5a Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Fri, 15 Apr 2022 16:43:23 +0100 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20361f200741..a99f215c5391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -105,6 +105,7 @@ - `[@jest/core]` Use `index.ts` instead of `jest.ts` as main export ([#12329](https://github.com/facebook/jest/pull/12329)) - `[jest-environment-jsdom]` [**BREAKING**] Migrate to ESM ([#12340](https://github.com/facebook/jest/pull/12340)) - `[jest-environment-node]` [**BREAKING**] Migrate to ESM ([#12340](https://github.com/facebook/jest/pull/12340)) +- `[jest-haste-map]` Remove legacy `isRegExpSupported` ([#12676](https://github.com/facebook/jest/pull/12676)) - `[@jest/fake-timers]` Update `@sinonjs/fake_timers` to v9 ([#12357](https://github.com/facebook/jest/pull/12357)) - `[jest-jasmine2, jest-runtime]` [**BREAKING**] Use `Symbol` to pass `jest.setTimeout` value instead of `jasmine` specific logic ([#12124](https://github.com/facebook/jest/pull/12124)) - `[jest-phabricator]` [**BREAKING**] Migrate to ESM ([#12341](https://github.com/facebook/jest/pull/12341))