Skip to content

Commit 9c02149

Browse files
committed
changesets
1 parent df034e7 commit 9c02149

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

.changeset/clever-feet-rest.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codeshift/initializer': patch
3+
---
4+
5+
Fixes test output template to ensure async methods are output

.changeset/green-mails-wink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codeshift/utils': minor
3+
---
4+
5+
Adds new node utils including `isNodeOfType` method

community/react/create-element-to-jsx/transform.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
1-
import { API, FileInfo, Options } from 'jscodeshift';
2-
import ReactUtils from '../utils/ReactUtils';
1+
import { API, FileInfo, Options, Collection } from 'jscodeshift';
2+
3+
const hasModule = (j: any, path: Collection, module: string) =>
4+
path
5+
.findVariableDeclarators()
6+
.filter(j.filters.VariableDeclarator.requiresModule(module))
7+
.size() === 1 ||
8+
path
9+
.find(j.ImportDeclaration, {
10+
type: 'ImportDeclaration',
11+
source: {
12+
type: 'Literal',
13+
},
14+
})
15+
// @ts-expect-error
16+
.filter(declarator => declarator.value.source.value === module)
17+
.size() === 1;
18+
19+
const hasReact = (j: any, path: Collection) =>
20+
hasModule(j, path, 'React') ||
21+
hasModule(j, path, 'react') ||
22+
hasModule(j, path, 'react/addons') ||
23+
hasModule(j, path, 'react-native');
324

425
export default function transformer(
526
file: FileInfo,
@@ -8,7 +29,6 @@ export default function transformer(
829
) {
930
const root = j(file.source);
1031
const printOptions = options.printOptions || {};
11-
const reactUtils = ReactUtils(j);
1232

1333
const encodeJSXTextValue = (value: string) =>
1434
value.replace(/</g, '&lt;').replace(/>/g, '&gt;');
@@ -234,7 +254,7 @@ export default function transformer(
234254
}
235255
};
236256

237-
if (options['explicit-require'] === false || reactUtils.hasReact(root)) {
257+
if (options['explicit-require'] === false || hasReact(j, root)) {
238258
const mutations = root
239259
.find(j.CallExpression, {
240260
callee: {

0 commit comments

Comments
 (0)