Skip to content

Commit ffbc88c

Browse files
committed
Format files
1 parent 72f4911 commit ffbc88c

File tree

2 files changed

+44
-50
lines changed

2 files changed

+44
-50
lines changed

src/__tests__/rehype-static-to-dynamic.test.ts

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,7 @@ describe('rehype-static-to-dynamic', () => {
10681068
assert.strictEqual(output, expected);
10691069
});
10701070

1071-
test(
1072-
'navigator with `.with(...)` merges screenOptions and screenListeners from plain objects',
1073-
async () => {
1071+
test('navigator with `.with(...)` merges screenOptions and screenListeners from plain objects', async () => {
10741072
const input = dedent /* javascript */ `
10751073
import { useWindowDimensions } from 'react-native';
10761074
import { createDrawerNavigator } from '@react-navigation/drawer';
@@ -1155,14 +1153,11 @@ describe('rehype-static-to-dynamic', () => {
11551153
}
11561154
`;
11571155

1158-
assert.strictEqual(output, expected);
1159-
}
1160-
);
1156+
assert.strictEqual(output, expected);
1157+
});
11611158

1162-
test(
1163-
'navigator with `.with(...)` merges static objects with wrapper functions',
1164-
async () => {
1165-
const input = dedent /* javascript */ `
1159+
test('navigator with `.with(...)` merges static objects with wrapper functions', async () => {
1160+
const input = dedent /* javascript */ `
11661161
import { createDrawerNavigator } from '@react-navigation/drawer';
11671162
import { createStaticNavigation } from '@react-navigation/native';
11681163
@@ -1196,13 +1191,13 @@ describe('rehype-static-to-dynamic', () => {
11961191
}
11971192
`;
11981193

1199-
const tree = createTestTree(input);
1200-
const plugin = rehypeStaticToDynamic();
1201-
await plugin(tree);
1194+
const tree = createTestTree(input);
1195+
const plugin = rehypeStaticToDynamic();
1196+
await plugin(tree);
12021197

1203-
const output = extractTransformedCode(tree);
1198+
const output = extractTransformedCode(tree);
12041199

1205-
const expected = dedent /* javascript */ `
1200+
const expected = dedent /* javascript */ `
12061201
import { createDrawerNavigator } from '@react-navigation/drawer';
12071202
import { NavigationContainer } from '@react-navigation/native';
12081203
@@ -1234,14 +1229,11 @@ describe('rehype-static-to-dynamic', () => {
12341229
}
12351230
`;
12361231

1237-
assert.strictEqual(output, expected);
1238-
}
1239-
);
1232+
assert.strictEqual(output, expected);
1233+
});
12401234

1241-
test(
1242-
'navigator with `.with(...)` merges static functions with wrapper objects',
1243-
async () => {
1244-
const input = dedent /* javascript */ `
1235+
test('navigator with `.with(...)` merges static functions with wrapper objects', async () => {
1236+
const input = dedent /* javascript */ `
12451237
import { createDrawerNavigator } from '@react-navigation/drawer';
12461238
import { createStaticNavigation } from '@react-navigation/native';
12471239
@@ -1275,13 +1267,13 @@ describe('rehype-static-to-dynamic', () => {
12751267
}
12761268
`;
12771269

1278-
const tree = createTestTree(input);
1279-
const plugin = rehypeStaticToDynamic();
1280-
await plugin(tree);
1270+
const tree = createTestTree(input);
1271+
const plugin = rehypeStaticToDynamic();
1272+
await plugin(tree);
12811273

1282-
const output = extractTransformedCode(tree);
1274+
const output = extractTransformedCode(tree);
12831275

1284-
const expected = dedent /* javascript */ `
1276+
const expected = dedent /* javascript */ `
12851277
import { createDrawerNavigator } from '@react-navigation/drawer';
12861278
import { NavigationContainer } from '@react-navigation/native';
12871279
@@ -1313,14 +1305,11 @@ describe('rehype-static-to-dynamic', () => {
13131305
}
13141306
`;
13151307

1316-
assert.strictEqual(output, expected);
1317-
}
1318-
);
1308+
assert.strictEqual(output, expected);
1309+
});
13191310

