Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,33 @@ describe('react-native-babel-preset transform snapshots', () => {
);

describe('specific feature transformations', () => {
it('runs codegen when the type arguments are separated by trivia', () => {
const code = `
// @flow strict-local
import type {ViewProps} from 'react-native';
import type {HostComponent} from 'react-native';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

type NativeProps = Readonly<{
...ViewProps,
}>;

export default codegenNativeComponent /* comment */ <NativeProps>(
'View',
) as HostComponent<NativeProps>;
`;
const config = preset.getPreset(code, {});
const result = babel.transformSync(code, {
...config,
babelrc: false,
configFile: false,
filename: MOCK_FILENAME,
sourceMaps: false,
});

expect(result?.code).toContain('__INTERNAL_VIEW_CONFIG');
});

it('handles async generators', () => {
const code = `
async function* gen() {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-babel-preset/src/configs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const getPreset = (src, options, babel) => {

if (
!options.disableStaticViewConfigsCodegen &&
(src === null || /\bcodegenNativeComponent</.test(src))
(isNull || src.indexOf('codegenNativeComponent') !== -1)
) {
extraPlugins.push([require('@react-native/babel-plugin-codegen')]);
}
Expand Down
Loading