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'; 'use client'
import { use } from "react";
import { useState } from 'react' import { useState, use } from 'react';
export default function Page(props: { params: Promise<{ slug: string }> }) { export default function Page(props: { params: Promise<{ slug: string }> }) {
const params = use(props.params); const params = use(props.params);
......
'use client'; 'use client'
import { use } from "react";
import { useState } from 'react' import { useState, use } from 'react';
interface PageProps { interface PageProps {
params: Promise<{ slug: string }> params: Promise<{ slug: string }>
......
...@@ -182,22 +182,19 @@ export function insertReactUseImport(root: Collection<any>, j: API['j']) { ...@@ -182,22 +182,19 @@ export function insertReactUseImport(root: Collection<any>, j: API['j']) {
if (!hasReactUseImport) { if (!hasReactUseImport) {
const reactImportDeclaration = root.find(j.ImportDeclaration, { const reactImportDeclaration = root.find(j.ImportDeclaration, {
source: { source: {
type: 'Literal',
value: 'react', value: 'react',
}, },
}) })
if (reactImportDeclaration.size() > 0) { if (reactImportDeclaration.size() > 0) {
const importNode = reactImportDeclaration.get().node
// Add 'use' to existing 'react' import declaration // Add 'use' to existing 'react' import declaration
reactImportDeclaration importNode.specifiers.push(j.importSpecifier(j.identifier('use')))
.get()
.node.specifiers.push(j.importSpecifier(j.identifier('use')))
} else { } else {
// Final all type imports to 'react' // Final all type imports to 'react'
const reactImport = root.find(j.ImportDeclaration, { const reactImport = root.find(j.ImportDeclaration, {
source: { source: {
type: 'Literal',
value: 'react', 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