mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[patch] Repro and fix for duplicate import statements
This commit is contained in:
@@ -109,7 +109,12 @@ export function updateExistingReactImportDeclaration(
|
||||
let didInsertUseMemoCache = false;
|
||||
program.traverse({
|
||||
ImportDeclaration(importDeclPath) {
|
||||
if (isNonNamespacedImportOfReact(importDeclPath)) {
|
||||
if (
|
||||
!didInsertUseMemoCache &&
|
||||
importDeclPath.node.importKind !== "type" &&
|
||||
importDeclPath.node.importKind !== "typeof" &&
|
||||
isNonNamespacedImportOfReact(importDeclPath)
|
||||
) {
|
||||
importDeclPath.pushContainer(
|
||||
"specifiers",
|
||||
t.importSpecifier(
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import type { SetStateAction, Dispatch } from "react";
|
||||
import { useState } from "react";
|
||||
|
||||
function Component(_props: {}) {
|
||||
const [x, _setX]: [number, Dispatch<SetStateAction<number>>] = useState(0);
|
||||
return { x };
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import type { SetStateAction, Dispatch } from "react";
|
||||
import { useState, unstable_useMemoCache as useMemoCache } from "react";
|
||||
|
||||
function Component(_props) {
|
||||
const $ = useMemoCache(2);
|
||||
const [x] = useState(0);
|
||||
const c_0 = $[0] !== x;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { x };
|
||||
$[0] = x;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import type { SetStateAction, Dispatch } from "react";
|
||||
import { useState } from "react";
|
||||
|
||||
function Component(_props: {}) {
|
||||
const [x, _setX]: [number, Dispatch<SetStateAction<number>>] = useState(0);
|
||||
return { x };
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
Reference in New Issue
Block a user