Skip to content

Commit 514fa30

Browse files
andrewdacenkofacebook-github-bot
authored andcommitted
Use RegExp instead of micromatch (facebook#52234)
Summary: Pull Request resolved: facebook#52234 Changelog: [Internal] Use raw regex instead of micromatch as it depends on node imports. Differential Revision: D77241819
1 parent 30ab428 commit 514fa30

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

private/react-native-fantom/src/__tests__/Fantom-itest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ describe('Fantom', () => {
475475
expect(
476476
root
477477
.getRenderedOutput({
478-
props: ['!width'],
478+
props: ['^(?!width$).*$'],
479479
})
480480
.toJSX(),
481481
).toEqual(<rn-view height="100.000000" />);

private/react-native-fantom/src/getFantomRenderedOutput.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
import type {RootTag} from 'react-native';
1212

13-
// $FlowExpectedError[untyped-import]
14-
import micromatch from 'micromatch';
1513
import * as React from 'react';
1614
import NativeFantom from 'react-native/src/private/testing/fantom/specs/NativeFantom';
1715

@@ -30,8 +28,7 @@ type FantomJsonObject = {
3028
type FantomJson = FantomJsonObject | $ReadOnlyArray<FantomJsonObject>;
3129

3230
type FantomRenderedOutputConfig = {
33-
// micromatch pattern to match prop names
34-
// see usage examples in https://github.com/micromatch/micromatch#examples
31+
// RegExp patterns to match prop names
3532
props?: $ReadOnlyArray<string>,
3633
};
3734

@@ -88,17 +85,20 @@ class FantomRenderedOutput {
8885
props: FantomJsonObject['props'],
8986
config: FantomRenderedOutputConfig,
9087
): FantomJsonObject['props'] {
91-
if (config.props == null) {
88+
const patterns = config.props;
89+
if (patterns == null) {
9290
return {...props};
9391
}
9492

95-
return micromatch(Object.keys(props), config.props ?? []).reduce(
96-
(acc, name) => {
97-
acc[name] = props[name];
98-
return acc;
99-
},
100-
{},
101-
);
93+
return Object.keys(props)
94+
.filter(key => patterns.some(pattern => new RegExp(pattern).test(key)))
95+
.reduce(
96+
(acc, name) => {
97+
acc[name] = props[name];
98+
return acc;
99+
},
100+
{} as FantomJsonObject['props'],
101+
);
102102
}
103103
}
104104

0 commit comments

Comments
 (0)