Skip to content

Commit

Permalink
codemod: fix merging react imports logic (#70706)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Oct 2, 2024
1 parent 3853a7f commit 39e06c7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client';
import { use } from "react";
'use client'

import { useState } from 'react'
import { useState, use } from 'react';

export default function Page(props: { params: Promise<{ slug: string }> }) {
const params = use(props.params);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client';
import { use } from "react";
'use client'

import { useState } from 'react'
import { useState, use } from 'react';

interface PageProps {
params: Promise<{ slug: string }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,19 @@ export function insertReactUseImport(root: Collection<any>, j: API['j']) {
if (!hasReactUseImport) {
const reactImportDeclaration = root.find(j.ImportDeclaration, {
source: {
type: 'Literal',
value: 'react',
},
})

if (reactImportDeclaration.size() > 0) {
const importNode = reactImportDeclaration.get().node

// Add 'use' to existing 'react' import declaration
reactImportDeclaration
.get()
.node.specifiers.push(j.importSpecifier(j.identifier('use')))
importNode.specifiers.push(j.importSpecifier(j.identifier('use')))
} else {
// Final all type imports to 'react'

const reactImport = root.find(j.ImportDeclaration, {
source: {
type: 'Literal',
value: 'react',
},
})
Expand Down

0 comments on commit 39e06c7

Please sign in to comment.