Skip to content
Closed
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 @@ -171,6 +171,21 @@ function transformCode(
return result?.code ?? null;
}

function transformCodeWithSourceOptimization(
code: string,
options: {[string]: unknown},
): string | null {
const config = preset.getPreset(code, options);
const result = babel.transformSync(code, {
...config,
babelrc: false,
configFile: false,
filename: MOCK_FILENAME,
sourceMaps: false,
});
return result?.code ?? null;
}

function getSnapshotPath(configName: string): string {
return path.join(OUTPUT_DIR, `${configName}.js`);
}
Expand Down Expand Up @@ -267,6 +282,16 @@ describe('react-native-babel-preset transform snapshots', () => {
);

describe('specific feature transformations', () => {
it('adds display names when React.createClass contains trivia', () => {
const code = `
const Component = React /* comment */ . createClass({
render() { return null; }
});
`;
const result = transformCodeWithSourceOptimization(code, {dev: false});
expect(result).toContain('displayName:"Component"');
});

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 @@ -190,7 +190,7 @@ const getPreset = (src, options, babel) => {
}
if (
isNull ||
src.indexOf('React.createClass') !== -1 ||
src.indexOf('createClass') !== -1 ||
src.indexOf('createReactClass') !== -1
) {
extraPlugins.push([require('@babel/plugin-transform-react-display-name')]);
Expand Down
Loading