1320-
test(
1321-
'navigator with `.with(...)` merges screenOptions and screenListeners when both are functions',
1322-
async () => {
1323-
const input = dedent /* javascript */ `
1311+
test('navigator with `.with(...)` merges screenOptions and screenListeners when both are functions', async () => {
1312+
const input = dedent /* javascript */ `
13241313
import { createDrawerNavigator } from '@react-navigation/drawer';
13251314
import { createStaticNavigation } from '@react-navigation/native';
13261315
@@ -1354,13 +1343,13 @@ describe('rehype-static-to-dynamic', () => {
13541343
}
13551344
`;
13561345

1357-
const tree = createTestTree(input);
1358-
const plugin = rehypeStaticToDynamic();
1359-
await plugin(tree);
1346+
const tree = createTestTree(input);
1347+
const plugin = rehypeStaticToDynamic();
1348+
await plugin(tree);
13601349

1361-
const output = extractTransformedCode(tree);
1350+
const output = extractTransformedCode(tree);
13621351

1363-
const expected = dedent /* javascript */ `
1352+
const expected = dedent /* javascript */ `
13641353
import { createDrawerNavigator } from '@react-navigation/drawer';
13651354
import { NavigationContainer } from '@react-navigation/native';
13661355
@@ -1392,9 +1381,8 @@ describe('rehype-static-to-dynamic', () => {
13921381
}
13931382
`;
13941383

1395-
assert.strictEqual(output, expected);
1396-
}
1397-
);
1384+
assert.strictEqual(output, expected);
1385+
});
13981386

13991387
test('drawer navigator', async () => {
14001388
const input = dedent /* javascript */ `

src/plugins/rehype-static-to-dynamic.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,11 @@ export async function convertStaticToDynamic(code: string): Promise<string> {
432432
}
433433

434434
const navigatorVariable = declarator.id.name; // e.g., "MyStack"
435-
const { type: navigatorType, config, withCallback } =
436-
navigatorCallInfo;
435+
const {
436+
type: navigatorType,
437+
config,
438+
withCallback,
439+
} = navigatorCallInfo;
437440

438441
navigatorInfos.push({
439442
originalName: navigatorVariable,
@@ -1388,10 +1391,7 @@ function createJsxAttributeFromPropValue(key: string, value: t.Expression) {
13881391
return t.jsxAttribute(t.jsxIdentifier(key), t.stringLiteral(value.value));
13891392
}
13901393

1391-
return t.jsxAttribute(
1392-
t.jsxIdentifier(key),
1393-
t.jsxExpressionContainer(value)
1394-
);
1394+
return t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(value));
13951395
}
13961396

13971397
function getJsxAttributeName(
@@ -1692,7 +1692,9 @@ function createFallbackMergedFunctionExpression(
16921692
[argIdentifier],
16931693
t.objectExpression([
16941694
t.spreadElement(createSpreadSourceExpression(staticValue, argIdentifier)),
1695-
t.spreadElement(createSpreadSourceExpression(dynamicValue, argIdentifier)),
1695+
t.spreadElement(
1696+
createSpreadSourceExpression(dynamicValue, argIdentifier)
1697+
),
16961698
])
16971699
);
16981700
}
@@ -1733,7 +1735,11 @@ function createMergedNavigatorPropExpression(
17331735
const params = getMergedFunctionParams(staticValue, dynamicValue);
17341736

17351737
if (staticObject && dynamicObject && params) {
1736-
return createMergedFunctionExpression(params, staticObject, dynamicObject);
1738+
return createMergedFunctionExpression(
1739+
params,
1740+
staticObject,
1741+
dynamicObject
1742+
);
17371743
}
17381744

17391745
return createFallbackMergedFunctionExpression(staticValue, dynamicValue);

0 commit comments

Comments
 (0)