fix missing react error with fragments in react-native (#60615)

This commit is contained in:
Isabel Duan 2024-11-26 13:24:44 -08:00 committed by GitHub
parent ee0e08bd96
commit 96410eb655
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 123 additions and 3 deletions

View File

@ -30018,7 +30018,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// #38720/60122, allow null as jsxFragmentFactory
let jsxFactorySym: Symbol | undefined;
if (!(isJsxOpeningFragment(node) && jsxFactoryNamespace === "null")) {
jsxFactorySym = resolveName(jsxFactoryLocation, jsxFactoryNamespace, compilerOptions.jsx === JsxEmit.Preserve ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value, jsxFactoryRefErr, /*isUse*/ true);
jsxFactorySym = resolveName(
jsxFactoryLocation,
jsxFactoryNamespace,
(compilerOptions.jsx === JsxEmit.Preserve || compilerOptions.jsx === JsxEmit.ReactNative) ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value,
jsxFactoryRefErr,
/*isUse*/ true,
);
}
if (jsxFactorySym) {
@ -30037,7 +30043,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const file = getSourceFileOfNode(node);
const localJsxNamespace = getLocalJsxNamespace(file);
if (localJsxNamespace) {
resolveName(jsxFactoryLocation, localJsxNamespace, compilerOptions.jsx === JsxEmit.Preserve ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value, jsxFactoryRefErr, /*isUse*/ true);
resolveName(
jsxFactoryLocation,
localJsxNamespace,
(compilerOptions.jsx === JsxEmit.Preserve || compilerOptions.jsx === JsxEmit.ReactNative) ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value,
jsxFactoryRefErr,
/*isUse*/ true,
);
}
}
}
@ -36825,7 +36837,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const jsxFactoryRefErr = diagnostics ? Diagnostics.Using_JSX_fragments_requires_fragment_factory_0_to_be_in_scope_but_it_could_not_be_found : undefined;
const jsxFactorySymbol = getJsxNamespaceContainerForImplicitImport(node) ??
resolveName(node, jsxFragmentFactoryName, compilerOptions.jsx === JsxEmit.Preserve ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value, /*nameNotFoundMessage*/ jsxFactoryRefErr, /*isUse*/ true);
resolveName(
node,
jsxFragmentFactoryName,
(compilerOptions.jsx === JsxEmit.Preserve || compilerOptions.jsx === JsxEmit.ReactNative) ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value,
/*nameNotFoundMessage*/ jsxFactoryRefErr,
/*isUse*/ true,
);
if (jsxFactorySymbol === undefined) return sourceFileLinks.jsxFragmentType = errorType;
if (jsxFactorySymbol.escapedName === ReactNames.Fragment) return sourceFileLinks.jsxFragmentType = getTypeOfSymbol(jsxFactorySymbol);

View File

@ -0,0 +1,18 @@
//// [tests/cases/compiler/jsxFragReactReferenceErrors.tsx] ////
//// [jsxFragReactReferenceErrors.tsx]
/// <reference path="/.lib/react18/react18.d.ts" />
/// <reference path="/.lib/react18/global.d.ts" />
export function Component(){
return <>
</>
}
//// [jsxFragReactReferenceErrors.jsx]
/// <reference path="react18/react18.d.ts" />
/// <reference path="react18/global.d.ts" />
export function Component() {
return <>
</>;
}

View File

@ -0,0 +1,11 @@
//// [tests/cases/compiler/jsxFragReactReferenceErrors.tsx] ////
=== jsxFragReactReferenceErrors.tsx ===
/// <reference path="react18/react18.d.ts" />
/// <reference path="react18/global.d.ts" />
export function Component(){
>Component : Symbol(Component, Decl(jsxFragReactReferenceErrors.tsx, 0, 0))
return <>
</>
}

View File

@ -0,0 +1,15 @@
//// [tests/cases/compiler/jsxFragReactReferenceErrors.tsx] ////
=== jsxFragReactReferenceErrors.tsx ===
/// <reference path="react18/react18.d.ts" />
/// <reference path="react18/global.d.ts" />
export function Component(){
>Component : () => JSX.Element
> : ^^^^^^^^^^^^^^^^^
return <>
><> </> : JSX.Element
> : ^^^^^^^^^^^
</>
}

View File

@ -0,0 +1,18 @@
//// [tests/cases/compiler/jsxFragReactReferenceErrors.tsx] ////
//// [jsxFragReactReferenceErrors.tsx]
/// <reference path="/.lib/react18/react18.d.ts" />
/// <reference path="/.lib/react18/global.d.ts" />
export function Component(){
return <>
</>
}
//// [jsxFragReactReferenceErrors.js]
/// <reference path="react18/react18.d.ts" />
/// <reference path="react18/global.d.ts" />
export function Component() {
return <>
</>;
}

View File

@ -0,0 +1,11 @@
//// [tests/cases/compiler/jsxFragReactReferenceErrors.tsx] ////
=== jsxFragReactReferenceErrors.tsx ===
/// <reference path="react18/react18.d.ts" />
/// <reference path="react18/global.d.ts" />
export function Component(){
>Component : Symbol(Component, Decl(jsxFragReactReferenceErrors.tsx, 0, 0))
return <>
</>
}

View File

@ -0,0 +1,15 @@
//// [tests/cases/compiler/jsxFragReactReferenceErrors.tsx] ////
=== jsxFragReactReferenceErrors.tsx ===
/// <reference path="react18/react18.d.ts" />
/// <reference path="react18/global.d.ts" />
export function Component(){
>Component : () => JSX.Element
> : ^^^^^^^^^^^^^^^^^
return <>
><> </> : JSX.Element
> : ^^^^^^^^^^^
</>
}

View File

@ -0,0 +1,14 @@
// @jsx: react-native, preserve
// @strict: true
// @skipLibCheck: true
// @target: ES2017
// @module: ESNext
// @esModuleInterop: true
/// <reference path="/.lib/react18/react18.d.ts" />
/// <reference path="/.lib/react18/global.d.ts" />
export function Component(){
return <>
</>
}