Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
);
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <>
</>;
}
Original file line number Diff line number Diff line change
@@ -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 <>
</>
}
Original file line number Diff line number Diff line change
@@ -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
> : ^^^^^^^^^^^

</>
}
Original file line number Diff line number Diff line change
@@ -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 <>
</>;
}
Original file line number Diff line number Diff line change
@@ -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 <>
</>
}
Original file line number Diff line number Diff line change
@@ -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
> : ^^^^^^^^^^^

</>
}
14 changes: 14 additions & 0 deletions tests/cases/compiler/jsxFragReactReferenceErrors.tsx
Original file line number Diff line number Diff line change
@@ -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 <>
</>
}