Unverified Commit 39e06c75 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

codemod: fix merging react imports logic (#70706)

parent 3853a7ff
'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);
......
'use client';
import { use } from "react";
'use client'
import { useState } from 'react'
import { useState, use } from 'react';
interface PageProps {
params: Promise<{ slug: string }>
......
......@@ -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',
},
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment