Skip to content

Commit 32ce95c

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Move transforms to build-types (facebook#50982)
Summary: Pull Request resolved: facebook#50982 Changelog: [Internal] Reviewed By: huntie Differential Revision: D73667539 fbshipit-source-id: dc9ab6f3efef17f8ffd58a854363b39a31ec59d7
1 parent 77c1eb6 commit 32ce95c

16 files changed

+119
-4
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
* @oncall react_native
10+
*/
11+
12+
const removeReactNativeImports = require('../removeReactNativeImports.js');
13+
const babel = require('@babel/core');
14+
15+
async function translate(code: string): Promise<string> {
16+
const result = await babel.transformAsync(code, {
17+
plugins: ['@babel/plugin-syntax-typescript', removeReactNativeImports],
18+
});
19+
20+
return result.code;
21+
}
22+
23+
describe('removeReactNativeImports', () => {
24+
test('should remove import and remove suffix', async () => {
25+
const code = `
26+
import {View as View_2} from 'react-native';
27+
const Foo = View_2;
28+
export default Foo;
29+
`;
30+
const result = await translate(code);
31+
expect(result).toMatchInlineSnapshot(`
32+
"const Foo = View;
33+
export default Foo;"
34+
`);
35+
});
36+
37+
test('should remove import and decrease suffix', async () => {
38+
const code = `
39+
import {View as View_3} from 'react-native';
40+
const Foo = View_3;
41+
export default Foo;
42+
`;
43+
const result = await translate(code);
44+
expect(result).toMatchInlineSnapshot(`
45+
"const Foo = View_2;
46+
export default Foo;"
47+
`);
48+
});
49+
});

0 commit comments

Comments
 (0)